Skip to content

Commit 95a92c3

Browse files
committed
added a change of color in the node for easier visualization of LCA and other tree algorithms
1 parent 507b7cc commit 95a92c3

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

Assets/red-circle.png

6.07 KB
Loading

includes/event_handler_class.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,28 @@ void event_handler::select_algorithms(const sf::Event &event, sf::RenderWindow &
6262
window.clear();
6363
clear_vectors();
6464
call_erdos_rentyi();
65-
display_random_graph(window);
65+
display_graph(window);
6666
update_text_position();
6767
}
6868
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Num4) || sf::Keyboard::isKeyPressed(sf::Keyboard::Numpad4)){
6969
window.clear();
7070
clear_vectors();
7171
call_erdos_rentyi(true);
72-
display_random_graph(window);
72+
display_graph(window);
7373
update_text_position();
7474
}
7575
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Num5) || sf::Keyboard::isKeyPressed(sf::Keyboard::Numpad5)){
7676
window.clear();
7777
clear_vectors();
7878
call_random_tree();
79-
display_random_graph(window);
79+
display_graph(window);
8080
update_text_position();
8181
}
8282
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Num6) || sf::Keyboard::isKeyPressed(sf::Keyboard::Numpad6)){
8383
window.clear();
8484
clear_vectors();
8585
call_random_conex_graph();
86-
display_random_graph(window);
86+
display_graph(window);
8787
update_text_position();
8888
}
8989
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Num7) || sf::Keyboard::isKeyPressed(sf::Keyboard::Numpad7)){
@@ -115,6 +115,7 @@ void event_handler::select_algorithms(const sf::Event &event, sf::RenderWindow &
115115
if (!parents.empty()){
116116
node lca = call_lca_lite(parents);
117117
std::cout << "El LCA es " << lca.id << std::endl;
118+
make_sprite_red(sprites[lca.id]);
118119
}
119120
else
120121
std::cout << "Hay, un ciclo, no es arbol" << std::endl;

includes/functions.hpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,16 @@
2222
*/
2323
sf::Sprite create_sprite(const sf::Vector2f &mouse){
2424
sf::Sprite sprite;
25-
sprite.setTexture(texture);
25+
sprite.setTexture(blue_circle);
2626
sprite.setScale(0.01f, 0.01f);
2727
sprite.setPosition(mouse);
2828
return sprite;
2929
}
30+
31+
void make_sprite_red(sf::Sprite &sprite){
32+
sprite.setTexture(red_circle);
33+
sprite.setScale(0.04f, 0.04f);
34+
}
3035
/**
3136
* @brief Creates a node
3237
*
@@ -290,7 +295,7 @@ node call_lca_lite(const std::vector<int> &padres){
290295
*
291296
* @param window
292297
*/
293-
void display_random_graph(const sf::RenderWindow &window){
298+
void display_graph(const sf::RenderWindow &window){
294299

295300
sf::Vector2u win_size = window.getSize();
296301
for (auto &v : vertices){
@@ -356,5 +361,5 @@ void display_tree_by_parents(std::vector<std::pair<int, int>> parents_with_index
356361
sprite_selected = false;
357362

358363
update_text_position();
359-
364+
make_sprite_red(sprites[parents_with_index[0].first]);
360365
}

includes/globals.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ std::string mouse_button = "";
1919
bool is_test = false;
2020

2121
//cosas para dibujar
22-
sf::Texture texture;
22+
sf::Texture blue_circle;
23+
sf::Texture red_circle;
2324
sf::Font font;
2425

2526
std::vector<sf::Text> textos_peso;

includes/visualizer.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class visualizer : event_handler{
2121

2222
window.clear();
2323
if (is_test){
24-
display_random_graph(window);
24+
display_graph(window);
2525
create_text_to_display();
2626
update_text_position();
2727
is_test = false;

0 commit comments

Comments
 (0)