]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/root.cpp
Only focus widgets if the container is focused
[libs/gltk.git] / source / root.cpp
index b4c16cfe8bf7973ded8a5f2b387b23c189f80bbd..a76da5b84cc6abcbe49f5ae99ccf35e8e6d47774 100644 (file)
@@ -1,9 +1,9 @@
 #include <msp/gl/blend.h>
 #include <msp/gl/extensions/arb_shader_objects.h>
 #include <msp/gl/programbuilder.h>
+#include <msp/gl/tests.h>
 #include <msp/gl/uniform.h>
 #include <msp/input/keys.h>
-#include <msp/time/units.h>
 #include <msp/time/utils.h>
 #include "label.h"
 #include "style.h"
@@ -13,7 +13,7 @@
 namespace Msp {
 namespace GLtk {
 
-Root::Root(const Resources &r, Graphics::Window &window):
+Root::Root(Resources &r, Graphics::Window &window):
        resources(r),
        keyboard(new Input::Keyboard(window)),
        input_method(0),
@@ -24,7 +24,7 @@ Root::Root(const Resources &r, Graphics::Window &window):
        init(&window);
 }
 
-Root::Root(const Resources &r, Graphics::Window *window, Input::Keyboard *k, Input::Mouse *m, Input::Touchscreen *t):
+Root::Root(Resources &r, Graphics::Window *window, Input::Keyboard *k, Input::Mouse *m, Input::Touchscreen *t):
        resources(r),
        keyboard(k),
        input_method(0),
@@ -58,6 +58,9 @@ void Root::init(Graphics::Window *window)
        else
                shprog = 0;
 
+       if(keyboard)
+               set_state(FOCUS);
+
        update_style();
 
        if(mouse)
@@ -91,6 +94,12 @@ Root::~Root()
 
 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;
@@ -144,6 +153,19 @@ void Root::render() const
        Widget::render(renderer);
 }
 
+void Root::render(GL::Renderer &renderer, const GL::Tag &tag) const
+{
+       if(tag.id)
+               return;
+
+       GL::Renderer::Push push(renderer);
+       renderer.set_camera(camera);
+       renderer.set_shader_program(shprog);
+       GL::BindRestore bind_blend(GL::Blend::alpha());
+       GL::BindRestore unbind_dtest(static_cast<GL::DepthTest *>(0));
+       Widget::render(renderer);
+}
+
 bool Root::button_press_event(unsigned btn)
 {
        if(visible)