1 #include <msp/gl/meshbuilder.h>
11 Image::Image(const GL::Texture2D *i):
17 void Image::autosize_special(const Part &part, Geometry &ageom) const
19 if(part.get_name()=="image")
21 const Sides &margin = part.get_margin();
24 ageom.w = max(ageom.w, image->get_width()+margin.left+margin.right);
25 ageom.h = max(ageom.h, image->get_height()+margin.top+margin.bottom);
29 ageom.w = max(ageom.w, margin.left+margin.right);
30 ageom.h = max(ageom.h, margin.top+margin.bottom);
35 void Image::set_image(const GL::Texture2D *i)
38 signal_autosize_changed.emit();
42 void Image::set_keep_aspect(bool ka)
48 void Image::rebuild_special(const Part &part)
50 if(part.get_name()=="image")
55 const Alignment &align = part.get_alignment();
56 Geometry rgeom = part.get_geometry();
57 align.apply(rgeom, geom, part.get_margin());
61 float aspect = static_cast<float>(image->get_width())/image->get_height();
62 if(rgeom.w<rgeom.h*aspect)
64 unsigned h = static_cast<unsigned>(rgeom.w/aspect);
65 rgeom.y += (rgeom.h-h)*align.y;
70 unsigned w = static_cast<unsigned>(rgeom.h*aspect);
71 rgeom.x += (rgeom.w-w)*align.x;
76 GL::MeshBuilder bld(part_cache.create_mesh(part, *image));
77 bld.color(1.0f, 1.0f, 1.0f);
78 bld.begin(GL::TRIANGLE_STRIP);
79 bld.texcoord(0.0, 1.0);
80 bld.vertex(rgeom.x, rgeom.y+rgeom.h);
81 bld.texcoord(0.0, 0.0);
82 bld.vertex(rgeom.x, rgeom.y);
83 bld.texcoord(1.0, 1.0);
84 bld.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h);
85 bld.texcoord(1.0, 0.0);
86 bld.vertex(rgeom.x+rgeom.w, rgeom.y);