+#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", 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<Appearance>(a),
theme(t)
{
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)
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)
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);
}
#ifndef APPEARANCE_H_
#define APPEARANCE_H_
+#include <list>
#include <msp/datafile/objectloader.h>
#include "color.h"
+class FilterStatement;
class Theme;
class Appearance
class Loader: public Msp::DataFile::ObjectLoader<Appearance>
{
private:
- const Theme &theme;
+ const Theme *theme;
public:
- Loader(Appearance &, const Theme &);
+ Loader(Appearance &, const Theme * = 0);
void background_color(unsigned, unsigned, unsigned);
void background_color_named(const std::string &);
public:
Appearance();
+ void merge_from(const Appearance &);
+
unsigned get_font_size() const { return font_size; }
const Color &get_border_color() const { return border_color; }
const Color &get_background_color() const { return background_color; }
const Color &get_text_color() const { return text_color; }
unsigned get_sound_type() const { return sound_type; }
unsigned get_sound_volume() const { return sound_volume; }
+
+ void add_lines(FilterStatement &) const;
};
#endif
using namespace std;
using namespace Msp;
-Category::Category():
+Category::Category(const string &n):
+ name(n),
condition(0),
order(0)
{ }
Category::Category(const Category &other):
+ name(other.name),
condition(other.condition ? other.condition->clone() : 0),
order(other.order),
appearance(other.appearance)
Category &Category::operator=(const Category &other)
{
delete condition;
+ name = other.name;
condition = (other.condition ? other.condition->clone() : 0);
order = other.order;
appearance = other.appearance;
void Category::create_statements(list<FilterStatement> &st) const
{
- st.clear();
- st.push_back(FilterStatement());
- st.back().add_line(format("SetFontSize %d", appearance.get_font_size()));
-
- const Color &bg_color = appearance.get_background_color();
- if(bg_color.defined)
- st.back().add_line(format("SetBackgroundColor %d %d %d", bg_color.r, bg_color.g, bg_color.b));
-
- const Color &brd_color = appearance.get_border_color();
- if(brd_color.defined)
- st.back().add_line(format("SetBorderColor %d %d %d", brd_color.r, brd_color.g, brd_color.b));
-
- const Color &txt_color = appearance.get_text_color();
- if(txt_color.defined)
- st.back().add_line(format("SetTextColor %d %d %d", txt_color.r, txt_color.g, txt_color.b));
-
- if(appearance.get_sound_type())
- st.back().add_line(format("PlayAlertSound %d %d", appearance.get_sound_type(), appearance.get_sound_volume()));
+ if(st.empty())
+ st.push_back(FilterStatement());
if(condition)
condition->add_lines(st);
DataFile::ObjectLoader<Category>(c),
poe(p),
compound(n),
- app_loader(c.appearance, p.get_theme())
+ app_loader(c.appearance)
{
add("and", &Loader::and_);
- add("appearance", &Loader::appearance);
add("base_type", &Loader::condition<BaseTypeCondition>);
add("class", &Loader::condition<ClassCondition>);
add_range<DropLevelCondition>("drop_level");
add_condition(cond.release());
}
-void Category::Loader::appearance(const std::string &name)
-{
- obj.appearance = poe.get_theme().get_appearance(name);
-}
-
template<typename T>
void Category::Loader::condition(typename T::Type value)
{
private:
void and_();
- void appearance(const std::string &);
template<typename T>
void condition(typename T::Type);
};
private:
+ std::string name;
Condition *condition;
unsigned order;
Appearance appearance;
public:
- Category();
+ Category(const std::string & = std::string());
Category(const Category &);
Category &operator=(const Category &);
~Category();
+ const std::string &get_name() const { return name; }
unsigned get_order() const { return order; }
+ const Appearance &get_appearance() const { return appearance; }
void create_statements(std::list<FilterStatement> &) const;
};
-#include <algorithm>
+#include <msp/core/algorithm.h>
#include <msp/core/maputils.h>
#include <msp/io/print.h>
#include "category.h"
void Filter::write(IO::Base &out) const
{
- for(list<const Category *>::const_iterator i=categories.begin(); i!=categories.end(); ++i)
+ for(list<Block>::const_iterator i=blocks.begin(); i!=blocks.end(); ++i)
{
list<FilterStatement> st;
- //IO::print(out, "# %s\n", i->first);
- (*i)->create_statements(st);
+ st.push_back(FilterStatement());
+ i->appearance.add_lines(st.back());
+ i->category->create_statements(st);
+
+ IO::print(out, "# %s\n", i->category->get_name());
for(list<FilterStatement>::const_iterator j=st.begin(); j!=st.end(); ++j)
j->write(out);
}
categs.push_back(&poe.get_category(name));
for(list<const Category *>::const_iterator i=categs.begin(); i!=categs.end(); ++i)
- {
- list<const Category *>::iterator j = find(obj.categories.begin(), obj.categories.end(), *i);
- if(j!=obj.categories.end())
- obj.categories.erase(j);
- }
+ for(list<Block>::iterator j=obj.blocks.begin(); j!=obj.blocks.end(); ++j)
+ if(j->category==*i)
+ {
+ obj.blocks.erase(j);
+ break;
+ }
}
void Filter::Loader::include(const string &name)
{
const Filter &base = poe.get_filter(name);
- obj.categories.insert(obj.categories.end(), base.categories.begin(), base.categories.end());
+ obj.blocks.insert(obj.blocks.end(), base.blocks.begin(), base.blocks.end());
}
void Filter::Loader::show(const string &name)
categs.push_back(&poe.get_category(name));
for(list<const Category *>::const_iterator i=categs.begin(); i!=categs.end(); ++i)
- if(find(obj.categories.begin(), obj.categories.end(), *i)==obj.categories.end())
- obj.categories.push_back(*i);
+ {
+ bool found = false;
+ for(list<Block>::const_iterator j=obj.blocks.begin(); (!found && j!=obj.blocks.end()); ++j)
+ found = (j->category==*i);
+
+ if(!found)
+ {
+ Block blk;
+ blk.category = *i;
+ blk.appearance = (*i)->get_appearance();
+ if(const Appearance *app = poe.get_theme().find_appearance((*i)->get_name()))
+ blk.appearance.merge_from(*app);
+ obj.blocks.push_back(blk);
+ }
+ }
}
#include <string>
#include <msp/datafile/objectloader.h>
#include <msp/io/base.h>
+#include "appearance.h"
class Category;
class PoeFilter;
};
private:
- std::list<const Category *> categories;
+ struct Block
+ {
+ const Category *category;
+ Appearance appearance;
+ };
+
+ std::list<Block> blocks;
bool abstract;
public:
void PoeFilter::Loader::category(const string &name)
{
- Category cat;
+ Category cat(name);
load_sub(cat, obj);
obj.categories[name] = cat;
}
return get_item(appearances, name);
}
+const Appearance *Theme::find_appearance(const string &name) const
+{
+ AppearanceMap::const_iterator i = appearances.find(name);
+ return (i!=appearances.end() ? &i->second : 0);
+}
+
Theme::Loader::Loader(Theme &t):
DataFile::ObjectLoader<Theme>(t)
void Theme::Loader::appearance(const string &name)
{
Appearance app;
- load_sub(app, obj);
+ Appearance::Loader ldr(app, &obj);
+ load_sub_with(ldr);
obj.set_appearance(name, app);
}
void set_appearance(const std::string &, const Appearance &);
const Appearance &get_appearance(const std::string &) const;
+ const Appearance *find_appearance(const std::string &) const;
};
#endif