From: Mikko Rasa Date: Sat, 23 May 2009 13:51:47 +0000 (+0000) Subject: Add graphics for toggle widget X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f9254f57b736927a57a2fd793ee18f6c9766dd43;p=r2c2.git Add graphics for toggle widget Make train panels a bit more compact Support reverse direction for trains --- diff --git a/gui.blend b/gui.blend index 9407d86..9e4becb 100644 Binary files a/gui.blend and b/gui.blend differ diff --git a/gui.png b/gui.png index b0fec5b..8e4ea01 100644 Binary files a/gui.png and b/gui.png differ diff --git a/locos.dat b/locos.dat index 46542e8..211daf4 100644 --- a/locos.dat +++ b/locos.dat @@ -3,22 +3,22 @@ locomotive 37844 { name "BR 50"; - function 0 "light"; - function 1 "smoke"; - function 2 "telex"; + function 0 "lght"; + function 1 "smke"; + function 2 "tlx"; function 3 "sfx"; - //function 5 "whstl"; + //function 5 "whst"; }; locomotive 33961 { name "BR 86"; - function 0 "light"; - function 2 "telex"; + function 0 "lght"; + function 2 "tlx"; }; locomotive 36850 { name "BR 185"; - function 0 "light"; + function 0 "lght"; }; diff --git a/marklin.res b/marklin.res index ce53e1c..f2f69f3 100644 --- a/marklin.res +++ b/marklin.res @@ -140,6 +140,20 @@ graphic "hsliderknob" shadow { top 0; right 2; bottom 3; left 0; }; }; +graphic "switchdown" +{ + texture "gui.png"; + slice 46 43 20 21; + shadow { top 0; right 2; bottom 3; left 0; }; +}; + +graphic "switchup" +{ + texture "gui.png"; + slice 67 43 20 21; + shadow { top 0; right 2; bottom 3; left 0; }; +}; + style "button" { font_color 0 0 0; @@ -197,6 +211,25 @@ style "button-red" }; }; +style "toggle" +{ + font_color 0.0 0.0 0.0; + + special "text" + { + align 0.5 1.0; + fill 0.0 0.0; + }; + + part + { + align 0.5 0.0; + fill 0.0 0.0; + graphic NORMAL "switchdown"; + graphic ACTIVE "switchup"; + }; +}; + style "panel" { part diff --git a/source/engineer/engineer.cpp b/source/engineer/engineer.cpp index 08e1466..14e98c6 100644 --- a/source/engineer/engineer.cpp +++ b/source/engineer/engineer.cpp @@ -110,6 +110,7 @@ void Engineer::add_train() train_prop = new TrainProperties(*this, ui_res, 0); root->add(*train_prop); train_prop->signal_ok.connect(sigc::mem_fun(this, &Engineer::dismiss_train_prop)); + train_prop->signal_cancel.connect(sigc::mem_fun(this, &Engineer::dismiss_train_prop)); train_prop_stale = false; train_prop->set_visible(true); } 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); } diff --git a/source/engineer/trainpanel.h b/source/engineer/trainpanel.h index 7cfaf8f..2597d04 100644 --- a/source/engineer/trainpanel.h +++ b/source/engineer/trainpanel.h @@ -9,9 +9,9 @@ Distributed under the GPL #define TRAINPANEL_H_ #include -#include #include #include +#include #include "libmarklin/train.h" class Engineer; @@ -26,7 +26,8 @@ private: Msp::GLtk::HSlider *sld_speed; Msp::GLtk::Label *lbl_speed; Msp::GLtk::Label *lbl_status; - std::map ind_funcs; + Msp::GLtk::Toggle *tgl_forward; + std::map tgl_funcs; public: TrainPanel(Engineer &, const Msp::GLtk::Resources &, Marklin::Train &); @@ -36,7 +37,8 @@ private: void loco_function_changed(unsigned, bool); void train_status_changed(const std::string &); void place_clicked(); - void func_clicked(unsigned); + void forward_toggled(bool); + void func_toggled(bool, unsigned); }; #endif diff --git a/source/engineer/trainproperties.cpp b/source/engineer/trainproperties.cpp index be3ba8d..d26cec0 100644 --- a/source/engineer/trainproperties.cpp +++ b/source/engineer/trainproperties.cpp @@ -64,4 +64,5 @@ void TrainProperties::ok_clicked() void TrainProperties::cancel_clicked() { + signal_cancel.emit(); } diff --git a/source/engineer/trainproperties.h b/source/engineer/trainproperties.h index 0171cf5..bcd0b1d 100644 --- a/source/engineer/trainproperties.h +++ b/source/engineer/trainproperties.h @@ -19,6 +19,7 @@ class TrainProperties: public Msp::GLtk::Panel { public: sigc::signal signal_ok; + sigc::signal signal_cancel; private: Engineer &engineer; diff --git a/source/libmarklin/locomotive.cpp b/source/libmarklin/locomotive.cpp index c7d6227..3088d46 100644 --- a/source/libmarklin/locomotive.cpp +++ b/source/libmarklin/locomotive.cpp @@ -56,6 +56,7 @@ void Locomotive::set_reverse(bool rev) { reverse = rev; send_command(false); + signal_reverse_changed.emit(reverse); } } @@ -129,6 +130,7 @@ bool Locomotive::reverse_timeout() { reverse = !reverse; send_command(true); + signal_reverse_changed.emit(reverse); return false; } diff --git a/source/libmarklin/locomotive.h b/source/libmarklin/locomotive.h index 9ebccda..4c1f056 100644 --- a/source/libmarklin/locomotive.h +++ b/source/libmarklin/locomotive.h @@ -24,6 +24,7 @@ class Locomotive public: sigc::signal signal_speed_changing; sigc::signal signal_speed_changed; + sigc::signal signal_reverse_changed; sigc::signal signal_function_changed; private: diff --git a/source/libmarklin/train.cpp b/source/libmarklin/train.cpp index 341921a..09f5870 100644 --- a/source/libmarklin/train.cpp +++ b/source/libmarklin/train.cpp @@ -36,6 +36,8 @@ Train::Train(TrafficManager &tm, Locomotive &l): { trfc_mgr.add_train(this); + loco.signal_reverse_changed.connect(sigc::mem_fun(this, &Train::locomotive_reverse_changed)); + const map &sensors = trfc_mgr.get_control().get_sensors(); for(map::const_iterator i=sensors.begin(); i!=sensors.end(); ++i) i->second->signal_state_changed.connect(sigc::bind(sigc::mem_fun(this, &Train::sensor_event), i->second)); @@ -75,6 +77,11 @@ void Train::set_speed(unsigned speed) pure_speed = false; } +void Train::set_reverse(bool rev) +{ + loco.set_reverse(rev); +} + void Train::place(Block *block, unsigned entry) { for(list::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end();) @@ -166,6 +173,18 @@ void Train::save(list &st) const st.push_back((DataFile::Statement("speed_scale"), speed_scale, speed_scale_weight)); } +void Train::locomotive_reverse_changed(bool) +{ + for(list::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i) + i->block->reserve(0); + rsv_blocks.clear(); + cur_blocks.reverse(); + for(list::iterator i=cur_blocks.begin(); i!=cur_blocks.end(); ++i) + i->entry = i->block->traverse(i->entry); + reserve_more(); + update_speed(); +} + void Train::sensor_event(bool state, Sensor *sensor) { unsigned addr = sensor->get_address(); diff --git a/source/libmarklin/train.h b/source/libmarklin/train.h index a4e2b15..4c19caf 100644 --- a/source/libmarklin/train.h +++ b/source/libmarklin/train.h @@ -66,6 +66,7 @@ public: void set_name(const std::string &); void set_speed(unsigned); + void set_reverse(bool); const std::string &get_name() const { return name; } Locomotive &get_locomotive() const { return loco; } const std::string &get_status() const { return status; } @@ -75,6 +76,7 @@ public: void tick(const Msp::Time::TimeStamp &, const Msp::Time::TimeDelta &); void save(std::list &) const; private: + void locomotive_reverse_changed(bool); void sensor_event(bool, Sensor *); void turnout_route_changing(unsigned, Turnout *); void turnout_route_changed(unsigned, Turnout *);