Loading...
Searching...
No Matches
Draggable.h
Go to the documentation of this file.
1//
2// Draggable.h
3//
4
5#ifndef DRAGGABLE_H
6#define DRAGGABLE_H
7
8#pragma once
9
14#include <SFML/Graphics.hpp>
15#include <optional>
16
18
19namespace ml
20{
26 {
27 public:
28 enum class State
29 {
33 };
34
35 enum class Flag
36 {
38 };
39 };
40
65 class Draggable : public EventReceiver,
66 public Customizable<DraggableManifest>
67 {
68 public:
71
72 Draggable() = default;
73 virtual ~Draggable() = default;
74
88 void setDragBounds(const sf::FloatRect& bounds);
89
98
99 private:
100 sf::Vector2f _dragOffset;
101 std::optional<sf::FloatRect> _dragBounds;
102
104 };
105
114 {
115 public:
116 bool occurred(const std::optional<sf::Event>& event) override;
117 bool filter(const std::optional<sf::Event>& event, Core* component) override;
118 void fire(const std::optional<sf::Event>& event) override;
119 };
120
121} // namespace ml
122
123ML_EXPORT(DraggableDispatcher)
124
125#endif // DRAGGABLE_H
#define ML_EXPORT(ClassName)
Register a Malena type with the framework.
Definition Export.h:38
Virtual base class for all Malena framework objects.
Definition Core.h:67
Dispatcher singleton for drag events.
Definition Draggable.h:114
bool occurred(const std::optional< sf::Event > &event) override
Return true when the incoming SFML event should trigger this dispatcher.
bool filter(const std::optional< sf::Event > &event, Core *component) override
void fire(const std::optional< sf::Event > &event) override
Deliver this event to all matching registered components.
friend class DraggableDispatcher
Definition Draggable.h:103
Draggable()=default
virtual ~Draggable()=default
void setDragBounds(const sf::FloatRect &bounds)
Constrain drag movement to an axis-aligned bounding rectangle.
DraggableManifest::Flag Flag
Definition Draggable.h:69
DraggableManifest::State State
Definition Draggable.h:70
void clearDragBounds()
Remove any previously set drag bounds.
Manifest for the Draggable trait.
Definition Draggable.h:26
@ LOCK_X
Lock horizontal — drag Y axis only.
Definition Draggable.h:31
@ FREE
Drag freely on both axes (default).
Definition Draggable.h:30
@ LOCK_Y
Lock vertical — drag X axis only.
Definition Draggable.h:32
@ DRAGGING
Set while the user is actively dragging.
Definition Draggable.h:37
Base class for all per-event dispatchers in the Malena event system.
Base class for all event-receiving traits.
Base class for all Malena manifests.
Definition Manifest.h:81
Definition Component.h:18
Rect< float > FloatRect
Vector2< float > Vector2f