]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/table.cpp
Add constraint types that allow flexible spacing between widgets
[libs/gltk.git] / source / table.cpp
index 4a74e17ba5edec6d2b4e5ac42e1e9d56d0948c7b..32db6c4af30ddbee2546730291bb8942e4477d3d 100644 (file)
@@ -1,5 +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"
@@ -39,24 +40,24 @@ void Table::set_columns(unsigned c)
 void Table::set_column_width(unsigned c, unsigned w)
 {
        if(c>=columns)
-               throw InvalidParameterValue("Column index out of bounds");
+               throw invalid_argument("Table::set_column_width");
        col_w[c] = w;
 }
 
 void Table::set_cell_text(unsigned r, unsigned c, const string &t)
 {
        if(r>=rows || c>=columns)
-               throw InvalidParameterValue("Cell coordinates out of bounds");
+               throw out_of_range("Table::set_cell_text");
 
        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")
        {
-               const GL::Font *const font = style->get_font();
-               const float font_size = font->get_default_size();
+               const GL::Font &font = style->get_font();
+               float font_size = style->get_font_size();
 
                unsigned free_width = geom.w;
                for(unsigned i=0; i<columns; ++i)
@@ -66,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;
@@ -80,16 +85,15 @@ void Table::render_special(const Part &part) const
                                Geometry rgeom;
                                rgeom.x = cgeom.x;
                                rgeom.y = cgeom.y;
-                               rgeom.w = static_cast<unsigned>(font->get_string_width(text)*font_size);
-                               rgeom.h = static_cast<unsigned>((font->get_ascent()-font->get_descent())*font_size);
+                               rgeom.w = static_cast<unsigned>(font.get_string_width(text)*font_size);
+                               rgeom.h = static_cast<unsigned>((font.get_ascent()-font.get_descent())*font_size);
 
                                part.get_alignment().apply(rgeom, cgeom, part.get_margin());
 
-                               GL::push_matrix();
-                               GL::translate(rgeom.x, rgeom.y, 0);
-                               GL::scale_uniform(font_size);
-                               font->draw_string(text);
-                               GL::pop_matrix();
+                               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);
 
                                cgeom.x += cgeom.w;
                        }