Gorgon Game Engine
KeyRepeater Class Reference

This class simplifies the use of repeated keystrokes when a key is pressed. More...

Inheritance diagram for KeyRepeater:
[legend]

Public Member Functions

 KeyRepeater ()
 Default constructor. More...
 
 KeyRepeater (const KeyRepeater &)=delete
 Disable copy constructor. More...
 
 KeyRepeater (const std::initializer_list< Key > &keys, int delay=100)
 Registers this repeater to the given event and registers the given keys. More...
 
template<class E_ >
 KeyRepeater (E_ &event, const std::initializer_list< Key > &keys, int delay=100)
 Registers this repeater to the given event and registers the given keys. More...
 
 ~KeyRepeater ()
 Destructor. More...
 
int GetAcceleration () const
 Returns the change in repeat delay per repeat in milliseconds, positive values will reduce delay by the given amount. More...
 
int GetAccelerationCount () const
 Returns how many times acceleration can be applied. More...
 
int GetAccelerationStart () const
 Returns the number of repeats after which the acceleration will start excluding first press if repeat on press is set. More...
 
int GetDelay () const
 Returns the delay between successive repeats in milliseconds. More...
 
virtual int GetDuration () const override
 Returns the duration of the animation if it is a known apriori. More...
 
int GetFinalDelay () const
 Returns the final delay between repeat events in milliseconds after acceleration is completed. More...
 
bool GetInitialDelay () const
 Returns the initial delay before the first (or second if instant repeat is on) key is repeated in milliseconds. More...
 
bool GetRepeatOnPress () const
 Returns whether the key will be repeated instantly when pressed. More...
 
bool GetRepeatOnRelease () const
 Returns if the key will be repeated right after the key is released. More...
 
bool IsKeyRegistered (Key key) const
 Returns whether a given is registered for automatic management. More...
 
bool IsPressed (Key key) const
 Checks if a key is pressed. More...
 
bool KeyEvent (Key &key, float amount)
 This function is used to handle key events. More...
 
void Press (Key key)
 Presses a key, effectively simulating keydown. More...
 
virtual bool Progress (unsigned &) override
 This function should progress the animation. More...
 
void Register (Key key)
 Registers the given key to be repeated. More...
 
template<class ... T_>
void Register (Key key, T_ &&... args)
 Registers the given keys to be repeated. More...
 
template<class E_ >
void RegisterTo (E_ &event, bool ignoremodified=false)
 Registers this repeater to the given event to obtain press and release actions. More...
 
void Release (Key key)
 Releases a key may cause a repeat. More...
 
void SetAcceleration (int value)
 Change in repeat delay per repeat in milliseconds, positive values will reduce delay by the given amount. More...
 
void SetAccelerationCount (int value)
 Set how many times acceleration can be applied. More...
 
void SetAccelerationStart (int value)
 Sets the number of repeats after which the acceleration will start excluding first press if repeat on press is set. More...
 
virtual void SetController (Animation::ControllerBase &controller) override
 Sets the controller to the given controller. More...
 
void SetDelay (int value)
 Repeat delay between successive repeat events in milliseconds. More...
 
void SetInitialDelay (int value)
 Sets the initial delay before the first (or second if instant repeat is on) key is repeated in milliseconds. More...
 
void SetRepeatOnPress (bool value)
 Sets whether the key will be repeated instantly when pressed. More...
 
void SetRepeatOnRelease (bool value)
 Sets if the key should be repeated right after the key is released. More...
 
void SetupAcceleration (int startdelay, int finaldelay, int rampup)
 This function allows easy setup for acceleration by supplying starting delay, final delay and the time it should take to reach final delay. More...
 
void Unregister (Key key)
 Unregisters a key from this repeater. More...
 
void UnregisterFrom ()
 Unregisters this repeater from its registered event. More...
 
- Public Member Functions inherited from Base
 Base (bool create=false)
 This constructor creates a new controller depending on the create parameter. More...
 
 Base (const Base &base)
 Copies the animation. More...
 
 Base (ControllerBase &controller)
 Sets the controller for this animation to the given controller. More...
 
virtual void DeleteAnimation () const
 Deletes this animation. More...
 
