#include <msp/gl/meshbuilder.h>
#include "image.h"
#include "part.h"
+#include "resources.h"
+#include "root.h"
#include "style.h"
using namespace std;
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
{
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<Root>();
+ if(!root)
+ return;
+
+ if(!icon_name.empty())
+ image = &root->get_resources().get<GL::Texture2D>(icon_name);
+ signal_autosize_changed.emit();
+ mark_rebuild();
}
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<Image, Widget::Loader>(img)
+{
+ add("icon", &Image::icon_name);
+}
+
} // namespace GLtk
} // namespace Msp