1 #include <msp/gl/meshbuilder.h>
12 Part::Part(const string &n):
15 fill(graphic, graphic+N_STATES_, static_cast<Graphic *>(0));
18 const Graphic *Part::get_graphic(State state) const
21 throw invalid_argument("Part::get_graphic");
23 return graphic[state];
26 void Part::build(const Geometry &parent, State state, PartCache &cache) const
28 if(!graphic[state] || !graphic[state]->get_texture())
31 Geometry rgeom = geom;
32 align.apply(rgeom, parent, margin);
33 GL::MeshBuilder bld(cache.create_mesh(*this, *graphic[state]->get_texture()));
34 bld.matrix() *= GL::Matrix::translation(rgeom.x, rgeom.y, 0);
35 graphic[state]->build(rgeom.w, rgeom.h, bld);
39 Part::Loader::Loader(Part &p, Resources &r):
40 DataFile::CollectionObjectLoader<Part>(p, &r)
42 add("graphic", &Loader::graphic);
43 add("align", &Loader::align);
44 add("fill", &Loader::fill);
45 add("margin", &Loader::margin);
46 add("size", &Loader::size);
49 Part::Loader::~Loader()
51 for(unsigned i=0; i<N_STATES_; ++i)
54 const Graphic &grph = *obj.graphic[i];
55 const Sides &shadow = grph.get_shadow();
56 obj.geom.w = max(obj.geom.w, grph.get_width()-shadow.left-shadow.right);
57 obj.geom.h = max(obj.geom.h, grph.get_height()-shadow.bottom-shadow.top);
61 void Part::Loader::graphic(State s, const string &n)
63 Graphic *grph = &get_collection().get<Graphic>(n);
64 for(int i=0; i<N_STATES_; ++i)
66 obj.graphic[i] = grph;
69 void Part::Loader::align(float x, float y)
75 void Part::Loader::fill(float w, float h)
81 void Part::Loader::margin()
86 void Part::Loader::size(unsigned w, unsigned h)