imgui key map

This commit is contained in:
Green Sky 2024-03-09 15:11:29 +01:00
parent 3087e10c5e
commit 633f885c65
No known key found for this signature in database
4 changed files with 117 additions and 14 deletions

View File

@ -85,3 +85,23 @@ uint64_t Doom::getTexID(void) {
return _render_texture;
}
void Doom::doomKeyDown(doom_key_t key) {
doom_key_down(key);
}
void Doom::doomKeyUp(doom_key_t key) {
doom_key_up(key);
}
void Doom::doomButtonDown(doom_button_t button) {
doom_button_down(button);
}
void Doom::doomButtonUp(doom_button_t button) {
doom_button_up(button);
}
void Doom::doomMouseMove(int delta_x, int delta_y) {
doom_mouse_move(delta_x, delta_y);
}

View File

@ -23,11 +23,11 @@ class Doom {
// since we dont have an abstraction for this, or wont know what to do with it
// these have to be called from the outside
//void doom_key_down(doom_key_t key);
//void doom_key_up(doom_key_t key);
//void doom_button_down(doom_button_t button);
//void doom_button_up(doom_button_t button);
//void doom_mouse_move(int delta_x, int delta_y);
void doomKeyDown(doom_key_t key);
void doomKeyUp(doom_key_t key);
void doomButtonDown(doom_button_t button);
void doomButtonUp(doom_button_t button);
void doomMouseMove(int delta_x, int delta_y);
//void doom_set_default_int(const char* name, int value);
//void doom_set_default_string(const char* name, const char* value);

View File

@ -2,6 +2,8 @@
#include <imgui.h>
#include <vector>
DoomIMGUI::DoomIMGUI(
TextureUploaderI& tu
) : _doom(tu) {
@ -10,13 +12,97 @@ DoomIMGUI::DoomIMGUI(
DoomIMGUI::~DoomIMGUI(void) {
}
const static std::vector<std::pair<ImGuiKey, doom_key_t>> g_all_keys {
{ImGuiKey_A, DOOM_KEY_A},
{ImGuiKey_Tab, DOOM_KEY_TAB},
{ImGuiKey_Enter, DOOM_KEY_ENTER},
{ImGuiKey_Escape, DOOM_KEY_ESCAPE},
{ImGuiKey_Space, DOOM_KEY_SPACE},
{ImGuiKey_Apostrophe, DOOM_KEY_APOSTROPHE},
{ImGuiKey_KeypadMultiply, DOOM_KEY_MULTIPLY}, // keypad?
{ImGuiKey_Comma, DOOM_KEY_COMMA},
{ImGuiKey_Minus, DOOM_KEY_MINUS},
{ImGuiKey_Period, DOOM_KEY_PERIOD},
{ImGuiKey_Slash, DOOM_KEY_SLASH},
{ImGuiKey_0, DOOM_KEY_0},
{ImGuiKey_1, DOOM_KEY_1},
{ImGuiKey_2, DOOM_KEY_2},
{ImGuiKey_3, DOOM_KEY_3},
{ImGuiKey_4, DOOM_KEY_4},
{ImGuiKey_5, DOOM_KEY_5},
{ImGuiKey_6, DOOM_KEY_6},
{ImGuiKey_7, DOOM_KEY_7},
{ImGuiKey_8, DOOM_KEY_8},
{ImGuiKey_9, DOOM_KEY_9},
{ImGuiKey_Semicolon, DOOM_KEY_SEMICOLON},
{ImGuiKey_Equal, DOOM_KEY_EQUALS},
{ImGuiKey_LeftBracket, DOOM_KEY_LEFT_BRACKET},
{ImGuiKey_RightBracket, DOOM_KEY_RIGHT_BRACKET},
{ImGuiKey_A, DOOM_KEY_A},
{ImGuiKey_B, DOOM_KEY_B},
{ImGuiKey_C, DOOM_KEY_C},
{ImGuiKey_D, DOOM_KEY_D},
{ImGuiKey_E, DOOM_KEY_E},
{ImGuiKey_F, DOOM_KEY_F},
{ImGuiKey_G, DOOM_KEY_G},
{ImGuiKey_H, DOOM_KEY_H},
{ImGuiKey_I, DOOM_KEY_I},
{ImGuiKey_J, DOOM_KEY_J},
{ImGuiKey_K, DOOM_KEY_K},
{ImGuiKey_L, DOOM_KEY_L},
{ImGuiKey_M, DOOM_KEY_M},
{ImGuiKey_N, DOOM_KEY_N},
{ImGuiKey_O, DOOM_KEY_O},
{ImGuiKey_P, DOOM_KEY_P},
{ImGuiKey_Q, DOOM_KEY_Q},
{ImGuiKey_R, DOOM_KEY_R},
{ImGuiKey_S, DOOM_KEY_S},
{ImGuiKey_T, DOOM_KEY_T},
{ImGuiKey_U, DOOM_KEY_U},
{ImGuiKey_V, DOOM_KEY_V},
{ImGuiKey_W, DOOM_KEY_W},
{ImGuiKey_X, DOOM_KEY_X},
{ImGuiKey_Y, DOOM_KEY_Y},
{ImGuiKey_Z, DOOM_KEY_Z},
{ImGuiKey_Backspace, DOOM_KEY_BACKSPACE},
{ImGuiKey_ModCtrl, DOOM_KEY_CTRL},
{ImGuiKey_LeftArrow, DOOM_KEY_LEFT_ARROW},
{ImGuiKey_UpArrow, DOOM_KEY_UP_ARROW},
{ImGuiKey_RightArrow, DOOM_KEY_RIGHT_ARROW},
{ImGuiKey_DownArrow, DOOM_KEY_DOWN_ARROW},
{ImGuiKey_ModShift, DOOM_KEY_SHIFT},
{ImGuiKey_ModAlt, DOOM_KEY_ALT},
{ImGuiKey_F1, DOOM_KEY_F1},
{ImGuiKey_F2, DOOM_KEY_F2},
{ImGuiKey_F3, DOOM_KEY_F3},
{ImGuiKey_F4, DOOM_KEY_F4},
{ImGuiKey_F5, DOOM_KEY_F5},
{ImGuiKey_F6, DOOM_KEY_F6},
{ImGuiKey_F7, DOOM_KEY_F7},
{ImGuiKey_F8, DOOM_KEY_F8},
{ImGuiKey_F9, DOOM_KEY_F9},
{ImGuiKey_F10, DOOM_KEY_F10},
{ImGuiKey_F11, DOOM_KEY_F11},
{ImGuiKey_F12, DOOM_KEY_F12},
{ImGuiKey_Pause, DOOM_KEY_PAUSE},
};
float DoomIMGUI::render(float time_delta) {
// tick doom either way
// while this is computing, and as such could be run in tick(), its still rendering
const float doom_interval = _doom.render(time_delta);
float doom_interval {1.f};
if (ImGui::Begin("doom")) {
ImGui::Image(reinterpret_cast<void*>(_doom.getTexID()), {320, 200});
for (const auto& [imkey, dokey] : g_all_keys) {
// TODO: unpress all keys on focus loss
if (ImGui::IsKeyPressed(imkey, false)) {
_doom.doomKeyDown(dokey);
}
if (ImGui::IsKeyReleased(imkey)) {
_doom.doomKeyUp(dokey);
}
}
doom_interval = _doom.render(time_delta);
ImGui::Image(reinterpret_cast<void*>(_doom.getTexID()), {320, 200*1.2});
}
ImGui::End();

View File

@ -14,8 +14,5 @@ class DoomIMGUI {
// render imgui
float render(float time_delta);
public: // custom doom api
uint64_t getTexID(void);
};