]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/image.cpp
Implement autosize() method for most widgets
[libs/gltk.git] / source / image.cpp
index 11003f4d1af56acbfb6b7367ec680f6e86bb1533..eb3bd6ef4da556337e712c14b81fa4fa656b6559 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,6 +10,7 @@ Distributed under the LGPL
 #include <msp/gl/matrix.h>
 #include "image.h"
 #include "part.h"
+#include "style.h"
 
 using namespace std;
 
@@ -23,6 +24,29 @@ Image::Image(const GL::Texture2D *i):
        focusable = false;
 }
 
+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;