From eb6eee5fabf05abca4a0434c2a8f8f62c900afec Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 15 Dec 2012 20:13:58 +0200 Subject: [PATCH] Miscellaneous improvements for handling graphics --- source/entry.cpp | 7 ++++--- source/hslider.cpp | 6 +++++- source/part.cpp | 3 +-- source/vslider.cpp | 6 +++++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/source/entry.cpp b/source/entry.cpp index 6e2063d..52a7b42 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -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); } } diff --git a/source/hslider.cpp b/source/hslider.cpp index fbd9b94..2a36443 100644 --- a/source/hslider.cpp +++ b/source/hslider.cpp @@ -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); } } diff --git a/source/part.cpp b/source/part.cpp index 7037d4b..f0ee4b9 100644 --- a/source/part.cpp +++ b/source/part.cpp @@ -12,8 +12,7 @@ namespace GLtk { Part::Part(const string &n): name(n) { - for(unsigned i=0; i(0)); } const Graphic *Part::get_graphic(State state) const diff --git a/source/vslider.cpp b/source/vslider.cpp index a32e484..1145b97 100644 --- a/source/vslider.cpp +++ b/source/vslider.cpp @@ -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); } } -- 2.45.2