X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Ftrainpanel.cpp;h=7c3ba71a5c8e1cf83cebe85d9b64f8c400cc5a4a;hb=f9254f57b736927a57a2fd793ee18f6c9766dd43;hp=b47093468cac16197a4bd890fe588f4010efb902;hpb=38fb8d56efde037a71c46a58bda314655e68ab6c;p=r2c2.git diff --git a/source/engineer/trainpanel.cpp b/source/engineer/trainpanel.cpp index b470934..7c3ba71 100644 --- a/source/engineer/trainpanel.cpp +++ b/source/engineer/trainpanel.cpp @@ -20,7 +20,7 @@ TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t): 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 +31,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.get_locomotive().signal_speed_changed.connect(sigc::mem_fun(this, &TrainPanel::loco_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) + 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; + 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 +78,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) @@ -87,9 +95,9 @@ void TrainPanel::loco_speed_changed(unsigned 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 +110,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); }