From: Mikko Rasa Date: Sat, 24 Aug 2013 12:43:43 +0000 (+0300) Subject: Give tools access to the keyboard X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a7bce7810670436ab667c034c80291b2f712d2a2;p=r2c2.git Give tools access to the keyboard --- diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index 292d5a9..cfe3938 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -398,14 +398,9 @@ void Designer::key_press(unsigned key) use_tool_with_selected_objects(); else if(key==Msp::Input::KEY_ESC) { - if(cur_tool) - { - delete cur_tool; - cur_tool = 0; - } - else if(mode==CATALOGUE) + if(mode==CATALOGUE) mode = SELECT; - else + else if(mode==SELECT) selection.clear(); } else if(key==Msp::Input::KEY_X) @@ -449,7 +444,7 @@ void Designer::key_press(unsigned key) template T *Designer::use_tool_with_selected_objects() { - T *tool = new T(*this, mouse, selection.get_objects()); + T *tool = new T(*this, keyboard, mouse, selection.get_objects()); use_tool(tool); return tool; } @@ -457,7 +452,7 @@ T *Designer::use_tool_with_selected_objects() template T *Designer::use_tool() { - T *tool = new T(*this, mouse); + T *tool = new T(*this, keyboard, mouse); use_tool(tool); return tool; } diff --git a/source/designer/elevatetool.cpp b/source/designer/elevatetool.cpp index 6675c5d..02c459b 100644 --- a/source/designer/elevatetool.cpp +++ b/source/designer/elevatetool.cpp @@ -5,8 +5,8 @@ using namespace std; using namespace Msp; using namespace R2C2; -ElevateTool::ElevateTool(Designer &d, Input::Mouse &m, const set &o): - Manipulator(d, m, o) +ElevateTool::ElevateTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set &o): + Manipulator(d, k, m, o) { origin = pointer.y; } diff --git a/source/designer/elevatetool.h b/source/designer/elevatetool.h index 34c54e7..801a69d 100644 --- a/source/designer/elevatetool.h +++ b/source/designer/elevatetool.h @@ -9,7 +9,7 @@ private: float origin; public: - ElevateTool(Designer &, Msp::Input::Mouse &, const std::set &); + ElevateTool(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &, const std::set &); virtual void axis_motion(unsigned, float, float); }; diff --git a/source/designer/extendtool.cpp b/source/designer/extendtool.cpp index a5dea81..3af4cf6 100644 --- a/source/designer/extendtool.cpp +++ b/source/designer/extendtool.cpp @@ -7,8 +7,8 @@ using namespace std; using namespace Msp; using namespace R2C2; -ExtendTool::ExtendTool(Designer &d, Input::Mouse &m, const set &objects): - Tool(d, m) +ExtendTool::ExtendTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set &objects): + Tool(d, k, m) { for(set::const_iterator i=objects.begin(); i!=objects.end(); ++i) if(Track *t = dynamic_cast(*i)) diff --git a/source/designer/extendtool.h b/source/designer/extendtool.h index 8a7ebeb..69e184a 100644 --- a/source/designer/extendtool.h +++ b/source/designer/extendtool.h @@ -14,7 +14,7 @@ private: std::vector extend_tracks; public: - ExtendTool(Designer &, Msp::Input::Mouse &, const std::set &); + ExtendTool(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &, const std::set &); virtual ~ExtendTool(); void connect(); diff --git a/source/designer/manipulator.cpp b/source/designer/manipulator.cpp index 6c917b1..7726922 100644 --- a/source/designer/manipulator.cpp +++ b/source/designer/manipulator.cpp @@ -10,8 +10,8 @@ using namespace std; using namespace R2C2; using namespace Msp; -Manipulator::Manipulator(Designer &d, Input::Mouse &m, const set &objs): - Tool(d, m) +Manipulator::Manipulator(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set &objs): + Tool(d, k, m) { set pending = objs; while(!pending.empty()) diff --git a/source/designer/manipulator.h b/source/designer/manipulator.h index efbdfa5..7b38366 100644 --- a/source/designer/manipulator.h +++ b/source/designer/manipulator.h @@ -30,7 +30,7 @@ protected: R2C2::Vector center; public: - Manipulator(Designer &, Msp::Input::Mouse &, const std::set &); + Manipulator(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &, const std::set &); virtual ~Manipulator(); private: diff --git a/source/designer/measure.cpp b/source/designer/measure.cpp index e123780..937856c 100644 --- a/source/designer/measure.cpp +++ b/source/designer/measure.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "designer.h" #include "3d/layout.h" @@ -10,8 +11,8 @@ using namespace std; using namespace R2C2; using namespace Msp; -Measure::Measure(Designer &d, Input::Mouse &m): - Tool(d, m), +Measure::Measure(Designer &d, Input::Keyboard &k, Input::Mouse &m): + Tool(d, k, m), start_pinned(false), mesh((GL::COLOR4_UBYTE, GL::VERTEX3)) { @@ -25,6 +26,25 @@ Measure::~Measure() designer.get_layout_3d().get_scene().remove(*this); } +void Measure::back() +{ + if(start_pinned) + { + start_pinned = false; + update_mesh(); + } + else + set_done(true); +} + +void Measure::key_press(unsigned key) +{ + if(key==Input::KEY_ESC) + back(); + else + Tool::key_press(key); +} + void Measure::button_press(unsigned btn) { if(btn==1) @@ -36,15 +56,7 @@ void Measure::button_press(unsigned btn) start_pinned = true; } else if(btn==3) - { - if(start_pinned) - { - start_pinned = false; - update_mesh(); - } - else - set_done(true); - } + back(); } void Measure::pointer_motion() diff --git a/source/designer/measure.h b/source/designer/measure.h index 41ea18e..31f5f2a 100644 --- a/source/designer/measure.h +++ b/source/designer/measure.h @@ -19,7 +19,7 @@ private: Msp::GL::Mesh mesh; public: - Measure(Designer &, Msp::Input::Mouse &); + Measure(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &); virtual ~Measure(); float get_parallel_distance() const { return par_dist; } @@ -27,6 +27,8 @@ public: const R2C2::Angle &get_angle_difference() const { return adiff; } private: + void back(); + virtual void key_press(unsigned); virtual void button_press(unsigned); virtual void pointer_motion(); diff --git a/source/designer/movetool.cpp b/source/designer/movetool.cpp index 29d2857..fa78ba7 100644 --- a/source/designer/movetool.cpp +++ b/source/designer/movetool.cpp @@ -6,8 +6,8 @@ using namespace std; using namespace Msp; using namespace R2C2; -MoveTool::MoveTool(Designer &d, Input::Mouse &m, const set &o): - Manipulator(d, m, o), +MoveTool::MoveTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set &o): + Manipulator(d, k, m, o), origin(ground_pointer) { for(ObjectArray::iterator i=objects.begin(); i!=objects.end(); ++i) diff --git a/source/designer/movetool.h b/source/designer/movetool.h index 40665c5..548315e 100644 --- a/source/designer/movetool.h +++ b/source/designer/movetool.h @@ -21,7 +21,7 @@ private: R2C2::Vector origin; public: - MoveTool(Designer &, Msp::Input::Mouse &, const std::set &); + MoveTool(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &, const std::set &); virtual void pointer_motion(); }; diff --git a/source/designer/rotatetool.cpp b/source/designer/rotatetool.cpp index 63f2371..858b223 100644 --- a/source/designer/rotatetool.cpp +++ b/source/designer/rotatetool.cpp @@ -4,8 +4,8 @@ using namespace std; using namespace Msp; using namespace R2C2; -RotateTool::RotateTool(Designer &d, Input::Mouse &m, const set &o): - Manipulator(d, m, o), +RotateTool::RotateTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set &o): + Manipulator(d, k, m, o), origin(Geometry::atan2(ground_pointer.y-center.y, ground_pointer.x-center.x)) { } diff --git a/source/designer/rotatetool.h b/source/designer/rotatetool.h index 3a2ce5d..8bb9fe0 100644 --- a/source/designer/rotatetool.h +++ b/source/designer/rotatetool.h @@ -10,7 +10,7 @@ private: R2C2::Angle angle; public: - RotateTool(Designer &, Msp::Input::Mouse &, const std::set &); + RotateTool(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &, const std::set &); virtual void pointer_motion(); }; diff --git a/source/designer/slopetool.cpp b/source/designer/slopetool.cpp index 96a78bf..58a50e1 100644 --- a/source/designer/slopetool.cpp +++ b/source/designer/slopetool.cpp @@ -5,8 +5,8 @@ using namespace std; using namespace Msp; using namespace R2C2; -SlopeTool::SlopeTool(Designer &d, Input::Mouse &m, const set &objects): - Tool(d, m), +SlopeTool::SlopeTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set &objects): + Tool(d, k, m), total_length(0) { for(set::const_iterator i=objects.begin(); i!=objects.end(); ++i) diff --git a/source/designer/slopetool.h b/source/designer/slopetool.h index 9edc1d8..d319bb7 100644 --- a/source/designer/slopetool.h +++ b/source/designer/slopetool.h @@ -12,7 +12,7 @@ private: float total_length; public: - SlopeTool(Designer &, Msp::Input::Mouse &, const std::set &); + SlopeTool(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &, const std::set &); void even_slope(bool =false); void flatten(); diff --git a/source/designer/tool.cpp b/source/designer/tool.cpp index ffd6e6b..eeef882 100644 --- a/source/designer/tool.cpp +++ b/source/designer/tool.cpp @@ -1,14 +1,17 @@ #include +#include #include "designer.h" #include "tool.h" using namespace Msp; -Tool::Tool(Designer &d, Input::Mouse &mouse): +Tool::Tool(Designer &d, Input::Keyboard &keyboard, Input::Mouse &mouse): designer(d), done(false), accepted(false) { + keyboard.signal_button_press.connect(sigc::bind_return(sigc::mem_fun(this, &Tool::key_press), false)); + keyboard.signal_button_release.connect(sigc::bind_return(sigc::mem_fun(this, &Tool::key_release), false)); mouse.signal_button_press.connect(sigc::bind_return(sigc::mem_fun(this, &Tool::button_press), false)); mouse.signal_axis_motion.connect(sigc::bind_return(sigc::mem_fun(this, &Tool::axis_motion), false)); @@ -30,6 +33,24 @@ void Tool::set_done(bool a) signal_done.emit(); } +void Tool::key_press(unsigned key) +{ + if(key==Input::KEY_ESC) + set_done(false); + else if(key==Input::KEY_SHIFT_L || key==Input::KEY_SHIFT_R) + shift_held = true; + else if(key==Input::KEY_CTRL_L || key==Input::KEY_CTRL_R) + ctrl_held = true; +} + +void Tool::key_release(unsigned key) +{ + if(key==Input::KEY_SHIFT_L || key==Input::KEY_SHIFT_R) + shift_held = false; + else if(key==Input::KEY_CTRL_L || key==Input::KEY_CTRL_R) + ctrl_held = false; +} + void Tool::button_press(unsigned btn) { if(btn==1) diff --git a/source/designer/tool.h b/source/designer/tool.h index 137ac5c..3119bc0 100644 --- a/source/designer/tool.h +++ b/source/designer/tool.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "libr2c2/geometry.h" @@ -20,11 +21,13 @@ protected: Designer &designer; R2C2::Vector pointer; R2C2::Vector ground_pointer; + bool shift_held; + bool ctrl_held; std::string status; bool done; bool accepted; - Tool(Designer &, Msp::Input::Mouse &); + Tool(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &); public: virtual ~Tool() { } @@ -36,6 +39,8 @@ public: bool is_done() const { return done; } protected: + virtual void key_press(unsigned); + virtual void key_release(unsigned); virtual void button_press(unsigned); virtual void axis_motion(unsigned, float, float); virtual void pointer_motion() { }