1 #include <msp/gl/meshbuilder.h>
11 Image::Image(const GL::Texture2D *i):
18 void Image::autosize()
25 if(const Part *image_part = style->get_part("image"))
27 const Sides &margin = image_part->get_margin();
30 geom.w = max(geom.w, image->get_width()+margin.left+margin.right);
31 geom.h = max(geom.h, image->get_height()+margin.top+margin.bottom);
35 geom.w = max(geom.w, margin.left+margin.right);
36 geom.h = max(geom.h, margin.top+margin.bottom);
43 void Image::set_image(const GL::Texture2D *i)
46 signal_autosize_changed.emit();
50 void Image::set_keep_aspect(bool ka)
56 void Image::rebuild_special(const Part &part)
58 if(part.get_name()=="image")
63 const Alignment &align = part.get_alignment();
64 Geometry rgeom = part.get_geometry();
65 align.apply(rgeom, geom, part.get_margin());
69 float aspect = static_cast<float>(image->get_width())/image->get_height();
70 if(rgeom.w<rgeom.h*aspect)
72 unsigned h = static_cast<unsigned>(rgeom.w/aspect);
73 rgeom.y += (rgeom.h-h)*align.y;
78 unsigned w = static_cast<unsigned>(rgeom.h*aspect);
79 rgeom.x += (rgeom.w-w)*align.x;
84 GL::MeshBuilder bld(part_cache.create_mesh(part, *image));
85 bld.color(1.0f, 1.0f, 1.0f);
87 bld.texcoord(0.0, 0.0);
88 bld.vertex(rgeom.x, rgeom.y);
89 bld.texcoord(1.0, 0.0);
90 bld.vertex(rgeom.x+rgeom.w, rgeom.y);
91 bld.texcoord(1.0, 1.0);
92 bld.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h);
93 bld.texcoord(0.0, 1.0);
94 bld.vertex(rgeom.x, rgeom.y+rgeom.h);