TDME2  1.9.200
TooltipScreenController.cpp
Go to the documentation of this file.
2 
3 #include <string>
4 
5 #include <tdme/tdme.h>
6 #include <tdme/engine/Engine.h>
12 #include <tdme/gui/GUI.h>
13 #include <tdme/gui/GUIParser.h>
14 #include <tdme/math/Math.h>
15 #include <tdme/utilities/Console.h>
19 
21 
22 using std::string;
23 using std::unordered_map;
24 
34 using tdme::math::Math;
39 
40 TooltipScreenController::TooltipScreenController()
41 {
42 }
43 
45 {
46  screenNode = nullptr;
47 }
48 
50 {
51  return screenNode;
52 }
53 
55 {
56  try {
57  screenNode = GUIParser::parse("resources/engine/gui", "popup_tooltip.xml");
58  screenNode->setEnabled(false);
59  tooltipNode = required_dynamic_cast<GUITextNode*>(screenNode->getNodeById("tooltip"));
60  } catch (Exception& exception) {
61  Console::println("TooltipScreenController::initialize(): An error occurred: " + string(exception.what()));
62  }
63 }
64 
66 {
67 }
68 
69 void TooltipScreenController::show(int mouseX, int mouseY, const string& tooltip)
70 {
71  auto scaledX = Engine::getInstance()->getGUI()->getScaledX(screenNode, mouseX);
72  auto scaledY = Engine::getInstance()->getGUI()->getScaledY(screenNode, mouseY + tooltipNode->getContentHeight() / 2);
73  scaledX = Math::min(scaledX, screenNode->getScreenWidth() - tooltipNode->getContentWidth());
74  scaledY = Math::min(scaledY, screenNode->getScreenHeight() - tooltipNode->getContentHeight());
76  tooltipNode->getRequestsConstraints().leftType = GUINode_RequestedConstraints_RequestedConstraintsType::PIXEL;
78  tooltipNode->getRequestsConstraints().topType = GUINode_RequestedConstraints_RequestedConstraintsType::PIXEL;
80  screenNode->setEnabled(true);
81  screenNode->layout();
82 }
83 
85 {
86  screenNode->setEnabled(false);
87 }
Engine main class.
Definition: Engine.h:131
GUI parser.
Definition: GUIParser.h:40
GUI node base class.
Definition: GUINode.h:64
GUINode_RequestedConstraints & getRequestsConstraints()
Definition: GUINode.h:405
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:72
void setEnabled(bool enabled)
Set enabled.
void layout() override
Layout.
GUINode * getNodeById(const string &nodeId)
Get GUI node by id.
void setText(const MutableString &text)
Set text.
Definition: GUITextNode.cpp:81
Standard math functions.
Definition: Math.h:19
void show(int mouseX, int mouseY, const string &tooltip)
Show tooltip.
Console class.
Definition: Console.h:29
Mutable utf8 aware string class.
Definition: MutableString.h:23
String tools class.
Definition: StringTools.h:22
std::exception Exception
Exception base class.
Definition: Exception.h:18
GUINode_RequestedConstraints_RequestedConstraintsType * topType
GUINode_RequestedConstraints_RequestedConstraintsType * leftType