]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/table.cpp
Cache widget parts in meshes
[libs/gltk.git] / source / table.cpp
index 1fe69619f911aa892563c27b54dba76e613d1c5d..32db6c4af30ddbee2546730291bb8942e4477d3d 100644 (file)
@@ -1,6 +1,6 @@
 #include <stdexcept>
 #include <msp/gl/matrix.h>
-#include <msp/gl/transform.h>
+#include <msp/gl/meshbuilder.h>
 #include "part.h"
 #include "style.h"
 #include "table.h"
@@ -52,7 +52,7 @@ void Table::set_cell_text(unsigned r, unsigned c, const string &t)
        data[r*columns+c] = t;
 }
 
-void Table::render_special(const Part &part) const
+void Table::rebuild_special(const Part &part, CachedPart &cache)
 {
        if(part.get_name()=="cells")
        {
@@ -67,6 +67,10 @@ void Table::render_special(const Part &part) const
                cgeom.h = geom.h/rows;
                cgeom.y = geom.h-cgeom.h;
 
+               cache.texture = &font.get_texture();
+               cache.clear_mesh();
+
+               GL::MeshBuilder bld(*cache.mesh);
                for(unsigned i=0; i<rows; ++i)
                {
                        cgeom.x = 0;
@@ -86,11 +90,10 @@ void Table::render_special(const Part &part) const
 
                                part.get_alignment().apply(rgeom, cgeom, part.get_margin());
 
-                               GL::push_matrix();
-                               GL::translate(rgeom.x, rgeom.y, 0);
-                               GL::scale_uniform(font_size);
+                               GL::MatrixStack::Push _push(bld.matrix());
+                               bld.matrix() *= GL::Matrix::translation(rgeom.x, rgeom.y, 0);
+                               bld.matrix() *= GL::Matrix::scaling(font_size);
                                font.draw_string(text);
-                               GL::pop_matrix();
 
                                cgeom.x += cgeom.w;
                        }