From b61361ee9f1f049fb3c22a38f68c757c7ca54cd0 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 22 Sep 2013 18:06:00 +0300 Subject: [PATCH] Support different font colors in different states --- source/button.cpp | 2 +- source/dropdown.cpp | 2 +- source/entry.cpp | 2 +- source/label.cpp | 2 +- source/style.cpp | 20 ++++++++++++++++++-- source/style.h | 7 ++++--- source/text.cpp | 8 ++++---- source/text.h | 5 +++-- source/toggle.cpp | 2 +- source/widget.h | 3 +++ 10 files changed, 37 insertions(+), 16 deletions(-) diff --git a/source/button.cpp b/source/button.cpp index 58fc134..8fd2de6 100644 --- a/source/button.cpp +++ b/source/button.cpp @@ -44,7 +44,7 @@ void Button::set_icon(const GL::Texture2D *i) void Button::rebuild_special(const Part &part) { if(part.get_name()=="text") - text.build(part, geom, part_cache); + text.build(part, state, geom, part_cache); if(part.get_name()=="icon") { if(icon) diff --git a/source/dropdown.cpp b/source/dropdown.cpp index 2aac55e..50aced9 100644 --- a/source/dropdown.cpp +++ b/source/dropdown.cpp @@ -72,7 +72,7 @@ void Dropdown::set_selected_index(int index) void Dropdown::rebuild_special(const Part &part) { if(part.get_name()=="text") - text.build(part, geom, part_cache); + text.build(part, state, geom, part_cache); else Widget::rebuild_special(part); } diff --git a/source/entry.cpp b/source/entry.cpp index 12eff06..f21aacb 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -102,7 +102,7 @@ void Entry::set_multiline(bool m) void Entry::rebuild_special(const Part &part) { if(part.get_name()=="text") - text.build(part, geom, first_row, part_cache); + text.build(part, state, geom, first_row, part_cache); else if(part.get_name()=="cursor") { const Graphic *graphic = part.get_graphic(state); diff --git a/source/label.cpp b/source/label.cpp index e6b7efb..2de02f6 100644 --- a/source/label.cpp +++ b/source/label.cpp @@ -29,7 +29,7 @@ void Label::autosize_special(const Part &part, Geometry &ageom) void Label::rebuild_special(const Part &part) { if(part.get_name()=="text") - text.build(part, geom, part_cache); + text.build(part, state, geom, part_cache); } void Label::on_style_change() diff --git a/source/style.cpp b/source/style.cpp index f26112a..369559d 100644 --- a/source/style.cpp +++ b/source/style.cpp @@ -18,6 +18,14 @@ const GL::Font &Style::get_font() const return *font; } +const GL::Color &Style::get_font_color(State s) const +{ + if(s>N_STATES_) + throw invalid_argument("Style::get_font_color"); + + return font_color[s]; +} + const Part *Style::get_part(const string &name) const { for(PartSeq::const_iterator i=parts.begin(); i!=parts.end(); ++i) @@ -38,6 +46,7 @@ Style::Loader::Loader(Style &s, Resources &r): } add("font", &Loader::font); + add("font_color", &Loader::font_color_normal); add("font_color", &Loader::font_color); add("font_size", &Style::font_size); add("part", &Loader::part); @@ -50,9 +59,16 @@ void Style::Loader::font(const string &n) obj.font_size = obj.font->get_native_size(); } -void Style::Loader::font_color(float r, float g, float b) +void Style::Loader::font_color_normal(float r, float g, float b) +{ + font_color(NORMAL, r, g, b); +} + +void Style::Loader::font_color(State s, float r, float g, float b) { - obj.font_color = GL::Color(r, g, b); + for(unsigned i=0; iget_font(); GL::MeshBuilder bld(cache.create_mesh(part, font.get_texture())); - bld.color(style->get_font_color()); + bld.color(style->get_font_color(state)); RenderData data; data.bld = &bld; diff --git a/source/text.h b/source/text.h index db58b24..f688d49 100644 --- a/source/text.h +++ b/source/text.h @@ -3,6 +3,7 @@ #include #include +#include "state.h" namespace Msp { namespace GLtk { @@ -53,8 +54,8 @@ public: unsigned coords_to_offset(unsigned, unsigned) const; Geometry coords_to_geometry(const Part &, const Geometry &, unsigned, unsigned, unsigned) const; - void build(const Part &, const Geometry &, PartCache &) const; - void build(const Part &, const Geometry &, unsigned, PartCache &) const; + void build(const Part &, State, const Geometry &, PartCache &) const; + void build(const Part &, State, const Geometry &, unsigned, PartCache &) const; Text &operator=(const std::string &); private: diff --git a/source/toggle.cpp b/source/toggle.cpp index cb80880..988b0a5 100644 --- a/source/toggle.cpp +++ b/source/toggle.cpp @@ -67,7 +67,7 @@ void Toggle::set_value(bool v) void Toggle::rebuild_special(const Part &part) { if(part.get_name()=="text") - text.build(part, geom, part_cache); + text.build(part, state, geom, part_cache); } void Toggle::button_press(int, int, unsigned btn) diff --git a/source/widget.h b/source/widget.h index dfef4ba..7c601d2 100644 --- a/source/widget.h +++ b/source/widget.h @@ -112,7 +112,10 @@ protected: void set_state(State s) { set_state(s, s); } void clear_state(State s) { set_state(s, NORMAL); } void set_state(State, State); +public: + State get_state() const { return state; } +protected: void rebuild(); virtual void rebuild_special(const Part &); -- 2.45.2