Tileson 1.4.0
A helpful json parser for Tiled maps
Loading...
Searching...
No Matches
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
10namespace 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 {};
45 bool wrap{};
46
47 //Previously missing properties
48 bool bold {false};
49 std::string fontFamily {"sans-serif"};
51 bool italic {false};
52 bool kerning {true};
53 int pixelSize {16};
54 bool strikeout {false};
55 bool underline {false};
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
69 }
70 };
71}
72
73#endif //TILESON_TEXT_HPP
Definition Color.hpp:17
Definition IJson.hpp:11
virtual size_t count(std::string_view key) const =0
Definition Text.hpp:13
TextAlignment horizontalAlignment
Definition Text.hpp:50
Text(IJson &json)
Definition Text.hpp:22
tson::Colori color
Definition Text.hpp:44
bool italic
Definition Text.hpp:51
std::string fontFamily
Definition Text.hpp:49
bool wrap
Definition Text.hpp:45
Text()=default
bool underline
Definition Text.hpp:55
bool strikeout
Definition Text.hpp:54
bool bold
Definition Text.hpp:48
TextAlignment verticalAlignment
Definition Text.hpp:56
std::string text
Definition Text.hpp:43
bool kerning
Definition Text.hpp:52
int pixelSize
Definition Text.hpp:53
Definition Base64.hpp:12
TextAlignment
Definition Enums.hpp:105
Color< uint8_t > Colori
Definition Color.hpp:89