]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/image.cpp
Avoid generating events during destruction of a widget
[libs/gltk.git] / source / image.cpp
index f7f61bbb9a73e2b4b84d48228bd4e2f3217d5782..3c0cfa53465a6f1befc6044c07a98652ed8a15bf 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
+Copyright © 2010-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -10,24 +10,47 @@ Distributed under the LGPL
 #include <msp/gl/matrix.h>
 #include "image.h"
 #include "part.h"
+#include "style.h"
 
 using namespace std;
 
 namespace Msp {
 namespace GLtk {
 
-Image::Image(const Resources &r, const GL::Texture2D *i):
-       Widget(r),
+Image::Image(const GL::Texture2D *i):
        image(i),
        keep_aspect(true)
 {
        focusable = false;
-       update_style();
+}
+
+void Image::autosize()
+{
+       if(!style)
+               return;
+
+       Widget::autosize();
+
+       if(const Part *image_part = style->get_part("image"))
+       {
+               const Sides &margin = image_part->get_margin();
+               if(image)
+               {
+                       geom.w = max(geom.w, image->get_width()+margin.left+margin.right);
+                       geom.h = max(geom.h, image->get_height()+margin.top+margin.bottom);
+               }
+               else
+               {
+                       geom.w = max(geom.w, margin.left+margin.right);
+                       geom.h = max(geom.h, margin.top+margin.bottom);
+               }
+       }
 }
 
 void Image::set_image(const GL::Texture2D *i)
 {
        image = i;
+       signal_autosize_changed.emit();
 }
 
 void Image::set_keep_aspect(bool ka)