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 Resources &r, const GL::Texture2D *i):
28 void Image::set_image(const GL::Texture2D *i)
33 void Image::set_keep_aspect(bool ka)
38 void Image::render_special(const Part &part) const
40 if(part.get_name()=="image")
45 const Alignment &align = part.get_alignment();
46 Geometry rgeom = part.get_geometry();
47 align.apply(rgeom, geom, part.get_margin());
51 float aspect = static_cast<float>(image->get_width())/image->get_height();
52 if(rgeom.w<rgeom.h*aspect)
54 unsigned h = static_cast<unsigned>(rgeom.w/aspect);
55 rgeom.y += (rgeom.h-h)*align.y;
60 unsigned w = static_cast<unsigned>(rgeom.h*aspect);
61 rgeom.x += (rgeom.w-w)*align.x;
66 GL::Bind _bind_tex(image);
67 GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
68 imm.color(1.0f, 1.0f, 1.0f);
70 imm.texcoord(0.0, 0.0);
71 imm.vertex(rgeom.x, rgeom.y);
72 imm.texcoord(1.0, 0.0);
73 imm.vertex(rgeom.x+rgeom.w, rgeom.y);
74 imm.texcoord(1.0, 1.0);
75 imm.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h);
76 imm.texcoord(0.0, 1.0);
77 imm.vertex(rgeom.x, rgeom.y+rgeom.h);