![]() |
Gorgon Game Engine
|
This class simplifies the use of repeated keystrokes when a key is pressed. More...
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... | |
![]() | |
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 ControllerBase & | GetController () 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, Key > | Repeat |
Press event that is called everytime a key is pressed. More... | |
Additional Inherited Members | |
![]() | |
virtual | ~Base () |
Virtual destructor. More... | |
![]() | |
ControllerBase * | controller |
Controller of this animation. More... | |
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.
KeyRepeater | ( | ) |
Default constructor.
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 | ( | 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().
|
delete |
Disable copy constructor.
~KeyRepeater | ( | ) |
Destructor.
References eventunregisterhelper::unregister().
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.
int GetAccelerationCount | ( | ) | const |
Returns how many times acceleration can be applied.
This number is counted after acceleration start.
int GetAccelerationStart | ( | ) | const |
Returns the number of repeats after which the acceleration will start excluding first press if repeat on press is set.
int GetDelay | ( | ) | const |
Returns the delay between successive repeats in milliseconds.
|
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.
int GetFinalDelay | ( | ) | const |
Returns the final delay between repeat events in milliseconds after acceleration is completed.
bool GetInitialDelay | ( | ) | const |
Returns the initial delay before the first (or second if instant repeat is on) key is repeated in milliseconds.
bool GetRepeatOnPress | ( | ) | const |
Returns whether the key will be repeated instantly when pressed.
bool GetRepeatOnRelease | ( | ) | const |
Returns if the key will be repeated right after the key is released.
bool IsKeyRegistered | ( | Key | key | ) | const |
Returns whether a given is registered for automatic management.
bool IsPressed | ( | Key | key | ) | const |
Checks if a key is pressed.
bool KeyEvent | ( | Key & | key, |
float | amount | ||
) |
This function is used to handle key events.
References KeyRepeater::Press(), and KeyRepeater::Release().
void Press | ( | Key | key | ) |
Presses a key, effectively simulating keydown.
Depeding on the settings, this may trigger repeat instantly.
References KeyRepeater::Repeat.
|
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.
void Register | ( | Key | key | ) |
Registers the given key to be repeated.
Registering keys are necessary only for automatic key acquisition from an event.
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().
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().
void Release | ( | Key | key | ) |
Releases a key may cause a repeat.
References KeyRepeater::Repeat.
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.
void SetAccelerationCount | ( | int | value | ) |
Set how many times acceleration can be applied.
This number is counted after acceleration start.
void SetAccelerationStart | ( | int | value | ) |
Sets the number of repeats after which the acceleration will start excluding first press if repeat on press is set.
|
overridevirtual |
Sets the controller to the given controller.
Reimplemented from Base.
References Base::controller, ControllerBase::GetProgress(), and Base::SetController().
void SetDelay | ( | int | value | ) |
Repeat delay between successive repeat events in milliseconds.
This is the initial value and can be altered by acceleration.
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.
void SetRepeatOnPress | ( | bool | value | ) |
Sets whether the key will be repeated instantly when pressed.
void SetRepeatOnRelease | ( | bool | value | ) |
Sets if the key should be repeated right after the key is released.
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().
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().
void UnregisterFrom | ( | ) |
Unregisters this repeater from its registered event.
References eventunregisterhelper::unregister().
Event<KeyRepeater, Key> Repeat |
Press event that is called everytime a key is pressed.