virtual ControllerBaseGetController () const
 Returns the controller of this animation. More...
 
virtual bool HasController () const
 Returns whether this animation has a controller. More...
 
virtual void RemoveController ()
 Removes the controller of this animation. More...
 

Public Attributes

Event< KeyRepeater, KeyRepeat
 Press event that is called everytime a key is pressed. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Base
virtual ~Base ()
 Virtual destructor. More...
 
- Protected Attributes inherited from Base
ControllerBasecontroller
 Controller of this animation. More...
 

Detailed Description

This class simplifies the use of repeated keystrokes when a key is pressed.

It can work automatically with a KeyEvent or manually when its functions is called. Every time a key repeats the associated event will be fired with the key. If a key is repeated multiple times in a single frame, the Repeat event will be fired that many times one after another. Initial delay, repeat interval, and repeat acceleration can be modified to customize behavior of the repeater.

KeyRepeater can repeat multiple keys. Multiple Repeat events can be fired in a single frame. The order of repeat events between keys is not defined. However, if the same key is repeated multiple times in the same frame, these repeats are always sequential. KeyRepeater has no notion of inverse keys (eg. left and right). The best course of action is to apply the effect of these keys separately.

KeyRepeater is not suitable for most games. It is designed mainly as a text editing tool.

KeyRepeater can also be used with mouse keys. However, as of now, mouse keys should be pressed and released manually.

KeyRepeater is also an animation, it is bound with a timer, and effected by the active animation governor.

Constructor & Destructor Documentation

◆ KeyRepeater() [1/4]

Default constructor.

◆ KeyRepeater() [2/4]

KeyRepeater ( E_ &  event,
const std::initializer_list< Key > &  keys,
int  delay = 100 
)

Registers this repeater to the given event and registers the given keys.

References KeyRepeater::Register(), KeyRepeater::RegisterTo(), and KeyRepeater::SetDelay().

◆ KeyRepeater() [3/4]

KeyRepeater ( const std::initializer_list< Key > &  keys,
int  delay = 100 
)

Registers this repeater to the given event and registers the given keys.

References KeyRepeater::Register(), and KeyRepeater::SetDelay().

◆ KeyRepeater() [4/4]

KeyRepeater ( const KeyRepeater )
delete

Disable copy constructor.

◆ ~KeyRepeater()

Destructor.

References eventunregisterhelper::unregister().

Member Function Documentation

◆ GetAcceleration()

int GetAcceleration ( ) const

Returns the change in repeat delay per repeat in milliseconds, positive values will reduce delay by the given amount.

You may use negative values to slow down.

◆ GetAccelerationCount()

int GetAccelerationCount ( ) const

Returns how many times acceleration can be applied.

This number is counted after acceleration start.

◆ GetAccelerationStart()

int GetAccelerationStart ( ) const

Returns the number of repeats after which the acceleration will start excluding first press if repeat on press is set.

◆ GetDelay()

int GetDelay ( ) const

Returns the delay between successive repeats in milliseconds.

◆ GetDuration()

virtual int GetDuration ( ) const
overridevirtual

Returns the duration of the animation if it is a known apriori.

If the animation can be progressed infinitely, if it is possible to derive optimal duration, it should be returned. In case when it is impossible to determine the duration, return 0.

Implements Base.

◆ GetFinalDelay()

int GetFinalDelay ( ) const

Returns the final delay between repeat events in milliseconds after acceleration is completed.

◆ GetInitialDelay()

bool GetInitialDelay ( ) const

Returns the initial delay before the first (or second if instant repeat is on) key is repeated in milliseconds.

◆ GetRepeatOnPress()

bool GetRepeatOnPress ( ) const

Returns whether the key will be repeated instantly when pressed.

◆ GetRepeatOnRelease()

bool GetRepeatOnRelease ( ) const

Returns if the key will be repeated right after the key is released.

◆ IsKeyRegistered()

bool IsKeyRegistered ( Key  key) const

Returns whether a given is registered for automatic management.

◆ IsPressed()

bool IsPressed ( Key  key) const

Checks if a key is pressed.

◆ KeyEvent()

