X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fpart.cpp;h=a74c91141ca717c86262c8a634f8db75ff359226;hb=8ffcd589660022f05d8b3b1dbb36c0c0aa91954a;hp=38e75d7c034d4526f08662ec732deb7d8493f83d;hpb=c1f038acb91eb3bfaa34dfd4729d19ed3f871a42;p=libs%2Fgltk.git diff --git a/source/part.cpp b/source/part.cpp index 38e75d7..a74c911 100644 --- a/source/part.cpp +++ b/source/part.cpp @@ -1,3 +1,11 @@ +/* $Id$ + +This file is part of libmspgltk +Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#include #include "geometry.h" #include "part.h" #include "resources.h" @@ -7,11 +15,8 @@ using namespace std; namespace Msp { namespace GLtk { -Part::Part(const Resources &r, const string &n): - res(r), - name(n), - fill_x(true), - fill_y(true) +Part::Part(const string &n): + name(n) { for(unsigned i=0; iget_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; - align.apply(geom, gw, gh); - graphic[state]->render(gw, gh); + if(!graphic[state]) + return; + + Geometry rgeom=geom; + align.apply(rgeom, parent, margin); + GL::translate(rgeom.x, rgeom.y, 0); + graphic[state]->render(rgeom.w, rgeom.h); } -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); + add("margin", &Loader::margin); + add("size", &Loader::size); } -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.geom.w=max(part.geom.w, part.graphic[i]->get_width()-shadow.left-shadow.right); + part.geom.h=max(part.geom.h, part.graphic[i]->get_height()-shadow.bottom-shadow.top); + } + else + part.graphic[i]=part.graphic[NORMAL]; } } -void Part::Loader::align(int x, int y) +void Part::Loader::graphic(State s, const string &n) +{ + part.graphic[s]=res.get(n); +} + +void Part::Loader::align(float x, float y) { part.align.x=x; part.align.y=y; } -void Part::Loader::fill(bool x, bool y) +void Part::Loader::fill(float w, float h) +{ + part.align.w=w; + part.align.h=h; +} + +void Part::Loader::margin() +{ + load_sub(part.margin); +} + +void Part::Loader::size(unsigned w, unsigned h) { - part.fill_x=x; - part.fill_y=y; + part.geom.w=w; + part.geom.h=h; } } // namespace GLtk