X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fpart.cpp;h=1d965385e1372d2b3da5e765fac3e26351d4dc8c;hb=d7ae291415a21cc886fe318070b41ac8d3e57a30;hp=38e75d7c034d4526f08662ec732deb7d8493f83d;hpb=c1f038acb91eb3bfaa34dfd4729d19ed3f871a42;p=libs%2Fgltk.git diff --git a/source/part.cpp b/source/part.cpp index 38e75d7..1d96538 100644 --- a/source/part.cpp +++ b/source/part.cpp @@ -7,9 +7,10 @@ using namespace std; namespace Msp { namespace GLtk { -Part::Part(const Resources &r, const string &n): - res(r), +Part::Part(const string &n): name(n), + width(1), + height(1), fill_x(true), fill_y(true) { @@ -27,33 +28,42 @@ const Graphic *Part::get_graphic(State state) const void Part::render(const Geometry &geom, State state) const { - const Graphic::Sides &shadow=graphic[state]->get_shadow(); - unsigned gw=(fill_x ? geom.w : graphic[state]->get_width())-shadow.left-shadow.right; - unsigned gh=(fill_y ? geom.h : graphic[state]->get_height())-shadow.top-shadow.bottom; + unsigned gw=(fill_x ? geom.w : width); + unsigned gh=(fill_y ? geom.h : height); align.apply(geom, gw, gh); graphic[state]->render(gw, gh); } -Part::Loader::Loader(Part &p): - part(p) +Part::Loader::Loader(Part &p, Resources &r): + part(p), + res(r) { add("graphic", &Loader::graphic); add("align", &Loader::align); add("fill", &Loader::fill); } -void Part::Loader::graphic(State s, const string &n) +Part::Loader::~Loader() { - part.graphic[s]=&part.res.get_graphic(n); - if(s==NORMAL) + for(unsigned i=0; iget_shadow(); + part.width=max(part.width, part.graphic[i]->get_width()-shadow.left-shadow.right); + part.height=max(part.height, part.graphic[i]->get_height()-shadow.bottom-shadow.top); + } + else + part.graphic[i]=part.graphic[NORMAL]; } } +void Part::Loader::graphic(State s, const string &n) +{ + part.graphic[s]=&res.get(n); +} + void Part::Loader::align(int x, int y) { part.align.x=x;