]> git.tdb.fi Git - r2c2.git/commitdiff
Connect manipulator directly to event signals
authorMikko Rasa <tdb@tdb.fi>
Thu, 4 Nov 2010 08:10:50 +0000 (08:10 +0000)
committerMikko Rasa <tdb@tdb.fi>
Thu, 4 Nov 2010 08:10:50 +0000 (08:10 +0000)
Give map_pointer_coords a better name

source/designer/designer.cpp
source/designer/designer.h
source/designer/manipulator.cpp
source/designer/manipulator.h

index c071b5b4612d46d47d331d6545fd07da008e7483..51dad8f1a6ee4d42b3bcab4bbae1667952e5953e 100644 (file)
@@ -49,7 +49,7 @@ Designer::Designer(int argc, char **argv):
        base_object(0),
        cur_route(0),
        mode(SELECT),
-       manipulator(*this, selection),
+       manipulator(*this, root, selection),
        measure(*this),
        camera_ctl(*this, root, camera),
        track_wrap(*this, selection)
@@ -248,7 +248,7 @@ void Designer::add_selection_to_route()
        show_route(cur_route);
 }
 
-Point Designer::map_pointer_coords(int x, int y)
+Point Designer::map_pointer_to_ground(int x, int y)
 {
        float xf = x*2.0/window.get_width()-1.0;
        float yf = y*2.0/window.get_height()-1.0;
@@ -379,7 +379,7 @@ void Designer::button_press(int x, int y, unsigned btn, unsigned mod)
        y = window.get_height()-y-1;
        mod = Input::mod_from_sys(mod);
 
-       Point ground = map_pointer_coords(x, y);
+       Point ground = map_pointer_to_ground(x, y);
 
        if(mode==CATALOGUE)
        {
@@ -413,8 +413,6 @@ void Designer::button_press(int x, int y, unsigned btn, unsigned mod)
                        }
                }
        }
-       else if(mode==MANIPULATE)
-               manipulator.button_press(x, y, ground.x, ground.y, btn);
        else if(mode==MEASURE)
                measure.button_press(x, y, ground.x, ground.y, btn);
 }
@@ -425,8 +423,7 @@ void Designer::pointer_motion(int x, int y)
 
        if(!root.get_child_at(x, y))
        {
-               Point ground = map_pointer_coords(x, y);
-               manipulator.pointer_motion(x, y, ground.x, ground.y);
+               Point ground = map_pointer_to_ground(x, y);
                measure.pointer_motion(x, y, ground.x, ground.y);
        }
 }
index dbbd1923ca1b47a9fb6c42a0cac464253c574618..07b34876a06cb4a97486fac32e0160601c9760e1 100644 (file)
@@ -101,7 +101,7 @@ public:
        Marklin::Route *get_current_route() const { return cur_route; }
        void add_selection_to_route();
 
-       Marklin::Point map_pointer_coords(int, int);
+       Marklin::Point map_pointer_to_ground(int, int);
 private:
        void tick();
        void key_press(unsigned, unsigned, wchar_t);
index aad20a084b84bcd0511192e25d2f7fb087502821..e9d6b955f05619e678223200398a8ea8db3b0c85 100644 (file)
@@ -17,12 +17,15 @@ using namespace std;
 using namespace Marklin;
 using namespace Msp;
 
-Manipulator::Manipulator(Designer &d, Selection &s):
+Manipulator::Manipulator(Designer &d, Graphics::EventSource &es, Selection &s):
        designer(d),
+       event_source(es),
        selection(s),
        mode(NONE),
        angle(0)
 {
+       event_source.signal_button_press.connect(sigc::mem_fun(this, &Manipulator::button_press));
+       event_source.signal_pointer_motion.connect(sigc::mem_fun(this, &Manipulator::pointer_motion));
        selection.signal_changed.connect(sigc::mem_fun(this, &Manipulator::selection_changed));
 }
 
@@ -306,11 +309,14 @@ void Manipulator::cancel()
        signal_done.emit(false);
 }
 
-void Manipulator::button_press(int, int, float, float, unsigned btn)
+void Manipulator::button_press(int, int, unsigned btn, unsigned)
 {
+       if(!mode)
+               return;
+
        if(btn==3)
                cancel();
-       else if(btn==1 && mode)
+       else if(btn==1)
        {
                Mode m = mode;
                mode = NONE;
@@ -350,10 +356,10 @@ void Manipulator::button_press(int, int, float, float, unsigned btn)
        }
 }
 
-void Manipulator::pointer_motion(int, int y, float gx, float gy)
+void Manipulator::pointer_motion(int x, int y)
 {
        pointer_y = y;
-       gpointer = Point(gx, gy, 0);
+       gpointer = designer.map_pointer_to_ground(x, event_source.get_height()-1-y);
 
        if(mode==MOVE)
        {
@@ -439,8 +445,8 @@ void Manipulator::pointer_motion(int, int y, float gx, float gy)
                                float ep_dir = i->track->get_endpoint_direction(j);
                                float c = cos(ep_dir);
                                float s = sin(ep_dir);
-                               float dx = gx-ep_pos.x;
-                               float dy = gy-ep_pos.y;
+                               float dx = gpointer.x-ep_pos.x;
+                               float dy = gpointer.y-ep_pos.y;
 
                                float len = dx*c+dy*s;
                                if(len<length)
index 8fddced8df910f159a25e240537434e0d9dc6248..55d2425ad8bfdb98596bd33877da65eaa25e18a8 100644 (file)
@@ -48,6 +48,7 @@ public:
 
 private:
        Designer &designer;
+       Msp::Graphics::EventSource &event_source;
        Selection &selection;
        std::vector<MTrack> tracks;
        Marklin::Point center;
@@ -63,7 +64,7 @@ private:
        std::vector<Marklin::Track *> extend_tracks;
 
 public:
-       Manipulator(Designer &, Selection &);
+       Manipulator(Designer &, Msp::Graphics::EventSource &, Selection &);
 
        void start_move();
        void start_rotate();
@@ -74,9 +75,9 @@ public:
        void even_slope(bool =false);
        void connect();
        void cancel();
-       void button_press(int, int, float, float, unsigned);
-       void pointer_motion(int, int, float, float);
 private:
+       void button_press(int, int, unsigned, unsigned);
+       void pointer_motion(int, int);
        void selection_changed();
        void update_tracks();
        void update_neighbors();