style_cascade.h Source File - ClanLib SDK
Description: style_cascade.h Source File

style_cascade.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 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** Mark Page
28*/
29
30#pragma once
31
32#include <memory>
33#include <string>
34#include <vector>
35#include "style_get_value.h"
36#include "property_hash.h"
37
38namespace clan
39{
40 class Style;
41 class StyleGetValue;
42 class Canvas;
43 class Font;
44 class ViewGeometry;
45
46#if defined(MICROSOFT_FINALLY_IMPLEMENTED_CONSTEXPR_TEN_YEARS_AFTER_EVERYONE_ELSE)
48 class PropertyNameConst
49 {
50 public:
51 template<std::size_t Length>
52 constexpr PropertyNameConst(const char(&text)[Length]) : text(text), length(Length - 1) { }
53
54 constexpr char operator[](std::size_t index) const { return index < length ? text[index] : throw std::out_of_range("PropertyNameConst operator[] out of bounds"); }
55 constexpr std::size_t size() const { return length; }
56 constexpr std::size_t hash() const { return hash(2166136261U, 0); }
57
58 private:
59 constexpr std::size_t hash(std::size_t value, std::size_t index) const { return index == length ? value : hash((value ^ (std::size_t)text[index]) * 16777619U, index + 1); }
60
61 const char * const text;
62 const std::size_t length;
63 };
64#endif
65
67 class StyleCascade
68 {
69 public:
70 StyleCascade() { }
71 StyleCascade(std::vector<Style *> cascade, const StyleCascade *parent = nullptr) : cascade(std::move(cascade)), parent(parent) { }
72
74 std::vector<Style *> cascade;
75
77 const StyleCascade *parent = nullptr;
78
80 StyleGetValue cascade_value(PropertyHash hash) const;
81
83 StyleGetValue specified_value(PropertyHash hash) const;
84
88 StyleGetValue computed_value(PropertyHash hash) const;
89
91 StyleGetValue compute_length(const StyleGetValue &length) const;
92
94 StyleGetValue compute_angle(const StyleGetValue &angle) const;
95
97 StyleGetValue compute_time(const StyleGetValue &time) const;
98
100 StyleGetValue compute_frequency(const StyleGetValue &frequency) const;
101
103 StyleGetValue compute_resolution(const StyleGetValue &resolution) const;
104
106 int array_size(PropertyHash hash) const;
107
109 void render_background(Canvas &canvas, const ViewGeometry &geometry) const;
110
112 void render_border(Canvas &canvas, const ViewGeometry &geometry) const;
113
115 Font font(Canvas &canvas) const;
116 };
117}
clan::Canvas
2D Graphics Canvas
Definition canvas.h:72
clan::Font
Font class.
Definition font.h:60
clan::PropertyHash
Definition property_hash.h:35
clan::StyleCascade::array_size
int array_size(PropertyHash hash) const
Value array size for the property.
clan::StyleCascade::StyleCascade
StyleCascade(std::vector< Style * > cascade, const StyleCascade *parent=nullptr)
Definition style_cascade.h:71
clan::StyleCascade::compute_resolution
StyleGetValue compute_resolution(const StyleGetValue &resolution) const
Convert resolution to dots per px unit (pixel ratio scale)
clan::StyleCascade::StyleCascade
StyleCascade()
Definition style_cascade.h:70
clan::StyleCascade::cascade_value
StyleGetValue cascade_value(PropertyHash hash) const
Find the first declared value in the cascade for the specified property.
clan::StyleCascade::render_border
void render_border(Canvas &canvas, const ViewGeometry &geometry) const
Render styled border.
clan::StyleCascade::render_background
void render_background(Canvas &canvas, const ViewGeometry &geometry) const
Render styled background.
clan::StyleCascade::compute_frequency
StyleGetValue compute_frequency(const StyleGetValue &frequency) const
Convert frequency to Hz.
clan::StyleCascade::computed_value
StyleGetValue computed_value(PropertyHash hash) const
clan::StyleCascade::compute_length
StyleGetValue compute_length(const StyleGetValue &length) const
Convert length into px (device independent pixel) units.
clan::StyleCascade::font
Font font(Canvas &canvas) const
Font used by this style cascade.
clan::StyleCascade::specified_value
StyleGetValue specified_value(PropertyHash hash) const
Resolve any inheritance or initial values for the cascade value.
clan::StyleCascade::compute_time
StyleGetValue compute_time(const StyleGetValue &time) const
Convert time to seconds.
clan::StyleCascade::compute_angle
StyleGetValue compute_angle(const StyleGetValue &angle) const
Convert angle into radians.
clan::StyleCascade::cascade
std::vector< Style * > cascade
Property sets to be examined.
Definition style_cascade.h:74
clan::StyleCascade::parent
const StyleCascade * parent
Parent cascade used for inheritance.
Definition style_cascade.h:77
clan::StyleGetValue
Style value returned by style classes.
Definition style_get_value.h:40
clan::Style
Style property set.
Definition style.h:46
clan::ViewGeometry
Definition view_geometry.h:39
clan::ShaderType::geometry
@ geometry
Definition shader_object.h:52
clan
Definition clanapp.h:36
clan::StyleValueType::time
@ time
value is an angle
Definition style_value_type.h:45
clan::StyleValueType::length
@ length
value is a keyword
Definition style_value_type.h:38
clan::StyleValueType::angle
@ angle
value is a color
Definition style_value_type.h:44
clan::StyleValueType::resolution
@ resolution
value is a frequency
Definition style_value_type.h:47
clan::StyleValueType::frequency
@ frequency
value is a time
Definition style_value_type.h:46
clan::PointerEventType::move
@ move
Pointer left area.
Definition pointer_event.h:59
clan::StyleTokenType::hash
@ hash
Syntax error.
Definition style_token.h:43