+/* $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"
+#include "engineer.h"
#include "trainpanel.h"
+using namespace std;
using namespace Msp;
using namespace Marklin;
engineer(e),
train(t)
{
- set_size(200, 100);
+ set_size(200, 172);
- add(*(lbl_addr=new GLtk::Label(res, lexical_cast(train.get_locomotive().get_address(), "%2d"))));
+ add(*(lbl_addr=new GLtk::Label(res, format("%2d", train.get_locomotive().get_address()))));
lbl_addr->set_style("digital");
lbl_addr->set_geometry(GLtk::Geometry(10, geom.h-34, 35, 24));
sld_speed->set_step(1);
sld_speed->signal_value_changed.connect(sigc::mem_fun(this, &TrainPanel::speed_slider_changed));
- add(*(lbl_speed=new GLtk::Label(res, " 0")));
+ add(*(lbl_speed=new GLtk::Label(res, format("%2d", train.get_locomotive().get_speed()))));
lbl_speed->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, 39, geom.w-20, 24));
+ train.signal_status_changed.connect(sigc::mem_fun(this, &TrainPanel::train_status_changed));
+
add(*(btn=new GLtk::Button(res, "Edit")));
btn->set_geometry(GLtk::Geometry(geom.w-50, 10, 40, 24));
+
+ add(*(btn=new GLtk::Button(res, "Place")));
+ btn->set_geometry(GLtk::Geometry(geom.w-90, 10, 40, 24));
+ btn->signal_clicked.connect(sigc::mem_fun(this, &TrainPanel::place_clicked));
}
void TrainPanel::speed_slider_changed(double v)
{
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);
+}
+
+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));
+}