Skylicht Engine
Loading...
Searching...
No Matches
CUIDraggable.h
1/*
2!@
3MIT License
4
5Copyright (c) 2024 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#include "CUIBase.h"
28
29namespace Skylicht
30{
31 namespace UI
32 {
57 class CUIDraggable : public CUIBase
58 {
59 protected:
60 core::vector2df m_offset;
61 core::vector3df m_oldPosition;
62
63 bool m_lockX;
64 bool m_lockY;
65
66 bool m_limitDragToRect;
67 core::rectf m_bounds;
68
69 public:
78 std::function<void(CUIDraggable*, float posX, float posY)> OnBeginDrag;
79
88 std::function<void(CUIDraggable*, float posX, float posY)> OnDrag;
89
98 std::function<void(CUIDraggable*, float posX, float posY)> OnEndDrag;
99
100 public:
109 CUIDraggable(CUIContainer* container, CGUIElement* element);
110
111 virtual ~CUIDraggable();
112
118 inline void lock(bool x, bool y)
119 {
120 m_lockX = x;
121 m_lockY = y;
122 }
123
128 inline void limitDragToRect(bool b)
129 {
130 m_limitDragToRect = b;
131 }
132
137 inline void setBounds(const core::rectf& r)
138 {
139 m_bounds = r;
140 }
141
142 protected:
143
144 virtual void onPointerDown(int pointerId, float pointerX, float pointerY);
145
146 virtual void onPointerUp(int pointerId, float pointerX, float pointerY);
147
148 virtual void onPointerMove(int pointerId, float pointerX, float pointerY);
149
157 virtual void updateDrag();
158
165 virtual void onBeginDrag();
166
173 virtual void onEndDrag();
174 };
175 }
176}
This is the base object class from which other GUIs inherit. It's an empty GUI and can contain child ...
Definition CGUIElement.h:51
CUIBase(CUIContainer *container, CGUIElement *element)
Constructor.
Top-level UI container and event router.
Definition CUIContainer.h:59
void setBounds(const core::rectf &r)
Set the rectangular bounds used when limitDragToRect(true) is active.
Definition CUIDraggable.h:137
virtual void onPointerMove(int pointerId, float pointerX, float pointerY)
Called when pointer moves while over or dragging the element.
std::function< void(CUIDraggable *, float posX, float posY)> OnEndDrag
Callback invoked when the drag operation ends.
Definition CUIDraggable.h:98
void lock(bool x, bool y)
Lock/unlock movement on each axis.
Definition CUIDraggable.h:118
virtual void onBeginDrag()
Internal hook invoked when a drag begins.
void limitDragToRect(bool b)
Enable or disable rectangular bounds for dragging.
Definition CUIDraggable.h:128
CUIDraggable(CUIContainer *container, CGUIElement *element)
Construct a draggable wrapper for a GUI element.
std::function< void(CUIDraggable *, float posX, float posY)> OnDrag
Callback invoked while dragging (on pointer move).
Definition CUIDraggable.h:88
virtual void onPointerDown(int pointerId, float pointerX, float pointerY)
Called when pointer is pressed down on the element.
std::function< void(CUIDraggable *, float posX, float posY)> OnBeginDrag
Callback invoked when a drag operation begins.
Definition CUIDraggable.h:78
virtual void updateDrag()
Apply pointer movement to the underlying element.
virtual void onPointerUp(int pointerId, float pointerX, float pointerY)
Called when pointer is released over the element.
virtual void onEndDrag()
Internal hook invoked when a drag ends.
Classes used to build the User Interface (UI).
Definition CAlphaMotion.h:32
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
vector3d< f32 > vector3df
Typedef for a f32 3d vector.
Definition vector3d.h:445
vector2d< f32 > vector2df
Typedef for f32 2d vector.
Definition vector2d.h:323
rect< f32 > rectf
Rectangle with float values.
Definition rect.h:271