TDME2  1.9.200
GUITextNode.cpp
Go to the documentation of this file.
2 
3 #include <string>
4 #include <vector>
5 
6 #include <tdme/tdme.h>
16 
17 using std::string;
18 using std::vector;
19 
30 
31 GUITextNode::GUITextNode(
32  GUIScreenNode* screenNode,
33  GUIParentNode* parentNode,
34  const string& id,
35  GUINode_Flow* flow,
36  const GUINode_Alignments& alignments,
37  const GUINode_RequestedConstraints& requestedConstraints,
38  const GUIColor& backgroundColor,
39  const string& backgroundImage,
40  const GUINode_Scale9Grid& backgroundImageScale9Grid,
41  const GUIColor& backgroundImageEffectColorMul,
42  const GUIColor& backgroundImageEffectColorAdd,
43  const GUINode_Border& border,
44  const GUINode_Padding& padding,
45  const GUINodeConditions& showOn,
46  const GUINodeConditions& hideOn,
47  const string& tooltip,
48  const string& font,
49  int size,
50  const string& color,
51  const MutableString& text
52 ):
53  GUINode(screenNode, parentNode, id, flow, alignments, requestedConstraints, backgroundColor, backgroundImage, backgroundImageScale9Grid, backgroundImageEffectColorMul, backgroundImageEffectColorAdd, border, padding, showOn, hideOn, tooltip)
54 {
55  this->font = font.empty() == true?nullptr:screenNode->getFont(font, size);
56  this->color = color.empty() == true || color.length() == 0?GUIColor():GUIColor(color);
57  this->text.set(text);
58  if (this->font != nullptr) this->font->initialize();
59 }
60 
62 {
63  return "text";
64 }
65 
67 {
68  return true;
69 }
70 
72 {
73  return font != nullptr?font->getTextWidth(text) + border.left + border.right + padding.left + padding.right:0;
74 }
75 
77 {
78  return font != nullptr?font->getLineHeight() + border.top + border.bottom + padding.top + padding.bottom:0;
79 }
80 
82  if (this->text.equals(text)) return;
83  this->text = text;
85 }
86 
88 {
89  if (font != nullptr) font->dispose();
91 }
92 
93 void GUITextNode::render(GUIRenderer* guiRenderer)
94 {
95  if (shouldRender() == false) return;
96 
97  GUINode::render(guiRenderer);
98  if (font != nullptr) {
100  guiRenderer,
103  text,
104  0,
105  0,
106  color
107  );
108  }
109 }
110 
GUI element node conditions.
GUI node base class.
Definition: GUINode.h:64
GUINode_Border border
Definition: GUINode.h:160
virtual void render(GUIRenderer *guiRenderer)
Render.
Definition: GUINode.cpp:509
GUINode_ComputedConstraints computedConstraints
Definition: GUINode.h:152
GUINode_Padding padding
Definition: GUINode.h:159
GUIScreenNode * screenNode
Definition: GUINode.h:147
bool shouldRender()
Returns if to render.
Definition: GUINode.h:302
virtual void dispose()
Dispose node.
Definition: GUINode.cpp:462
GUI parent node base class thats supporting child nodes.
Definition: GUIParentNode.h:42
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:72
void invalidateLayout(GUINode *node)
Mark a node to be invalidated regarding layout.
GUIFont * getFont(const string &fileName, int size)
Get font.
const string getNodeType() override
Definition: GUITextNode.cpp:61
void dispose() override
Dispose node.
Definition: GUITextNode.cpp:87
void setText(const MutableString &text)
Set text.
Definition: GUITextNode.cpp:81
void render(GUIRenderer *guiRenderer) override
Render.
Definition: GUITextNode.cpp:93
GUI font class.
Definition: GUIFont.h:41
void drawString(GUIRenderer *guiRenderer, int x, int y, const MutableString &text, int offset, int length, const GUIColor &color, int selectionStartIndex=-1, int selectionEndIndex=-1, const GUIColor &backgroundColor=GUIColor::GUICOLOR_TRANSPARENT)
Draw string.
Definition: GUIFont.cpp:344
int getTextWidth(const MutableString &text)
Text width.
Definition: GUIFont.cpp:249
Mutable utf8 aware string class.
Definition: MutableString.h:23
bool equals(const string &s2) const
Equals.
MutableString & set(char c)
Set character.
std::exception Exception
Exception base class.
Definition: Exception.h:18
GUI node border entity.
GUI node padding entity.
GUI node scale 9 grid entity.