-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphDisplay.h
More file actions
82 lines (67 loc) · 2.29 KB
/
GraphDisplay.h
File metadata and controls
82 lines (67 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef GRAPH_DRAWING_GRAPHDISPLAY_H
#define GRAPH_DRAWING_GRAPHDISPLAY_H
#include <vector>
#include <iostream>
#include <SFML/Graphics.hpp>
#include "graph.h"
#include <unordered_map>
const sf::Color VertexColor(65, 94, 206);
const sf::Color SelectedVertexColor(181, 55, 55);
const sf::Color veryLightGray(210, 210, 210);
const sf::Color backgroundColor = sf::Color::White;
class Graph;
struct pair_hash {
template <class T1, class T2>
std::size_t operator () (const std::pair<T1,T2> &p) const {
auto h1 = std::hash<T1>{}(p.first);
auto h2 = std::hash<T2>{}(p.second);
return h1 ^ h2;
}
};
class GraphDisplay {
private:
sf::RenderWindow window;
const int windowWidth;
const int windowHeight;
std::vector<sf::CircleShape> verticesDisplay;
std::vector<sf::Text> idDisplay;
std::unordered_map<std::pair<int, int>, sf::RectangleShape, pair_hash> edgesDisplay;
std::unordered_map<std::pair<int, int>, sf::Text, pair_hash> weightsDisplay;
std::vector<sf::RectangleShape> buttons;
std::vector<sf::Text> buttonLabels;
std::vector<std::function<void()>> buttonFunctions;
sf::RectangleShape bar;
sf::Text errorText;
sf::Font font;
int idFontSize;
int weightFontSize;
sf::Event event;
std::vector<int> selected;
int draggingIndex;
float vertexRadius;
float edgeThickness;
bool isWeightDisplayed;
bool isIdDisplayed;
Graph * graph;
void setUpWeight(sf::Text *weight, const sf::Vector2f& startPoint, const sf::Vector2f& endPoint);
void calculateEdgePosition(sf::RectangleShape* line, const sf::Vector2f& startPoint, const sf::Vector2f& endPoint, float distance) const;
void initializeDisplay();
void dragVertexHandler(sf::Vector2f offset);
void clearSelection();
void addSelection(int i);
void setUpID(int i);
void setUpVertices(int i);
void windowDraw();
void addButton(const sf::Vector2f& size, const sf::Vector2f& position, const std::function<void()>& function, const std::string& label);
void showBFS();
void resetAll();
void showShortestPath();
void showKruskal();
void drawGraphSpecifics();
void firstFrames();
public:
explicit GraphDisplay(Graph *graph);
~GraphDisplay();
void draw();
};
#endif //GRAPH_DRAWING_GRAPHDISPLAY_H