Repository navigation
Expand file tree
/
Copy pathShapePainterObject.cpp
More file actions
162 lines (138 loc) · 4.84 KB
/
Copy pathShapePainterObject.cpp
File metadata and controls
162 lines (138 loc) · 4.84 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/**
GDevelop - Primitive Drawing Extension
Copyright (c) 2008-2016 Florian Rival (Florian.Rival@gmail.com)
This project is released under the MIT License.
*/
#include "ShapePainterObject.h"
#include "GDCore/CommonTools.h"
#include "GDCore/Project/InitialInstance.h"
#include "GDCore/Project/Object.h"
#include "GDCore/Project/Project.h"
#include "GDCore/Serialization/SerializerElement.h"
#include "GDCore/Tools/Localization.h"
using namespace std;
ShapePainterObjectBase::ShapePainterObjectBase()
: fillColorR(255),
fillColorG(255),
fillColorB(255),
fillOpacity(255),
outlineSize(1),
outlineColorR(0),
outlineColorG(0),
outlineColorB(0),
outlineOpacity(255),
clearBetweenFrames(true),
absoluteCoordinates(false),
antialiasing("none") {}
ShapePainterObject::ShapePainterObject() {}
void ShapePainterObjectBase::DoUnserializeFrom(
gd::Project& project, const gd::SerializerElement& element) {
fillOpacity =
element.GetChild("fillOpacity", 0, "FillOpacity").GetValue().GetInt();
outlineSize =
element.GetChild("outlineSize", 0, "OutlineSize").GetValue().GetInt();
outlineOpacity = element.GetChild("outlineOpacity", 0, "OutlineOpacity")
.GetValue()
.GetInt();
fillColorR =
element.GetChild("fillColor", 0, "FillColor").GetIntAttribute("r");
fillColorG =
element.GetChild("fillColor", 0, "FillColor").GetIntAttribute("g");
fillColorB =
element.GetChild("fillColor", 0, "FillColor").GetIntAttribute("b");
outlineColorR =
element.GetChild("outlineColor", 0, "OutlineColor").GetIntAttribute("r");
outlineColorG =
element.GetChild("outlineColor", 0, "OutlineColor").GetIntAttribute("g");
outlineColorB =
element.GetChild("outlineColor", 0, "OutlineColor").GetIntAttribute("b");
absoluteCoordinates =
element.GetChild("absoluteCoordinates", 0, "AbsoluteCoordinates")
.GetValue()
.GetBool();
clearBetweenFrames =
element.HasChild("clearBetweenFrames")
? element.GetChild("clearBetweenFrames").GetValue().GetBool()
: true;
antialiasing = element.HasChild("antialiasing")
? element.GetChild("antialiasing").GetValue().GetString()
: "none";
}
void ShapePainterObject::DoUnserializeFrom(
gd::Project& project, const gd::SerializerElement& element) {
ShapePainterObjectBase::DoUnserializeFrom(project, element);
}
void ShapePainterObjectBase::DoSerializeTo(
gd::SerializerElement& element) const {
element.AddChild("fillOpacity").SetValue(fillOpacity);
element.AddChild("outlineSize").SetValue(outlineSize);
element.AddChild("outlineOpacity").SetValue(outlineOpacity);
element.AddChild("fillColor")
.SetAttribute("r", (int)fillColorR)
.SetAttribute("g", (int)fillColorG)
.SetAttribute("b", (int)fillColorB);
element.AddChild("outlineColor")
.SetAttribute("r", (int)outlineColorR)
.SetAttribute("g", (int)outlineColorG)
.SetAttribute("b", (int)outlineColorB);
element.AddChild("absoluteCoordinates").SetValue(absoluteCoordinates);
element.AddChild("clearBetweenFrames").SetValue(clearBetweenFrames);
element.AddChild("antialiasing").SetValue(antialiasing);
}
void ShapePainterObject::DoSerializeTo(gd::SerializerElement& element) const {
ShapePainterObjectBase::DoSerializeTo(element);
}
/**
* Change the color filter of the sprite object
*/
void ShapePainterObjectBase::SetFillColor(unsigned int r,
unsigned int g,
unsigned int b) {
fillColorR = r;
fillColorG = g;
fillColorB = b;
}
void ShapePainterObjectBase::SetFillOpacity(double val) {
if (val > 255)
val = 255;
else if (val < 0)
val = 0;
fillOpacity = val;
}
/**
* Change the color filter of the sprite object
*/
void ShapePainterObjectBase::SetOutlineColor(unsigned int r,
unsigned int g,
unsigned int b) {
outlineColorR = r;
outlineColorG = g;
outlineColorB = b;
}
void ShapePainterObjectBase::SetOutlineOpacity(double val) {
if (val > 255)
val = 255;
else if (val < 0)
val = 0;
outlineOpacity = val;
}
/**
* Change the fill color
*/
void ShapePainterObjectBase::SetFillColor(const gd::String& color) {
std::vector<gd::String> colors = color.Split(U';');
if (colors.size() < 3) return;
fillColorR = colors[0].To<int>();
fillColorG = colors[1].To<int>();
fillColorB = colors[2].To<int>();
}
/**
* Change the color of the outline
*/
void ShapePainterObjectBase::SetOutlineColor(const gd::String& color) {
std::vector<gd::String> colors = color.Split(U';');
if (colors.size() < 3) return;
outlineColorR = colors[0].To<int>();
outlineColorG = colors[1].To<int>();
outlineColorB = colors[2].To<int>();
}