1 #include <msp/core/algorithm.h>
10 const GL::Font &Style::get_font() const
13 throw logic_error("!font");
17 const GL::Color &Style::get_font_color(State s) const
20 throw invalid_argument("Style::get_font_color");
25 const GL::Sampler &Style::get_sampler() const
28 throw logic_error("!sampler");
32 const Part *Style::find_part(const string &name) const
34 auto i = find_if(parts, [&name](const Part &p){ return p.get_name()==name; });
35 return (i!=parts.end() ? &*i : nullptr);
38 bool Style::compare_states(State s1, State s2) const
40 if(s1>=N_STATES_ || s2>=N_STATES_)
41 throw invalid_argument("Style::compare_states");
43 const GL::Color &c1 = font_color[s1];
44 const GL::Color &c2 = font_color[s2];
45 if(c1.r!=c2.r || c1.g!=c2.g || c1.b!=c2.b)
48 for(const Part &p: parts)
49 if(p.get_graphic(s1)!=p.get_graphic(s2))
56 Style::Loader::Loader(Style &s, Resources &r):
57 DataFile::CollectionObjectLoader<Style, Resources>(s, &r)
61 obj.font = &get_collection().get_default_font();
62 obj.font_size = obj.font->get_native_size();
65 obj.sampler = &get_collection().get<GL::Sampler>("linear_clamp.samp");
67 add("font", &Loader::font);
68 add("font_color", &Loader::font_color_normal);
69 add("font_color", &Loader::font_color);
70 add("font_size", &Style::font_size);
71 add("part", &Loader::part);
72 add("part", &Loader::unnamed_part);
73 add("sampler", &Style::sampler);
76 void Style::Loader::font(const string &n)
78 obj.font = &get_collection().get<GL::Font>(n);
79 obj.font_size = obj.font->get_native_size();
82 void Style::Loader::font_color_normal(float r, float g, float b)
84 font_color(NORMAL, r, g, b);
87 void Style::Loader::font_color(State s, float r, float g, float b)
89 for(unsigned i=0; i<N_STATES_; ++i)
91 obj.font_color[i] = GL::Color(r, g, b);
94 void Style::Loader::part(const string &n)
97 load_sub(p, get_collection());
98 obj.parts.push_back(p);
101 void Style::Loader::unnamed_part()