]> git.tdb.fi Git - r2c2.git/blobdiff - source/engineer/trainpanel.cpp
Code reformatting: add spaces around assignment operators
[r2c2.git] / source / engineer / trainpanel.cpp
index cd41c2343d2adde8a354dbebaa2d307718608163..b47093468cac16197a4bd890fe588f4010efb902 100644 (file)
@@ -1,3 +1,10 @@
+/* $Id$
+
+This file is part of the MSP Märklin suite
+Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
 #include <msp/gltk/button.h>
 #include <msp/strings/formatter.h>
 #include "libmarklin/locomotive.h"
@@ -13,7 +20,7 @@ TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t):
        engineer(e),
        train(t)
 {
-       set_size(200, 131);
+       set_size(200, 172);
 
        add(*(lbl_addr=new GLtk::Label(res, format("%2d", train.get_locomotive().get_address()))));
        lbl_addr->set_style("digital");
@@ -35,13 +42,31 @@ TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t):
        lbl_speed->set_geometry(GLtk::Geometry(10, geom.h-63, 35, 24));
        train.get_locomotive().signal_speed_changed.connect(sigc::mem_fun(this, &TrainPanel::loco_speed_changed));
 
+       GLtk::Button *btn;
+
+       const map<unsigned, string> &funcs = train.get_locomotive().get_type().get_functions();
+       unsigned x = 10;
+       for(map<unsigned, string>::const_iterator i=funcs.begin(); i!=funcs.end(); ++i, x+=40)
+       {
+               string fname = i->second;
+               fname[0] = toupper(fname[0]);
+               add(*(btn=new GLtk::Button(res, fname)));
+               btn->set_geometry(GLtk::Geometry(x, 68, 40, 24));
+               btn->signal_clicked.connect(sigc::bind(sigc::mem_fun(this, &TrainPanel::func_clicked), i->first));
+
+               GLtk::Indicator *ind = new GLtk::Indicator(res);
+               add(*ind);
+               ind->set_geometry(GLtk::Geometry(x, 92, 40, 12));
+               ind->set_active(train.get_locomotive().get_function(i->first));
+               ind_funcs[i->first] = ind;
+       }
+       train.get_locomotive().signal_function_changed.connect(sigc::mem_fun(this, &TrainPanel::loco_function_changed));
+
        add(*(lbl_status=new GLtk::Label(res, train.get_status())));
        lbl_status->set_style("digital");
-       lbl_status->set_geometry(GLtk::Geometry(10, geom.h-92, geom.w-20, 24));
+       lbl_status->set_geometry(GLtk::Geometry(10, 39, geom.w-20, 24));
        train.signal_status_changed.connect(sigc::mem_fun(this, &TrainPanel::train_status_changed));
 
-       GLtk::Button *btn;
-
        add(*(btn=new GLtk::Button(res, "Edit")));
        btn->set_geometry(GLtk::Geometry(geom.w-50, 10, 40, 24));
 
@@ -60,6 +85,13 @@ void TrainPanel::loco_speed_changed(unsigned speed)
        lbl_speed->set_text(format("%2d", speed));
 }
 
+void TrainPanel::loco_function_changed(unsigned func, bool value)
+{
+       map<unsigned, GLtk::Indicator *>::iterator i = ind_funcs.find(func);
+       if(i!=ind_funcs.end())
+               i->second->set_active(value);
+}
+
 void TrainPanel::train_status_changed(const string &s)
 {
        lbl_status->set_text(s);
@@ -69,3 +101,8 @@ void TrainPanel::place_clicked()
 {
        engineer.place_train(train);
 }
+
+void TrainPanel::func_clicked(unsigned func)
+{
+       train.get_locomotive().set_function(func, !train.get_locomotive().get_function(func));
+}