Simple GUI Library
control.cpp
Go to the documentation of this file.
1/**
2 * @author Nikita Mochalov (github.com/tralf-strues)
3 * @file control.cpp
4 * @date 2021-11-07
5 *
6 * @copyright Copyright (c) 2021
7 */
8
10
11namespace Sgl
12{
13 Control::~Control()
14 {
15 if (m_DefaultSkin != nullptr)
16 {
17 delete m_DefaultSkin;
18 }
19
20 if (m_Skin != m_DefaultSkin && m_Skin != nullptr)
21 {
22 delete m_Skin;
23 }
24 }
25
26 Component* Control::getHitComponent(int32_t x, int32_t y)
27 {
28 if (!isInteractable()) { return nullptr; }
29
30 Component* hitted = Parent::getHitComponent(x, y);
31
32 if (hitted != nullptr)
33 {
34 return hitted;
35 }
36
37 if (m_Skin != nullptr)
38 {
39 return m_Skin->getHitComponent(x, y);
40 }
41
42 return nullptr;
43 }
44
45 void Control::layoutChildren()
46 {
47 if (m_Skin != nullptr)
48 {
49 m_Skin->layoutChildren();
50 }
51 else
52 {
53 Parent::layoutChildren();
54 }
55 }
56
57 void Control::prerenderSelf()
58 {
59 if (m_Skin != nullptr)
60 {
61 Sml::Renderer::getInstance().pushSetTarget(getSnapshot());
62
63 m_Skin->prerenderControl();
64
65 Sml::Renderer::getInstance().popTarget();
66 }
67 }
68
69 int32_t Control::computeCustomPrefWidth(int32_t height) const
70 {
71 if (m_Skin != nullptr)
72 {
73 return m_Skin->computePrefWidth(height);
74 }
75
76 return 0;
77 }
78
79 int32_t Control::computeCustomPrefHeight(int32_t width) const
80 {
81 if (m_Skin != nullptr)
82 {
83 return m_Skin->computePrefHeight(width);
84 }
85
86 return 0;
87 }
88
89 int32_t Control::computeCustomMinWidth(int32_t height) const
90 {
91 if (m_Skin != nullptr)
92 {
93 return m_Skin->computeMinWidth(height);
94 }
95
96 return 0;
97 }
98
99 int32_t Control::computeCustomMinHeight(int32_t width) const
100 {
101 if (m_Skin != nullptr)
102 {
103 return m_Skin->computeMinHeight(width);
104 }
105
106 return 0;
107 }
108
109 int32_t Control::computeCustomMaxWidth(int32_t height) const
110 {
111 if (m_Skin != nullptr)
112 {
113 return m_Skin->computeMaxWidth(height);
114 }
115
116 return 0;
117 }
118
119 int32_t Control::computeCustomMaxHeight(int32_t width) const
120 {
121 if (m_Skin != nullptr)
122 {
123 return m_Skin->computeMaxHeight(width);
124 }
125
126 return 0;
127 }
128}