X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Froot.cpp;h=f4bad55beb546dfa91ee0dd9d960a7a0451b2fed;hb=2b1a962fba03a01d641f5b6e2b8d75c6e71e2d40;hp=89db305ea5bd291e7cfc9823c7a5a2964a837ec6;hpb=d9d787503ae41842309f74a2eabc5b848abe1f22;p=libs%2Fgltk.git diff --git a/source/root.cpp b/source/root.cpp index 89db305..f4bad55 100644 --- a/source/root.cpp +++ b/source/root.cpp @@ -15,33 +15,44 @@ Root::Root(const Resources &r, Graphics::Window &window): mouse(new Input::Mouse(window)), own_input(true) { - set_geometry(Geometry(0, 0, window.get_width(), window.get_height())); - - init(); + init(&window); } -Root::Root(const Resources &r, Input::Keyboard *k, Input::Mouse *m): +Root::Root(const Resources &r, Graphics::Window *window, Input::Keyboard *k, Input::Mouse *m): resources(r), keyboard(k), mouse(m), own_input(false) { - init(); + init(window); } -void Root::init() +void Root::init(Graphics::Window *window) { + if(window) + set_geometry(Geometry(0, 0, window->get_width(), window->get_height())); + lbl_tooltip = 0; tooltip_target = 0; + camera.set_orthographic(geom.w, geom.h); + update_camera(); + update_style(); - mouse->signal_button_press.connect(sigc::mem_fun(this, &Root::button_press_event)); - mouse->signal_button_release.connect(sigc::mem_fun(this, &Root::button_release_event)); - mouse->signal_axis_motion.connect(sigc::mem_fun(this, &Root::axis_motion_event)); - keyboard->signal_button_press.connect(sigc::mem_fun(this, &Root::key_press_event)); - keyboard->signal_button_release.connect(sigc::mem_fun(this, &Root::key_release_event)); - keyboard->signal_character.connect(sigc::mem_fun(this, &Root::character_event)); + if(mouse) + { + mouse->signal_button_press.connect(sigc::mem_fun(this, &Root::button_press_event)); + mouse->signal_button_release.connect(sigc::mem_fun(this, &Root::button_release_event)); + mouse->signal_axis_motion.connect(sigc::mem_fun(this, &Root::axis_motion_event)); + } + + if(keyboard) + { + keyboard->signal_button_press.connect(sigc::mem_fun(this, &Root::key_press_event)); + keyboard->signal_button_release.connect(sigc::mem_fun(this, &Root::key_release_event)); + keyboard->signal_character.connect(sigc::mem_fun(this, &Root::character_event)); + } } Root::~Root() @@ -101,35 +112,47 @@ void Root::tick() void Root::render() const { - GL::MatrixStack::projection() = GL::Matrix::ortho_bottomleft(geom.w, geom.h); - GL::MatrixStack::modelview() = GL::Matrix(); GL::Bind bind_blend(GL::Blend::alpha()); - GL::Renderer renderer(0); + GL::Renderer renderer(&camera); Widget::render(renderer); } -void Root::button_press_event(unsigned btn) +bool Root::button_press_event(unsigned btn) { if(visible) { + Widget *old_focus = pointer_focus; + int x, y; get_pointer(x, y); button_press(x, y, btn); + + if(pointer_focus || old_focus) + return true; } + + return false; } -void Root::button_release_event(unsigned btn) +bool Root::button_release_event(unsigned btn) { if(visible) { + Widget *old_focus = pointer_focus; + int x, y; get_pointer(x, y); button_release(x, y, btn); + + if(pointer_focus || old_focus) + return true; } + + return false; } -void Root::axis_motion_event(unsigned, float, float) +bool Root::axis_motion_event(unsigned, float, float) { if(visible) { @@ -149,26 +172,58 @@ void Root::axis_motion_event(unsigned, float, float) lbl_tooltip->set_visible(false); tooltip_target = 0; } + + if(pointer_focus) + return true; } + + return false; } -void Root::key_press_event(unsigned key) +bool Root::key_press_event(unsigned key) { // XXX Modifiers if(visible) + { + Widget *old_focus = input_focus; + key_press(key, 0); + + if(input_focus || old_focus) + return true; + } + + return false; } -void Root::key_release_event(unsigned key) +bool Root::key_release_event(unsigned key) { if(visible) + { + Widget *old_focus = input_focus; + key_release(key, 0); + + if(input_focus || old_focus) + return true; + } + + return false; } -void Root::character_event(StringCodec::unichar ch) +bool Root::character_event(StringCodec::unichar ch) { if(visible) + { + Widget *old_focus = input_focus; + character(ch); + + if(input_focus || old_focus) + return true; + } + + return false; } void Root::get_pointer(int &x, int &y) @@ -177,5 +232,24 @@ void Root::get_pointer(int &x, int &y) y = (mouse->get_axis_value(1)*0.5+0.5)*geom.h; } +void Root::update_camera() +{ + camera.set_position(GL::Vector3(geom.w/2.0f, geom.h/2.0f, geom.h/2.0f)); + camera.set_depth_clip(geom.h*0.1f, geom.h*0.9f); + camera.set_orthographic(geom.w, geom.h); +} + +void Root::on_geometry_change() +{ + Panel::on_geometry_change(); + update_camera(); +} + +void Root::on_child_added(Widget &wdg) +{ + if(&wdg!=lbl_tooltip) + Panel::on_child_added(wdg); +} + } // namespace GLtk } // namespace Msp