]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/widget.cpp
Add Container class
[libs/gltk.git] / source / widget.cpp
index be1f0a0cc90fb981bc0ea1a121e3f3f92d95030e..84d042573ec18aff63230eca34cada3e150dbab3 100644 (file)
@@ -1,10 +1,11 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2009  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>
@@ -64,8 +65,17 @@ void Widget::set_visible(bool v)
 
        visible=v;
 
-       if(!visible && parent)
-               parent->child_hidden(*this);
+       signal_visibility_changed.emit(visible);
+}
+
+void Widget::set_focus()
+{
+       if(!parent)
+               throw InvalidState("No parent");
+       if(!visible)
+               throw InvalidState("Can't set focus on invisible widget");
+
+       signal_request_focus.emit();
 }
 
 void Widget::render() const
@@ -108,9 +118,9 @@ 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();
 }
@@ -147,16 +157,16 @@ void Widget::update_style()
        on_style_change();
 }
 
-void Widget::set_parent(Panel *p)
+void Widget::set_parent(Container *p)
 {
        if(parent && p)
-               throw InvalidState("Widget is already in a Panel");
+               throw InvalidState("Widget is already in a Container");
        parent=p;
 
        on_reparent();
 }
 
-void Widget::set_parent(Widget &w, Panel *p)
+void Widget::set_parent(Widget &w, Container *p)
 {
        w.set_parent(p);
 }