X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fimage.cpp;h=1da782d28a2579e66d4079d8ffb915f703627255;hb=HEAD;hp=f1180c39e1664491fd239560d59f251b8194074a;hpb=b3234ca0277c5e282a2a0a2558b58edb25750653;p=libs%2Fgltk.git diff --git a/source/image.cpp b/source/image.cpp index f1180c3..6e24d71 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; @@ -9,11 +11,8 @@ namespace Msp { namespace GLtk { Image::Image(const GL::Texture2D *i): - image(i), - keep_aspect(true) -{ - focusable = false; -} + image(i) +{ } void Image::autosize_special(const Part &part, Geometry &ageom) const { @@ -36,14 +35,37 @@ 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(); + mark_rebuild(); +} + +void Image::set_icon(const string &n) +{ + icon_name = n; + update_icon(); } void Image::set_keep_aspect(bool ka) { keep_aspect = ka; - rebuild(); + mark_rebuild(); +} + +void Image::update_icon() +{ + image = nullptr; + if(!style) + return; + + Root *root = find_ancestor(); + if(!root) + return; + + if(!icon_name.empty()) + image = &root->get_resources().get(icon_name); + signal_autosize_changed.emit(); + mark_rebuild(); } void Image::rebuild_special(const Part &part) @@ -89,5 +111,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