]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/part.cpp
Adapt to Collection API changes
[libs/gltk.git] / source / part.cpp
index b75e98ff7491cddca368cfc0061cf0ee8774fe2a..127397924f19cf5039b2fe8f1b34df780be8ed8f 100644 (file)
@@ -1,10 +1,3 @@
-/* $Id$
-
-This file is part of libmspgltk
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include <msp/gl/transform.h>
 #include "geometry.h"
 #include "part.h"
@@ -25,7 +18,7 @@ Part::Part(const string &n):
 const Graphic *Part::get_graphic(State state) const
 {
        if(state>N_STATES_)
-               throw InvalidParameterValue("Invalid state");
+               throw invalid_argument("Part::get_graphic");
 
        return graphic[state];
 }
@@ -43,8 +36,7 @@ void Part::render(const Geometry &parent, State state) const
 
 
 Part::Loader::Loader(Part &p, Resources &r):
-       part(p),
-       res(r)
+       DataFile::CollectionObjectLoader<Part>(p, &r)
 {
        add("graphic", &Loader::graphic);
        add("align",   &Loader::align);
@@ -56,43 +48,44 @@ Part::Loader::Loader(Part &p, Resources &r):
 Part::Loader::~Loader()
 {
        for(unsigned i=0; i<N_STATES_; ++i)
-               if(part.graphic[i])
+               if(obj.graphic[i])
                {
-                       const Sides &shadow = part.graphic[i]->get_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);
+                       const Graphic &grph = *obj.graphic[i];
+                       const Sides &shadow = grph.get_shadow();
+                       obj.geom.w = max(obj.geom.w, grph.get_width()-shadow.left-shadow.right);
+                       obj.geom.h = max(obj.geom.h, grph.get_height()-shadow.bottom-shadow.top);
                }
 }
 
 void Part::Loader::graphic(State s, const string &n)
 {
-       Graphic *grph = res.get<Graphic>(n);
+       Graphic *grph = &get_collection().get<Graphic>(n);
        for(int i=0; i<N_STATES_; ++i)
                if((i&s)==s)
-                       part.graphic[i] = grph;
+                       obj.graphic[i] = grph;
 }
 
 void Part::Loader::align(float x, float y)
 {
-       part.align.x = x;
-       part.align.y = y;
+       obj.align.x = x;
+       obj.align.y = y;
 }
 
 void Part::Loader::fill(float w, float h)
 {
-       part.align.w = w;
-       part.align.h = h;
+       obj.align.w = w;
+       obj.align.h = h;
 }
 
 void Part::Loader::margin()
 {
-       load_sub(part.margin);
+       load_sub(obj.margin);
 }
 
 void Part::Loader::size(unsigned w, unsigned h)
 {
-       part.geom.w = w;
-       part.geom.h = h;
+       obj.geom.w = w;
+       obj.geom.h = h;
 }
 
 } // namespace GLtk