1 #include <msp/gl/meshbuilder.h>
12 Part::Part(const string &n):
16 const Graphic *Part::get_graphic(State state) const
19 throw invalid_argument("Part::get_graphic");
21 return graphic[state];
24 void Part::build(const Geometry &parent, State state, PartCache &cache) const
26 if(!graphic[state] || !graphic[state]->get_texture())
29 Geometry rgeom = geom;
30 align.apply(rgeom, parent, margin);
31 GL::MeshBuilder bld(cache.create_mesh(*this, *graphic[state]->get_texture()));
32 bld.transform(GL::Matrix::translation(rgeom.x, rgeom.y, 0));
33 graphic[state]->build(rgeom.w, rgeom.h, bld);
37 Part::Loader::Loader(Part &p, Resources &r):
38 DataFile::CollectionObjectLoader<Part>(p, &r)
40 add("graphic", &Loader::graphic);
41 add("align", &Loader::align);
42 add("fill", &Loader::fill);
43 add("margin", &Loader::margin);
44 add("size", &Loader::size);
47 Part::Loader::~Loader()
49 for(unsigned i=0; i<N_STATES_; ++i)
52 const Graphic &grph = *obj.graphic[i];
53 const Sides &shadow = grph.get_shadow();
54 obj.geom.w = max(obj.geom.w, grph.get_width()-shadow.left-shadow.right);
55 obj.geom.h = max(obj.geom.h, grph.get_height()-shadow.bottom-shadow.top);
59 void Part::Loader::graphic_normal(const string &n)
64 void Part::Loader::graphic(State s, const string &n)
66 Graphic *grph = (n.empty() ? nullptr : &get_collection().get<Graphic>(n));
67 for(int i=0; i<N_STATES_; ++i)
69 obj.graphic[i] = grph;
72 void Part::Loader::align(float x, float y)
78 void Part::Loader::fill(float w, float h)
84 void Part::Loader::margin()
89 void Part::Loader::size(unsigned w, unsigned h)