TGUI  0.10-dev
ClickableWidget.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2021 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25
26#ifndef TGUI_CLICKABLE_WIDGET_HPP
27#define TGUI_CLICKABLE_WIDGET_HPP
28
29
30#include <TGUI/Widget.hpp>
31
33
34namespace tgui
35{
39 class TGUI_API ClickableWidget : public Widget
40 {
41 public:
42
43 typedef std::shared_ptr<ClickableWidget> Ptr;
44 typedef std::shared_ptr<const ClickableWidget> ConstPtr;
45
46
54 ClickableWidget(const char* typeName = "ClickableWidget", bool initRenderer = true);
55
56
65 static ClickableWidget::Ptr create(Layout2d size = {"100%", "100%"});
66
67
77
78
83 bool isMouseOnWidget(Vector2f pos) const override;
84
88 void leftMousePressed(Vector2f pos) override;
89
93 void leftMouseReleased(Vector2f pos) override;
94
98 void rightMousePressed(Vector2f pos) override;
99
103 void rightMouseReleased(Vector2f pos) override;
104
108 void rightMouseButtonNoLongerDown() override;
109
110
118 void draw(BackendRenderTarget& target, RenderStates states) const override;
119
120
122 protected:
123
133 Signal& getSignal(String signalName) override;
134
135
137 // Makes a copy of the widget
139 Widget::Ptr clone() const override
140 {
141 return std::make_shared<ClickableWidget>(*this);
142 }
143
144
146 public:
147
148 SignalVector2f onMousePress = {"MousePressed"};
149 SignalVector2f onMouseRelease = {"MouseReleased"};
150 SignalVector2f onClick = {"Clicked"};
151
152 SignalVector2f onRightMousePress = {"RightMousePressed"};
153 SignalVector2f onRightMouseRelease = {"RightMouseReleased"};
154 SignalVector2f onRightClick = {"RightClicked"};
155
156
158 private:
159
160 bool m_rightMouseDown = false;
161
163 };
164
166}
167
169
170#endif // TGUI_CLICKABLE_WIDGET_HPP
171
Base class for render targets.
Definition: BackendRenderTarget.hpp:48
Clickable widget.
Definition: ClickableWidget.hpp:40
static ClickableWidget::Ptr create(Layout2d size={"100%", "100%"})
Creates a new clickable widget.
bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
std::shared_ptr< ClickableWidget > Ptr
Shared widget pointer.
Definition: ClickableWidget.hpp:43
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: ClickableWidget.hpp:139
static ClickableWidget::Ptr copy(ClickableWidget::ConstPtr widget)
Makes a copy of another clickable widget.
std::shared_ptr< const ClickableWidget > ConstPtr
Shared constant widget pointer.
Definition: ClickableWidget.hpp:44
Class to store the position or size of a widget.
Definition: Layout.hpp:262
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:58
Wrapper class to store strings.
Definition: String.hpp:79
The parent class for every widget.
Definition: Widget.hpp:70
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:73
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
States used for drawing.
Definition: RenderStates.hpp:39