Loading...
Searching...
No Matches
Draggable.h
Go to the documentation of this file.
1// Copyright (c) 2025 Dave R. Smith. All rights reserved.
2// Malena Framework — Proprietary Software. See LICENSE for terms.
3
4//
5// Draggable.h
6//
7
8#ifndef MALENA_DRAGGABLE_H
9#define MALENA_DRAGGABLE_H
10
11#pragma once
12
18#include <SFML/Graphics.hpp>
19#include <optional>
20
22
23namespace ml
24{
30 {
31 public:
32 enum class State
33 {
34 FREE,
35 LOCK_X,
36 LOCK_Y
37 };
38
39 enum class Flag
40 {
42 };
43 };
44
70 public Customizable<DraggableManifest>
71 {
72 public:
75
76 Draggable() = default;
77 virtual ~Draggable() = default;
78
92 void setDragBounds(const sf::FloatRect& bounds);
93
102
103 private:
104 sf::Vector2f _dragOffset;
105 std::optional<sf::FloatRect> _dragBounds;
106
108 };
109
118 {
119 public:
120 bool occurred(const std::optional<sf::Event>& event) override;
121 bool filter(const std::optional<sf::Event>& event, Core* component) override;
122 void fire(const std::optional<sf::Event>& event) override;
123 };
124
125} // namespace ml
126
127ML_EXPORT(DraggableDispatcher)
128
129#endif // MALENA_DRAGGABLE_H
#define ML_EXPORT(ClassName)
Register a Malena type with the framework.
Definition Export.h:43
Virtual base class for all Malena framework objects.
Definition Core.h:69
Dispatcher singleton for drag events.
Definition Draggable.h:118
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:107
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:73
DraggableManifest::State State
Definition Draggable.h:74
void clearDragBounds()
Remove any previously set drag bounds.
Manifest for the Draggable trait.
Definition Draggable.h:30
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:51
@ DRAGGING
A drag gesture is currently in progress (set by DraggableDispatcher).
Definition Flag.h:73
#define MALENA_API
Definition Component.h:22
Rect< float > FloatRect
Vector2< float > Vector2f