From 11d1b67a9180a0e468b56e355fbe0c88d104ef72 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 28 Nov 2012 20:34:54 +0200 Subject: [PATCH] Make font size a property of Style --- source/dropdown.cpp | 2 +- source/entry.cpp | 9 ++++----- source/list.cpp | 4 ++-- source/style.cpp | 3 ++- source/style.h | 2 ++ source/table.cpp | 2 +- source/text.cpp | 12 ++++++------ 7 files changed, 18 insertions(+), 16 deletions(-) diff --git a/source/dropdown.cpp b/source/dropdown.cpp index 87ea5ee..d1a7bd7 100644 --- a/source/dropdown.cpp +++ b/source/dropdown.cpp @@ -32,7 +32,7 @@ void Dropdown::autosize() { const Sides &margin = text_part->get_margin(); const GL::Font *font = style->get_font(); - float font_size = font->get_default_size(); + float font_size = style->get_font_size(); unsigned line_height = static_cast((font->get_ascent()-font->get_descent())*font_size); geom.h = max(geom.h, line_height+margin.top+margin.bottom); } diff --git a/source/entry.cpp b/source/entry.cpp index 0e1414c..261cf8b 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -36,13 +36,13 @@ void Entry::autosize() { const Sides &margin = text_part->get_margin(); const GL::Font &font = *style->get_font(); - unsigned en_width = static_cast(font.get_string_width("n")*font.get_native_size()); + unsigned en_width = static_cast(font.get_string_width("n")*style->get_font_size()); geom.w = max(geom.w, 10*en_width+margin.left+margin.right); - unsigned line_height = static_cast((font.get_ascent()-font.get_descent())*font.get_native_size()); + unsigned line_height = static_cast((font.get_ascent()-font.get_descent())*style->get_font_size()); if(multiline) { - unsigned line_spacing = font.get_native_size()*6/5; + unsigned line_spacing = style->get_font_size()*6/5; geom.h = max(geom.h, line_height+line_spacing*2+margin.top+margin.bottom); } else @@ -245,8 +245,7 @@ void Entry::check_view_range() if(!multiline || !text_part) return; - const GL::Font *font = style->get_font(); - float font_size = font->get_default_size(); + float font_size = style->get_font_size(); unsigned line_spacing = static_cast(font_size*6/5); const Sides &margin = text_part->get_margin(); diff --git a/source/list.cpp b/source/list.cpp index a180369..e1f39b7 100644 --- a/source/list.cpp +++ b/source/list.cpp @@ -40,7 +40,7 @@ void List::autosize_rows(unsigned n) if(items_part) { const Sides &margin = items_part->get_margin(); - float font_size = style->get_font()->get_default_size(); + float font_size = style->get_font_size(); unsigned max_w = 0; for(vector::iterator i=items.begin(); i!=items.end(); ++i) @@ -223,7 +223,7 @@ void List::on_style_change() items_part = style->get_part("items"); const GL::Font &font = *style->get_font(); - row_height = static_cast((font.get_ascent()-font.get_descent())*font.get_default_size()); + row_height = static_cast((font.get_ascent()-font.get_descent())*style->get_font_size()); check_view_range(); } diff --git a/source/style.cpp b/source/style.cpp index 0138ec2..50c2e77 100644 --- a/source/style.cpp +++ b/source/style.cpp @@ -7,7 +7,8 @@ namespace Msp { namespace GLtk { Style::Style(Resources &r): - font(&r.get_default_font()) + font(&r.get_default_font()), + font_size(font->get_native_size()) { } const Part *Style::get_part(const string &name) const diff --git a/source/style.h b/source/style.h index 3521031..29c5e34 100644 --- a/source/style.h +++ b/source/style.h @@ -41,12 +41,14 @@ public: private: const GL::Font *font; + unsigned font_size; GL::Color font_color; PartSeq parts; public: Style(Resources &); const GL::Font *get_font() const { return font; } + unsigned get_font_size() const { return font_size; } const GL::Color &get_font_color() const { return font_color; } const PartSeq &get_parts() const { return parts; } const Part *get_part(const std::string &) const; diff --git a/source/table.cpp b/source/table.cpp index 936be5c..67a93bc 100644 --- a/source/table.cpp +++ b/source/table.cpp @@ -57,7 +57,7 @@ void Table::render_special(const Part &part) const if(part.get_name()=="cells") { const GL::Font *const font = style->get_font(); - const float font_size = font->get_default_size(); + float font_size = style->get_font_size(); unsigned free_width = geom.w; for(unsigned i=0; iget_font()->get_default_size(); + float font_size = style->get_font_size(); for(vector::iterator i=lines.begin(); i!=lines.end(); ++i) i->width = static_cast(style->get_font()->get_string_width(text.substr(i->start, i->length))*font_size); } @@ -58,7 +58,7 @@ unsigned Text::get_height() const return lines.size(); const GL::Font *font = style->get_font(); - float font_size = font->get_default_size(); + float font_size = style->get_font_size(); unsigned line_height = static_cast((font->get_ascent()-font->get_descent())*font_size); unsigned line_spacing = line_height*6/5; return line_height+(lines.size()-1)*line_spacing; @@ -183,7 +183,7 @@ Text &Text::operator=(const string &t) void Text::find_lines() { lines.clear(); - float font_size = (style ? style->get_font()->get_default_size() : 1); + float font_size = (style ? style->get_font_size() : 1); string::size_type start = 0; while(1) { @@ -213,7 +213,7 @@ void Text::process_lines(const Part &part, const Geometry &parent, unsigned firs return; const GL::Font *font = style->get_font(); - float font_size = font->get_default_size(); + float font_size = style->get_font_size(); unsigned line_height = static_cast((font->get_ascent()-font->get_descent())*font_size); unsigned line_spacing = static_cast(font_size*6/5); unsigned height = line_height+(lines.size()-1)*line_spacing; @@ -244,7 +244,7 @@ void Text::render_line(unsigned i, const Geometry &rgeom, RenderData &data) cons GL::PushMatrix _pushm; GL::translate(rgeom.x, rgeom.y, 0); - GL::scale_uniform(font->get_default_size()); + GL::scale_uniform(style->get_font_size()); font->build_string(text.substr(line.start, line.length), *data.bld); } @@ -257,7 +257,7 @@ void Text::coords_to_geom_line(unsigned i, const Geometry &rgeom, CoordsToGeomDa const GL::Font *font = style->get_font(); data.result = rgeom; - data.result.x += static_cast(font->get_string_width(text.substr(line.start, data.col))*font->get_default_size()); + data.result.x += static_cast(font->get_string_width(text.substr(line.start, data.col))*style->get_font_size()); } } -- 2.43.0