]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/widget.cpp
Implement set_size and set_position in terms of set_geometry
[libs/gltk.git] / source / widget.cpp
index 4b48e8ba11400d2f410790de92b8464e890b68b3..e73e5cf56ef89630c0b36944792ed7a225018e58 100644 (file)
@@ -30,18 +30,12 @@ Widget::~Widget()
 
 void Widget::set_position(int x, int y)
 {
-       geom.x = x;
-       geom.y = y;
-       on_geometry_change();
-       rebuild();
+       set_geometry(Geometry(x, y, geom.w, geom.h));
 }
 
 void Widget::set_size(unsigned w, unsigned h)
 {
-       geom.w = w;
-       geom.h = h;
-       on_geometry_change();
-       rebuild();
+       set_geometry(Geometry(geom.x, geom.y, w, h));
 }
 
 void Widget::autosize()
@@ -70,10 +64,20 @@ void Widget::set_parent(Container *p)
                throw hierarchy_error("widget already parented");
        else if(p==parent)
                return;
-       parent = p;
 
-       on_reparent();
-       update_style();
+       try
+       {
+               parent = p;
+
+               on_reparent();
+               update_style();
+       }
+       catch(...)
+       {
+               // The container has not yet added the widget as its child
+               parent = 0;
+               throw;
+       }
 }
 
 void Widget::set_style(const string &s)
@@ -160,24 +164,24 @@ void Widget::rebuild()
        }
 }
 
-void Widget::render() const
+void Widget::render(GL::Renderer &renderer) const
 {
        if(!style)
                throw logic_error(format("Attempt to render a widget with null style (class=\"%s\", style_name=\"%s\")", get_class(), style_name));
 
-       GL::MatrixStack::Push _pushm(GL::MatrixStack::modelview());
-       GL::MatrixStack::modelview() *= GL::Matrix::translation(geom.x, geom.y, 0);
+       GL::MatrixStack::Push _pushm(renderer.matrix_stack());
+       renderer.matrix_stack() *= GL::Matrix::translation(geom.x, geom.y, 0);
        const Style::PartSeq &parts = style->get_parts();
        list<CachedPart>::const_iterator j = cached_parts.begin();
        for(Style::PartSeq::const_iterator i=parts.begin(); (i!=parts.end() && j!=cached_parts.end()); ++i, ++j)
        {
                if(j->mesh && j->texture)
                {
-                       GL::Bind bind_tex(j->texture);
-                       j->mesh->draw();
+                       renderer.set_texture(j->texture);
+                       j->mesh->draw(renderer);
                }
                else if(!i->get_name().empty())
-                       render_special(*i);
+                       render_special(*i, renderer);
        }
 }