]> git.tdb.fi Git - r2c2.git/commitdiff
Give tools access to the keyboard
authorMikko Rasa <tdb@tdb.fi>
Sat, 24 Aug 2013 12:43:43 +0000 (15:43 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 24 Aug 2013 12:43:43 +0000 (15:43 +0300)
17 files changed:
source/designer/designer.cpp
source/designer/elevatetool.cpp
source/designer/elevatetool.h
source/designer/extendtool.cpp
source/designer/extendtool.h
source/designer/manipulator.cpp
source/designer/manipulator.h
source/designer/measure.cpp
source/designer/measure.h
source/designer/movetool.cpp
source/designer/movetool.h
source/designer/rotatetool.cpp
source/designer/rotatetool.h
source/designer/slopetool.cpp
source/designer/slopetool.h
source/designer/tool.cpp
source/designer/tool.h

index 292d5a9cb12a3e43c6b952b9306d8588644987b2..cfe3938a91d3c6258d631467f14d1bd0ad7ae5ac 100644 (file)
@@ -398,14 +398,9 @@ void Designer::key_press(unsigned key)
                use_tool_with_selected_objects<ElevateTool>();
        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<typename T>
 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<typename T>
 T *Designer::use_tool()
 {
-       T *tool = new T(*this, mouse);
+       T *tool = new T(*this, keyboard, mouse);
        use_tool(tool);
        return tool;
 }
index 6675c5de3ab225858a5cea39744c87acbf328585..02c459b9b7babcb726ba9efc7538c60873deac73 100644 (file)
@@ -5,8 +5,8 @@ using namespace std;
 using namespace Msp;
 using namespace R2C2;
 
-ElevateTool::ElevateTool(Designer &d, Input::Mouse &m, const set<Object *> &o):
-       Manipulator(d, m, o)
+ElevateTool::ElevateTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set<Object *> &o):
+       Manipulator(d, k, m, o)
 {
        origin = pointer.y;
 }
index 34c54e7e1fe95a5e7305b3f2ec0ebd13fec9e88c..801a69de9a35bbc426acf00d3b902ececf2bbd0f 100644 (file)
@@ -9,7 +9,7 @@ private:
        float origin;
 
 public:
