From: Mikko Rasa Date: Thu, 4 Nov 2010 08:10:50 +0000 (+0000) Subject: Connect manipulator directly to event signals X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f4c6c924dcf439a6a68d2761fab196eaab165916;p=r2c2.git Connect manipulator directly to event signals Give map_pointer_coords a better name --- diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index c071b5b..51dad8f 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -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); } } diff --git a/source/designer/designer.h b/source/designer/designer.h index dbbd192..07b3487 100644 --- a/source/designer/designer.h +++ b/source/designer/designer.h @@ -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); diff --git a/source/designer/manipulator.cpp b/source/designer/manipulator.cpp index aad20a0..e9d6b95 100644 --- a/source/designer/manipulator.cpp +++ b/source/designer/manipulator.cpp @@ -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 tracks; Marklin::Point center; @@ -63,7 +64,7 @@ private: std::vector 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();