diff --git a/src/kekengine/cpp/engine.cpp b/src/kekengine/cpp/engine.cpp index 3af4b72..e1f6208 100644 --- a/src/kekengine/cpp/engine.cpp +++ b/src/kekengine/cpp/engine.cpp @@ -51,7 +51,11 @@ static void onCursorPosCallback(GLFWwindow *window, double x, double y) { static void onKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods) { if(Input::isKeyboardCaptured()) { - if(key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) Input::uncaptureKeyboardInput(kekData.activeKeyboardCapture.id); + if(key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) { + Input::uncaptureKeyboardInput(kekData.activeKeyboardCapture.id); + }else if(key == GLFW_KEY_BACKSPACE && (action == GLFW_PRESS || action == GLFW_REPEAT)) { + kekData.activeKeyboardCapture.callback(window, KEK_INPUT_DELETE); + } return; } diff --git a/src/kekengine/cpp/input.cpp b/src/kekengine/cpp/input.cpp index bc6ebaa..e169e54 100644 --- a/src/kekengine/cpp/input.cpp +++ b/src/kekengine/cpp/input.cpp @@ -101,17 +101,21 @@ GLFWCursorMode getCursorMode() { KeyboardCapture captureKeyboardInput(KeyCharCallback callback, Callable uncaptureCallback) { KeyboardCapture id = nextID++; - kekData.activeKeyboardCapture.id = id; - kekData.activeKeyboardCapture.callback = callback; - kekData.activeKeyboardCapture.uncaptureCallback = uncaptureCallback; + kekData.activeKeyboardCapture = { + id, + callback, + uncaptureCallback + }; return id; } bool uncaptureKeyboardInput(KeyboardCapture capture) { if(capture == KEK_INVALID_ID || capture != kekData.activeKeyboardCapture.id) return false; - kekData.activeKeyboardCapture.id = KEK_INVALID_ID; - kekData.activeKeyboardCapture.callback = KeyCharCallback(); - kekData.activeKeyboardCapture.uncaptureCallback = Callable(); + kekData.activeKeyboardCapture = { + KEK_INVALID_ID, + KeyCharCallback(), + Callable() + }; return true; } diff --git a/src/kekengine/include/constants.h b/src/kekengine/include/constants.h index df6623f..8b82345 100644 --- a/src/kekengine/include/constants.h +++ b/src/kekengine/include/constants.h @@ -40,3 +40,5 @@ #define KEK_DEFAULT_FONT "font/MaredivRegular-yeg3.ttf" #define KEK_DEFAULT_FONT_SIZE_PIXELS 24 + +#define KEK_INPUT_DELETE -1u diff --git a/src/kekgame/cpp/kekgame.cpp b/src/kekgame/cpp/kekgame.cpp index 05cfa77..7a045d3 100644 --- a/src/kekgame/cpp/kekgame.cpp +++ b/src/kekgame/cpp/kekgame.cpp @@ -23,7 +23,11 @@ void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods, v void onButtonClick(void *data) { Input::captureKeyboardInput(KeyCharCallback([](GLFWwindow *window, unsigned int codepoint, void *data) { std::u32string str = Unicode::convertStdToU32(button->text->getText()); - str.push_back(codepoint); + if(codepoint == KEK_INPUT_DELETE) { + str = str.substr(0, str.length() - 1); + }else { + str.push_back(codepoint); + } button->text->setText(Unicode::convertU32ToStd(str)); }, nullptr), Callable()); }