]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/widget.cpp
Add Widget::set_focus
[libs/gltk.git] / source / widget.cpp
index 0128367c2b32a6a6c54ae458b3d3a994b38cdf2e..48b647b71850b464bf8da56f102170d64bc8cf6e 100644 (file)
@@ -5,6 +5,7 @@ Copyright © 2007  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
+#include <msp/gl/immediate.h>
 #include <msp/gl/matrix.h>
 #include <msp/gl/transform.h>
 #include <msp/strings/formatter.h>
@@ -68,6 +69,16 @@ void Widget::set_visible(bool v)
                parent->child_hidden(*this);
 }
 
+void Widget::set_focus()
+{
+       if(!parent)
+               throw InvalidState("No parent");
+       if(!visible)
+               throw InvalidState("Can't set focus on invisible widget");
+
+       parent->grab_focus(*this);
+}
+
 void Widget::render() const
 {
        if(!style)
@@ -108,13 +119,33 @@ void Widget::render_text(const Part &part, const string &text) const
        GL::scale_uniform(font_size);
 
        const GL::Color &color=style->get_font_color();
-       glColor3f(color.r, color.g, color.b);
-       font->draw_string(text);
-       glColor3f(1, 1, 1);
+       GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
+       imm.color(color.r, color.g, color.b);
+       font->draw_string(text, imm);
 
        GL::pop_matrix();
 }
 
+void Widget::pointer_enter()
+{
+       state|=HOVER;
+}
+
+void Widget::pointer_leave()
+{
+       state&=~HOVER;
+}
+
+void Widget::focus_in()
+{
+       state|=FOCUS;
+}
+
+void Widget::focus_out()
+{
+       state&=~FOCUS;
+}
+
 void Widget::update_style()
 {
        string sname=get_class();