gui/algowin.cc
author deba
Mon, 03 Apr 2006 16:05:26 +0000
changeset 2033 7bf1f64962c2
parent 1879 01d41844ef46
permissions -rw-r--r--
Small corrections
     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)
    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);
    36       set_title("Algo Win Demo");
    37       break;
    38     case 1:
    39       ab=new KruskalBox(tabnames);
    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   ab->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoWin::emit_new_map_signal));
    47 
    48   runbutton=new Gtk::Button("Run");
    49   runbutton->signal_released().connect(sigc::mem_fun(*ab,&AlgoBox::run));
    50   runbutton->signal_activate().connect(sigc::mem_fun(*ab,&AlgoBox::run));
    51 
    52   closebutton=new Gtk::Button("Close");
    53   closebutton->signal_released().connect(sigc::mem_fun(*this,&AlgoWin::on_hide));
    54   closebutton->signal_activate().connect(sigc::mem_fun(*this,&AlgoWin::on_hide));
    55       
    56   Gtk::HBox * hbox=new Gtk::HBox();
    57 
    58   hbox->pack_start(*runbutton);
    59   hbox->pack_start(*closebutton);
    60 
    61   vbox->pack_start(*label);
    62   vbox->pack_start(*ab);
    63   vbox->pack_start(*hbox);
    64       
    65   add(*vbox);
    66 
    67   show_all_children();
    68 };
    69 
    70 void AlgoWin::update_tablist(std::vector<std::string> tabnames)
    71 {
    72   ab->update_tablist(tabnames);
    73 }
    74 
    75 void AlgoWin::update_maplist(MapStorage * mapstorage)
    76 {
    77   ab->update_maplist(mapstorage);
    78 }
    79 
    80 void AlgoWin::on_hide()
    81 {
    82   signal_closed.emit(this);
    83   Gtk::Window::on_hide();
    84 }
    85 
    86 void AlgoWin::emit_tab_change(std::string newtab)
    87 {
    88   signal_maplist_need.emit(this, newtab);
    89 }