X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fimage.cpp;h=1da782d28a2579e66d4079d8ffb915f703627255;hb=78e05360d70542d343401241ff9ddddfed18c5cd;hp=383f906911993d2a83d8d434ec791f8c0e90d303;hpb=4b52d16bc895f9d969383d7a7d6a3558c1972cc5;p=libs%2Fgltk.git diff --git a/source/image.cpp b/source/image.cpp index 383f906..1da782d 100644 --- a/source/image.cpp +++ b/source/image.cpp @@ -1,6 +1,8 @@ #include #include "image.h" #include "part.h" +#include "resources.h" +#include "root.h" #include "style.h" using namespace std; @@ -35,16 +37,43 @@ void Image::autosize_special(const Part &part, Geometry &ageom) const void Image::set_image(const GL::Texture2D *i) { image = i; + icon_name = string(); signal_autosize_changed.emit(); rebuild(); } +void Image::set_icon(const string &n) +{ + icon_name = n; + update_icon(); +} + void Image::set_keep_aspect(bool ka) { keep_aspect = ka; rebuild(); } +void Image::update_icon() +{ + if(style) + { + Root *root = find_ancestor(); + if(root) + { + if(icon_name.empty()) + image = 0; + else + image = &root->get_resources().get(icon_name); + signal_autosize_changed.emit(); + rebuild(); + return; + } + } + + image = 0; +} + void Image::rebuild_special(const Part &part) { if(part.get_name()=="image") @@ -88,5 +117,24 @@ void Image::rebuild_special(const Part &part) } } +void Image::on_style_change() +{ + if(!icon_name.empty()) + update_icon(); +} + +void Image::on_reparent() +{ + if(!icon_name.empty()) + update_icon(); +} + + +Image::Loader::Loader(Image &img): + DataFile::DerivedObjectLoader(img) +{ + add("icon", &Image::icon_name); +} + } // namespace GLtk } // namespace Msp