Tileson
1.4.0
A helpful json parser for Tiled maps
Loading...
Searching...
No Matches
include
tiled
Text.hpp
Go to the documentation of this file.
1
//
2
// Created by robin on 05.08.2019.
3
//
4
5
#ifndef TILESON_TEXT_HPP
6
#define TILESON_TEXT_HPP
7
8
#include <string>
9
10
namespace
tson
11
{
12
class
Text
13
{
14
public
:
15
inline
Text
() =
default
;
21
//inline Text(std::string _text, bool _wrap, tson::Colori _color) : text {std::move(_text)}, wrap {_wrap}, color {_color} {};
22
inline
explicit
Text
(
IJson
&json)
23
{
24
bool
hasColor = json.
count
(
"color"
) > 0;
25
tson::Color
c = (hasColor) ?
tson::Colori
(json[
"color"
].get<std::string>()) :
tson::Colori
();
26
color
= c;
27
text
= (json.
count
(
"text"
) > 0) ? json[
"text"
].get<std::string>() :
""
;
28
wrap
= (json.
count
(
"wrap"
) > 0) ? json[
"wrap"
].get<bool>() :
false
;
29
30
//Previously missing properties
31
bold
= (json.
count
(
"bold"
) > 0) ? json[
"bold"
].get<bool>() :
false
;
32
fontFamily
= (json.
count
(
"fontfamily"
) > 0) ? json[
"fontfamily"
].get<std::string>() :
"sans-serif"
;
33
horizontalAlignment
= (json.
count
(
"halign"
) > 0) ? resolveTextAlignmentByString(json[
"halign"
].get<std::string>()) :
TextAlignment::Left
;
34
italic
= (json.
count
(
"italic"
) > 0) ? json[
"italic"
].get<bool>() :
false
;
35
kerning
= (json.
count
(
"kerning"
) > 0) ? json[
"kerning"
].get<bool>() :
true
;
36
pixelSize
= (json.
count
(
"pixelsize"
) > 0) ? json[
"pixelsize"
].get<int32_t>() : 16;
37
strikeout
= (json.
count
(
"strikeout"
) > 0) ? json[
"strikeout"
].get<bool>() :
false
;
38
underline
= (json.
count
(
"underline"
) > 0) ? json[
"underline"
].get<bool>() :
false
;
39
verticalAlignment
= (json.
count
(
"valign"
) > 0) ? resolveTextAlignmentByString(json[
"valign"
].get<std::string>()) :
TextAlignment::Top
;
40
};
41
42
//Just make it simple
43
std::string
text
{};
44
tson::Colori
color
{};
45
bool
wrap
{};
46
47
//Previously missing properties
48
bool
bold
{
false
};
49
std::string
fontFamily
{
"sans-serif"
};
50
TextAlignment
horizontalAlignment
{
TextAlignment::Left
};
51
bool
italic
{
false
};
52
bool
kerning
{
true
};
53
int
pixelSize
{16};
54
bool
strikeout
{
false
};
55
bool
underline
{
false
};
56
TextAlignment
verticalAlignment
{
TextAlignment::Top
};
57
58
private
:
59
[[nodiscard]]
TextAlignment
resolveTextAlignmentByString(
const
std::string &str)
const
60
{
61
if
(str ==
"left"
)
return
TextAlignment::Left
;
62
if
(str ==
"center"
)
return
TextAlignment::Center
;
63
if
(str ==
"right"
)
return
TextAlignment::Right
;
64
if
(str ==
"justify"
)
return
TextAlignment::Justify
;
65
if
(str ==
"top"
)
return
TextAlignment::Top
;
66
if
(str ==
"bottom"
)
return
TextAlignment::Bottom
;
67
68
return
TextAlignment::Unresolved
;
69
}
70
};
71
}
72
73
#endif
//TILESON_TEXT_HPP
tson::Color
Definition
Color.hpp:17
tson::IJson
Definition
IJson.hpp:11
tson::IJson::count
virtual size_t count(std::string_view key) const =0
tson::Text
Definition
Text.hpp:13
tson::Text::horizontalAlignment
TextAlignment horizontalAlignment
Definition
Text.hpp:50
tson::Text::Text
Text(IJson &json)
Definition
Text.hpp:22
tson::Text::color
tson::Colori color
Definition
Text.hpp:44
tson::Text::italic
bool italic
Definition
Text.hpp:51
tson::Text::fontFamily
std::string fontFamily
Definition
Text.hpp:49
tson::Text::wrap
bool wrap
Definition
Text.hpp:45
tson::Text::Text
Text()=default
tson::Text::underline
bool underline
Definition
Text.hpp:55
tson::Text::strikeout
bool strikeout
Definition
Text.hpp:54
tson::Text::bold
bool bold
Definition
Text.hpp:48
tson::Text::verticalAlignment
TextAlignment verticalAlignment
Definition
Text.hpp:56
tson::Text::text
std::string text
Definition
Text.hpp:43
tson::Text::kerning
bool kerning
Definition
Text.hpp:52
tson::Text::pixelSize
int pixelSize
Definition
Text.hpp:53
tson
Definition
Base64.hpp:12
tson::TextAlignment
TextAlignment
Definition
Enums.hpp:105
tson::TextAlignment::Bottom
@ Bottom
tson::TextAlignment::Unresolved
@ Unresolved
tson::TextAlignment::Justify
@ Justify
tson::TextAlignment::Center
@ Center
tson::TextAlignment::Right
@ Right
tson::TextAlignment::Left
@ Left
tson::TextAlignment::Top
@ Top
tson::Colori
Color< uint8_t > Colori
Definition
Color.hpp:89
Generated by
1.9.8