]> git.tdb.fi Git - r2c2.git/blob - mainpanel.cpp
667e95fa17a1fb5c658f18657270a4111bbc8bd0
[r2c2.git] / mainpanel.cpp
1 /* $Id$
2
3 This file is part of R²C²
4 Copyright © 2006-2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #include <msp/gltk/button.h>
9 #include "libr2c2/driver.h"
10 #include "engineer.h"
11 #include "mainpanel.h"
12 #include "trainproperties.h"
13
14 using namespace std;
15 using namespace Msp;
16
17 MainPanel::MainPanel(Engineer &e):
18         engineer(e)
19 {
20         set_size(200, 117);
21
22         GLtk::Button *btn;
23
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));
28
29         add(*(ind_off=new GLtk::Indicator));
30         ind_off->set_geometry(GLtk::Geometry(10, 95, 40, 12));
31         ind_off->set_style("red");
32
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));
37
38         add(*(ind_on=new GLtk::Indicator));
39         ind_on->set_geometry(GLtk::Geometry(50, 95, 40, 12));
40         ind_on->set_style("green");
41
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));
45
46         add(*(ind_halt=new GLtk::Indicator));
47         ind_halt->set_geometry(GLtk::Geometry(90, 95, 40, 12));
48
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));
53
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));
57
58         add(*(lbl_status=new GLtk::Label));
59         lbl_status->set_geometry(GLtk::Geometry(10, 10, 180, 20));
60         lbl_status->set_style("digital");
61
62         R2C2::Driver &driver = engineer.get_layout().get_driver();
63         if(driver.get_power())
64                 ind_on->set_active(true);
65         else
66                 ind_off->set_active(true);
67
68         driver.signal_power.connect(sigc::mem_fun(this, &MainPanel::power_event));
69         driver.signal_halt.connect(sigc::mem_fun(this, &MainPanel::halt_event));
70 }
71
72 void MainPanel::set_status_text(const string &txt)
73 {
74         lbl_status->set_text(txt);
75 }
76
77 void MainPanel::power_on()
78 {
79         engineer.get_layout().get_driver().set_power(true);
80 }
81
82 void MainPanel::power_off()
83 {
84         engineer.get_layout().get_driver().set_power(false);
85 }
86
87 void MainPanel::toggle_halt()
88 {
89         R2C2::Driver &driver = engineer.get_layout().get_driver();
90         driver.halt(!driver.is_halted());
91 }
92
93 void MainPanel::new_loc()
94 {
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);
99 }
100
101 void MainPanel::quit()
102 {
103         engineer.quit();
104 }
105
106 void MainPanel::power_event(bool p)
107 {
108         ind_on->set_active(p);
109         ind_off->set_active(!p);
110 }
111
112 void MainPanel::halt_event(bool h)
113 {
114         ind_halt->set_active(h);
115 }