1 #include "ge211_event.h" 3 #include <SDL_events.h> 4 #include "../3rdparty/utf8-cpp/utf8.h" 12 bool map_button(uint8_t input, Mouse_button& output) noexcept
16 output = Mouse_button::left;
18 case SDL_BUTTON_MIDDLE:
19 output = Mouse_button::middle;
21 case SDL_BUTTON_RIGHT:
22 output = Mouse_button::right;
33 static Key map_key(
const SDL_KeyboardEvent& e) noexcept
35 if (e.keysym.sym >= 0 && e.keysym.sym < 128) {
38 switch (e.keysym.sym) {
67 Key::Key(
const SDL_KeyboardEvent& e) noexcept
71 static const char* mouse_button_name(
Mouse_button button) noexcept
74 case Mouse_button::left:
76 case Mouse_button::middle:
78 case Mouse_button::right:
87 return os << mouse_button_name(button);
90 static const char* key_type_name(
Key::Type type) noexcept
120 return os << key_type_name(type);
128 return os <<
"Key::code('" <<
char(key.
code()) <<
"')";
130 return os <<
"Key::code(" << key.
code() <<
")";
132 return os <<
"Key::" << key.
type() <<
"()";
138 return type_ ==
Type::code && !iswcntrl(code_);
146 char* end = utf8::append(code_, buffer);
147 return std::string(buffer, end);
Mouse_button
A representation of a mouse button.
Represents a key on the keyboard.
static Key shift() noexcept
Constructs the shift key.
std::string as_text() const
Returns a representation of the key's code as a std::string.
Type
The possible types of keys.
static Key command() noexcept
Constructs the command (or meta) key.
The game engine namespace.
bool is_textual() const noexcept
Does the key represent printable text? This is true for some but not all Type::code keys...
Key() noexcept
Constructs the empty key, with type Key::Type::other.
static Key left() noexcept
Constructs the left arrow key.
Any other, unknown or invalid key.
std::ostream & operator<<(std::ostream &os, Mouse_button button)
Prints a Mouse_button on a std::ostream.
char32_t code() const noexcept
The Unicode code point of the key, if it has one.
Indicates a key with an Unicode value, which can be gotten with Key::code() const.
static Key control() noexcept
Constructs the control key.
static Key code(char32_t c)
Constructs a key with the given Unicode code point code.
static Key up() noexcept
Constructs the up arrow key.
static Key down() noexcept
Constructs the down arrow key.
static Key alt() noexcept
Constructs the alt (or option) key.
static Key right() noexcept
Constructs the right arrow key.
Type type() const noexcept
The type of the key.