3 This file is part of R²C²
4 Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/gltk/button.h>
9 #include "libr2c2/driver.h"
11 #include "mainpanel.h"
12 #include "trainproperties.h"
17 MainPanel::MainPanel(Engineer &e):
24 add(*(btn=new GLtk::Button("Off")));
25 btn->set_geometry(GLtk::Geometry(10, 70, 40, 25));
26 btn->set_style("red");
27 btn->signal_clicked.connect(sigc::mem_fun(this, &MainPanel::power_off));
29 add(*(ind_off=new GLtk::Indicator));
30 ind_off->set_geometry(GLtk::Geometry(10, 95, 40, 12));
31 ind_off->set_style("red");
33 add(*(btn=new GLtk::Button("On")));
34 btn->set_geometry(GLtk::Geometry(50, 70, 40, 25));
35 btn->set_style("green");
36 btn->signal_clicked.connect(sigc::mem_fun(this, &MainPanel::power_on));
38 add(*(ind_on=new GLtk::Indicator));
39 ind_on->set_geometry(GLtk::Geometry(50, 95, 40, 12));
40 ind_on->set_style("green");
42 add(*(btn=new GLtk::Button("Halt")));
43 btn->set_geometry(GLtk::Geometry(90, 70, 40, 25));
44 btn->signal_clicked.connect(sigc::mem_fun(this, &MainPanel::toggle_halt));
46 add(*(ind_halt=new GLtk::Indicator));
47 ind_halt->set_geometry(GLtk::Geometry(90, 95, 40, 12));
49 add(*(btn=new GLtk::Button("Quit")));
50 btn->set_geometry(GLtk::Geometry(150, 70, 40, 25));
51 btn->set_style("red");
52 btn->signal_clicked.connect(sigc::mem_fun(this, &MainPanel::quit));
54 add(*(btn=new GLtk::Button("+Loc")));
55 btn->set_geometry(GLtk::Geometry(10, 40, 40, 25));
56 btn->signal_clicked.connect(sigc::mem_fun(this, &MainPanel::new_loc));
58 add(*(lbl_status=new GLtk::Label));
59 lbl_status->set_geometry(GLtk::Geometry(10, 10, 180, 20));
60 lbl_status->set_style("digital");
62 R2C2::Driver &driver = engineer.get_layout().get_driver();
63 if(driver.get_power())
64 ind_on->set_active(true);
66 ind_off->set_active(true);
68 driver.signal_power.connect(sigc::mem_fun(this, &MainPanel::power_event));
69 driver.signal_halt.connect(sigc::mem_fun(this, &MainPanel::halt_event));
72 void MainPanel::set_status_text(const string &txt)
74 lbl_status->set_text(txt);
77 void MainPanel::power_on()
79 engineer.get_layout().get_driver().set_power(true);
82 void MainPanel::power_off()
84 engineer.get_layout().get_driver().set_power(false);
87 void MainPanel::toggle_halt()
89 R2C2::Driver &driver = engineer.get_layout().get_driver();
90 driver.halt(!driver.is_halted());
93 void MainPanel::new_loc()
95 TrainProperties *dialog = new TrainProperties(engineer, 0);
96 engineer.get_root().add(*dialog);
97 dialog->set_position(geom.x+geom.w, geom.y+geom.h-dialog->get_geometry().h);
98 dialog->set_visible(true);
101 void MainPanel::quit()
106 void MainPanel::power_event(bool p)
108 ind_on->set_active(p);
109 ind_off->set_active(!p);
112 void MainPanel::halt_event(bool h)
114 ind_halt->set_active(h);