]> git.tdb.fi Git - poefilter.git/blobdiff - source/appearance.cpp
Add inheritance for appearances
[poefilter.git] / source / appearance.cpp
index bdb25bc97f6b2a5123eb30c04b6027c51aac7778..ffe47ff576600b13e4e11d1828bf91fb3c1e67cf 100644 (file)
@@ -1,26 +1,68 @@
+#include <msp/strings/format.h>
 #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<Appearance>(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("text_color", &Loader::text_color);
+       add("text_color", &Loader::text_color_alpha);
        add("text_color", &Loader::text_color_named);
 }
 
@@ -29,9 +71,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 +88,29 @@ 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::text_color(unsigned r, unsigned g, unsigned b)
@@ -54,7 +118,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);
 }