X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fimage.cpp;h=bff790427657ae3256596220d68bfd81c657d079;hb=39cf4c8d917dc60c087fb4af6885bfa78f6fba34;hp=11003f4d1af56acbfb6b7367ec680f6e86bb1533;hpb=91997dd3189b93a67179822ec2fed5f2a7bddb74;p=libs%2Fgltk.git diff --git a/source/image.cpp b/source/image.cpp index 11003f4..bff7904 100644 --- a/source/image.cpp +++ b/source/image.cpp @@ -1,15 +1,9 @@ -/* $Id$ - -This file is part of libmspgltk -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include #include #include #include "image.h" #include "part.h" +#include "style.h" using namespace std; @@ -23,9 +17,33 @@ 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; + signal_autosize_changed.emit(); } void Image::set_keep_aspect(bool ka)