X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Froot.cpp;h=8d32c467b26eb5924e1825d6d51ff37d01de65a7;hb=394e5c9969a30b604bfaf78fc05a8c2d5c98ab5b;hp=e9e62f6785c3a203914dfb10594d1a0db74c812d;hpb=f8f2f18e886429b70325ff36989bb126de617716;p=libs%2Fgltk.git diff --git a/source/root.cpp b/source/root.cpp index e9e62f6..8d32c46 100644 --- a/source/root.cpp +++ b/source/root.cpp @@ -1,62 +1,48 @@ #include -#include -#include -#include #include -#include #include #include "label.h" #include "style.h" +#include "resources.h" #include "root.h" #include "systemkeyboardinput.h" +using namespace std; + namespace Msp { namespace GLtk { -Root::Root(Resources &r, Graphics::Window &window): - resources(r), - keyboard(new Input::Keyboard(window)), - input_method(0), - mouse(new Input::Mouse(window)), - touchscreen(0), - own_input(true) +Root::Root(Resources &r, Graphics::Window &window, unique_ptr k, unique_ptr m): + Root(r, &window, k.get(), m.get(), nullptr) { - init(&window); + own_input[0] = move(k); + own_input[1] = move(m); } +Root::Root(Resources &r, Graphics::Window &window): + Root(r, window, make_unique(window), make_unique(window)) +{ } + Root::Root(Resources &r, Graphics::Window *window, Input::Keyboard *k, Input::Mouse *m, Input::Touchscreen *t): resources(r), keyboard(k), - input_method(0), mouse(m), - touchscreen(t), - own_input(false) -{ - init(window); -} - -void Root::init(Graphics::Window *window) + touchscreen(t) { 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(); - if(GL::ARB_shader_objects) - { - shprog = new GL::Program; - GL::ProgramBuilder::StandardFeatures features; - features.material = true; - features.texture = true; - GL::ProgramBuilder(features).add_shaders(*shprog); - shprog->link(); - } - else - shprog = 0; + shprog = &resources.get("ui.shader"); + + blend.enabled = true; + blend.src_factor = GL::SRC_ALPHA; + blend.dst_factor = GL::ONE_MINUS_SRC_ALPHA; + + if(keyboard) + set_state(FOCUS); update_style(); @@ -68,7 +54,7 @@ void Root::init(Graphics::Window *window) } if(keyboard && !input_method) - input_method = new SystemKeyboardInput(*this, *keyboard); + input_method = make_unique(*this, *keyboard); if(touchscreen) { @@ -78,23 +64,18 @@ void Root::init(Graphics::Window *window) } } -Root::~Root() -{ - delete shprog; - delete input_method; - if(own_input) - { - delete keyboard; - delete mouse; - } -} - void Root::tick() { + Time::TimeStamp t = Time::now(); + Time::TimeDelta dt = (last_tick ? t-last_tick : Time::zero); + last_tick = t; + + animate(dt); + if(tooltip_timeout && Time::now()>tooltip_timeout) { std::string tip; - if(Widget *wdg = get_descendant_at(pointer_x, pointer_y)) + if(Widget *wdg = find_descendant_at(pointer_x, pointer_y)) { tip = wdg->get_tooltip(); tooltip_target = wdg; @@ -135,25 +116,22 @@ void Root::tick() } } -void Root::render(const GL::Tag &tag) const +void Root::setup_frame(GL::Renderer &) { - if(tag.id) - return; - - GL::Bind bind_blend(GL::Blend::alpha()); - - GL::Renderer renderer(&camera); - renderer.set_shader_program(shprog); - Widget::render(renderer); + rebuild_hierarchy(); } -void Root::render(GL::Renderer &renderer, const GL::Tag &tag) const +void Root::render(GL::Renderer &renderer, GL::Tag tag) const { if(tag.id) return; - renderer.end(); - render(tag); + GL::Renderer::Push push(renderer); + renderer.set_camera(camera); + renderer.set_shader_program(shprog); + renderer.set_blend(&blend); + renderer.set_depth_test(nullptr); + Widget::render(renderer); } bool Root::button_press_event(unsigned btn) @@ -204,11 +182,11 @@ bool Root::axis_motion_event(unsigned, float, float) pointer_y = y; tooltip_timeout = Time::now()+700*Time::msec; } - else if(get_descendant_at(x, y)!=tooltip_target) + else if(find_descendant_at(x, y)!=tooltip_target) { if(lbl_tooltip) lbl_tooltip->set_visible(false); - tooltip_target = 0; + tooltip_target = nullptr; } if(pointer_focus) @@ -287,9 +265,9 @@ void Root::update_camera() camera.set_orthographic(geom.w, geom.h); } -void Root::on_geometry_change() +void Root::on_size_change() { - Panel::on_geometry_change(); + Panel::on_size_change(); update_camera(); }