X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fappearance.cpp;h=51ff10d36e1e99596198911dc7f039f66916243c;hb=HEAD;hp=bdb25bc97f6b2a5123eb30c04b6027c51aac7778;hpb=74086c211f082f6f47c3d038dd308a257a81e006;p=poefilter.git diff --git a/source/appearance.cpp b/source/appearance.cpp index bdb25bc..51ff10d 100644 --- a/source/appearance.cpp +++ b/source/appearance.cpp @@ -1,26 +1,98 @@ +#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) + sound_volume(100), + show_icon(false), + icon_shape(CIRCLE), + icon_color(WHITE), + icon_size(1), + show_beam(false), + beam_color(WHITE) { } -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; + } + if(other.show_icon) + { + show_icon = true; + icon_shape = other.icon_shape; + icon_color = other.icon_color; + icon_size = other.icon_size; + } + if(other.show_beam) + { + show_beam = true; + beam_color = other.beam_color; + } +} + +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(show_icon) + st.add_line(format("MinimapIcon %d %s %s", icon_size, icon_color, icon_shape)); + + if(sound_type) + { + st.add_line(format("PlayAlertSound %d %d", sound_type, sound_volume)); + st.add_line("DisableDropSound"); + } + + if(show_beam) + st.add_line(format("PlayEffect %s", beam_color)); +} + + +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("inherit", &Loader::inherit); + add("light_beam", &Loader::light_beam); + add("minimap_icon", &Loader::minimap_icon); + add("minimap_icon", &Loader::minimap_icon_size); add("text_color", &Loader::text_color); + add("text_color", &Loader::text_color_alpha); add("text_color", &Loader::text_color_named); } @@ -29,9 +101,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 +118,48 @@ 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::inherit(const string &name) +{ + if(!theme) + throw logic_error("No theme"); + obj = theme->get_appearance(name); +} + +void Appearance::Loader::light_beam(EffectColor color) +{ + obj.show_beam = true; + obj.beam_color = color; +} + +void Appearance::Loader::minimap_icon(EffectColor color, IconShape shape) +{ + minimap_icon_size(color, shape, 1); +} + +void Appearance::Loader::minimap_icon_size(EffectColor color, IconShape shape, unsigned size) +{ + obj.show_icon = true; + obj.icon_shape = shape; + obj.icon_color = color; + obj.icon_size = size; } void Appearance::Loader::text_color(unsigned r, unsigned g, unsigned b) @@ -54,7 +167,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); }