| e8555c89 Andy McCall |
1 |
#ifndef SDLKEY_HH |
| 2 |
#define SDLKEY_HH |
| 3 |
|
| 4 |
#include "zstring_view.hh" |
| 5 |
|
| 6 |
#include <SDL.h> |
| 7 |
|
| 8 |
#include <cstdint> |
| 9 |
#include <optional> |
| 10 |
#include <string> |
| 11 |
#include <string_view> |
| 12 |
|
| 13 |
namespace openmsx { |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
struct SDLKey { |
| 19 |
SDL_Keysym sym; |
| 20 |
bool down; |
| 21 |
|
| 22 |
[[nodiscard]] static SDLKey create(SDL_Keycode code, SDL_Scancode scancode, bool down, uint16_t mod = 0) { |
| 23 |
SDL_Keysym sym; |
| 24 |
sym.scancode = scancode; |
| 25 |
sym.sym = code; |
| 26 |
sym.mod = mod; |
| 27 |
sym.unused = 0; |
| 28 |
return {.sym = sym, .down = down}; |
| 29 |
} |
| 30 |
|
| 31 |
[[nodiscard]] static SDLKey createDown(SDL_Keycode code, SDL_Scancode scancode) { |
| 32 |
return create(code, scancode, true); |
| 33 |
} |
| 34 |
|
| 35 |
[[nodiscard]] static std::optional<SDLKey> fromString(std::string_view name); |
| 36 |
[[nodiscard]] static SDL_Keycode keycodeFromString(zstring_view name); |
| 37 |
|
| 38 |
|
| 39 |
[[nodiscard]] std::string toString() const; |
| 40 |
[[nodiscard]] static std::string toString(SDL_Keycode code); |
| 41 |
}; |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
#endif |