style.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2016 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28 
29 #pragma once
30 
31 #include "../../Core/Text/string_format.h"
32 #include "../../Core/Math/cl_math.h"
33 #include "../../Display/2D/color.h"
34 #include "style_get_value.h"
35 #include <memory>
36 
37 namespace clan
38 {
39  class StyleImpl;
40  class StyleGetValue;
41 
43  class Style
44  {
45  public:
46  Style();
47  Style(const Style &) = delete;
48  ~Style();
49  Style &operator=(const Style &) = delete;
50 
59  void set(const std::string &properties);
60 
61  template <class Arg1, typename... Values>
62  void set(const std::string &properties, Arg1 arg1, Values... values)
63  {
64  set(string_format(properties, arg1, values...));
65  }
66 
68  StyleGetValue declared_value(const char *property_name) const;
69  StyleGetValue declared_value(const std::string &property_name) const { return declared_value(property_name.c_str()); }
70 
72  static std::string to_rgba(const Colorf &c)
73  {
74  return string_format(
75  "rgba(%1,%2,%3,%4)",
76  clamp((int)std::round(c.r * 255), 0, 255),
77  clamp((int)std::round(c.g * 255), 0, 255),
78  clamp((int)std::round(c.b * 255), 0, 255),
79  c.a);
80  }
81 
82  private:
83  std::unique_ptr<StyleImpl> impl;
84  };
85 }
Definition: clanapp.h:35
Floating point color description class (for float).
Definition: color.h:798
Type b
Definition: vec4.h:81
static std::string to_rgba(const Colorf &c)
Static helper that generates a "rgba(%1,%2,%3,%4)" string for the given color.
Definition: style.h:72
StyleGetValue declared_value(const std::string &property_name) const
Definition: style.h:69
std::string string_format(const std::string &format)
See clan::StringFormat for details.
Definition: string_format.h:157
StyleGetValue declared_value(const char *property_name) const
Retrieve the declared value for a property.
void set(const std::string &properties, Arg1 arg1, Values...values)
Definition: style.h:62
Type r
Definition: vec4.h:79
Type a
Definition: vec4.h:82
Type g
Definition: vec4.h:80
Style value returned by style classes.
Definition: style_get_value.h:39
void set(const std::string &properties)
Style & operator=(const Style &)=delete
Style property set.
Definition: style.h:43