Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Clark Lin
hw3d
Commits
cf87f10a
Commit
cf87f10a
authored
Feb 03, 2019
by
chili
Browse files
housekp: optional kbd evt
parent
06326223
Changes
2
Show whitespace changes
Inline
Side-by-side
hw3d/Keyboard.cpp
View file @
cf87f10a
...
@@ -24,7 +24,7 @@ bool Keyboard::KeyIsPressed( unsigned char keycode ) const noexcept
...
@@ -24,7 +24,7 @@ bool Keyboard::KeyIsPressed( unsigned char keycode ) const noexcept
return
keystates
[
keycode
];
return
keystates
[
keycode
];
}
}
Keyboard
::
Event
Keyboard
::
ReadKey
()
noexcept
std
::
optional
<
Keyboard
::
Event
>
Keyboard
::
ReadKey
()
noexcept
{
{
if
(
keybuffer
.
size
()
>
0u
)
if
(
keybuffer
.
size
()
>
0u
)
{
{
...
@@ -32,10 +32,7 @@ Keyboard::Event Keyboard::ReadKey() noexcept
...
@@ -32,10 +32,7 @@ Keyboard::Event Keyboard::ReadKey() noexcept
keybuffer
.
pop
();
keybuffer
.
pop
();
return
e
;
return
e
;
}
}
else
return
{};
{
return
Keyboard
::
Event
();
}
}
}
bool
Keyboard
::
KeyIsEmpty
()
const
noexcept
bool
Keyboard
::
KeyIsEmpty
()
const
noexcept
...
@@ -43,7 +40,7 @@ bool Keyboard::KeyIsEmpty() const noexcept
...
@@ -43,7 +40,7 @@ bool Keyboard::KeyIsEmpty() const noexcept
return
keybuffer
.
empty
();
return
keybuffer
.
empty
();
}
}
char
Keyboard
::
ReadChar
()
noexcept
std
::
optional
<
char
>
Keyboard
::
ReadChar
()
noexcept
{
{
if
(
charbuffer
.
size
()
>
0u
)
if
(
charbuffer
.
size
()
>
0u
)
{
{
...
@@ -51,10 +48,7 @@ char Keyboard::ReadChar() noexcept
...
@@ -51,10 +48,7 @@ char Keyboard::ReadChar() noexcept
charbuffer
.
pop
();
charbuffer
.
pop
();
return
charcode
;
return
charcode
;
}
}
else
return
{};
{
return
0
;
}
}
}
bool
Keyboard
::
CharIsEmpty
()
const
noexcept
bool
Keyboard
::
CharIsEmpty
()
const
noexcept
...
...
hw3d/Keyboard.h
View file @
cf87f10a
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#pragma once
#pragma once
#include <queue>
#include <queue>
#include <bitset>
#include <bitset>
#include <optional>
class
Keyboard
class
Keyboard
{
{
...
@@ -32,17 +33,11 @@ public:
...
@@ -32,17 +33,11 @@ public:
{
{
Press
,
Press
,
Release
,
Release
,
Invalid
};
};
private:
private:
Type
type
;
Type
type
;
unsigned
char
code
;
unsigned
char
code
;
public:
public:
Event
()
noexcept
:
type
(
Type
::
Invalid
),
code
(
0u
)
{}
Event
(
Type
type
,
unsigned
char
code
)
noexcept
Event
(
Type
type
,
unsigned
char
code
)
noexcept
:
:
type
(
type
),
type
(
type
),
...
@@ -56,10 +51,6 @@ public:
...
@@ -56,10 +51,6 @@ public:
{
{
return
type
==
Type
::
Release
;
return
type
==
Type
::
Release
;
}
}
bool
IsValid
()
const
noexcept
{
return
type
!=
Type
::
Invalid
;
}
unsigned
char
GetCode
()
const
noexcept
unsigned
char
GetCode
()
const
noexcept
{
{
return
code
;
return
code
;
...
@@ -71,11 +62,11 @@ public:
...
@@ -71,11 +62,11 @@ public:
Keyboard
&
operator
=
(
const
Keyboard
&
)
=
delete
;
Keyboard
&
operator
=
(
const
Keyboard
&
)
=
delete
;
// key event stuff
// key event stuff
bool
KeyIsPressed
(
unsigned
char
keycode
)
const
noexcept
;
bool
KeyIsPressed
(
unsigned
char
keycode
)
const
noexcept
;
Event
ReadKey
()
noexcept
;
std
::
optional
<
Event
>
ReadKey
()
noexcept
;
bool
KeyIsEmpty
()
const
noexcept
;
bool
KeyIsEmpty
()
const
noexcept
;
void
FlushKey
()
noexcept
;
void
FlushKey
()
noexcept
;
// char event stuff
// char event stuff
char
ReadChar
()
noexcept
;
std
::
optional
<
char
>
ReadChar
()
noexcept
;
bool
CharIsEmpty
()
const
noexcept
;
bool
CharIsEmpty
()
const
noexcept
;
void
FlushChar
()
noexcept
;
void
FlushChar
()
noexcept
;
void
Flush
()
noexcept
;
void
Flush
()
noexcept
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment