]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/widget.cpp
Reorder class members
[libs/gltk.git] / source / widget.cpp
index 48ae0eda4b042b3e4096a2d7f494d3ea77db2e44..e20ea82b56fcf085a2cab9a8eb7a1e0e96aaad19 100644 (file)
@@ -1,14 +1,27 @@
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007  Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
 #include <msp/gl/matrix.h>
 #include <msp/gl/transform.h>
 #include "resources.h"
 #include "widget.h"
 
-#include <iostream>
 using namespace std;
 
 namespace Msp {
 namespace GLtk {
 
+Widget::Widget(const Resources &r):
+       res(r),
+       style(0),
+       state(NORMAL),
+       visible(true)
+{ }
+
 void Widget::set_position(int x, int y)
 {
        geom.x=x;
@@ -44,39 +57,6 @@ void Widget::render() const
        GL::pop_matrix();
 }
 
-bool Widget::button_press(int x, int y, unsigned btn)
-{
-       if(x>=geom.x && y>=geom.y && x<geom.x+static_cast<int>(geom.w) && y<geom.y+static_cast<int>(geom.h))
-       {
-               on_button_press(x, y, btn);
-               return true;
-       }
-
-       return false;
-}
-
-bool Widget::button_release(int x, int y, unsigned btn)
-{
-       if(x>=geom.x && y>=geom.y && x<geom.x+static_cast<int>(geom.w) && y<geom.y+static_cast<int>(geom.h))
-       {
-               on_button_release(x, y, btn);
-               return true;
-       }
-
-       return false;
-}
-
-Widget::Widget(const Resources &r):
-       res(r),
-       style(0),
-       state(NORMAL)
-{ }
-
-void Widget::update_style()
-{
-       style=&res.get_style(get_class(), style_name);
-}
-
 void Widget::render_part(const Part &part) const
 {
        render_graphic(part);
@@ -98,10 +78,10 @@ void Widget::render_text(const Part &part, const string &text) const
 
        GL::push_matrix();
 
-       part.get_alignment().apply(geom, text_w, static_cast<unsigned>(font_size));
+       part.get_alignment().apply(geom, text_w, static_cast<unsigned>(font->get_ascent()*font_size));
        GL::scale_uniform(font_size);
 
-       const Color &color=style->get_font_color();
+       const GL::Color &color=style->get_font_color();
        glColor3f(color.r, color.g, color.b);
        font->draw_string(text);
        glColor3f(1, 1, 1);
@@ -109,5 +89,41 @@ void Widget::render_text(const Part &part, const string &text) const
        GL::pop_matrix();
 }
 
+void Widget::update_style()
+{
+       string sname=get_class();
+       if(!style_name.empty())
+       {
+               sname+='-';
+               sname+=style_name;
+       }
+       style=res.get<Style>(sname);
+}
+
+
+Widget::Loader::Loader(Widget &w):
+       wdg(w)
+{
+       add("position", &Loader::position);
+       add("size",     &Loader::size);
+       add("style",    &Loader::style);
+       add("visible",  &Widget::visible);
+}
+
+void Widget::Loader::position(int x, int y)
+{
+       wdg.set_position(x, y);
+}
+
+void Widget::Loader::size(unsigned w, unsigned h)
+{
+       wdg.set_size(w, h);
+}
+
+void Widget::Loader::style(const string &s)
+{
+       wdg.set_style(s);
+}
+
 } // namespace GLtk
 } // namespace Msp