guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
drag_interaction.cpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#include "guillaume/components/drag_interaction.hpp"
24
26{
28 {
29 return _dragging;
30 }
31
33 {
34 if (_dragging == dragging) {
35 return *this;
36 }
37 _dragging = dragging;
38 setHasChanged(true);
39 return *this;
40 }
41
42 utility::math::Vector2F DragInteraction::getLastPosition(void) const
43 {
44 return _lastPosition;
45 }
46
48 const utility::math::Vector2F &position)
49 {
50 _lastPosition = position;
51 return *this;
52 }
53
54 utility::math::Vector2F DragInteraction::getDelta(void) const
55 {
56 return _delta;
57 }
58
60 DragInteraction::setDelta(const utility::math::Vector2F &delta)
61 {
62 _delta = delta;
63 setHasChanged(true);
64 return *this;
65 }
66
69 {
70 _onDragStart = handler;
71 return *this;
72 }
73
76 {
77 return _onDragStart;
78 }
79
82 {
83 _onDrag = handler;
84 return *this;
85 }
86
88 {
89 return _onDrag;
90 }
91
94 {
95 _onDragEnd = handler;
96 return *this;
97 }
98
101 {
102 return _onDragEnd;
103 }
104} // namespace guillaume::components
State of a drag gesture on an entity: whether it is in progress, how far the pointer moved since the ...
DragEndHandler getOnDragEndHandler(void) const
Get the callback run when a drag ends.
DragHandler getOnDragHandler(void) const
Get the callback run on each move of a drag.
std::function< void( const utility::math::Vector2F &)> DragHandler
Called on each move.
DragInteraction & setOnDragStartHandler(const DragStartHandler &handler)
Store the callback run when a drag starts.
DragInteraction & setOnDragEndHandler(const DragEndHandler &handler)
Store the callback run when a drag ends.
DragInteraction(void)=default
Construct a component with no drag in progress and no handler.
DragInteraction & setLastPosition(const utility::math::Vector2F &position)
Record the pointer position the next delta is measured from.
DragStartHandler getOnDragStartHandler(void) const
Get the callback run when a drag starts.
bool isDragging(void) const
Check whether a drag is in progress.
utility::math::Vector2F getDelta(void) const
Get the movement of the pointer between the two last motion events of the drag.
DragInteraction & setDelta(const utility::math::Vector2F &delta)
Record the movement of the pointer since the previous motion event.
std::function< void(void)> DragStartHandler
Callback run when a drag starts.
utility::math::Vector2F getLastPosition(void) const
Get the pointer position at the last motion event of the drag.
DragInteraction & setOnDragHandler(const DragHandler &handler)
Store the callback run on each move of a drag.
DragInteraction & setDragging(bool dragging)
Record whether a drag is in progress.
std::function< void(void)> DragEndHandler
Callback run when a drag ends.
void setHasChanged(bool hasChanged)
Raise or lower the changed flag.
Definition component.cpp:32
State. Every class here is plain data attached to an entity.