1 #include <msp/gl/bindable.h>
2 #include <msp/gl/immediate.h>
3 #include <msp/gl/matrix.h>
13 Image::Image(const GL::Texture2D *i):
20 void Image::autosize()
27 if(const Part *image_part = style->get_part("image"))
29 const Sides &margin = image_part->get_margin();
32 geom.w = max(geom.w, image->get_width()+margin.left+margin.right);
33 geom.h = max(geom.h, image->get_height()+margin.top+margin.bottom);
37 geom.w = max(geom.w, margin.left+margin.right);
38 geom.h = max(geom.h, margin.top+margin.bottom);
43 void Image::set_image(const GL::Texture2D *i)
46 signal_autosize_changed.emit();
49 void Image::set_keep_aspect(bool ka)
54 void Image::render_special(const Part &part) const
56 if(part.get_name()=="image")
61 const Alignment &align = part.get_alignment();
62 Geometry rgeom = part.get_geometry();
63 align.apply(rgeom, geom, part.get_margin());
67 float aspect = static_cast<float>(image->get_width())/image->get_height();
68 if(rgeom.w<rgeom.h*aspect)
70 unsigned h = static_cast<unsigned>(rgeom.w/aspect);
71 rgeom.y += (rgeom.h-h)*align.y;
76 unsigned w = static_cast<unsigned>(rgeom.h*aspect);
77 rgeom.x += (rgeom.w-w)*align.x;
82 GL::Bind _bind_tex(image);
83 GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
84 imm.color(1.0f, 1.0f, 1.0f);
86 imm.texcoord(0.0, 0.0);
87 imm.vertex(rgeom.x, rgeom.y);
88 imm.texcoord(1.0, 0.0);
89 imm.vertex(rgeom.x+rgeom.w, rgeom.y);
90 imm.texcoord(1.0, 1.0);
91 imm.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h);
92 imm.texcoord(0.0, 1.0);
93 imm.vertex(rgeom.x, rgeom.y+rgeom.h);