From 2abb7008a1e2b93b77742693becf6fe0b8567d6e Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 18 Nov 2010 18:52:38 +0000 Subject: [PATCH] More toolbar buttons Add shortcut keys to tooltips Don't start extend if no suitable tracks are selected Check that we are in select mode before doing stuff --- source/designer/designer.cpp | 67 ++++++++++++++++++++++++--------- source/designer/designer.h | 4 ++ source/designer/layoutbar.cpp | 11 ++++-- source/designer/manipulator.cpp | 18 ++++++++- source/designer/manipulator.h | 2 +- source/designer/routebar.cpp | 3 +- source/designer/trackbar.cpp | 32 +++++++++++++--- 7 files changed, 107 insertions(+), 30 deletions(-) diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index 34398f3..86fc349 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -189,12 +189,30 @@ void Designer::quit() void Designer::new_track() { + if(mode!=SELECT) + return; + mode = CATALOGUE; + lbl_status->set_text("Select new track or press Esc to cancel"); +} + +void Designer::erase_tracks() +{ + if(mode!=SELECT) + return; + + set tracks = selection.get_tracks(); + selection.clear(); + for(set::iterator i=tracks.begin(); i!=tracks.end(); ++i) + { + overlay->clear(layout_3d->get_track(**i)); + delete *i; + } } void Designer::track_properties() { - if(selection.empty()) + if(mode!=SELECT || selection.empty()) return; TrackProperties *track_prop = new TrackProperties(selection); @@ -206,9 +224,34 @@ void Designer::track_properties() track_prop->signal_response.connect(sigc::mem_fun(this, &Designer::track_properties_response)); } +void Designer::extend_track() +{ + if(mode!=SELECT) + return; + + if(manipulator.start_extend()) + mode = MANIPULATE; +} + +void Designer::connect_tracks() +{ + if(mode!=SELECT) + return; + + manipulator.connect(); +} + +void Designer::flatten_tracks() +{ + if(mode!=SELECT) + return; + + manipulator.flatten(); +} + void Designer::rename_route() { - if(!cur_route) + if(mode!=SELECT || !cur_route) return; InputDialog *input = new InputDialog(*this, "Route name", cur_route->get_name()); @@ -282,10 +325,7 @@ void Designer::key_press(unsigned key, unsigned mod, wchar_t) mod = Input::mod_from_sys(mod); if(key==Msp::Input::KEY_N && (mod&Input::MOD_SHIFT)) - { - manipulator.start_extend(); - mode = MANIPULATE; - } + extend_track(); else if(key==Msp::Input::KEY_N) new_track(); else if(key==Msp::Input::KEY_G) @@ -332,16 +372,7 @@ void Designer::key_press(unsigned key, unsigned mod, wchar_t) selection.clear(); } else if(key==Msp::Input::KEY_X) - { - set tracks = selection.get_tracks(); - selection.clear(); - for(set::iterator i=tracks.begin(); i!=tracks.end(); ++i) - { - overlay->clear(layout_3d->get_track(**i)); - layout->remove_track(**i); - delete *i; - } - } + erase_tracks(); else if(key==Msp::Input::KEY_F && (mod&Input::MOD_SHIFT)) { const set &tracks = selection.get_tracks(); @@ -358,7 +389,7 @@ void Designer::key_press(unsigned key, unsigned mod, wchar_t) } } else if(key==Msp::Input::KEY_F) - manipulator.flatten(); + flatten_tracks(); else if(key==Msp::Input::KEY_E && (mod&Input::MOD_SHIFT)) manipulator.even_slope(true); else if(key==Msp::Input::KEY_E) @@ -366,7 +397,7 @@ void Designer::key_press(unsigned key, unsigned mod, wchar_t) else if(key==Msp::Input::KEY_A) add_selection_to_route(); else if(key==Msp::Input::KEY_C) - manipulator.connect(); + connect_tracks(); else if(key==Msp::Input::KEY_V) svg_export(); else if(key==Msp::Input::KEY_P) diff --git a/source/designer/designer.h b/source/designer/designer.h index e8d0d76..2a53745 100644 --- a/source/designer/designer.h +++ b/source/designer/designer.h @@ -94,7 +94,11 @@ public: Msp::GLtk::Root &get_root() { return root; } void new_track(); + void erase_tracks(); void track_properties(); + void extend_track(); + void connect_tracks(); + void flatten_tracks(); void rename_route(); void svg_export(); diff --git a/source/designer/layoutbar.cpp b/source/designer/layoutbar.cpp index d47485f..3e17eac 100644 --- a/source/designer/layoutbar.cpp +++ b/source/designer/layoutbar.cpp @@ -11,7 +11,7 @@ Distributed under the GPL using namespace Msp; Layoutbar::Layoutbar(Designer &designer): - Toolbar("Layout", 120) + Toolbar("Layout", 160) { GLtk::Button *btn; @@ -21,11 +21,16 @@ Layoutbar::Layoutbar(Designer &designer): pnl_content->add(*(btn = new GLtk::Button("Save"))); btn->set_geometry(GLtk::Geometry(40, 10, 40, 24)); - btn->set_tooltip("Save current layout"); + btn->set_tooltip("Save current layout (W)"); btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::save)); - pnl_content->add(*(btn = new GLtk::Button("Quit"))); + pnl_content->add(*(btn = new GLtk::Button("SVG"))); btn->set_geometry(GLtk::Geometry(80, 10, 40, 24)); + btn->set_tooltip("Export layout as SVG (V)"); + btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::svg_export)); + + pnl_content->add(*(btn = new GLtk::Button("Quit"))); + btn->set_geometry(GLtk::Geometry(120, 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/manipulator.cpp b/source/designer/manipulator.cpp index 23ea138..720309b 100644 --- a/source/designer/manipulator.cpp +++ b/source/designer/manipulator.cpp @@ -59,12 +59,26 @@ void Manipulator::start_elevate() mode = ELEVATE; } -void Manipulator::start_extend() +bool Manipulator::start_extend() { if(mode) cancel(); - mode = EXTEND; + bool ok = false; + const set &stracks = selection.get_tracks(); + for(set::const_iterator i=stracks.begin(); (!ok && i!=stracks.end()); ++i) + { + const vector &links = (*i)->get_links(); + for(vector::const_iterator j=links.begin(); (!ok && j!=links.end()); ++j) + ok = !*j; + } + + if(ok) + mode = EXTEND; + else + signal_status.emit("No free endpoints"); + + return ok; } void Manipulator::duplicate() diff --git a/source/designer/manipulator.h b/source/designer/manipulator.h index 66b5d1a..75fafe5 100644 --- a/source/designer/manipulator.h +++ b/source/designer/manipulator.h @@ -69,7 +69,7 @@ public: void start_move(); void start_rotate(); void start_elevate(); - void start_extend(); + bool start_extend(); void duplicate(); void flatten(); void even_slope(bool =false); diff --git a/source/designer/routebar.cpp b/source/designer/routebar.cpp index 0a2b979..da9a5cf 100644 --- a/source/designer/routebar.cpp +++ b/source/designer/routebar.cpp @@ -28,6 +28,7 @@ Routebar::Routebar(Designer &d): pnl_content->add(*(btn = new GLtk::Button("Del"))); btn->set_geometry(GLtk::Geometry(250, 10, 40, 24)); + btn->set_style("red"); btn->set_tooltip("Delete the current route"); btn->signal_clicked.connect(sigc::mem_fun(this, &Routebar::delete_route_clicked)); @@ -38,7 +39,7 @@ Routebar::Routebar(Designer &d): 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->set_tooltip("Add selected tracks to current route (A)"); 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)); diff --git a/source/designer/trackbar.cpp b/source/designer/trackbar.cpp index 9d7ebc5..b05f3c8 100644 --- a/source/designer/trackbar.cpp +++ b/source/designer/trackbar.cpp @@ -11,17 +11,39 @@ Distributed under the GPL using namespace Msp; Trackbar::Trackbar(Designer &designer): - Toolbar("Track", 80) + Toolbar("Track", 240) { GLtk::Button *btn; - pnl_content->add(*(btn = new GLtk::Button("+Trk"))); + pnl_content->add(*(btn = new GLtk::Button("New"))); btn->set_geometry(GLtk::Geometry(0, 10, 40, 24)); - btn->set_tooltip("Add a track piece"); + btn->set_style("green"); + btn->set_tooltip("Add a track piece (N)"); btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::new_track)); - pnl_content->add(*(btn = new GLtk::Button("Prop"))); + pnl_content->add(*(btn = new GLtk::Button("Del"))); btn->set_geometry(GLtk::Geometry(40, 10, 40, 24)); - btn->set_tooltip("Change properties of selected tracks"); + btn->set_style("red"); + btn->set_tooltip("Delete selected tracks (X)"); + btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::erase_tracks)); + + pnl_content->add(*(btn = new GLtk::Button("Prop"))); + btn->set_geometry(GLtk::Geometry(80, 10, 40, 24)); + btn->set_tooltip("Change properties of selected tracks (P)"); btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::track_properties)); + + pnl_content->add(*(btn = new GLtk::Button("Xtnd"))); + btn->set_geometry(GLtk::Geometry(120, 10, 40, 24)); + btn->set_tooltip("Extend straight track out of free endpoint (Shift+N)"); + btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::extend_track)); + + pnl_content->add(*(btn = new GLtk::Button("Conn"))); + btn->set_geometry(GLtk::Geometry(160, 10, 40, 24)); + btn->set_tooltip("Connect free endpoints of selected tracks (C)"); + btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::connect_tracks)); + + pnl_content->add(*(btn = new GLtk::Button("Flat"))); + btn->set_geometry(GLtk::Geometry(200, 10, 40, 24)); + btn->set_tooltip("Make selected tracks flat (F)"); + btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::flatten_tracks)); } -- 2.45.2