TGUI  1.3-dev
Loading...
Searching...
No Matches
ClickableWidget.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 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
34TGUI_MODULE_EXPORT namespace tgui
35{
39 class TGUI_API ClickableWidget : public Widget
40 {
41 public:
42
43 using Ptr = std::shared_ptr<ClickableWidget>;
44 using ConstPtr = std::shared_ptr<const ClickableWidget>;
45
46 static constexpr const char StaticWidgetType[] = "ClickableWidget";
47
48
56 ClickableWidget(const char* typeName = StaticWidgetType, bool initRenderer = true);
57
58
67 TGUI_NODISCARD static ClickableWidget::Ptr create(const Layout2d& size = {"100%", "100%"});
68
69
78 TGUI_NODISCARD static ClickableWidget::Ptr copy(const ClickableWidget::ConstPtr& widget);
79
80
85 TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override;
86
90 bool leftMousePressed(Vector2f pos) override;
91
95 void leftMouseReleased(Vector2f pos) override;
96
100 void rightMousePressed(Vector2f pos) override;
101
105 void rightMouseReleased(Vector2f pos) override;
106
110 void rightMouseButtonNoLongerDown() override;
111
112
120 void draw(BackendRenderTarget& target, RenderStates states) const override;
121
122
124 protected:
125
135 TGUI_NODISCARD Signal& getSignal(String signalName) override;
136
137
139 // Makes a copy of the widget
141 TGUI_NODISCARD Widget::Ptr clone() const override;
142
143
145 public:
146
147 SignalVector2f onMousePress = {"MousePressed"};
148 SignalVector2f onMouseRelease = {"MouseReleased"};
149 SignalVector2f onClick = {"Clicked"};
150
151 SignalVector2f onRightMousePress = {"RightMousePressed"};
152 SignalVector2f onRightMouseRelease = {"RightMouseReleased"};
153 SignalVector2f onRightClick = {"RightClicked"};
154
155
157 private:
158
159 bool m_rightMouseDown = false;
160
162 };
163
165}
166
168
169#endif // TGUI_CLICKABLE_WIDGET_HPP
170
Base class for render targets.
Definition BackendRenderTarget.hpp:48
Clickable widget.
Definition ClickableWidget.hpp:40
TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
bool leftMousePressed(Vector2f pos) override
Called by the parent when the left mouse button goes down on top of the widget.
TGUI_NODISCARD Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
std::shared_ptr< const ClickableWidget > ConstPtr
Shared constant widget pointer.
Definition ClickableWidget.hpp:44
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
std::shared_ptr< ClickableWidget > Ptr
Shared widget pointer.
Definition ClickableWidget.hpp:43
static TGUI_NODISCARD ClickableWidget::Ptr create(const Layout2d &size={"100%", "100%"})
Creates a new clickable widget.
static TGUI_NODISCARD ClickableWidget::Ptr copy(const ClickableWidget::ConstPtr &widget)
Makes a copy of another clickable widget.
TGUI_NODISCARD Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
Class to store the position or size of a widget.
Definition Layout.hpp:305
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:62
Wrapper class to store strings.
Definition String.hpp:101
The parent class for every widget.
Definition Widget.hpp:84
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:87
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
States used for drawing.
Definition RenderStates.hpp:39