galaxy
1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
Text.cpp
Go to the documentation of this file.
1
7
8
#include <nlohmann/json.hpp>
9
10
#include "
Text.hpp
"
11
12
namespace
galaxy
13
{
14
namespace
components
15
{
16
Text::Text
()
17
: Serializable {}
18
{
19
}
20
21
Text::Text
(
const
nlohmann::json& json)
22
: Serializable {}
23
{
24
deserialize
(json);
25
}
26
27
Text::Text
(
Text
&& t)
28
: Serializable {}
29
{
30
this->
m_text
= std::move(t.m_text);
31
}
32
33
Text
&
Text::operator=
(
Text
&& t)
34
{
35
if
(
this
!= &t)
36
{
37
this->
m_text
= std::move(t.m_text);
38
}
39
40
return
*
this
;
41
}
42
43
Text::~Text
()
44
{
45
}
46
47
nlohmann::json
Text::serialize
()
48
{
49
nlohmann::json json =
"{}"
_json;
50
51
json[
"text"
] =
m_text
.get_text();
52
json[
"size"
] =
m_text
.get_size();
53
json[
"font"
] =
m_text
.get_font();
54
json[
"alignment"
] =
static_cast<
int
>
(
m_text
.get_alignment());
55
56
json[
"colour"
] = nlohmann::json::object();
57
json[
"colour"
][
"r"
] =
m_text
.m_colour.r<std::uint8_t>();
58
json[
"colour"
][
"g"
] =
m_text
.m_colour.g<
float
>();
59
json[
"colour"
][
"b"
] =
m_text
.m_colour.b<
float
>();
60
json[
"colour"
][
"a"
] =
m_text
.m_colour.a<
float
>();
61
62
return
json;
63
}
64
65
void
Text::deserialize
(
const
nlohmann::json& json)
66
{
67
graphics::Colour colour;
68
const
auto
& colson = json.at(
"colour"
);
69
70
m_text
.m_colour.set_r(colson.at(
"r"
).get<std::uint8_t>());
71
m_text
.m_colour.set_g(colson.at(
"g"
).get<std::uint8_t>());
72
m_text
.m_colour.set_b(colson.at(
"b"
).get<std::uint8_t>());
73
m_text
.m_colour.set_a(colson.at(
"a"
).get<std::uint8_t>());
74
75
const
int
alignment = json.at(
"alignment"
);
76
m_text
.create(json.at(
"text"
), json.at(
"size"
), json.at(
"font"
), colour,
static_cast<
graphics::Text::Alignment
>
(alignment));
77
}
78
}
// namespace components
79
}
// namespace galaxy
Text.hpp
galaxy::components::Text
String of glyphs rendered with a font.
Definition
Text.hpp:22
galaxy::components::Text::Text
Text()
Constructor.
Definition
Text.cpp:16
galaxy::components::Text::~Text
virtual ~Text()
Destructor.
Definition
Text.cpp:43
galaxy::components::Text::serialize
nlohmann::json serialize() override
Serializes object.
Definition
Text.cpp:47
galaxy::components::Text::operator=
Text & operator=(Text &&)
Move assignment operator.
Definition
Text.cpp:33
galaxy::components::Text::m_text
graphics::Text m_text
Text object.
Definition
Text.hpp:81
galaxy::components::Text::deserialize
void deserialize(const nlohmann::json &json) override
Deserializes from object.
Definition
Text.cpp:65
galaxy
Timer.hpp galaxy.
Definition
Async.hpp:17
galaxy
src
galaxy
components
Text.cpp
Generated on Sat Mar 1 2025 14:49:36 for galaxy by
1.12.0