X-Git-Url: http://git.tdb.fi/?p=poefilter.git;a=blobdiff_plain;f=source%2Fappearance.cpp;h=f1bb993c90544f65a2dcb758a36a54a98e4bf5c3;hp=bdb25bc97f6b2a5123eb30c04b6027c51aac7778;hb=0388bdcffe5c2c3e720afa9aa911268eac9c32de;hpb=74086c211f082f6f47c3d038dd308a257a81e006 diff --git a/source/appearance.cpp b/source/appearance.cpp index bdb25bc..f1bb993 100644 --- a/source/appearance.cpp +++ b/source/appearance.cpp @@ -1,16 +1,54 @@ +#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", background_color.r, background_color.g, background_color.b)); + + if(border_color.defined) + st.add_line(format("SetBorderColor %d %d %d", border_color.r, border_color.g, border_color.b)); + + if(text_color.defined) + st.add_line(format("SetTextColor %d %d %d", text_color.r, text_color.g, text_color.b)); + + 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) { @@ -31,7 +69,9 @@ void Appearance::Loader::background_color(unsigned r, unsigned g, unsigned b) 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) @@ -41,12 +81,15 @@ void Appearance::Loader::border_color(unsigned r, unsigned g, unsigned b) 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) @@ -56,5 +99,7 @@ void Appearance::Loader::text_color(unsigned r, unsigned g, unsigned b) 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); }