X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fengineer%2Ftrainpanel.cpp;h=a8c0e90536580d3c7c40a27a32300d940446fb22;hb=010d8321e982d1684fcbff5bf6fc2bdec7cb7bae;hp=9f3bf1a95f1c8303b8b6b432c6803f19326d3e4f;hpb=3e9c210ddc036cd015228504cc0803c909e27f84;p=r2c2.git diff --git a/source/engineer/trainpanel.cpp b/source/engineer/trainpanel.cpp index 9f3bf1a..a8c0e90 100644 --- a/source/engineer/trainpanel.cpp +++ b/source/engineer/trainpanel.cpp @@ -16,11 +16,12 @@ using namespace Msp; using namespace Marklin; TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t): + Widget(r), Panel(r), engineer(e), train(t) { - set_size(200, 172); + set_size(200, 145); add(*(lbl_addr=new GLtk::Label(res, format("%2d", train.get_locomotive().get_address())))); lbl_addr->set_style("digital"); @@ -31,41 +32,46 @@ TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t): lbl_name->set_geometry(GLtk::Geometry(45, geom.h-34, geom.w-55, 24)); train.signal_name_changed.connect(sigc::mem_fun(lbl_name, &GLtk::Label::set_text)); + 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-58, 35, 24)); + train.signal_target_speed_changed.connect(sigc::mem_fun(this, &TrainPanel::train_speed_changed)); + add(*(sld_speed=new GLtk::HSlider(res))); - sld_speed->set_geometry(GLtk::Geometry(50, geom.h-56, geom.w-60, 10)); + sld_speed->set_geometry(GLtk::Geometry(50, geom.h-51, geom.w-80, 10)); sld_speed->set_range(0, 14); 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, 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)); + add(*(tgl_forward=new GLtk::Toggle(res))); + tgl_forward->set_text("Fwd"); + tgl_forward->set_geometry(GLtk::Geometry(geom.w-30, geom.h-59, 20, 27)); + tgl_forward->set_value(!train.get_locomotive().get_reverse()); + tgl_forward->signal_toggled.connect(sigc::mem_fun(this, &TrainPanel::forward_toggled)); - GLtk::Button *btn; + add(*(lbl_status=new GLtk::Label(res, train.get_status()))); + lbl_status->set_style("digital"); + lbl_status->set_geometry(GLtk::Geometry(10, 34, geom.w-20, 24)); + train.signal_status_changed.connect(sigc::mem_fun(this, &TrainPanel::train_status_changed)); - 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) + 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+=35) { - 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; + string fname = i->second; + fname[0] = toupper(fname[0]); + GLtk::Toggle *tgl; + add(*(tgl=new GLtk::Toggle(res))); + tgl->set_text(fname); + tgl->set_geometry(GLtk::Geometry(x, geom.h-85, 35, 27)); + tgl->set_value(train.get_locomotive().get_function(i->first)); + tgl->signal_toggled.connect(sigc::bind(sigc::mem_fun(this, &TrainPanel::func_toggled), i->first)); + + tgl_funcs[i->first] = tgl; } 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)); + GLtk::Button *btn; add(*(btn=new GLtk::Button(res, "Edit"))); btn->set_geometry(GLtk::Geometry(geom.w-50, 10, 40, 24)); @@ -73,6 +79,9 @@ TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t): 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)); + + add(*(btn=new GLtk::Button(res, "GoTo"))); + btn->set_geometry(GLtk::Geometry(geom.w-130, 10, 40, 24)); } void TrainPanel::speed_slider_changed(double v) @@ -80,16 +89,17 @@ void TrainPanel::speed_slider_changed(double v) train.set_speed(static_cast(v)); } -void TrainPanel::loco_speed_changed(unsigned speed) +void TrainPanel::train_speed_changed(unsigned speed) { lbl_speed->set_text(format("%2d", speed)); + sld_speed->set_value(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); + map::iterator i = tgl_funcs.find(func); + if(i!=tgl_funcs.end()) + i->second->set_value(value); } void TrainPanel::train_status_changed(const string &s) @@ -102,7 +112,12 @@ void TrainPanel::place_clicked() engineer.place_train(train); } -void TrainPanel::func_clicked(unsigned func) +void TrainPanel::forward_toggled(bool value) +{ + train.set_reverse(!value); +} + +void TrainPanel::func_toggled(bool value, unsigned func) { - train.get_locomotive().set_function(func, !train.get_locomotive().get_function(func)); + train.get_locomotive().set_function(func, value); }