X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Ftrainpanel.cpp;h=b47093468cac16197a4bd890fe588f4010efb902;hb=38fb8d56efde037a71c46a58bda314655e68ab6c;hp=cd41c2343d2adde8a354dbebaa2d307718608163;hpb=bc955b09faf8365a72d07bb5ee1253c9b958c897;p=r2c2.git diff --git a/source/engineer/trainpanel.cpp b/source/engineer/trainpanel.cpp index cd41c23..b470934 100644 --- a/source/engineer/trainpanel.cpp +++ b/source/engineer/trainpanel.cpp @@ -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 #include #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 &funcs = train.get_locomotive().get_type().get_functions(); + unsigned x = 10; + for(map::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::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)); +}