1 #include <msp/core/algorithm.h>
16 const GL::Font &Style::get_font() const
19 throw logic_error("!font");
23 const GL::Color &Style::get_font_color(State s) const
26 throw invalid_argument("Style::get_font_color");
31 const GL::Sampler &Style::get_sampler() const
34 throw logic_error("!sampler");
38 const Part *Style::get_part(const string &name) const
40 auto i = find_if(parts, [&name](const Part &p){ return p.get_name()==name; });
41 return (i!=parts.end() ? &*i : 0);
44 bool Style::compare_states(State s1, State s2) const
46 if(s1>=N_STATES_ || s2>=N_STATES_)
47 throw invalid_argument("Style::compare_states");
49 const GL::Color &c1 = font_color[s1];
50 const GL::Color &c2 = font_color[s2];
51 if(c1.r!=c2.r || c1.g!=c2.g || c1.b!=c2.b)
54 for(const Part &p: parts)
55 if(p.get_graphic(s1)!=p.get_graphic(s2))
62 Style::Loader::Loader(Style &s, Resources &r):
63 DataFile::CollectionObjectLoader<Style, Resources>(s, &r)
67 obj.font = &get_collection().get_default_font();
68 obj.font_size = obj.font->get_native_size();
71 obj.sampler = &get_collection().get<GL::Sampler>("linear_clamp.samp");
73 add("font", &Loader::font);
74 add("font_color", &Loader::font_color_normal);
75 add("font_color", &Loader::font_color);
76 add("font_size", &Style::font_size);
77 add("part", &Loader::part);
78 add("part", &Loader::unnamed_part);
79 add("sampler", &Style::sampler);
82 void Style::Loader::font(const string &n)
84 obj.font = &get_collection().get<GL::Font>(n);
85 obj.font_size = obj.font->get_native_size();
88 void Style::Loader::font_color_normal(float r, float g, float b)
90 font_color(NORMAL, r, g, b);
93 void Style::Loader::font_color(State s, float r, float g, float b)
95 for(unsigned i=0; i<N_STATES_; ++i)
97 obj.font_color[i] = GL::Color(r, g, b);
100 void Style::Loader::part(const string &n)
103 load_sub(p, get_collection());
104 obj.parts.push_back(p);
107 void Style::Loader::unnamed_part()