X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Ftrainpanel.cpp;h=8c23f26164c3ed15a3ab6ee278af9a9875516be6;hb=447d621e93e71b710fed0920b473350122426b97;hp=cd41c2343d2adde8a354dbebaa2d307718608163;hpb=25b79ab38c2be2e5c89b8240504f641fd9c4899c;p=r2c2.git diff --git a/source/engineer/trainpanel.cpp b/source/engineer/trainpanel.cpp index cd41c23..8c23f26 100644 --- a/source/engineer/trainpanel.cpp +++ b/source/engineer/trainpanel.cpp @@ -13,7 +13,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 +35,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 +78,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 +94,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)); +}