-       ElevateTool(Designer &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
+       ElevateTool(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
 
        virtual void axis_motion(unsigned, float, float);
 };
index a5dea819a192132aca5454864203bcc7dddf8bb1..3af4cf6cd0b1398f719e79346e3151794ff52939 100644 (file)
@@ -7,8 +7,8 @@ using namespace std;
 using namespace Msp;
 using namespace R2C2;
 
-ExtendTool::ExtendTool(Designer &d, Input::Mouse &m, const set<Object *> &objects):
-       Tool(d, m)
+ExtendTool::ExtendTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set<Object *> &objects):
+       Tool(d, k, m)
 {
        for(set<Object *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
                if(Track *t = dynamic_cast<Track *>(*i))
index 8a7ebebe6fadd75de56549756c0e61bba6acb2b0..69e184aceae37afc7ce3837725d9b0bfc3535ed9 100644 (file)
@@ -14,7 +14,7 @@ private:
        std::vector<R2C2::Track *> extend_tracks;
 
 public:
-       ExtendTool(Designer &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
+       ExtendTool(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
        virtual ~ExtendTool();
 
        void connect();
index 6c917b1824b9c585039fad2d24119e2ca3a8661a..77269228b88567f92dc9575dd1a49ce7c955f98a 100644 (file)
@@ -10,8 +10,8 @@ using namespace std;
 using namespace R2C2;
 using namespace Msp;
 
-Manipulator::Manipulator(Designer &d, Input::Mouse &m, const set<Object *> &objs):
-       Tool(d, m)
+Manipulator::Manipulator(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set<Object *> &objs):
+       Tool(d, k, m)
 {
        set<Object *> pending = objs;
        while(!pending.empty())
index efbdfa5fba351bf02bfff552e315a06d22f25ccb..7b3836649d5cfd5a1a6e7c15fea920bde2b6399c 100644 (file)
@@ -30,7 +30,7 @@ protected:
        R2C2::Vector center;
 
 public:
-       Manipulator(Designer &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
+       Manipulator(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
        virtual ~Manipulator();
 
 private:
index e12378061fe35dadefdcfe21da818d0f160f8172..937856c55bcce61a5baaae44c21d33907d3a9947 100644 (file)
@@ -1,6 +1,7 @@
 #include <cmath>
 #include <msp/gl/meshbuilder.h>
 #include <msp/gl/renderer.h>
+#include <msp/input/keys.h>
 #include <msp/strings/format.h>
 #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()
index 41ea18ee91135f237e809c8fdb27c90d66ad3146..31f5f2a7b9323574ce3a01ba374e3a95d48ed84a 100644 (file)
@@ -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();
 
index 29d2857faab119edc68603746e58849b64b32173..fa78ba73c3a38e14b11e15ae59772dce62e83d4b 100644 (file)
@@ -6,8 +6,8 @@ using namespace std;
 using namespace Msp;
 using namespace R2C2;
 
-MoveTool::MoveTool(Designer &d, Input::Mouse &m, const set<Object *> &o):
-       Manipulator(d, m, o),
+MoveTool::MoveTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set<Object *> &o):
+       Manipulator(d, k, m, o),
        origin(ground_pointer)
 {
        for(ObjectArray::iterator i=objects.begin(); i!=objects.end(); ++i)
index 40665c5bfa5eba6f15b1dcc15fca1a3d166f32ea..548315e06444bd86df3edafd1ab7e175eb8960f6 100644 (file)
@@ -21,7 +21,7 @@ private:
        R2C2::Vector origin;
 
 public:
-       MoveTool(Designer &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
+       MoveTool(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
 
        virtual void pointer_motion();
 };
index 63f237197ccf96680289418a38510a0d66221b8c..858b2230b0c0acf7925123ddbdb92ec4d4f4aa0b 100644 (file)
@@ -4,8 +4,8 @@ using namespace std;
 using namespace Msp;
 using namespace R2C2;
 
-RotateTool::RotateTool(Designer &d, Input::Mouse &m, const set<Object *> &o):
-       Manipulator(d, m, o),
+RotateTool::RotateTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set<Object *> &o):
+       Manipulator(d, k, m, o),
        origin(Geometry::atan2(ground_pointer.y-center.y, ground_pointer.x-center.x))
 { }
 
index 3a2ce5dd27258adf916b50416e6ba913d155dcf9..8bb9fe01d3611761e2552a4ff03a98dcbdc6fa4c 100644 (file)
@@ -10,7 +10,7 @@ private:
        R2C2::Angle angle;
 
 public:
-       RotateTool(Designer &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
+       RotateTool(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
 
        virtual void pointer_motion();
 };
index 96a78bf6aaefdb1f845e42f3154808d5deefcddc..58a50e1507cf7efad982cf0b0aaaedb08929fe8f 100644 (file)
@@ -5,8 +5,8 @@ using namespace std;
 using namespace Msp;
 using namespace R2C2;
 
-SlopeTool::SlopeTool(Designer &d, Input::Mouse &m, const set<Object *> &objects):
-       Tool(d, m),
+SlopeTool::SlopeTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set<Object *> &objects):
+       Tool(d, k, m),
        total_length(0)
 {
        for(set<Object *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
index 9edc1d8c817c3fdf8167fd19f57ca925006f4279..d319bb7715c90bc0aad77a29dd3e5a99bfd7dd09 100644 (file)
@@ -12,7 +12,7 @@ private:
        float total_length;
 
 public:
-       SlopeTool(Designer &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
+       SlopeTool(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
 
        void even_slope(bool =false);
        void flatten();
index ffd6e6b6c5385201a1f5041eab1bbd27a71aafb5..eeef8829c9bc994af6c67b84381fb52380bb719f 100644 (file)
@@ -1,14 +1,17 @@
 #include <sigc++/bind.h>
+#include <msp/input/keys.h>
 #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)
index 137ac5c326e26fd767fd14decc604a26a0eeae65..3119bc0327ce715dedf00f76bbcbc399e9b6213d 100644 (file)
@@ -4,6 +4,7 @@
 #include <string>
 #include <sigc++/signal.h>
 #include <sigc++/trackable.h>
+#include <msp/input/keyboard.h>
 #include <msp/input/mouse.h>
 #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() { }