|
1 #include <algowin.h> |
|
2 #include <kruskalbox.h> |
|
3 |
|
4 sigc::signal<void, AlgoWin *> AlgoWin::signal_closing() |
|
5 { |
|
6 return signal_closed; |
|
7 } |
|
8 |
|
9 sigc::signal<void, AlgoWin *, std::string> AlgoWin::signal_maplist_needed() |
|
10 { |
|
11 return signal_maplist_need; |
|
12 } |
|
13 |
|
14 bool AlgoWin::closeIfEscapeIsPressed(GdkEventKey* e) |
|
15 { |
|
16 if(e->keyval==GDK_Escape) |
|
17 { |
|
18 on_hide(); |
|
19 } |
|
20 return true; |
|
21 } |
|
22 |
|
23 AlgoWin::AlgoWin(int algoid, std::vector<std::string> tabnames, std::vector<std::string> nodemapnames,std::vector<std::string> edgemapnames) |
|
24 { |
|
25 signal_key_press_event().connect(sigc::mem_fun(*this, &AlgoWin::closeIfEscapeIsPressed)); |
|
26 |
|
27 Gtk::VBox * vbox=new Gtk::VBox(); |
|
28 vbox->set_spacing(5); |
|
29 |
|
30 Gtk::Label * label=new Gtk::Label("Select graph:"); |
|
31 |
|
32 switch(algoid) |
|
33 { |
|
34 case 0: |
|
35 ab=new AlgoBox(tabnames, nodemapnames, edgemapnames); |
|
36 set_title("Algo Win Demo"); |
|
37 break; |
|
38 case 1: |
|
39 ab=new KruskalBox(tabnames, nodemapnames, edgemapnames); |
|
40 set_title("Kruskal Algorithm"); |
|
41 break; |
|
42 default: |
|
43 break; |
|
44 } |
|
45 ab->signal_maplist_needed().connect(sigc::mem_fun(*this, &AlgoWin::emit_tab_change)); |
|
46 |
|
47 runbutton=new Gtk::Button("Run"); |
|
48 runbutton->signal_released().connect(sigc::mem_fun(*ab,&AlgoBox::run)); |
|
49 runbutton->signal_activate().connect(sigc::mem_fun(*ab,&AlgoBox::run)); |
|
50 |
|
51 closebutton=new Gtk::Button("Close"); |
|
52 closebutton->signal_released().connect(sigc::mem_fun(*this,&AlgoWin::on_hide)); |
|
53 closebutton->signal_activate().connect(sigc::mem_fun(*this,&AlgoWin::on_hide)); |
|
54 |
|
55 Gtk::HBox * hbox=new Gtk::HBox(); |
|
56 |
|
57 hbox->pack_start(*runbutton); |
|
58 hbox->pack_start(*closebutton); |
|
59 |
|
60 vbox->pack_start(*label); |
|
61 vbox->pack_start(*ab); |
|
62 vbox->pack_start(*hbox); |
|
63 |
|
64 add(*vbox); |
|
65 |
|
66 show_all_children(); |
|
67 }; |
|
68 |
|
69 void AlgoWin::update_tablist(std::vector<std::string> tabnames) |
|
70 { |
|
71 ab->update_tablist(tabnames); |
|
72 } |
|
73 |
|
74 void AlgoWin::update_maplist(std::vector<std::string> nodemapnames, std::vector<std::string> edgemapnames) |
|
75 { |
|
76 ab->update_maplist(nodemapnames, edgemapnames); |
|
77 } |
|
78 |
|
79 void AlgoWin::on_hide() |
|
80 { |
|
81 signal_closed.emit(this); |
|
82 Gtk::Window::on_hide(); |
|
83 } |
|
84 |
|
85 void AlgoWin::emit_tab_change(std::string newtab) |
|
86 { |
|
87 signal_maplist_need.emit(this, newtab); |
|
88 } |