]> git.tdb.fi Git - libs/gltk.git/commitdiff
Miscellaneous improvements for handling graphics
authorMikko Rasa <tdb@tdb.fi>
Sat, 15 Dec 2012 18:13:58 +0000 (20:13 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 15 Dec 2012 18:13:58 +0000 (20:13 +0200)
source/entry.cpp
source/hslider.cpp
source/part.cpp
source/vslider.cpp

index 6e2063d04abec1de23c73baeb8417094c9ca0a73..52a7b429d269e0013e71c44d7d918a9a8dca55b5 100644 (file)
@@ -110,7 +110,8 @@ void Entry::rebuild_special(const Part &part, CachedPart &cache)
                text.build(part, geom, first_row, cache);
        else if(part.get_name()=="cursor")
        {
-               if(!text_part || !part.get_graphic(state))
+               const Graphic *graphic = part.get_graphic(state);
+               if(!text_part || !graphic)
                {
                        cache.texture = 0;
                        return;
@@ -127,12 +128,12 @@ void Entry::rebuild_special(const Part &part, CachedPart &cache)
 
                Geometry rgeom = text.coords_to_geometry(*text_part, geom, first_row, row, col);
 
-               cache.texture = part.get_graphic(state)->get_texture();
+               cache.texture = graphic->get_texture();
                cache.clear_mesh();
 
                GL::MeshBuilder bld(*cache.mesh);
                bld.matrix() *= GL::Matrix::translation(rgeom.x, rgeom.y, 0);
-               part.get_graphic(state)->build(part.get_geometry().w, part.get_geometry().h, bld);
+               graphic->build(part.get_geometry().w, part.get_geometry().h, bld);
        }
 }
 
index fbd9b943a8c4703dc8fe77acc542df843777173f..2a3644367ea52adb85beeb1f2f02abad007fc25c 100644 (file)
@@ -32,6 +32,10 @@ void HSlider::rebuild_special(const Part &part, CachedPart &cache)
 {
        if(part.get_name()=="slider")
        {
+               const Graphic *graphic = part.get_graphic(state);
+               if(!graphic)
+                       return;
+
                Alignment align = part.get_alignment();
                if(max>min)
                        align.x = (value-min)/(max-min);
@@ -44,7 +48,7 @@ void HSlider::rebuild_special(const Part &part, CachedPart &cache)
 
                GL::MeshBuilder bld(*cache.mesh);
                bld.matrix() *= GL::Matrix::translation(pgeom.x, pgeom.y, 0);
-               part.get_graphic(state)->build(pgeom.w, pgeom.h, bld);
+               graphic->build(pgeom.w, pgeom.h, bld);
        }
 }
 
index 7037d4b3384374568bc662a9edc1df3299776ba3..f0ee4b920a226bd2108bd946523ae92cf4550447 100644 (file)
@@ -12,8 +12,7 @@ namespace GLtk {
 Part::Part(const string &n):
        name(n)
 {
-       for(unsigned i=0; i<N_STATES_; ++i)
-               graphic[i] = 0;
+       fill(graphic, graphic+N_STATES_, static_cast<Graphic *>(0));
 }
 
 const Graphic *Part::get_graphic(State state) const
index a32e484906c19b0944599a47f8b0932adde24b0b..1145b97c3c762e67dfec564997baa6d6a0114e16 100644 (file)
@@ -32,6 +32,10 @@ void VSlider::rebuild_special(const Part &part, CachedPart &cache)
 {
        if(part.get_name()=="slider")
        {
+               const Graphic *graphic = part.get_graphic(state);
+               if(!graphic)
+                       return;
+
                Alignment align = part.get_alignment();
                if(max>min)
                        align.y = (value-min)/(max-min);
@@ -44,7 +48,7 @@ void VSlider::rebuild_special(const Part &part, CachedPart &cache)
 
                GL::MeshBuilder bld(*cache.mesh);
                bld.matrix() *= GL::Matrix::translation(pgeom.x, pgeom.y, 0);
-               part.get_graphic(state)->build(pgeom.w, pgeom.h, bld);
+               graphic->build(pgeom.w, pgeom.h, bld);
        }
 }