X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fimage.cpp;h=eb3bd6ef4da556337e712c14b81fa4fa656b6559;hb=43ac7c4514658754d09552463425bcd344fb9ded;hp=11003f4d1af56acbfb6b7367ec680f6e86bb1533;hpb=73afd124ab87e8bace98db55517a56c797a9b8c7;p=libs%2Fgltk.git diff --git a/source/image.cpp b/source/image.cpp index 11003f4..eb3bd6e 100644 --- a/source/image.cpp +++ b/source/image.cpp @@ -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 #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;