+/* $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"
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");
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));
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);
{
engineer.place_train(train);
}
+
+void TrainPanel::func_clicked(unsigned func)
+{
+ train.get_locomotive().set_function(func, !train.get_locomotive().get_function(func));
+}