File: RocketDecoratorsInstancer.cpp

package info (click to toggle)
freespace2 25.0.0~rc11%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 47,232 kB
  • sloc: cpp: 657,500; ansic: 22,305; sh: 293; python: 200; makefile: 198; xml: 181
file content (99 lines) | stat: -rw-r--r-- 3,565 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "RocketDecoratorsInstancer.h"

#include <Rocket/Core/Colour.h>
#include <Rocket/Core/PropertyParser.h>
#include <Rocket/Core/StyleSheetSpecification.h>

namespace scpui {
namespace decorators {

// UnderlineDecoratorInstancer Implementation
UnderlineDecoratorInstancer::UnderlineDecoratorInstancer()
{
	RegisterProperty("thickness", "1.0").AddParser("number");
	RegisterProperty("style", "solid").AddParser("keyword", "solid, dashed, dotted");
	RegisterProperty("length", "5.0").AddParser("number");
	RegisterProperty("space", "3.0").AddParser("number");
	RegisterProperty("color-setting", "default").AddParser("keyword", "default, element");
	RegisterProperty("color", "white").AddParser("color");

	RegisterShorthand("shorthand", "style, thickness, length, space");
}

Rocket::Core::Decorator* UnderlineDecoratorInstancer::InstanceDecorator(const Rocket::Core::String& /*name*/,
	const Rocket::Core::PropertyDictionary& prop_dict)
{
	// librocket documentation says the best way to get a keyword is by index so get
	// that and convert it for readability to an enum for downstream methods	
	int style_idx = prop_dict.GetProperty("style")->Get<int>();
	LineStyle style;
	if (style_idx < 0 || style_idx >= static_cast<int>(LineStyle::Num_styles)) {
		style = LineStyle::Solid;
	} else {
		style = static_cast<LineStyle>(style_idx);
	}

	auto thickness = prop_dict.GetProperty("thickness")->Get<float>();
	auto length = prop_dict.GetProperty("length")->Get<float>();
	auto space = prop_dict.GetProperty("space")->Get<float>();
	Rocket::Core::Colourb color = prop_dict.GetProperty("color")->Get<Rocket::Core::Colourb>();
	bool use_element_color = prop_dict.GetProperty("color-setting")->Get<int>();

	return new DecoratorUnderline(thickness, style, length, space, color, use_element_color);
}

void UnderlineDecoratorInstancer::ReleaseDecorator(Rocket::Core::Decorator* decorator)
{
	delete decorator;
}

void UnderlineDecoratorInstancer::Release()
{
	delete this;
}

// BorderDecoratorInstancer Implementation
BorderDecoratorInstancer::BorderDecoratorInstancer()
{
	// Register border properties
	RegisterProperty("thickness", "1.0").AddParser("number");
	RegisterProperty("length", "10.0").AddParser("number");
	RegisterProperty("length-h", "10.0").AddParser("number");
	RegisterProperty("length-v", "10.0").AddParser("number");
	RegisterProperty("color", "white").AddParser("color");

	RegisterShorthand("shorthand", "thickness, length-h, length-v");
}

Rocket::Core::Decorator* BorderDecoratorInstancer::InstanceDecorator(const Rocket::Core::String& /*name*/,
	const Rocket::Core::PropertyDictionary& prop_dict)
{
	auto thickness = prop_dict.GetProperty("thickness")->Get<float>();

	// Check if horizontal or vertical lengths are defined, and fallback to "length" if needed
	float length_h = prop_dict.GetProperty("length-h")
								? prop_dict.GetProperty("length-h")->Get<float>()
								: prop_dict.GetProperty("length")->Get<float>();
	float length_v = prop_dict.GetProperty("length-v")
								? prop_dict.GetProperty("length-v")->Get<float>()
								: prop_dict.GetProperty("length")->Get<float>();

	// Fetch the border color, defaults to white if not set
	Rocket::Core::Colourb color = prop_dict.GetProperty("color")->Get<Rocket::Core::Colourb>();

	return new DecoratorCornerBorders(thickness, length_h, length_v, color);
}


void BorderDecoratorInstancer::ReleaseDecorator(Rocket::Core::Decorator* decorator)
{
	delete decorator;
}

void BorderDecoratorInstancer::Release()
{
	delete this;
}

} // namespace decorators
} // namespace scpui