Sparkle 0.0.1
Loading...
Searching...
No Matches
spk::DeviceInputTrigger< Device, DeviceValue > Class Template Reference

Trigger that responds to device input state changes. More...

#include <spk_input_trigger.hpp>

Inheritance diagram for spk::DeviceInputTrigger< Device, DeviceValue >:
Inheritance graph
Collaboration diagram for spk::DeviceInputTrigger< Device, DeviceValue >:
Collaboration graph

Public Types

using Job = std::function<void(const Device *)>
 Callback type invoked when the trigger fires.
using Predicate = std::function<bool()>
 Predicate type tested before firing.

Public Member Functions

 DeviceInputTrigger (DeviceValue p_deviceValue, spk::InputState p_state, spk::Duration p_repeatInterval, const Job &p_jobCallback)
 Creates a device trigger with a callback.
 DeviceInputTrigger (DeviceValue p_deviceValue, spk::InputState p_state, spk::Duration p_repeatInterval, const Predicate &p_predicateCallback, const Job &p_jobCallback)
 Creates a device trigger with predicate and callback.
void setDeviceValue (const DeviceValue &p_deviceValue, const spk::InputState &p_state)
 Sets the device value and target state.
void setRepeatInterval (const spk::Duration &p_repeatInterval)
 Sets the repeat interval.
void setCallback (const Job &p_callback)
 Sets the callback to invoke when triggered.
void setPredicate (Predicate p_callback)
 Sets the predicate tested before firing.
bool isInitialized () const override
 Reports whether the trigger is initialized.
void initialize (spk::UpdateEvent &p_event) override
 Initializes the trigger by extracting the device from an update event.
const Device * device () const
 Returns the assigned device.
void setDevice (const Device *p_device)
 Manually sets the device.
void update () override
 Updates the trigger and fires callbacks if needed.
Public Member Functions inherited from spk::InputTrigger
virtual ~InputTrigger ()=default
 Virtual destructor.

Static Public Attributes

static const long long NoRepeat = -1
 Constant meaning no repeat interval.

Detailed Description

template<typename Device, typename DeviceValue>
class spk::DeviceInputTrigger< Device, DeviceValue >

Trigger that responds to device input state changes.

Template Parameters
DeviceDevice type (e.g. Mouse, Keyboard).
DeviceValueValue type for indexing device state.

Constructor & Destructor Documentation

◆ DeviceInputTrigger() [1/2]

template<typename Device, typename DeviceValue>
spk::DeviceInputTrigger< Device, DeviceValue >::DeviceInputTrigger ( DeviceValue p_deviceValue,
spk::InputState p_state,
spk::Duration p_repeatInterval,
const Job & p_jobCallback )
inline

Creates a device trigger with a callback.

Parameters
p_deviceValueDevice input identifier.
p_stateTarget input state.
p_repeatIntervalRepeat interval duration.
p_jobCallbackCallback invoked on trigger.

◆ DeviceInputTrigger() [2/2]

template<typename Device, typename DeviceValue>
spk::DeviceInputTrigger< Device, DeviceValue >::DeviceInputTrigger ( DeviceValue p_deviceValue,
spk::InputState p_state,
spk::Duration p_repeatInterval,
const Predicate & p_predicateCallback,
const Job & p_jobCallback )
inline

Creates a device trigger with predicate and callback.

Parameters
p_deviceValueDevice input identifier.
p_stateTarget input state.
p_repeatIntervalRepeat interval duration.
p_predicateCallbackPredicate tested before firing.
p_jobCallbackCallback invoked on trigger.

Member Function Documentation

◆ device()

template<typename Device, typename DeviceValue>
const Device * spk::DeviceInputTrigger< Device, DeviceValue >::device ( ) const
inline

Returns the assigned device.

Returns
Device pointer or nullptr.

◆ initialize()

template<typename Device, typename DeviceValue>
void spk::DeviceInputTrigger< Device, DeviceValue >::initialize ( spk::UpdateEvent & p_event)
inlineoverridevirtual

Initializes the trigger by extracting the device from an update event.

Parameters
p_eventUpdate event providing device references.

Implements spk::InputTrigger.

◆ isInitialized()

template<typename Device, typename DeviceValue>
bool spk::DeviceInputTrigger< Device, DeviceValue >::isInitialized ( ) const
inlineoverridevirtual

Reports whether the trigger is initialized.

Returns
True if a device is assigned.

Implements spk::InputTrigger.

◆ setCallback()

template<typename Device, typename DeviceValue>
void spk::DeviceInputTrigger< Device, DeviceValue >::setCallback ( const Job & p_callback)
inline

Sets the callback to invoke when triggered.

Parameters
p_callbackCallback function.

◆ setDevice()

template<typename Device, typename DeviceValue>
void spk::DeviceInputTrigger< Device, DeviceValue >::setDevice ( const Device * p_device)
inline

Manually sets the device.

Parameters
p_deviceDevice pointer.

◆ setDeviceValue()

template<typename Device, typename DeviceValue>
void spk::DeviceInputTrigger< Device, DeviceValue >::setDeviceValue ( const DeviceValue & p_deviceValue,
const spk::InputState & p_state )
inline

Sets the device value and target state.

Parameters
p_deviceValueDevice input identifier.
p_stateTarget input state.

◆ setPredicate()

template<typename Device, typename DeviceValue>
void spk::DeviceInputTrigger< Device, DeviceValue >::setPredicate ( Predicate p_callback)
inline

Sets the predicate tested before firing.

Parameters
p_callbackPredicate function.

◆ setRepeatInterval()

template<typename Device, typename DeviceValue>
void spk::DeviceInputTrigger< Device, DeviceValue >::setRepeatInterval ( const spk::Duration & p_repeatInterval)
inline

Sets the repeat interval.

Parameters
p_repeatIntervalRepeat interval duration.

◆ update()

template<typename Device, typename DeviceValue>
void spk::DeviceInputTrigger< Device, DeviceValue >::update ( )
inlineoverridevirtual

Updates the trigger and fires callbacks if needed.

Implements spk::InputTrigger.


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