Skip to content

Commit 2f589f1

Browse files
committed
Improve UI styling
- Make UI buttons and headers looks nicer - Allow maps width and height to be controllable - Fix some bugs
1 parent c9a723f commit 2f589f1

File tree

23 files changed

+487
-278
lines changed

23 files changed

+487
-278
lines changed

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,10 @@
44

55
A tool for visualizing numerous pathfinding algorithms in two dimensions.
66

7-
This project involves minimal implementations of the popular planning algorithms, including both graph-based and sampling-based planners. We provide an easy-to-use GUI to control the animation process and explore different planner configurations. This is an ongoing work and current implementation of the project only involves four search-based planning algorithms: BFS, DFS, DIJKSTRA and A-Star and two sampling-based planners: RRT and RRT*. The project extensively uses SFML, ImGui and Modern C++ features such as smart pointers, lamda expressions along with multi-threading concepts.
7+
This project involves minimal implementations of the popular planning algorithms, including both graph-based and sampling-based planners. We provide an easy-to-use GUI to control the animation process and explore different planner configurations. Current implementation of the project involves four search-based planning algorithms: BFS, DFS, DIJKSTRA and A-Star and two sampling-based planners: RRT and RRT*. The project extensively uses SFML, ImGui and Modern C++ features such as smart pointers, lamda expressions along with multi-threading concepts.
88

99
![](figures/img0.png)
1010

11-
## How to use
12-
13-
- to place/remove obstacle cells (`left-CLICKED`)
14-
- to change starting cell (`left-SHIFT + left-CLICKED`)
15-
- to change end cell (`left-CTRL + left-CLICKED`)
16-
1711
## Dependencies
1812

1913
* cmake >= 3.14

figures/img0.png

168 KB
Loading

include/Game.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class Game {
3636
void update();
3737
void render();
3838
void initGuiTheme();
39-
void renderMenuBar(ImGuiIO& io);
39+
void renderNewPlannerMenu();
40+
void renderRunMenu(ImGuiIO& io);
4041
void setGraphBasedPlanner(const int id);
4142
void setSamplingBasedPlanner(const int id);
4243
void showHowToUseWindow();
@@ -52,10 +53,13 @@ class Game {
5253
float dt_;
5354
std::stack<std::unique_ptr<State>> states_;
5455
std::string curr_planner_;
55-
std::shared_ptr<LoggerPanel> logger_panel_;
56+
std::shared_ptr<gui::LoggerPanel> logger_panel_;
5657
bool disable_run_;
57-
bool show_how_to_use_window_{false};
58-
bool show_about_window_{false};
58+
bool show_how_to_use_window_{true};
59+
bool show_about_window_{true};
60+
bool show_control_panel_{true};
61+
bool show_console_{true};
62+
bool show_stats_panel_{true};
5963
};
6064

6165
} // namespace path_finding_visualizer

include/LoggerPanel.h renamed to include/Gui.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <imgui.h>
55

66
namespace path_finding_visualizer {
7+
namespace gui {
78

89
class LoggerPanel {
910
public:
@@ -73,4 +74,61 @@ class LoggerPanel {
7374
}
7475
};
7576

77+
// Helper to display a little (?) mark which shows a tooltip when hovered.
78+
// In your own code you may want to display an actual icon if you are using a
79+
// merged icon fonts (see docs/FONTS.md)
80+
inline void HelpMarker(const char* desc) {
81+
ImGui::TextDisabled("(?)");
82+
if (ImGui::IsItemHovered()) {
83+
ImGui::BeginTooltip();
84+
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
85+
ImGui::TextUnformatted(desc);
86+
ImGui::PopTextWrapPos();
87+
ImGui::EndTooltip();
88+
}
89+
}
90+
91+
inline bool inputInt(const std::string& label, int* val, const int& min_val,
92+
const int& max_val, const int& step = 1,
93+
const int& step_fast = 100,
94+
const std::string& help_marker = "",
95+
ImGuiInputTextFlags flags = 0) {
96+
flags |= ImGuiInputTextFlags_EnterReturnsTrue;
97+
bool is_active = ImGui::InputInt(label.c_str(), val, step, step_fast, flags);
98+
if (!help_marker.empty()) {
99+
ImGui::SameLine();
100+
HelpMarker(help_marker.c_str());
101+
}
102+
if (is_active) {
103+
if (*val < min_val)
104+
*val = min_val;
105+
else if (*val > max_val)
106+
*val = max_val;
107+
}
108+
return is_active;
109+
}
110+
111+
inline bool inputDouble(const std::string& label, double* val,
112+
const double& min_val, const double& max_val,
113+
const double& step = 0.0, const double& step_fast = 0.0,
114+
const std::string& help_marker = "",
115+
const char* format = "%.6f",
116+
ImGuiInputTextFlags flags = 0) {
117+
flags |= ImGuiInputTextFlags_EnterReturnsTrue;
118+
bool is_active =
119+
ImGui::InputDouble(label.c_str(), val, step, step_fast, format, flags);
120+
if (!help_marker.empty()) {
121+
ImGui::SameLine();
122+
HelpMarker(help_marker.c_str());
123+
}
124+
if (is_active) {
125+
if (*val < min_val)
126+
*val = min_val;
127+
else if (*val > max_val)
128+
*val = max_val;
129+
}
130+
return is_active;
131+
}
132+
133+
} // namespace gui
76134
} // namespace path_finding_visualizer

include/State.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <string>
1212
#include <vector>
1313

14-
#include "LoggerPanel.h"
14+
#include "Gui.h"
1515

1616
/*
1717
State Base Class
@@ -22,14 +22,14 @@ namespace path_finding_visualizer {
2222
class State {
2323
private:
2424
protected:
25-
std::shared_ptr<LoggerPanel> logger_panel_;
25+
std::shared_ptr<gui::LoggerPanel> logger_panel_;
2626
sf::Vector2f mousePositionWindow_;
2727
bool is_reset_;
2828
bool is_running_;
2929

3030
public:
3131
// Constructor
32-
State(std::shared_ptr<LoggerPanel> logger_panel);
32+
State(std::shared_ptr<gui::LoggerPanel> logger_panel);
3333

3434
// Destructor
3535
virtual ~State();

include/States/Algorithms/GraphBased/ASTAR/ASTAR.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct MinimumDistanceASTAR {
2121
class ASTAR : public BFS {
2222
public:
2323
// Constructor
24-
ASTAR(std::shared_ptr<LoggerPanel> logger_panel);
24+
ASTAR(std::shared_ptr<gui::LoggerPanel> logger_panel);
2525

2626
// Destructor
2727
virtual ~ASTAR();

include/States/Algorithms/GraphBased/BFS/BFS.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace graph_based {
1111
class BFS : public GraphBased {
1212
public:
1313
// Constructor
14-
BFS(std::shared_ptr<LoggerPanel> logger_panel);
14+
BFS(std::shared_ptr<gui::LoggerPanel> logger_panel);
1515

1616
// Destructor
1717
virtual ~BFS();

include/States/Algorithms/GraphBased/DFS/DFS.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace graph_based {
1010
class DFS : public BFS {
1111
public:
1212
// Constructor
13-
DFS(std::shared_ptr<LoggerPanel> logger_panel);
13+
DFS(std::shared_ptr<gui::LoggerPanel> logger_panel);
1414

1515
// Destructor
1616
virtual ~DFS();

include/States/Algorithms/GraphBased/DIJKSTRA/DIJKSTRA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct MinimumDistanceDIJKSTRA {
2121
class DIJKSTRA : public BFS {
2222
public:
2323
// Constructor
24-
DIJKSTRA(std::shared_ptr<LoggerPanel> logger_panel);
24+
DIJKSTRA(std::shared_ptr<gui::LoggerPanel> logger_panel);
2525

2626
// Destructor
2727
virtual ~DIJKSTRA();

include/States/Algorithms/GraphBased/GraphBased.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <queue>
1111
#include <vector>
1212

13-
#include "LoggerPanel.h"
13+
#include "Gui.h"
1414
#include "MessageQueue.h"
1515
#include "State.h"
1616
#include "States/Algorithms/GraphBased/Node.h"
@@ -22,7 +22,7 @@ namespace graph_based {
2222
class GraphBased : public State {
2323
public:
2424
// Constructor
25-
GraphBased(std::shared_ptr<LoggerPanel> logger_panel);
25+
GraphBased(std::shared_ptr<gui::LoggerPanel> logger_panel);
2626

2727
// Destructor
2828
virtual ~GraphBased();
@@ -55,6 +55,7 @@ class GraphBased : public State {
5555
// initialization Functions
5656
void initColors();
5757
void initVariables();
58+
void initGridMapParams();
5859
void initNodes(bool reset = true, bool reset_neighbours_only = false);
5960

6061
// colors
@@ -68,13 +69,13 @@ class GraphBased : public State {
6869
// Map Variables
6970
int no_of_grid_rows_;
7071
int no_of_grid_cols_;
71-
int gridSize_;
72-
int slider_grid_size_;
72+
int grid_size_;
73+
int ui_grid_size_;
7374
sf::Vector2f init_grid_xy_;
7475
// 0 = 4 connected grid, 1 = 8 connected grid
7576
int grid_connectivity_;
76-
unsigned int mapWidth_;
77-
unsigned int mapHeight_;
77+
unsigned int map_width_;
78+
unsigned int map_height_;
7879

7980
// Algorithm related
8081
std::string algo_name_;

0 commit comments

Comments
 (0)