X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdesigner%2Fdesigner.cpp;h=5811b84d195a7afc82853e22bea6ee0570319d64;hb=32316772d422223827833366a7ee2d0a76d76ff1;hp=76a31a51d4094be8a09d5959cb4f141f8022b4de;hpb=d15ac13f2e170f155b4bbd124df48400c339b644;p=r2c2.git diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index 76a31a5..5811b84 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -11,9 +11,9 @@ #include #include #include -#include +#include +#include #include -#include #include #include #include @@ -38,17 +38,17 @@ using namespace std; using namespace R2C2; using namespace Msp; -Application::RegApp Designer::reg; - Designer::Designer(int argc, char **argv): window(1280, 960), + keyboard(window), + mouse(window), ui_res("r2c2.res"), root(ui_res, window), base_object(0), cur_route(0), cur_zone(0), mode(SELECT), - manipulator(*this, root, selection), + manipulator(*this, mouse, selection), measure(*this) { window.set_title("Railway Designer"); @@ -89,17 +89,17 @@ Designer::Designer(int argc, char **argv): main_view = new View3D(*layout_3d, window.get_width(), window.get_height()); GL::Pipeline *pipeline = &main_view->get_pipeline(); - GL::PipelinePass *pass = &pipeline->add_pass("unlit"); - pass->depth_test = &GL::DepthTest::lequal(); - pass->blend = &GL::Blend::alpha(); + GL::Pipeline::Pass *pass = &pipeline->add_pass("unlit"); + pass->set_depth_test(&GL::DepthTest::lequal()); + pass->set_blend(&GL::Blend::alpha()); pass = &pipeline->add_pass("blended"); - pass->lighting = &layout_3d->get_lighting(); - pass->depth_test = &GL::DepthTest::lequal(); - pass->blend = &GL::Blend::alpha(); + pass->set_lighting(&layout_3d->get_lighting()); + pass->set_depth_test(&GL::DepthTest::lequal()); + pass->set_blend(&GL::Blend::alpha()); pass = &pipeline->add_pass("overlay"); - pass->blend = &GL::Blend::alpha(); + pass->set_blend(&GL::Blend::alpha()); if(base_object) pipeline->add_renderable(*base_object); @@ -107,9 +107,9 @@ Designer::Designer(int argc, char **argv): pipeline->add_renderable_for_pass(layout_3d->get_endpoint_scene(), "unlit"); // Setup UI - root.signal_key_press.connect(sigc::mem_fun(this, &Designer::key_press)); - root.signal_button_press.connect(sigc::mem_fun(this, &Designer::button_press)); - root.signal_pointer_motion.connect(sigc::mem_fun(this, &Designer::pointer_motion)); + keyboard.signal_button_press.connect(sigc::mem_fun(this, &Designer::key_press)); + mouse.signal_button_press.connect(sigc::mem_fun(this, &Designer::button_press)); + mouse.signal_axis_motion.connect(sigc::mem_fun(this, &Designer::axis_motion)); root.signal_tooltip.connect(sigc::mem_fun(this, &Designer::tooltip)); toolbars.push_back(new Layoutbar(*this)); @@ -138,8 +138,9 @@ Designer::Designer(int argc, char **argv): pipeline->add_renderable_for_pass(*track_wrap, "unlit"); overlay = new Overlay3D(ui_res.get_default_font()); pipeline->add_renderable_for_pass(*overlay, "overlay"); + pipeline->add_renderable_for_pass(measure, "unlit"); - camera_ctl = new CameraController(*main_view, root); + camera_ctl = new CameraController(*main_view, keyboard, mouse); cat_view->get_camera().set_look_direction(GL::Vector3(0, 0.13053, -0.99144)); cat_view->view_all(true); main_view->view_all(); @@ -280,7 +281,7 @@ void Designer::add_selection_to_route() { cur_route->add_tracks(selection.get_tracks()); } - catch(const Exception &e) + catch(const exception &e) { lbl_status->set_text(e.what()); } @@ -319,7 +320,7 @@ void Designer::add_selection_to_zone() { cur_zone->add_tracks(selection.get_tracks()); } - catch(const Exception &e) + catch(const exception &e) { lbl_status->set_text(e.what()); } @@ -327,11 +328,9 @@ void Designer::add_selection_to_zone() show_zone(*cur_zone); } -Vector Designer::map_pointer_to_ground(int x, int y) +Vector Designer::map_pointer_to_ground(const Vector &p) { - float xf = x*2.0/window.get_width()-1.0; - float yf = y*2.0/window.get_height()-1.0; - GL::Vector4 vec = main_view->get_camera().unproject(GL::Vector4(xf, yf, 0, 0)); + GL::Vector4 vec = main_view->get_camera().unproject(GL::Vector4(p.x, p.y, 0, 0)); const GL::Vector3 &pos = main_view->get_camera().get_position(); return Vector(pos.x-vec.x*pos.z/vec.z, pos.y-vec.y*pos.z/vec.z); @@ -359,12 +358,11 @@ void Designer::tick() window.swap_buffers(); } -void Designer::key_press(unsigned key, unsigned mod, wchar_t) +void Designer::key_press(unsigned key) { - key = Input::key_from_sys(key); - mod = Input::mod_from_sys(mod); + bool shift = keyboard.get_button_state(Input::KEY_SHIFT_L) || keyboard.get_button_state(Input::KEY_SHIFT_R); - if(key==Msp::Input::KEY_N && (mod&Input::MOD_SHIFT)) + if(key==Msp::Input::KEY_N && shift) extend_track(); else if(key==Msp::Input::KEY_N) new_track(); @@ -388,7 +386,7 @@ void Designer::key_press(unsigned key, unsigned mod, wchar_t) save(); else if(key==Msp::Input::KEY_PLUS) selection.select_more(); - else if(key==Msp::Input::KEY_L && (mod&Input::MOD_SHIFT)) + else if(key==Msp::Input::KEY_L && shift) selection.select_blocks(); else if(key==Msp::Input::KEY_L) selection.select_linked(); @@ -413,7 +411,7 @@ void Designer::key_press(unsigned key, unsigned mod, wchar_t) } else if(key==Msp::Input::KEY_X) erase_tracks(); - else if(key==Msp::Input::KEY_F && (mod&Input::MOD_SHIFT)) + else if(key==Msp::Input::KEY_F && shift) { const set &tracks = selection.get_tracks(); const set <racks = layout->get_tracks(); @@ -430,7 +428,7 @@ void Designer::key_press(unsigned key, unsigned mod, wchar_t) } else if(key==Msp::Input::KEY_F) flatten_tracks(); - else if(key==Msp::Input::KEY_E && (mod&Input::MOD_SHIFT)) + else if(key==Msp::Input::KEY_E && shift) manipulator.even_slope(true); else if(key==Msp::Input::KEY_E) manipulator.even_slope(); @@ -449,18 +447,18 @@ void Designer::key_press(unsigned key, unsigned mod, wchar_t) track_properties(); } -void Designer::button_press(int x, int y, unsigned btn, unsigned mod) +void Designer::button_press(unsigned btn) { - y = window.get_height()-y-1; - mod = Input::mod_from_sys(mod); + bool shift = keyboard.get_button_state(Input::KEY_SHIFT_L) || keyboard.get_button_state(Input::KEY_SHIFT_R); - Vector ground = map_pointer_to_ground(x, y); + Vector pointer(mouse.get_axis_value(0), mouse.get_axis_value(1)); + Vector ground = map_pointer_to_ground(pointer); if(mode==CATALOGUE) { if(btn==1) { - Track *ctrack = pick_track(x, y); + Track *ctrack = pick_track(pointer); if(ctrack) { Track *track = new Track(*layout, ctrack->get_type()); @@ -479,27 +477,29 @@ void Designer::button_press(int x, int y, unsigned btn, unsigned mod) { if(btn==1) { - Track *track = pick_track(x, y); + Track *track = pick_track(pointer); if(track) { - if(!(mod&Input::MOD_SHIFT)) + if(!shift) selection.clear(); selection.toggle_track(track); } } } else if(mode==MEASURE) - measure.button_press(x, y, ground.x, ground.y, btn); + measure.button_press(ground.x, ground.y, btn); } -void Designer::pointer_motion(int x, int y) +void Designer::axis_motion(unsigned, float, float) { - y = window.get_height()-y-1; + Vector pointer(mouse.get_axis_value(0), mouse.get_axis_value(1)); + float wx = pointer.x*window.get_width(); + float wy = pointer.y*window.get_height(); - if(!root.get_child_at(x, y)) + if(!root.get_child_at(wx, wy)) { - Vector ground = map_pointer_to_ground(x, y); - measure.pointer_motion(x, y, ground.x, ground.y); + Vector ground = map_pointer_to_ground(pointer); + measure.pointer_motion(ground.x, ground.y); } } @@ -509,22 +509,9 @@ void Designer::render() View3D *view = (mode==CATALOGUE ? cat_view : main_view); view->render(); - if(mode==MEASURE) - { - GL::Bind bind_depth(GL::DepthTest::lequal()); - measure.render(); - } - GL::matrix_mode(GL::PROJECTION); - GL::load_identity(); - GL::ortho_bottomleft(window.get_width(), window.get_height()); - GL::matrix_mode(GL::MODELVIEW); - GL::load_identity(); - - GL::Bind bind_blend(GL::Blend::alpha()); root.render(); - // XXX Should fix GLtk so these would not be needed - GL::Texture::unbind(); + // XXX Should fix GLtk so this would not be needed glColor3f(1.0, 1.0, 1.0); } @@ -540,14 +527,11 @@ void Designer::track_removed(Track &trk) new_tracks.erase(i); } -Track *Designer::pick_track(int x, int y) +Track *Designer::pick_track(const Vector &pointer) { - float xx = x*2.0/window.get_width()-1.0; - float yy = y*2.0/window.get_height()-1.0; - View3D &view = *(mode==CATALOGUE ? cat_view : main_view); const GL::Vector3 &cpos = view.get_camera().get_position(); - GL::Vector4 cray = view.get_camera().unproject(GL::Vector4(xx, yy, 0, 0)); + GL::Vector4 cray = view.get_camera().unproject(GL::Vector4(pointer.x, pointer.y, 0, 0)); return view.get_layout().get_layout().pick_track(Vector(cpos.x, cpos.y, cpos.z), Vector(cray.x, cray.y, cray.z)); } @@ -562,14 +546,14 @@ void Designer::update_track_icon(Track3D &track) if(unsigned sid = track.get_track().get_sensor_id()) { overlay->add_graphic(track, "sensor"); - overlay->set_label(track, lexical_cast(sid)); + overlay->set_label(track, lexical_cast(sid)); } else if(unsigned tid = track.get_track().get_turnout_id()) { if(tid<0x800) { overlay->add_graphic(track, "turnout"); - overlay->set_label(track, lexical_cast(tid)); + overlay->set_label(track, lexical_cast(tid)); } } } @@ -647,7 +631,7 @@ void Designer::svg_export_accept(const string &text) string Designer::tooltip(int x, int y) { - if(Track *track = pick_track(x, y)) + if(Track *track = pick_track(Vector(x*2.0f/window.get_width()-1.0f, y*2.0f/window.get_height()-1.0f, 0))) { const TrackType &ttype = track->get_type(); string info = format("%d %s", ttype.get_article_number(), ttype.get_description());