style_set_value.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 <string>
32 #include "../../Display/2D/color.h"
33 #include "style_value_type.h"
34 #include "style_dimension.h"
35 
36 namespace clan
37 {
40  {
41  public:
44 
47 
49  float number = 0.0f;
50 
53 
56 
58  bool is_undefined() const { return type == StyleValueType::undefined; }
59 
61  bool is_keyword() const { return type == StyleValueType::keyword; }
62  bool is_keyword(const char *keyword) const { return is_keyword() && text == keyword; }
63  bool is_keyword(const std::string &keyword) const { return is_keyword() && text == keyword; }
64 
66  bool is_length() const { return type == StyleValueType::length; }
67 
69  bool is_angle() const { return type == StyleValueType::angle; }
70 
72  bool is_time() const { return type == StyleValueType::time; }
73 
75  bool is_frequency() const { return type == StyleValueType::frequency; }
76 
78  bool is_resolution() const { return type == StyleValueType::resolution; }
79 
81  bool is_percentage() const { return type == StyleValueType::percentage; }
82 
84  bool is_number() const { return type == StyleValueType::number; }
85 
87  bool is_string() const { return type == StyleValueType::string; }
88 
90  bool is_url() const { return type == StyleValueType::url; }
91 
93  bool is_color() const { return type == StyleValueType::color; }
94 
97 
100 
103 
106 
109 
112 
115 
118 
120  static StyleSetValue from_number(float number) { StyleSetValue v; v.type = StyleValueType::number; v.number = number; return v; }
121 
124 
126  static StyleSetValue from_color(const Colorf &color) { StyleSetValue v; v.type = StyleValueType::color; v.color = color; return v; }
127  };
128 }
value is an angle
value is a percentage number
static StyleSetValue from_angle(float angle, StyleDimension dimension=StyleDimension::rad)
Create style value from an angle.
Definition: style_set_value.h:105
Definition: clanapp.h:35
Floating point color description class (for float).
Definition: color.h:798
static StyleSetValue from_string(const std::string &text)
Create style value from a string.
Definition: style_set_value.h:99
bool is_keyword(const std::string &keyword) const
Definition: style_set_value.h:63
turns (1 in a full circle)
static StyleSetValue from_length(float length, StyleDimension dimension=StyleDimension::px)
Create style value from a length.
Definition: style_set_value.h:102
float number
Value number.
Definition: style_set_value.h:49
gradians/gons/grades (400 in a full circle)
std::string text
Text when the type is a text string.
Definition: style_set_value.h:46
static StyleSetValue from_url(const std::string &url)
Create style value from an url.
Definition: style_set_value.h:123
bool is_undefined() const
Check if value is undefined.
Definition: style_set_value.h:58
bool is_url() const
Check if value is an url.
Definition: style_set_value.h:90
StyleValueType type
Variant type.
Definition: style_set_value.h:43
static StyleSetValue from_resolution(float resolution, StyleDimension dimension=StyleDimension::dppx)
Create style value from a resolution.
Definition: style_set_value.h:114
bool is_angle() const
Check if value is an angle.
Definition: style_set_value.h:69
bool is_number() const
Check if value is a number.
Definition: style_set_value.h:84
static StyleSetValue from_time(float t, StyleDimension dimension=StyleDimension::s)
Create style value from a time.
Definition: style_set_value.h:108
value is a text string
Colorf color
Value color.
Definition: style_set_value.h:55
bool is_resolution() const
Check if value is a resolution.
Definition: style_set_value.h:78
static StyleSetValue from_color(const Colorf &color)
Create style value from a color.
Definition: style_set_value.h:126
StyleDimension
Unit of a style value.
Definition: style_dimension.h:34
value is a keyword
static StyleSetValue from_percentage(float percentage)
Create style value from a percentage.
Definition: style_set_value.h:117
bool is_color() const
Check if value is a color.
Definition: style_set_value.h:93
StyleValueType
Style value type.
Definition: style_value_type.h:34
bool is_percentage() const
Check if value is a percentage.
Definition: style_set_value.h:81
static StyleSetValue from_keyword(const std::string &keyword)
Create style value from a keyword.
Definition: style_set_value.h:96
bool is_frequency() const
Check if value is a frequency.
Definition: style_set_value.h:75
Style value variable.
Definition: style_set_value.h:39
static StyleSetValue from_number(float number)
Create style value from a number.
Definition: style_set_value.h:120
bool is_keyword(const char *keyword) const
Definition: style_set_value.h:62
bool is_time() const
Check if value is a time.
Definition: style_set_value.h:72
bool is_length() const
Check if value is a length.
Definition: style_set_value.h:66
static StyleSetValue from_frequency(float freq, StyleDimension dimension=StyleDimension::hz)
Create style value from a frequency.
Definition: style_set_value.h:111
bool is_string() const
Check if value is a string.
Definition: style_set_value.h:87
StyleDimension dimension
Dimension used by value.
Definition: style_set_value.h:52
bool is_keyword() const
Check if value is a keyword.
Definition: style_set_value.h:61