guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
guillaume::systems::Drag Class Reference

Turns "button held while the pointer moves" into a drag gesture. More...

#include <headers/guillaume/systems/drag.hpp>

Inheritance diagram for guillaume::systems::Drag:
Collaboration diagram for guillaume::systems::Drag:

Public Member Functions

 Drag (event::EventBus &eventBus)
 Create the system, in the Event phase, and subscribe it to mouse motion events.
 ~Drag (void)
 Destructor.
void prepare (void) override
 Take the next pending mouse motion event, once per frame.
void update (const ecs::Entity::Identifier &entityIdentifier) override
 Start, continue or end the drag of one entity.
Public Member Functions inherited from guillaume::ecs::SystemFiller< components::DragInteraction, components::Transform, components::Bound, components::MouseButtonInteraction, components::HandButtonInteraction >
 SystemFiller (Phase phase)
 Create the system and set its signature from ComponentTypes.
virtual ~SystemFiller (void)=default
 Virtual destructor.
Public Member Functions inherited from guillaume::ecs::System
 System (Phase phase)
 Create a system that runs in a given phase, with an empty signature.
virtual ~System (void)=default
 Virtual destructor.
Phase getPhase (void) const noexcept
 Get the phase of the frame in which the system runs.
Entity::Signature getSignature (void) const noexcept
 Get the component types an entity must declare to be visited by this system.
void routine (ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry, const ecs::EntityTreeTraveler &traveler)
 Run the system once over a scene: prepare(), update() on each matching entity, cleanup().
void bindComponentRegistry (ecs::ComponentRegistry &componentRegistry)
 Bind a component registry so update() can be called directly, without routine().
void unbindComponentRegistry (void)
 Drop the binding made by bindComponentRegistry().
virtual void cleanup (void)
 Called once per pass, after the last update().
Public Member Functions inherited from guillaume::event::EventManager< utility::event::MouseMotionEvent >
 EventManager (EventBus &eventBus)
 Subscribe to a bus; events of type EventType published after this call are queued.
virtual ~EventManager (void)=default
 Virtual destructor.
bool hasPendingEvents (void) const
 Tell whether at least one event is queued, waiting for consumeNextEvent().

Additional Inherited Members

Protected Member Functions inherited from guillaume::ecs::System
template<InheritFromComponent... ComponentTypes>
void setSignature (void)
 Replace the signature by the one made of the given component types.
ecs::EntityRegistry & getEntityRegistry (void)
 Get the entity registry of the scene being processed.
const ecs::EntityRegistry & getEntityRegistry (void) const
 Get the entity registry of the scene being processed, read-only.
ecs::ComponentRegistry & getComponentRegistry (void)
 Get the component registry of the scene being processed.
const ecs::ComponentRegistry & getComponentRegistry (void) const
 Get the component registry of the scene being processed, read-only.
template<InheritFromComponent ComponentType>
bool hasComponent (const ecs::Entity::Identifier &entityIdentifier) const
 Tell whether an entity has a component, in the bound registry.
template<InheritFromComponent ComponentType>
ComponentType & getComponent (const ecs::Entity::Identifier &entityIdentifier)
 Get a component of an entity from the bound registry, to read or modify it.
template<InheritFromComponent ComponentType>
const ComponentType & getComponent (const ecs::Entity::Identifier &entityIdentifier) const
 Get a component of an entity from the bound registry, read-only.
template<InheritFromComponent ComponentType>
bool requireComponent (const ecs::Entity::Identifier &entityIdentifier)
 Tell whether an entity has a component, and log a warning naming the entity and the component when it does not.
Protected Member Functions inherited from guillaume::event::EventManager< utility::event::MouseMotionEvent >
void consumeNextEvent (void)
 Take the oldest queued event and make it the last event.
std::shared_ptr< EventType > getLastEvent (void)
 Get the event taken by the most recent consumeNextEvent() that found one.

Detailed Description

Turns "button held while the pointer moves" into a drag gesture.

Runs in the Event phase on entities that have a components::DragInteraction, Transform, Bound, MouseButtonInteraction and HandButtonInteraction. An entity is grabbed while its left mouse button or its hand button A is pressed (as recorded by systems::MouseButton and systems::HandButton, registered before this system) and it is not disabled. The system writes the dragging flag, the last position and the delta of components::DragInteraction, and calls its handlers:

  • drag start, on the first frame the entity is grabbed;
  • drag, on each following frame, with the pointer movement since the previous frame;
  • drag end, when the button is released or the entity is disabled.

The system does not move the entity: the drag handler decides what the movement does.

Note
Positions always come from the last mouse motion event, also when the grab comes from the hand button. Nothing happens until a first mouse motion event has been received.
See also
components::DragInteraction
systems::MouseButton

Definition at line 67 of file drag.hpp.

Constructor & Destructor Documentation

◆ Drag()

guillaume::systems::Drag::Drag ( event::EventBus & eventBus)

Create the system, in the Event phase, and subscribe it to mouse motion events.

Parameters
eventBusThe event bus delivering the mouse motion events.

Definition at line 28 of file drag.cpp.

Here is the call graph for this function:

◆ ~Drag()

guillaume::systems::Drag::~Drag ( void )

Destructor.

Definition at line 38 of file drag.cpp.

Member Function Documentation

◆ prepare()

void guillaume::systems::Drag::prepare ( void )
overridevirtual

Take the next pending mouse motion event, once per frame.

When none is pending, the previous event stays the current one.

Reimplemented from guillaume::ecs::System.

Definition at line 42 of file drag.cpp.

Here is the call graph for this function:

◆ update()

void guillaume::systems::Drag::update ( const ecs::Entity::Identifier & entityIdentifier)
overridevirtual

Start, continue or end the drag of one entity.

Calls the drag start, drag or drag end handler of its components::DragInteraction when the gesture reaches that step.

Parameters
entityIdentifierThe entity holding the components::DragInteraction.

Implements guillaume::ecs::System.

Definition at line 47 of file drag.cpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files: