X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fappearance.cpp;h=ccd847666b388900534464f1ae196b0d09737e53;hb=9931bfa14fbaef1e6fe8858fcb56c4beb9a17c67;hp=bdb25bc97f6b2a5123eb30c04b6027c51aac7778;hpb=74086c211f082f6f47c3d038dd308a257a81e006;p=poefilter.git diff --git a/source/appearance.cpp b/source/appearance.cpp index bdb25bc..ccd8476 100644 --- a/source/appearance.cpp +++ b/source/appearance.cpp @@ -1,26 +1,67 @@ +#include #include "appearance.h" +#include "filter.h" #include "theme.h" using namespace std; using namespace Msp; Appearance::Appearance(): - font_size(32), + font_size(0), sound_type(0), sound_volume(100) { } -Appearance::Loader::Loader(Appearance &a, const Theme &t): +void Appearance::merge_from(const Appearance &other) +{ + if(other.font_size) + font_size = other.font_size; + if(other.border_color.defined) + border_color = other.border_color; + if(other.background_color.defined) + background_color = other.background_color; + if(other.text_color.defined) + text_color = other.text_color; + if(other.sound_type) + { + sound_type = other.sound_type; + sound_volume = other.sound_volume; + } +} + +void Appearance::add_lines(FilterStatement &st) const +{ + if(font_size) + st.add_line(format("SetFontSize %d", font_size)); + + if(background_color.defined) + st.add_line(format("SetBackgroundColor %d %d %d %d", background_color.r, background_color.g, background_color.b, background_color.a)); + + if(border_color.defined) + st.add_line(format("SetBorderColor %d %d %d %d", border_color.r, border_color.g, border_color.b, border_color.a)); + + if(text_color.defined) + st.add_line(format("SetTextColor %d %d %d %d", text_color.r, text_color.g, text_color.b, text_color.a)); + + if(sound_type) + st.add_line(format("PlayAlertSound %d %d", sound_type, sound_volume)); +} + + +Appearance::Loader::Loader(Appearance &a, const Theme *t): DataFile::ObjectLoader(a), theme(t) { add("alert_sound", &Appearance::sound_type, &Appearance::sound_volume); add("background_color", &Loader::background_color); + add("background_color", &Loader::background_color_alpha); add("background_color", &Loader::background_color_named); add("border_color", &Loader::border_color); + add("border_color", &Loader::border_color_alpha); add("border_color", &Loader::border_color_named); add("font_size", &Loader::font_size); add("text_color", &Loader::text_color); + add("text_color", &Loader::text_color_alpha); add("text_color", &Loader::text_color_named); } @@ -29,9 +70,16 @@ void Appearance::Loader::background_color(unsigned r, unsigned g, unsigned b) obj.background_color = Color(r, g, b); } +void Appearance::Loader::background_color_alpha(unsigned r, unsigned g, unsigned b, unsigned a) +{ + obj.background_color = Color(r, g, b, a); +} + void Appearance::Loader::background_color_named(const string &name) { - obj.background_color = theme.get_color(name); + if(!theme) + throw logic_error("No theme"); + obj.background_color = theme->get_color(name); } void Appearance::Loader::border_color(unsigned r, unsigned g, unsigned b) @@ -39,14 +87,22 @@ void Appearance::Loader::border_color(unsigned r, unsigned g, unsigned b) obj.border_color = Color(r, g, b); } +void Appearance::Loader::border_color_alpha(unsigned r, unsigned g, unsigned b, unsigned a) +{ + obj.border_color = Color(r, g, b, a); +} + void Appearance::Loader::border_color_named(const string &name) { - obj.border_color = theme.get_color(name); + if(!theme) + throw logic_error("No theme"); + obj.border_color = theme->get_color(name); } void Appearance::Loader::font_size(float s) { - obj.font_size = theme.get_base_font_size()*s+0.5f; + float base_size = (theme ? theme->get_base_font_size() : 32); + obj.font_size = base_size*s+0.5f; } void Appearance::Loader::text_color(unsigned r, unsigned g, unsigned b) @@ -54,7 +110,14 @@ void Appearance::Loader::text_color(unsigned r, unsigned g, unsigned b) obj.text_color = Color(r, g, b); } +void Appearance::Loader::text_color_alpha(unsigned r, unsigned g, unsigned b, unsigned a) +{ + obj.text_color = Color(r, g, b, a); +} + void Appearance::Loader::text_color_named(const string &name) { - obj.text_color = theme.get_color(name); + if(!theme) + throw logic_error("No theme"); + obj.text_color = theme->get_color(name); }