3 This file is part of libmspgltk
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/gl/bindable.h>
9 #include <msp/gl/immediate.h>
10 #include <msp/gl/matrix.h>
19 Image::Image(const GL::Texture2D *i):
26 void Image::set_image(const GL::Texture2D *i)
31 void Image::set_keep_aspect(bool ka)
36 void Image::render_special(const Part &part) const
38 if(part.get_name()=="image")
43 const Alignment &align = part.get_alignment();
44 Geometry rgeom = part.get_geometry();
45 align.apply(rgeom, geom, part.get_margin());
49 float aspect = static_cast<float>(image->get_width())/image->get_height();
50 if(rgeom.w<rgeom.h*aspect)
52 unsigned h = static_cast<unsigned>(rgeom.w/aspect);
53 rgeom.y += (rgeom.h-h)*align.y;
58 unsigned w = static_cast<unsigned>(rgeom.h*aspect);
59 rgeom.x += (rgeom.w-w)*align.x;
64 GL::Bind _bind_tex(image);
65 GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
66 imm.color(1.0f, 1.0f, 1.0f);
68 imm.texcoord(0.0, 0.0);
69 imm.vertex(rgeom.x, rgeom.y);
70 imm.texcoord(1.0, 0.0);
71 imm.vertex(rgeom.x+rgeom.w, rgeom.y);
72 imm.texcoord(1.0, 1.0);
73 imm.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h);
74 imm.texcoord(0.0, 1.0);
75 imm.vertex(rgeom.x, rgeom.y+rgeom.h);