From: Mikko Rasa Date: Thu, 18 Nov 2010 18:20:07 +0000 (+0000) Subject: Split the single large toolbar into a few smaller collapsible ones X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=c6b9a38300cc2ecfc0df66af162620b9ea5a1e3e;p=r2c2.git Split the single large toolbar into a few smaller collapsible ones Replace turnout and sensor ID setting with a track properties dialog Add left and right arrow button styles --- diff --git a/gui.blend b/gui.blend index f70f183..6171856 100644 Binary files a/gui.blend and b/gui.blend differ diff --git a/gui.png b/gui.png index 50c8c5b..0f23100 100644 Binary files a/gui.png and b/gui.png differ diff --git a/r2c2.res b/r2c2.res index b40871e..642433f 100644 --- a/r2c2.res +++ b/r2c2.res @@ -10,7 +10,11 @@ style "root" style "label" { font_color 0 0 0; - special "text"; + special "text" + { + align 0.0 0.5; + fill 0.0 0.0; + }; }; style "image" @@ -97,28 +101,56 @@ graphic "up_arrow_button" { texture "gui.png"; slice 2 18 13 13; - shadow { top 0; right 1; bottom 2; left 0; }; + shadow { right 1; bottom 2; }; }; graphic "up_arrow_button_pressed" { texture "gui.png"; - slice 17 18 13 13; - shadow { top 0; right 1; bottom 2; left 0; }; + slice 17 19 13 12; + shadow { right 1; bottom 1; }; }; graphic "down_arrow_button" { texture "gui.png"; slice 2 4 13 13; - shadow { top 0; right 1; bottom 2; left 0; }; + shadow { right 1; bottom 2; }; }; graphic "down_arrow_button_pressed" { texture "gui.png"; - slice 17 4 13 13; - shadow { top 0; right 1; bottom 2; left 0; }; + slice 17 5 13 12; + shadow { right 1; bottom 1; }; +}; + +graphic "right_arrow_button" +{ + texture "gui.png"; + slice 32 17 12 14; + shadow { right 1; bottom 2; }; +}; + +graphic "right_arrow_button_pressed" +{ + texture "gui.png"; + slice 32 3 12 13; + shadow { right 1; bottom 1; }; +}; + +graphic "left_arrow_button" +{ + texture "gui.png"; + slice 46 2 12 14; + shadow { right 1; bottom 2; }; +}; + +graphic "left_arrow_button_pressed" +{ + texture "gui.png"; + slice 60 3 12 13; + shadow { right 1; bottom 1; }; }; style "button" @@ -200,6 +232,28 @@ style "button-arrow_down" }; }; +style "button-arrow_right" +{ + part + { + graphic NORMAL "right_arrow_button"; + graphic ACTIVE "right_arrow_button_pressed"; + align 0.5 0.5; + fill 0.0 0.0; + }; +}; + +style "button-arrow_left" +{ + part + { + graphic NORMAL "left_arrow_button"; + graphic ACTIVE "left_arrow_button_pressed"; + align 0.5 0.5; + fill 0.0 0.0; + }; +}; + graphic "yellow_lamp" { texture "gui.png"; diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index 8ab0465..34398f3 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -31,11 +31,14 @@ Distributed under the GPL #include "3d/path.h" #include "designer.h" #include "input.h" +#include "layoutbar.h" #include "manipulator.h" #include "measure.h" +#include "routebar.h" #include "selection.h" #include "svgexporter.h" -#include "toolbar.h" +#include "trackbar.h" +#include "trackproperties.h" using namespace std; using namespace R2C2; @@ -124,10 +127,17 @@ Designer::Designer(int argc, char **argv): root.signal_pointer_motion.connect(sigc::mem_fun(this, &Designer::pointer_motion)); root.signal_tooltip.connect(sigc::mem_fun(this, &Designer::tooltip)); - toolbar = new Toolbar(*this); - root.add(*toolbar); - toolbar->set_position(0, window.get_height()-toolbar->get_geometry().h); - toolbar->set_focusable(false); + toolbars.push_back(new Layoutbar(*this)); + toolbars.push_back(new Trackbar(*this)); + toolbars.push_back(new Routebar(*this)); + for(vector::iterator i=toolbars.begin(); i!=toolbars.end(); ++i) + { + root.add(**i); + if(i!=toolbars.begin()) + (*i)->expand(false); + (*i)->signal_expanded.connect(sigc::hide(sigc::mem_fun(this, &Designer::arrange_toolbars))); + } + arrange_toolbars(); GLtk::Panel *statusbar = new GLtk::Panel; root.add(*statusbar); @@ -182,39 +192,18 @@ void Designer::new_track() mode = CATALOGUE; } -void Designer::set_turnout_id() +void Designer::track_properties() { - Track *track = selection.get_track(); - if(selection.size()==1 && track->get_type().is_turnout()) - { - InputDialog *input = new InputDialog(*this, "Turnout ID", lexical_cast(track->get_turnout_id())); - input->signal_accept.connect(sigc::mem_fun(this, &Designer::turnout_id_accept)); - } -} + if(selection.empty()) + return; -void Designer::set_sensor_id() -{ - const set &tracks = selection.get_tracks(); - bool ok = false; - int id = -1; - for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) - { - if(!(*i)->get_type().is_turnout()) - ok = true; - if(static_cast((*i)->get_sensor_id())!=id) - { - if(id==-1) - id = (*i)->get_sensor_id(); - else - id = -2; - } - } + TrackProperties *track_prop = new TrackProperties(selection); + root.add(*track_prop); + const GLtk::Geometry &root_geom = root.get_geometry(); + const GLtk::Geometry &dlg_geom = track_prop->get_geometry(); + track_prop->set_position((root_geom.w-dlg_geom.w)/2, (root_geom.h-dlg_geom.h)/2); - if(ok) - { - InputDialog *input = new InputDialog(*this, "Sensor ID", (id>=0 ? lexical_cast(id) : string())); - input->signal_accept.connect(sigc::mem_fun(this, &Designer::sensor_id_accept)); - } + track_prop->signal_response.connect(sigc::mem_fun(this, &Designer::track_properties_response)); } void Designer::rename_route() @@ -374,16 +363,14 @@ void Designer::key_press(unsigned key, unsigned mod, wchar_t) manipulator.even_slope(true); else if(key==Msp::Input::KEY_E) manipulator.even_slope(); - else if(key==Msp::Input::KEY_T) - set_turnout_id(); - else if(key==Msp::Input::KEY_S) - set_sensor_id(); else if(key==Msp::Input::KEY_A) add_selection_to_route(); else if(key==Msp::Input::KEY_C) manipulator.connect(); else if(key==Msp::Input::KEY_V) svg_export(); + else if(key==Msp::Input::KEY_P) + track_properties(); } void Designer::button_press(int x, int y, unsigned btn, unsigned mod) @@ -581,25 +568,22 @@ void Designer::measure_done() selection_changed(); } -void Designer::turnout_id_accept(const string &text) +void Designer::arrange_toolbars() { - Track *track = selection.get_track(); - unsigned id = (text.empty() ? 0 : lexical_cast(text)); - track->set_turnout_id(id); - - update_track_icon(layout_3d->get_track(*track)); + unsigned x = 0; + for(vector::iterator i=toolbars.begin(); i!=toolbars.end(); ++i) + { + const GLtk::Geometry &geom = (*i)->get_geometry(); + (*i)->set_position(x, window.get_height()-geom.h); + x += geom.w; + } } -void Designer::sensor_id_accept(const string &text) +void Designer::track_properties_response(int) { const set &tracks = selection.get_tracks(); - unsigned id = (text.empty() ? 0 : lexical_cast(text)); for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) - { - (*i)->set_sensor_id(id); - update_track_icon(layout_3d->get_track(**i)); - } } void Designer::route_name_accept(const string &text) diff --git a/source/designer/designer.h b/source/designer/designer.h index 9fc2961..e8d0d76 100644 --- a/source/designer/designer.h +++ b/source/designer/designer.h @@ -50,7 +50,7 @@ private: Msp::GLtk::Resources ui_res; Msp::GLtk::Root root; - Toolbar *toolbar; + std::vector toolbars; Msp::GLtk::Label *lbl_status; R2C2::Catalogue catalogue; @@ -94,8 +94,7 @@ public: Msp::GLtk::Root &get_root() { return root; } void new_track(); - void set_turnout_id(); - void set_sensor_id(); + void track_properties(); void rename_route(); void svg_export(); @@ -120,8 +119,8 @@ private: void manipulation_done(bool); void measure_changed(); void measure_done(); - void turnout_id_accept(const std::string &); - void sensor_id_accept(const std::string &); + void arrange_toolbars(); + void track_properties_response(int); void route_name_accept(const std::string &); void svg_export_accept(const std::string &); std::string tooltip(int, int); diff --git a/source/designer/layoutbar.cpp b/source/designer/layoutbar.cpp new file mode 100644 index 0000000..d47485f --- /dev/null +++ b/source/designer/layoutbar.cpp @@ -0,0 +1,32 @@ +/* $Id$ + +This file is part of R²C² +Copyright © 2010 Mikkosoft Productions, Mikko Rasa +Distributed under the GPL +*/ + +#include "designer.h" +#include "layoutbar.h" + +using namespace Msp; + +Layoutbar::Layoutbar(Designer &designer): + Toolbar("Layout", 120) +{ + GLtk::Button *btn; + + pnl_content->add(*(btn = new GLtk::Button("Load"))); + btn->set_geometry(GLtk::Geometry(0, 10, 40, 24)); + btn->set_tooltip("Load layout (not implemented)"); + + pnl_content->add(*(btn = new GLtk::Button("Save"))); + btn->set_geometry(GLtk::Geometry(40, 10, 40, 24)); + btn->set_tooltip("Save current layout"); + btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::save)); + + pnl_content->add(*(btn = new GLtk::Button("Quit"))); + btn->set_geometry(GLtk::Geometry(80, 10, 40, 24)); + btn->set_style("red"); + btn->set_tooltip("Exit Designer"); + btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::quit)); +} diff --git a/source/designer/layoutbar.h b/source/designer/layoutbar.h new file mode 100644 index 0000000..20a129c --- /dev/null +++ b/source/designer/layoutbar.h @@ -0,0 +1,21 @@ +/* $Id$ + +This file is part of R²C² +Copyright © 2010 Mikkosoft Productions, Mikko Rasa +Distributed under the GPL +*/ + +#ifndef LAYOUTBAR_H_ +#define LAYOUTBAR_H_ + +#include "toolbar.h" + +class Designer; + +class Layoutbar: public Toolbar +{ +public: + Layoutbar(Designer &); +}; + +#endif diff --git a/source/designer/routebar.cpp b/source/designer/routebar.cpp new file mode 100644 index 0000000..0a2b979 --- /dev/null +++ b/source/designer/routebar.cpp @@ -0,0 +1,107 @@ +/* $Id$ + +This file is part of R²C² +Copyright © 2010 Mikkosoft Productions, Mikko Rasa +Distributed under the GPL +*/ + +#include +#include "libr2c2/route.h" +#include "designer.h" +#include "routebar.h" + +using namespace std; +using namespace Msp; +using namespace R2C2; + +Routebar::Routebar(Designer &d): + Toolbar("Route", 370), + designer(d) +{ + pnl_content->add(*(drp_routes = new GLtk::Dropdown)); + drp_routes->set_geometry(GLtk::Geometry(0, 10, 250, 20)); + drp_routes->set_tooltip("Select route to edit"); + drp_routes->append("(new route)"); + drp_routes->signal_item_selected.connect(sigc::mem_fun(this, &Routebar::route_selected)); + + GLtk::Button *btn; + + pnl_content->add(*(btn = new GLtk::Button("Del"))); + btn->set_geometry(GLtk::Geometry(250, 10, 40, 24)); + btn->set_tooltip("Delete the current route"); + btn->signal_clicked.connect(sigc::mem_fun(this, &Routebar::delete_route_clicked)); + + pnl_content->add(*(btn = new GLtk::Button("Name"))); + btn->set_geometry(GLtk::Geometry(290, 10, 40, 24)); + btn->set_tooltip("Rename the current route"); + btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::rename_route)); + + pnl_content->add(*(btn = new GLtk::Button("Add"))); + btn->set_geometry(GLtk::Geometry(330, 10, 40, 24)); + btn->set_tooltip("Add selected tracks to current route"); + btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::add_selection_to_route)); + + designer.get_layout().signal_route_added.connect(sigc::mem_fun(this, &Routebar::route_added)); + designer.get_layout().signal_route_removed.connect(sigc::hide(sigc::mem_fun(this, &Routebar::update_routes))); + + const set &routes = designer.get_layout().get_routes(); + for(set::const_iterator i=routes.begin(); i!=routes.end(); ++i) + (*i)->signal_name_changed.connect(sigc::hide(sigc::mem_fun(this, &Routebar::update_routes))); + + update_routes(); +} + +void Routebar::route_selected(unsigned index, const string &) +{ + if(index==drp_routes->get_n_items()-1) + { + Layout &layout = designer.get_layout(); + const set &routes = layout.get_routes(); + Route *route = new Route(layout); + route->set_name(format("Route %d", routes.size())); + designer.edit_route(route); + + int selected = -1; + unsigned n = 0; + for(set::const_iterator i=routes.begin(); (selected<0 && i!=routes.end()); ++i, ++n) + if(*i==route) + selected = n; + drp_routes->set_selected_index(selected); + } + else + { + const set &routes = designer.get_layout().get_routes(); + set::const_iterator i = routes.begin(); + advance(i, index); + designer.edit_route(*i); + } +} + +void Routebar::delete_route_clicked() +{ + Route *route = designer.get_current_route(); + designer.edit_route(0); + delete route; +} + +void Routebar::route_added(Route &r) +{ + r.signal_name_changed.connect(sigc::hide(sigc::mem_fun(this, &Routebar::update_routes))); + update_routes(); +} + +void Routebar::update_routes() +{ + drp_routes->clear(); + const set &routes = designer.get_layout().get_routes(); + int selected = -1; + unsigned n = 0; + for(set::const_iterator i=routes.begin(); i!=routes.end(); ++i, ++n) + { + drp_routes->append((*i)->get_name()); + if(*i==designer.get_current_route()) + selected = n; + } + drp_routes->append("(new route)"); + drp_routes->set_selected_index(selected); +} diff --git a/source/designer/routebar.h b/source/designer/routebar.h new file mode 100644 index 0000000..005b004 --- /dev/null +++ b/source/designer/routebar.h @@ -0,0 +1,30 @@ +/* $Id$ + +This file is part of R²C² +Copyright © 2010 Mikkosoft Productions, Mikko Rasa +Distributed under the GPL +*/ + +#ifndef ROUTEBAR_H_ +#define ROUTEBAR_H_ + +#include +#include "toolbar.h" + +class Routebar: public Toolbar +{ +private: + Designer &designer; + Msp::GLtk::Dropdown *drp_routes; + +public: + Routebar(Designer &); + +private: + void route_selected(unsigned, const std::string &); + void delete_route_clicked(); + void route_added(R2C2::Route &); + void update_routes(); +}; + +#endif diff --git a/source/designer/selection.h b/source/designer/selection.h index 479f5af..a3d8b30 100644 --- a/source/designer/selection.h +++ b/source/designer/selection.h @@ -24,6 +24,7 @@ public: const std::set &get_tracks() const { return tracks; } R2C2::Track *get_track() const; unsigned size() const { return tracks.size(); } + bool empty() const { return tracks.empty(); } void clear(); diff --git a/source/designer/toolbar.cpp b/source/designer/toolbar.cpp index c6d859b..a4046f5 100644 --- a/source/designer/toolbar.cpp +++ b/source/designer/toolbar.cpp @@ -1,143 +1,64 @@ /* $Id$ This file is part of R²C² -Copyright © 2009-2010 Mikkosoft Productions, Mikko Rasa +Copyright © 2010 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ -#include -#include -#include "libr2c2/route.h" -#include "designer.h" #include "toolbar.h" using namespace std; using namespace Msp; -using namespace R2C2; -Toolbar::Toolbar(Designer &d): - designer(d) +Toolbar::Toolbar(const string &name, unsigned w): + content_width(w), + expanded(true) { - set_size(640, 40); + set_focusable(false); - GLtk::Button *btn; - GLtk::Label *lbl; + add(*(lbl_title = new GLtk::Label(name))); - add(*(btn=new GLtk::Button("Load"))); - btn->set_geometry(GLtk::Geometry(5, 10, 40, 24)); - btn->set_tooltip("Load layout (not implemented)"); + add(*(btn_expand = new GLtk::Button)); + btn_expand->set_size(15, 20); + btn_expand->set_style("arrow_left"); + btn_expand->set_tooltip("Collapse toolbar"); + btn_expand->signal_clicked.connect(sigc::mem_fun(this, &Toolbar::expand_clicked)); - add(*(btn=new GLtk::Button("Save"))); - btn->set_geometry(GLtk::Geometry(45, 10, 40, 24)); - btn->set_tooltip("Save current layout"); - btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::save)); - - add(*(btn=new GLtk::Button("Quit"))); - btn->set_geometry(GLtk::Geometry(85, 10, 40, 24)); - btn->set_style("red"); - btn->set_tooltip("Exit Designer"); - btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::quit)); - - add(*(btn=new GLtk::Button("+Trk"))); - btn->set_geometry(GLtk::Geometry(135, 10, 40, 24)); - btn->set_tooltip("Add a track piece"); - btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::new_track)); - - add(*(btn=new GLtk::Button("Trnt"))); - btn->set_geometry(GLtk::Geometry(175, 10, 40, 24)); - btn->set_tooltip("Set turnout ID of selected track"); - btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::set_turnout_id)); - - add(*(btn=new GLtk::Button("Sens"))); - btn->set_geometry(GLtk::Geometry(215, 10, 40, 24)); - btn->set_tooltip("Set sensor ID of selected tracks"); - btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::set_sensor_id)); - - add(*(lbl=new GLtk::Label("Routes:"))); - lbl->set_geometry(GLtk::Geometry(265, 22, 40, 13)); - - add(*(drp_routes=new GLtk::Dropdown)); - drp_routes->set_geometry(GLtk::Geometry(265, 5, 250, 17)); - drp_routes->set_tooltip("Select route to edit"); - drp_routes->append("(new route)"); - drp_routes->signal_item_selected.connect(sigc::mem_fun(this, &Toolbar::route_selected)); - - add(*(btn=new GLtk::Button("Del"))); - btn->set_geometry(GLtk::Geometry(515, 10, 40, 24)); - btn->set_tooltip("Delete the current route"); - btn->signal_clicked.connect(sigc::mem_fun(this, &Toolbar::delete_route_clicked)); - - add(*(btn=new GLtk::Button("Name"))); - btn->set_geometry(GLtk::Geometry(555, 10, 40, 24)); - btn->set_tooltip("Rename the current route"); - btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::rename_route)); - - add(*(btn=new GLtk::Button("Add"))); - btn->set_geometry(GLtk::Geometry(595, 10, 40, 24)); - btn->set_tooltip("Add selected tracks to current route"); - btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::add_selection_to_route)); - - designer.get_layout().signal_route_added.connect(sigc::mem_fun(this, &Toolbar::route_added)); - designer.get_layout().signal_route_removed.connect(sigc::hide(sigc::mem_fun(this, &Toolbar::update_routes))); - - const set &routes = designer.get_layout().get_routes(); - for(set::const_iterator i=routes.begin(); i!=routes.end(); ++i) - (*i)->signal_name_changed.connect(sigc::hide(sigc::mem_fun(this, &Toolbar::update_routes))); - - update_routes(); + add(*(pnl_content = new GLtk::Panel)); + pnl_content->set_size(content_width, 40); + pnl_content->set_style("group"); } -void Toolbar::route_selected(unsigned index, const string &) +void Toolbar::expand(bool e) { - if(index==drp_routes->get_n_items()-1) - { - Layout &layout = designer.get_layout(); - const set &routes = layout.get_routes(); - Route *route = new Route(layout); - route->set_name(format("Route %d", routes.size())); - designer.edit_route(route); + expanded = e; + btn_expand->set_style(expanded ? "arrow_left" : "arrow_right"); + btn_expand->set_tooltip(expanded ? "Collapse toolbar" : "Expand toolbar"); + pnl_content->set_visible(expanded); - int selected = -1; - unsigned n = 0; - for(set::const_iterator i=routes.begin(); (selected<0 && i!=routes.end()); ++i, ++n) - if(*i==route) - selected = n; - drp_routes->set_selected_index(selected); - } - else - { - const set &routes = designer.get_layout().get_routes(); - set::const_iterator i = routes.begin(); - advance(i, index); - designer.edit_route(*i); - } -} + unsigned w = lbl_title->get_geometry().w+40; + if(expanded) + w += content_width+5; + set_size(w, 40); -void Toolbar::delete_route_clicked() -{ - Route *route = designer.get_current_route(); - designer.edit_route(0); - delete route; + signal_expanded.emit(expanded); } -void Toolbar::route_added(Route &r) +void Toolbar::expand_clicked() { - r.signal_name_changed.connect(sigc::hide(sigc::mem_fun(this, &Toolbar::update_routes))); - update_routes(); + expand(!expanded); } -void Toolbar::update_routes() +void Toolbar::on_style_change() { - drp_routes->clear(); - const set &routes = designer.get_layout().get_routes(); - int selected = -1; - unsigned n = 0; - for(set::const_iterator i=routes.begin(); i!=routes.end(); ++i, ++n) - { - drp_routes->append((*i)->get_name()); - if(*i==designer.get_current_route()) - selected = n; - } - drp_routes->append("(new route)"); - drp_routes->set_selected_index(selected); + lbl_title->autosize(); + const GLtk::Geometry &lbl_geom = lbl_title->get_geometry(); + unsigned w = lbl_geom.w+40; + if(expanded) + w += content_width+5; + set_size(w, 40); + + lbl_title->set_position(10, (geom.h-lbl_geom.h)/2); + btn_expand->set_position(lbl_geom.w+15, 10); + pnl_content->set_position(lbl_geom.w+35, 0); } diff --git a/source/designer/toolbar.h b/source/designer/toolbar.h index 9029a9c..5a2d86c 100644 --- a/source/designer/toolbar.h +++ b/source/designer/toolbar.h @@ -1,33 +1,38 @@ /* $Id$ This file is part of R²C² -Copyright © 2009 Mikkosoft Productions, Mikko Rasa +Copyright © 2010 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ #ifndef TOOLBAR_H_ #define TOOLBAR_H_ -#include -#include +#include +#include #include -#include "libr2c2/route.h" -class Designer; - -class Toolbar: public Msp::GLtk::Panel, public sigc::trackable +class Toolbar: public Msp::GLtk::Panel { +public: + sigc::signal signal_expanded; + private: - Designer &designer; - Msp::GLtk::Dropdown *drp_routes; + unsigned content_width; + Msp::GLtk::Label *lbl_title; + Msp::GLtk::Button *btn_expand; + bool expanded; +protected: + Msp::GLtk::Panel *pnl_content; + + Toolbar(const std::string &, unsigned); public: - Toolbar(Designer &); + void expand(bool); + private: - void route_selected(unsigned, const std::string &); - void delete_route_clicked(); - void route_added(R2C2::Route &); - void update_routes(); + void expand_clicked(); + virtual void on_style_change(); }; #endif diff --git a/source/designer/trackbar.cpp b/source/designer/trackbar.cpp new file mode 100644 index 0000000..9d7ebc5 --- /dev/null +++ b/source/designer/trackbar.cpp @@ -0,0 +1,27 @@ +/* $Id$ + +This file is part of R²C² +Copyright © 2010 Mikkosoft Productions, Mikko Rasa +Distributed under the GPL +*/ + +#include "designer.h" +#include "trackbar.h" + +using namespace Msp; + +Trackbar::Trackbar(Designer &designer): + Toolbar("Track", 80) +{ + GLtk::Button *btn; + + pnl_content->add(*(btn = new GLtk::Button("+Trk"))); + btn->set_geometry(GLtk::Geometry(0, 10, 40, 24)); + btn->set_tooltip("Add a track piece"); + btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::new_track)); + + pnl_content->add(*(btn = new GLtk::Button("Prop"))); + btn->set_geometry(GLtk::Geometry(40, 10, 40, 24)); + btn->set_tooltip("Change properties of selected tracks"); + btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::track_properties)); +} diff --git a/source/designer/trackbar.h b/source/designer/trackbar.h new file mode 100644 index 0000000..7123a19 --- /dev/null +++ b/source/designer/trackbar.h @@ -0,0 +1,21 @@ +/* $Id$ + +This file is part of R²C² +Copyright © 2010 Mikkosoft Productions, Mikko Rasa +Distributed under the GPL +*/ + +#ifndef TRACKBAR_H_ +#define TRACKBAR_H_ + +#include "toolbar.h" + +class Designer; + +class Trackbar: public Toolbar +{ +public: + Trackbar(Designer &); +}; + +#endif diff --git a/source/designer/trackproperties.cpp b/source/designer/trackproperties.cpp new file mode 100644 index 0000000..ce806c5 --- /dev/null +++ b/source/designer/trackproperties.cpp @@ -0,0 +1,94 @@ +/* $Id$ + +This file is part of R²C² +Copyright © 2010 Mikkosoft Productions, Mikko Rasa +Distributed under the GPL +*/ + +#include +#include +#include "libr2c2/tracktype.h" +#include "selection.h" +#include "trackproperties.h" + +using namespace std; +using namespace Msp; +using namespace R2C2; + +TrackProperties::TrackProperties(const Selection &s): + selection(s) +{ + set_size(300, 110); + + GLtk::Label *lbl; + + add(*(lbl = new GLtk::Label("Track properties"))); + lbl->set_geometry(GLtk::Geometry(10, geom.h-30, geom.w-20, 20)); + + add(*(lbl = new GLtk::Label("Turnout ID"))); + lbl->set_geometry(GLtk::Geometry(10, geom.h-65, 70, 20)); + + add(*(ent_turnout_id = new GLtk::Entry)); + ent_turnout_id->set_geometry(GLtk::Geometry(80, geom.h-65, 50, 20)); + + add(*(lbl = new GLtk::Label("Sensor ID"))); + lbl->set_geometry(GLtk::Geometry(150, geom.h-65, 70, 20)); + + add(*(ent_sensor_id = new GLtk::Entry)); + ent_sensor_id->set_geometry(GLtk::Geometry(220, geom.h-65, 50, 20)); + + GLtk::Button *btn; + + add_button(*(btn = new GLtk::Button("Cncl")), 0); + btn->set_geometry(GLtk::Geometry(geom.w-90, 10, 40, 24)); + btn->set_style("red"); + + add_button(*(btn = new GLtk::Button("OK")), 1); + btn->set_geometry(GLtk::Geometry(geom.w-50, 10, 40, 24)); + btn->set_style("green"); + + if(selection.size()==1) + { + if(unsigned tid = selection.get_track()->get_turnout_id()) + ent_turnout_id->set_text(lexical_cast(tid)); + } + + const set &tracks = selection.get_tracks(); + int sensor_id = -1; + for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) + { + if(static_cast((*i)->get_sensor_id())!=sensor_id) + { + if(sensor_id==-1) + sensor_id = (*i)->get_sensor_id(); + else + sensor_id = -2; + } + } + + if(sensor_id>=0) + ent_sensor_id->set_text(lexical_cast(sensor_id)); +} + +void TrackProperties::on_response(int code) +{ + if(code==1) + { + if(selection.size()==1) + { + Track *track = selection.get_track(); + if(track->get_type().is_turnout()) + track->set_turnout_id(lexical_cast(ent_turnout_id->get_text())); + } + + string sensor_id_text = ent_sensor_id->get_text(); + if(!sensor_id_text.empty()) + { + unsigned sensor_id = lexical_cast(sensor_id_text); + const set &tracks = selection.get_tracks(); + for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) + if(!(*i)->get_type().is_turnout()) + (*i)->set_sensor_id(sensor_id); + } + } +} diff --git a/source/designer/trackproperties.h b/source/designer/trackproperties.h new file mode 100644 index 0000000..a1fe450 --- /dev/null +++ b/source/designer/trackproperties.h @@ -0,0 +1,30 @@ +/* $Id$ + +This file is part of R²C² +Copyright © 2010 Mikkosoft Productions, Mikko Rasa +Distributed under the GPL +*/ + +#ifndef TRACKPROPERTIES_H_ +#define TRACKPROPERTIES_H_ + +#include +#include + +class Selection; + +class TrackProperties: public Msp::GLtk::Dialog +{ +private: + const Selection &selection; + Msp::GLtk::Entry *ent_turnout_id; + Msp::GLtk::Entry *ent_sensor_id; + +public: + TrackProperties(const Selection &); + +private: + virtual void on_response(int); +}; + +#endif