1 #include <msp/gl/meshbuilder.h>
12 Part::Part(const string &n):
15 for(unsigned i=0; i<N_STATES_; ++i)
19 const Graphic *Part::get_graphic(State state) const
22 throw invalid_argument("Part::get_graphic");
24 return graphic[state];
27 void Part::build(const Geometry &parent, State state, CachedPart &cache) const
35 cache.texture = graphic[state]->get_texture();
38 Geometry rgeom = geom;
39 align.apply(rgeom, parent, margin);
40 GL::MeshBuilder bld(*cache.mesh);
41 bld.matrix() *= GL::Matrix::translation(rgeom.x, rgeom.y, 0);
42 graphic[state]->build(rgeom.w, rgeom.h, bld);
46 Part::Loader::Loader(Part &p, Resources &r):
47 DataFile::CollectionObjectLoader<Part>(p, &r)
49 add("graphic", &Loader::graphic);
50 add("align", &Loader::align);
51 add("fill", &Loader::fill);
52 add("margin", &Loader::margin);
53 add("size", &Loader::size);
56 Part::Loader::~Loader()
58 for(unsigned i=0; i<N_STATES_; ++i)
61 const Graphic &grph = *obj.graphic[i];
62 const Sides &shadow = grph.get_shadow();
63 obj.geom.w = max(obj.geom.w, grph.get_width()-shadow.left-shadow.right);
64 obj.geom.h = max(obj.geom.h, grph.get_height()-shadow.bottom-shadow.top);
68 void Part::Loader::graphic(State s, const string &n)
70 Graphic *grph = &get_collection().get<Graphic>(n);
71 for(int i=0; i<N_STATES_; ++i)
73 obj.graphic[i] = grph;
76 void Part::Loader::align(float x, float y)
82 void Part::Loader::fill(float w, float h)
88 void Part::Loader::margin()
93 void Part::Loader::size(unsigned w, unsigned h)