Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
TextLabel.cpp
Go to the documentation of this file.
1
2
3#include "Headers/TextLabel.h"
5
6namespace Divide {
7
11
13
15 const UColour4& colour,
16 const U8 fontSize)
17 : _fontSize(fontSize),
18 _font(_ID(font)),
19 _colour(colour)
20{
21 // First one found
22 if (s_defaultHashValue == 0) {
24
31 }
32}
33
35 const size_t previousHash = _hash;
36 _hash = 17;
38 _fontSize,
39 _width,
40 _blurAmount,
41 _spacing,
42 _alignFlag,
43 _colour.r,
44 _colour.g,
45 _colour.b,
46 _colour.a,
47 _bold,
48 _italic);
49
50 if (previousHash != _hash) {
53 }
54
55 return Hashable::getHash();
56}
57
58const TextLabelStyle& TextLabelStyle::get(const size_t textLabelStyleHash) {
59 bool styleFound = false;
60 const TextLabelStyle& style = get(textLabelStyleHash, styleFound);
61 // Return the state block's descriptor
62 return style;
63}
64
65const TextLabelStyle& TextLabelStyle::get(const size_t textLabelStyleHash, bool& styleFound) {
66 styleFound = false;
67
69 // Find the render state block associated with the received hash value
70 const TextLabelStyleMap::const_iterator it = s_textLabelStyle.find(textLabelStyleHash);
71 if (it != std::cend(s_textLabelStyle)) {
72 styleFound = true;
73 return it->second;
74 }
75
76 return s_textLabelStyle.find(s_defaultHashValue)->second;
77}
78
79const Str<64>& TextLabelStyle::fontName(const size_t fontNameHash) {
80 return s_fontName[fontNameHash];
81}
82
83TextElement::TextElement(const TextLabelStyle& textLabelStyle, const RelativePosition2D& position)
84 : TextElement(textLabelStyle.getHash(), position)
85{
86}
87
88TextElement::TextElement(const size_t textLabelStyleHash, const RelativePosition2D& position)
89 : _textLabelStyleHash(textLabelStyleHash),
90 _position(position)
91{
92}
93
94void TextElement::text(const char* text, const bool multiLine) {
95 if (multiLine) {
96 Util::Split<TextType, eastl::string>(text, '\n', _text);
97 return;
98 }
99
100 _text = { text };
101}
102
104{
105 _data.push_back(element);
106}
107} //namespace Divide
#define NO_DESTROY
static FontNameHashMap s_fontName
Definition: TextLabel.h:59
hashMap< size_t, TextLabelStyle > TextLabelStyleMap
Definition: TextLabel.h:53
static SharedMutex s_textLableStyleMutex
Definition: TextLabel.h:55
static const TextLabelStyle & get(size_t textLabelStyleHash)
Definition: TextLabel.cpp:58
static size_t s_defaultHashValue
Definition: TextLabel.h:56
static TextLabelStyleMap s_textLabelStyle
Definition: TextLabel.h:54
size_t getHash() const override
Definition: TextLabel.cpp:34
static const Str< 64 > & fontName(size_t fontNameHash)
Definition: TextLabel.cpp:79
hashMap< size_t, Str< 64 > > FontNameHashMap
Definition: TextLabel.h:58
TextLabelStyle(const char *font, const UColour4 &colour, U8 fontSize)
Definition: TextLabel.cpp:14
constexpr const char * DROID_SERIF
Definition: TextLabel.h:46
constexpr const char * BATANG
Definition: TextLabel.h:44
constexpr const char * DIVIDE_DEFAULT
Definition: TextLabel.h:43
constexpr const char * DROID_SERIF_ITALIC
Definition: TextLabel.h:47
constexpr const char * DROID_SERIF_BOLD
Definition: TextLabel.h:48
constexpr const char * DEJA_VU
Definition: TextLabel.h:45
void Hash_combine(size_t &seed, const T &v, const Rest &... rest) noexcept
a la Boost
Definition: MathHelper.inl:799
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
std::lock_guard< mutex > LockGuard
Definition: SharedMutex.h:55
void insert(eastl::vector< T, A1 > &target, const eastl::vector< T, A2 > &source)
Definition: Vector.h:97
uint8_t U8
std::shared_mutex SharedMutex
Definition: SharedMutex.h:43
std::shared_lock< mutex > SharedLock
Definition: SharedMutex.h:49
constexpr U64 _ID(const char *const str, const U64 value=val_64_const) noexcept
virtual size_t getHash() const
Definition: Hashable.h:46
size_t _hash
Definition: Hashable.h:49
void text(const char *text, const bool multiLine)
Definition: TextLabel.cpp:94