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