]> git.tdb.fi Git - r2c2.git/commitdiff
Add graphics for toggle widget
authorMikko Rasa <tdb@tdb.fi>
Sat, 23 May 2009 13:51:47 +0000 (13:51 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sat, 23 May 2009 13:51:47 +0000 (13:51 +0000)
Make train panels a bit more compact
Support reverse direction for trains

13 files changed:
gui.blend
gui.png
locos.dat
marklin.res
source/engineer/engineer.cpp
source/engineer/trainpanel.cpp
source/engineer/trainpanel.h
source/engineer/trainproperties.cpp
source/engineer/trainproperties.h
source/libmarklin/locomotive.cpp
source/libmarklin/locomotive.h
source/libmarklin/train.cpp
source/libmarklin/train.h

index 9407d861862eb0fb707693304464c216474a37f1..9e4becbbd502db90fab14d8fdead73515eb2fb96 100644 (file)
Binary files a/gui.blend and b/gui.blend differ
diff --git a/gui.png b/gui.png
index b0fec5b3b9912f030ebedf78fa43f355130be3c9..8e4ea011e1b687b38e4b3963305cb06be9242fe9 100644 (file)
Binary files a/gui.png and b/gui.png differ
index 46542e8ab0a7fa7e16b12a26ca8efb3028dd9b89..211daf49457327b8c2e05eb0d6efbc4f7fb936fd 100644 (file)
--- 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";
 };
index ce53e1ce67e23ed11f1a9870d36ad6fdd99a5a67..f2f69f378979c90410911d581b6b8fee98066aa2 100644 (file)
@@ -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
index 08e1466893f209a445c6d69e49c2fe03136209ee..14e98c6b6b7aa2074bcfdb6c5f59a7ad0b696caa 100644 (file)
@@ -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);
 }
index b47093468cac16197a4bd890fe588f4010efb902..7c3ba71a5c8e1cf83cebe85d9b64f8c400cc5a4a 100644 (file)
@@ -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<unsigned, string> &funcs = train.get_locomotive().get_type().get_functions();
        unsigned x = 10;
-       for(map<unsigned, string>::const_iterator i=funcs.begin(); i!=funcs.end(); ++i, x+=40)
+       for(map<unsigned, string>::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<unsigned, GLtk::Indicator *>::iterator i = ind_funcs.find(func);
-       if(i!=ind_funcs.end())
-               i->second->set_active(value);
+       map<unsigned, GLtk::Toggle *>::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);
 }
index 7cfaf8fec5056136b6e849511e96cb10fd750dd5..2597d040c3c76f2e05afad4a214c7b8df2bd1f8b 100644 (file)
@@ -9,9 +9,9 @@ Distributed under the GPL
 #define TRAINPANEL_H_
 
 #include <msp/gltk/hslider.h>
-#include <msp/gltk/indicator.h>
 #include <msp/gltk/label.h>
 #include <msp/gltk/panel.h>
+#include <msp/gltk/toggle.h>
 #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<unsigned, Msp::GLtk::Indicator *> ind_funcs;
+       Msp::GLtk::Toggle *tgl_forward;
+       std::map<unsigned, Msp::GLtk::Toggle *> 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
index be3ba8daa410091746b9efb3cde1f7407b30aa1b..d26cec08b649524606f23c232bf2e98d28a10fc7 100644 (file)
@@ -64,4 +64,5 @@ void TrainProperties::ok_clicked()
 
 void TrainProperties::cancel_clicked()
 {
+       signal_cancel.emit();
 }
index 0171cf59f64e3bf420f0f6a5cea45a5378b26c40..bcd0b1df921ff6f85dfe02491b9be5792f29874b 100644 (file)
@@ -19,6 +19,7 @@ class TrainProperties: public Msp::GLtk::Panel
 {
 public:
        sigc::signal<void> signal_ok;
+       sigc::signal<void> signal_cancel;
 
 private:
        Engineer &engineer;
index c7d6227cddb938e5d3acfbbb6cc2c8f564ca771f..3088d4655ba3d100b2c64d2c704782e4e3c04e57 100644 (file)
@@ -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;
 }
 
index 9ebccdae5e3bff30814ecba38324e7f607e58914..4c1f056eefec7ab65bf0ab0906dd461f3eba2624 100644 (file)
@@ -24,6 +24,7 @@ class Locomotive
 public:
        sigc::signal<void, unsigned> signal_speed_changing;
        sigc::signal<void, unsigned> signal_speed_changed;
+       sigc::signal<void, bool> signal_reverse_changed;
        sigc::signal<void, unsigned, bool> signal_function_changed;
 
 private:
index 341921aaf511000a406869cd78f0b566641ec420..09f587020588bc69fd91c5f51d2747a9094a7110 100644 (file)
@@ -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<unsigned, Sensor *> &sensors = trfc_mgr.get_control().get_sensors();
        for(map<unsigned, Sensor *>::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<BlockRef>::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end();)
@@ -166,6 +173,18 @@ void Train::save(list<DataFile::Statement> &st) const
        st.push_back((DataFile::Statement("speed_scale"), speed_scale, speed_scale_weight));
 }
 
+void Train::locomotive_reverse_changed(bool)
+{
+       for(list<BlockRef>::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i)
+               i->block->reserve(0);
+       rsv_blocks.clear();
+       cur_blocks.reverse();
+       for(list<BlockRef>::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();
index a4e2b150a327647236ebfa9f1d47350df2b218a0..4c19caf01a9625a9921b4a345bd4baada65a177e 100644 (file)
@@ -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<Msp::DataFile::Statement> &) const;
 private:
+       void locomotive_reverse_changed(bool);
        void sensor_event(bool, Sensor *);
        void turnout_route_changing(unsigned, Turnout *);
        void turnout_route_changed(unsigned, Turnout *);