Divide Framework
0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
AutoKeyRepeat.cpp
Go to the documentation of this file.
1
2
3
#include "
Headers/AutoKeyRepeat.h
"
4
5
namespace
Divide
{
6
namespace
Input {
7
8
AutoRepeatKey::AutoRepeatKey
(
const
D64
repeatDelay,
const
D64
initialDelay) noexcept
9
: _key(
nullptr
, 0),
10
_elapsed(0.0),
11
_delay(initialDelay),
12
_repeatDelay(repeatDelay),
13
_initialDelay(initialDelay)
14
{
15
}
16
17
void
AutoRepeatKey::begin
(
const
KeyEvent
&evt)
noexcept
{
18
_key = evt;
19
_elapsed = 0.0;
20
_delay = _initialDelay;
21
}
22
23
void
AutoRepeatKey::end
( [[maybe_unused]]
const
KeyEvent
&evt )
noexcept
24
{
25
_key._key =
KeyCode::KC_UNASSIGNED
;
26
}
27
28
// Inject key repeats if the _repeatDelay expired between calls
29
void
AutoRepeatKey::update
(
const
U64
deltaTimeUS) {
30
if
(
_key
.
_key
==
KeyCode::KC_UNASSIGNED
) {
31
return
;
32
}
33
34
_elapsed
+=
Time::MicrosecondsToSeconds
(deltaTimeUS);
35
if
(
_elapsed
<
_delay
)
return
;
36
37
_elapsed
-=
_delay
;
38
_delay
=
_repeatDelay
;
39
40
do
{
41
repeatKey
(
_key
);
42
_elapsed
-=
_repeatDelay
;
43
}
while
(
_elapsed
>=
_repeatDelay
);
44
45
_elapsed
= 0.0;
46
}
47
48
};
// namespace Input
49
};
// namespace Divide
AutoKeyRepeat.h
Divide::Input::AutoRepeatKey::_delay
D64 _delay
Definition:
AutoKeyRepeat.h:49
Divide::Input::AutoRepeatKey::begin
void begin(const KeyEvent &evt) noexcept
Called when a key is pressed.
Definition:
AutoKeyRepeat.cpp:17
Divide::Input::AutoRepeatKey::repeatKey
virtual void repeatKey(const Input::KeyEvent &evt)=0
Override this to define custom events for key repeats.
Divide::Input::AutoRepeatKey::AutoRepeatKey
AutoRepeatKey(D64 repeatDelay=0.035, D64 initialDelay=0.300) noexcept
Default constructor.
Definition:
AutoKeyRepeat.cpp:8
Divide::Input::AutoRepeatKey::end
void end(const KeyEvent &evt) noexcept
Called when a key is released.
Definition:
AutoKeyRepeat.cpp:23
Divide::Input::AutoRepeatKey::update
void update(U64 deltaTimeUS)
Update the internal time interval between frames (microseconds)
Definition:
AutoKeyRepeat.cpp:29
Divide::Input::AutoRepeatKey::_key
KeyEvent _key
Definition:
AutoKeyRepeat.h:46
Divide::Input::AutoRepeatKey::_repeatDelay
D64 _repeatDelay
Time intervals between key injections.
Definition:
AutoKeyRepeat.h:51
Divide::Input::AutoRepeatKey::_elapsed
D64 _elapsed
Definition:
AutoKeyRepeat.h:48
Divide::Input::KeyCode::KC_UNASSIGNED
@ KC_UNASSIGNED
Divide::Time::MicrosecondsToSeconds
constexpr T MicrosecondsToSeconds(U a) noexcept
Definition:
MathHelper.inl:725
Divide
Handle console commands that start with a forward slash.
Definition:
AIProcessor.cpp:7
Divide::D64
double D64
Definition:
PlatformDataTypes.h:83
Divide::U64
uint64_t U64
Definition:
PlatformDataTypes.h:47
Divide::Input::KeyEvent
Definition:
InputAggregatorInterface.h:131
Divide::Input::KeyEvent::_key
KeyCode _key
Definition:
InputAggregatorInterface.h:135
Source
Platform
Input
AutoKeyRepeat.cpp
Generated on Fri May 17 2024 16:59:54 for Divide Framework by
1.9.6