From ad5b639b3d0bed8f4cf7cca5e628924ef5f2e3f1 Mon Sep 17 00:00:00 2001 From: stoney Date: Mon, 21 Jul 2025 00:33:55 +0400 Subject: [PATCH 01/62] feat(main): basic setup. user can draw nodes and edges --- src/main.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index a8b928e..853e3a6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,44 @@ +#include "board.h" #include +#include "raylib.h" int main() { - std::cout << "HELLO WORLD\n"; + int monitor = GetCurrentMonitor(); + InitWindow(1200, 800, "Graph Visualizer"); + SetWindowMinSize(1200, 800); + SetTargetFPS(60); + + Board board; + Vector2 selectedNode = {-1, -1}; + + while (!WindowShouldClose()) { + Vector2 mouse = GetMousePosition(); + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { + board.addNode(mouse); + } + + if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) { + Vector2 nodePosition = board.isInNodeDomain(mouse); + if (nodePosition.x != 0.0f && nodePosition.y != 0.0f) { + if (selectedNode.x == -1) { + selectedNode.x = nodePosition.x; + selectedNode.y = nodePosition.y; + std::cout << "Node 1 was chosen successfully\n"; + } else { + std::cout << "Added the edge between Node 1 and Node2\n"; + board.addEdge(selectedNode, nodePosition); + selectedNode = {-1, -1}; + } + } + } + + BeginDrawing(); + ClearBackground(WHITE); + board.drawNodes(); + board.drawEdges(); + + EndDrawing(); + } + + CloseWindow(); } From 0bd06e8dfe96b7e0d845d2957f627e719eb5cac0 Mon Sep 17 00:00:00 2001 From: stoney Date: Mon, 21 Jul 2025 01:19:19 +0400 Subject: [PATCH 02/62] feat(sidebar): Working prototype --- CMakeLists.txt | 1 + src/sidebar.cpp | 31 +++++++++++++++++++++++++++++++ src/sidebar.h | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 src/sidebar.cpp create mode 100644 src/sidebar.h diff --git a/CMakeLists.txt b/CMakeLists.txt index fae0810..aa82104 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ set(SOURCES src/test.cpp src/board.cpp src/node.cpp + src/sidebar.cpp ) add_executable(${PROJECT_NAME} ${SOURCES}) diff --git a/src/sidebar.cpp b/src/sidebar.cpp new file mode 100644 index 0000000..3682efa --- /dev/null +++ b/src/sidebar.cpp @@ -0,0 +1,31 @@ +#include "raylib.h" +#include "sidebar.h" +#include +#include + +const float margin = 10.0f; + +Sidebar::Sidebar(int screenHeight) : + x(0), + width(250), + height(screenHeight) +{ + float buttonHeight = 60.0f; + float yOffset = margin; + std::vector labels = {"Run", "Pause", "Stop", "DFS", "BFS", "Dijkstra", "Bellman-Ford"}; + + for (const auto& label : labels) { + buttons.emplace_back(Rectangle{(float)x + margin, yOffset, (float)width - 2 * margin, (float)buttonHeight}, label); + yOffset += (buttonHeight + margin); + } +} + +void Sidebar::draw() { + DrawRectangle(x, 0, width, height, GRAY); + + for (const auto& button : buttons) { + DrawRectangleRec(button.domain, LIGHTGRAY); + DrawRectangleLinesEx(button.domain, 2, DARKGRAY); + DrawText(button.label.c_str(), button.domain.x + margin, button.domain.y + margin, 18, BLACK); + } +} diff --git a/src/sidebar.h b/src/sidebar.h new file mode 100644 index 0000000..01d610c --- /dev/null +++ b/src/sidebar.h @@ -0,0 +1,41 @@ +#ifndef SIDEBAR_H +#define SIDEBAR_H + +#include "raylib.h" +#include +#include + + +struct Button { + Rectangle domain; + std::string label; + bool clicked; + + Button(Rectangle rect, const std::string& str) + : domain(rect), label(str), clicked(false) {} +}; + + +class Sidebar { +private: + int x; + int width; + int height; + + std::vector