diff --git a/source/code/DialogBox.cpp b/source/code/DialogBox.cpp index 8ef8556..b84974f 100644 --- a/source/code/DialogBox.cpp +++ b/source/code/DialogBox.cpp @@ -134,7 +134,6 @@ static bool insideRect (int x, int y, int height, int width) { // For use with the mouse/gamepad keyboard int keyboardRowLimit = 20; - void DialogBox::Draw(SDL_Renderer* target) { DrawBackground(globalData.screen); this->x = globalData.xsize/2-300; @@ -210,8 +209,20 @@ void DialogBox::ProcessInput(const SDL_Event& event, bool& processed) { auto topx = globalData.xsize/2-400+(i%keyboardRowLimit)*40-5; auto topy = globalData.ysize/2+150+(i/keyboardRowLimit)*40-5; if (insideRect(topx, topy, 30, 30)) { - std::cout << f.GetText() << " pressed\n"; - rk->putchar(f.GetText()); + std::string insertChar = f.GetText(); + std::cout << insertChar << " pressed\n"; + if (insertChar == backspace) { + rk->emulateBackspace(); + } + else if (insertChar == leftChar) { + rk->cursorLeft(); + } + else if (insertChar == rightChar) { + rk->cursorRight(); + } + else { + rk->putchar(f.GetText()); + } } } } diff --git a/source/code/DialogBox.hpp b/source/code/DialogBox.hpp index 2561541..7fcff21 100644 --- a/source/code/DialogBox.hpp +++ b/source/code/DialogBox.hpp @@ -61,7 +61,10 @@ private: sago::SagoTextField cursorLabel; std::string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" - ".,:!?+_^@#%&=*"; + ".,:!?+_^@#%&=*" "‹›«"; + const std::string leftChar = "‹"; + const std::string rightChar = "›"; + const std::string backspace = "«"; std::vector gamePadChars; std::vector gamePadCharFields; int selectedChar = 0; diff --git a/source/code/ReadKeyboard.cpp b/source/code/ReadKeyboard.cpp index ee806f5..d88c529 100644 --- a/source/code/ReadKeyboard.cpp +++ b/source/code/ReadKeyboard.cpp @@ -71,6 +71,30 @@ bool ReadKeyboard::ReadKey(const SDL_Event& key) { return ReadKey(key.key.keysym.sym); } +bool ReadKeyboard::cursorLeft() { + if (position>text_string.begin()) { + utf8::prior(position, text_string.begin()); + return true; + } + return false; +} +bool ReadKeyboard::cursorRight() { + if (positiontext_string.begin()) { + utf8::prior(position, text_string.begin()); + ReadKeyboard::removeChar(); + return true; + } + return false; +} + bool ReadKeyboard::ReadKey(SDL_Keycode keyPressed) { if (keyPressed == SDLK_DELETE) { if ((text_string.length()>0)&& (positiontext_string.begin()) { - utf8::prior(position, text_string.begin()); - ReadKeyboard::removeChar(); - return true; - } - return false; + return emulateBackspace(); } if (keyPressed == SDLK_HOME) { position = text_string.begin(); @@ -94,12 +113,12 @@ bool ReadKeyboard::ReadKey(SDL_Keycode keyPressed) { position=text_string.end(); return true; } - if ((keyPressed == SDLK_LEFT) && (position>text_string.begin())) { - utf8::prior(position, text_string.begin()); + if (keyPressed == SDLK_LEFT) { + cursorLeft(); return true; } - if ((keyPressed == SDLK_RIGHT) && (position