X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Fengineer.cpp;h=365fee0d6333d02c65875c518fcb7fe1042bf9a5;hb=ec1f75d72e5c4f7f7c9dafdf80f58c30ffb1a855;hp=bc32dfb848a52d92c4069aeb076760fc90d05182;hpb=29433673a88dffd61ecb8e6c8fe6ab38e2012586;p=r2c2.git diff --git a/source/engineer/engineer.cpp b/source/engineer/engineer.cpp index bc32dfb..365fee0 100644 --- a/source/engineer/engineer.cpp +++ b/source/engineer/engineer.cpp @@ -35,6 +35,8 @@ using namespace Msp; Engineer::Engineer(int argc, char **argv): options(argc, argv), window(options.screen_w, options.screen_h, options.fullscreen), + keyboard(window), + mouse(window), layout(catalogue, (options.driver.empty() ? 0 : Driver::create(options.driver))), layout_3d(layout), server(0), @@ -43,8 +45,6 @@ Engineer::Engineer(int argc, char **argv): picking_track(0), picking_entry(0), picking_path(0), - pointer_x(0), - pointer_y(0), pointer_moved(false) { // Setup GUI @@ -53,8 +53,8 @@ Engineer::Engineer(int argc, char **argv): DataFile::load(ui_res, "r2c2.res"); root = new GLtk::Root(ui_res, window); - root->signal_button_press.connect(sigc::mem_fun(this, &Engineer::button_press)); - root->signal_pointer_motion.connect(sigc::mem_fun(this, &Engineer::pointer_motion)); + mouse.signal_button_press.connect(sigc::mem_fun(this, &Engineer::button_press)); + mouse.signal_axis_motion.connect(sigc::mem_fun(this, &Engineer::axis_motion)); root->set_visible(true); main_panel = new MainPanel(*this); @@ -203,7 +203,7 @@ void Engineer::tick() if(picking) { - Track *track = pick_track(pointer_x, window.get_height()-pointer_y-1); + Track *track = pick_track(pointer); if(track && track!=picking_track) { picking_track = track; @@ -240,7 +240,7 @@ void Engineer::tick() window.swap_buffers(); } -void Engineer::button_press(int x, int y, unsigned btn, unsigned) +void Engineer::button_press(unsigned btn) { if(picking) { @@ -259,7 +259,7 @@ void Engineer::button_press(int x, int y, unsigned btn, unsigned) } else { - Track *track = pick_track(x, window.get_height()-y-1); + Track *track = pick_track(pointer); if(track) { if(track->get_turnout_id()) @@ -292,10 +292,12 @@ void Engineer::button_press(int x, int y, unsigned btn, unsigned) } } -void Engineer::pointer_motion(int x, int y) +void Engineer::axis_motion(unsigned axis, float value, float) { - pointer_x = x; - pointer_y = y; + if(axis==0) + pointer.x = value; + if(axis==1) + pointer.y = value; pointer_moved = true; } @@ -381,12 +383,10 @@ void Engineer::reset_block_color(const Block &block) set_block_color(block, GL::Color(1)); } -Track *Engineer::pick_track(int x, int y) +Track *Engineer::pick_track(const Vector &p) { const GL::Vector3 &start = camera.get_position(); - float xx = x*2.0/window.get_width()-1.0; - float yy = y*2.0/window.get_height()-1.0; - GL::Vector4 ray = camera.unproject(GL::Vector4(xx, yy, 0, 0)); + GL::Vector4 ray = camera.unproject(GL::Vector4(p.x, p.y, 0, 0)); return layout.pick_track(Vector(start.x, start.y, start.z), Vector(ray.x, ray.y, ray.z)); }