]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/part.cpp
Rework event passing system to allow for pointer grabs
[libs/gltk.git] / source / part.cpp
index 38e75d7c034d4526f08662ec732deb7d8493f83d..45449932618ec8a692b9b7cd5f20e275e0ad285d 100644 (file)
@@ -10,6 +10,8 @@ namespace GLtk {
 Part::Part(const Resources &r, const string &n):
        res(r),
        name(n),
+       width(1),
+       height(1),
        fill_x(true),
        fill_y(true)
 {
@@ -27,9 +29,8 @@ const Graphic *Part::get_graphic(State state) const
 
 void Part::render(const Geometry &geom, State state) const
 {
-       const Graphic::Sides &shadow=graphic[state]->get_shadow();
-       unsigned gw=(fill_x ? geom.w : graphic[state]->get_width())-shadow.left-shadow.right;
-       unsigned gh=(fill_y ? geom.h : graphic[state]->get_height())-shadow.top-shadow.bottom;
+       unsigned gw=(fill_x ? geom.w : width);
+       unsigned gh=(fill_y ? geom.h : height);
        align.apply(geom, gw, gh);
        graphic[state]->render(gw, gh);
 }
@@ -43,17 +44,26 @@ Part::Loader::Loader(Part &p):
        add("fill",    &Loader::fill);
 }
 
-void Part::Loader::graphic(State s, const string &n)
+Part::Loader::~Loader()
 {
-       part.graphic[s]=&part.res.get_graphic(n);
-       if(s==NORMAL)
+       for(unsigned i=0; i<N_STATES_; ++i)
        {
-               for(unsigned i=0; i<N_STATES_; ++i)
-                       if(!part.graphic[i])
-                               part.graphic[i]=part.graphic[s];
+               if(part.graphic[i])
+               {
+                       const Sides &shadow=part.graphic[i]->get_shadow();
+                       part.width=max(part.width, part.graphic[i]->get_width()-shadow.left-shadow.right);
+                       part.height=max(part.height, part.graphic[i]->get_height()-shadow.bottom-shadow.top);
+               }
+               else
+                       part.graphic[i]=part.graphic[NORMAL];
        }
 }
 
+void Part::Loader::graphic(State s, const string &n)
+{
+       part.graphic[s]=&part.res.get_graphic(n);
+}
+
 void Part::Loader::align(int x, int y)
 {
        part.align.x=x;