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)
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;
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)
{
}
}
}
- 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);
}
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);
}
}
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);
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));
}
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;
}
}
-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)
{
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)
private:
Designer &designer;
+ Msp::Graphics::EventSource &event_source;
Selection &selection;
std::vector<MTrack> tracks;
Marklin::Point center;
std::vector<Marklin::Track *> extend_tracks;
public:
- Manipulator(Designer &, Selection &);
+ Manipulator(Designer &, Msp::Graphics::EventSource &, Selection &);
void start_move();
void start_rotate();
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();