3 This file is part of libmspgltk
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/gl/transform.h>
11 #include "resources.h"
18 Part::Part(const string &n):
23 for(unsigned i=0; i<N_STATES_; ++i)
27 const Graphic *Part::get_graphic(State state) const
30 throw InvalidParameterValue("Invalid state");
32 return graphic[state];
35 void Part::render(const Geometry &parent, State state) const
42 rgeom.w=parent.w-margin.left-margin.right;
44 rgeom.h=parent.h-margin.bottom-margin.top;
45 align.apply(rgeom, parent, margin);
46 GL::translate(rgeom.x, rgeom.y, 0);
47 graphic[state]->render(rgeom.w, rgeom.h);
51 Part::Loader::Loader(Part &p, Resources &r):
55 add("graphic", &Loader::graphic);
56 add("align", &Loader::align);
57 add("fill", &Loader::fill);
58 add("margin", &Loader::margin);
61 Part::Loader::~Loader()
63 for(unsigned i=0; i<N_STATES_; ++i)
67 const Sides &shadow=part.graphic[i]->get_shadow();
68 part.geom.w=max(part.geom.w, part.graphic[i]->get_width()-shadow.left-shadow.right);
69 part.geom.h=max(part.geom.h, part.graphic[i]->get_height()-shadow.bottom-shadow.top);
72 part.graphic[i]=part.graphic[NORMAL];
76 void Part::Loader::graphic(State s, const string &n)
78 part.graphic[s]=res.get<Graphic>(n);
81 void Part::Loader::align(float x, float y)
87 void Part::Loader::fill(bool x, bool y)
93 void Part::Loader::margin()
95 load_sub(part.margin);