X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fimage.cpp;h=8dbf6cf74fe881e6e871be3894e0ae51aa3147b6;hb=9f38197854e699a6093a906ab43f4238f3cd2388;hp=5dcb2e3f5b84b8e727a98b3aa6180c3642b35a24;hpb=707b59d45ae50b69c94918f8f74313283b304597;p=libs%2Fgltk.git diff --git a/source/image.cpp b/source/image.cpp index 5dcb2e3..8dbf6cf 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,10 +11,8 @@ namespace Msp { namespace GLtk { Image::Image(const GL::Texture2D *i): - image(i), - keep_aspect(true) + image(i) { - focusable = false; } void Image::autosize_special(const Part &part, Geometry &ageom) const @@ -36,14 +36,41 @@ 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() +{ + 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(); + mark_rebuild(); + return; + } + } + + image = 0; } void Image::rebuild_special(const Part &part) @@ -76,18 +103,37 @@ void Image::rebuild_special(const Part &part) GL::MeshBuilder bld(part_cache.create_mesh(part, *image)); bld.color(1.0f, 1.0f, 1.0f); - bld.begin(GL::QUADS); + bld.begin(GL::TRIANGLE_STRIP); + bld.texcoord(0.0, 1.0); + bld.vertex(rgeom.x, rgeom.y+rgeom.h); bld.texcoord(0.0, 0.0); bld.vertex(rgeom.x, rgeom.y); - bld.texcoord(1.0, 0.0); - bld.vertex(rgeom.x+rgeom.w, rgeom.y); bld.texcoord(1.0, 1.0); bld.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h); - bld.texcoord(0.0, 1.0); - bld.vertex(rgeom.x, rgeom.y+rgeom.h); + bld.texcoord(1.0, 0.0); + bld.vertex(rgeom.x+rgeom.w, rgeom.y); bld.end(); } } +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