bool KeyEvent ( Key key,
float  amount 
)

This function is used to handle key events.

References KeyRepeater::Press(), and KeyRepeater::Release().

◆ Press()

void Press ( Key  key)

Presses a key, effectively simulating keydown.

Depeding on the settings, this may trigger repeat instantly.

References KeyRepeater::Repeat.

◆ Progress()

bool Progress ( unsigned &  leftover)
overridevirtual

This function should progress the animation.

Notice that this function is called internally. Unless a change to the controller has been made and instant update of the animation is required there is no need to call this function. Returning true from this function denotes that the further progress is possible. If progress should end, leftover parameter should be set to the amount of time that cannot be progressed. Progress function should also mind uncontrollable controllers.

Implements Base.

References Base::controller, ControllerBase::GetProgress(), and KeyRepeater::Repeat.

◆ Register() [1/2]

void Register ( Key  key)

Registers the given key to be repeated.

Registering keys are necessary only for automatic key acquisition from an event.

◆ Register() [2/2]

void Register ( Key  key,
T_ &&...  args 
)

Registers the given keys to be repeated.

Registering keys are necessary only for automatic key acquisition from an event.

References KeyRepeater::Register().

◆ RegisterTo()

void RegisterTo ( E_ &  event,
bool  ignoremodified = false 
)

Registers this repeater to the given event to obtain press and release actions.

This event handler will only work for registered keys and will return 0 for all other keys. If ignoremodified is set, keys will not be triggered when a modifier key is pressed. This class depends on the event and should be destroyed or UnregisteredFrom before the event is destroyed.

References KeyRepeater::KeyEvent(), and KeyRepeater::UnregisterFrom().

◆ Release()

void Release ( Key  key)

Releases a key may cause a repeat.

References KeyRepeater::Repeat.

◆ SetAcceleration()

void SetAcceleration ( int  value)

Change in repeat delay per repeat in milliseconds, positive values will reduce delay by the given amount.

You may use negative values to slow down.

◆ SetAccelerationCount()

void SetAccelerationCount ( int  value)

Set how many times acceleration can be applied.

This number is counted after acceleration start.

◆ SetAccelerationStart()

void SetAccelerationStart ( int  value)

Sets the number of repeats after which the acceleration will start excluding first press if repeat on press is set.

◆ SetController()

virtual void SetController ( Animation::ControllerBase controller)
overridevirtual

Sets the controller to the given controller.

Reimplemented from Base.

References Base::controller, ControllerBase::GetProgress(), and Base::SetController().

◆ SetDelay()

void SetDelay ( int  value)

Repeat delay between successive repeat events in milliseconds.

This is the initial value and can be altered by acceleration.

◆ SetInitialDelay()

void SetInitialDelay ( int  value)

Sets the initial delay before the first (or second if instant repeat is on) key is repeated in milliseconds.

Set 0 to disable.

◆ SetRepeatOnPress()

void SetRepeatOnPress ( bool  value)

Sets whether the key will be repeated instantly when pressed.

◆ SetRepeatOnRelease()

void SetRepeatOnRelease ( bool  value)

Sets if the key should be repeated right after the key is released.

◆ SetupAcceleration()

void SetupAcceleration ( int  startdelay,
int  finaldelay,
int  rampup 
)

This function allows easy setup for acceleration by supplying starting delay, final delay and the time it should take to reach final delay.

This function will calculate nearest values to match the given setup.

References KeyRepeater::SetAcceleration(), KeyRepeater::SetAccelerationCount(), KeyRepeater::SetAccelerationStart(), and KeyRepeater::SetDelay().

◆ Unregister()

void Unregister ( Key  key)

Unregisters a key from this repeater.

Unregistering a key will trigger a release if key is pressed. The key can be pressed again later on using Press function however, it will not automatically be acquired from the event that this repeater is registered to.

References KeyRepeater::Release().

◆ UnregisterFrom()

void UnregisterFrom ( )

Unregisters this repeater from its registered event.

References eventunregisterhelper::unregister().

Member Data Documentation

◆ Repeat

Event<KeyRepeater, Key> Repeat

Press event that is called everytime a key is pressed.


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