From 8d315ba74452e244b9e112150ec5449def877f84 Mon Sep 17 00:00:00 2001 From: titiger Date: Mon, 9 Nov 2015 01:31:24 +0100 Subject: [PATCH] first steps for ctrl-v for input Problems remaining: paste probably iss too long for ( problem for text input labels ) paste is countet as one single input which deletes the whole pasted string on pressing backspace. --- source/glest_game/game/chat_manager.cpp | 6 ++++-- .../sources/platform/sdl/window.cpp | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/source/glest_game/game/chat_manager.cpp b/source/glest_game/game/chat_manager.cpp index b430ef9a..d6fb38df 100644 --- a/source/glest_game/game/chat_manager.cpp +++ b/source/glest_game/game/chat_manager.cpp @@ -99,10 +99,12 @@ bool ChatManager::textInput(std::string inputText) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] inputText [%s]\n",__FILE__,__FUNCTION__,__LINE__,inputText.c_str()); int maxTextLenAllowed = (customCB != NULL ? this->maxCustomTextLength : maxTextLenght); - if(editEnabled && (int)textCharLength.size() < maxTextLenAllowed) { + int maxpaste=0; + maxpaste=maxTextLenAllowed-text.length(); + if(editEnabled && (int)text.length() < maxTextLenAllowed) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); textCharLength.push_back(inputText.length()); - this->text +=inputText; + this->text +=inputText.substr (0,maxpaste); updateAutoCompleteBuffer(); return true; } diff --git a/source/shared_lib/sources/platform/sdl/window.cpp b/source/shared_lib/sources/platform/sdl/window.cpp index 701d5bb9..ad5bc916 100644 --- a/source/shared_lib/sources/platform/sdl/window.cpp +++ b/source/shared_lib/sources/platform/sdl/window.cpp @@ -341,6 +341,27 @@ bool Window::handleEvent() { if(global_window) { keyDownConsumed=global_window->eventSdlKeyDown(event.key); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + + switch (event.key.keysym.sym) { + case SDLK_v: + if (event.key.keysym.mod & KMOD_CTRL) { + /* Ctrl-V, paste form clipbord */ + char *text = SDL_GetClipboardText(); + if (*text) { + printf("Clipboard text: %s\n", text); + if(global_window->eventTextInput(text) == true) { + keyDownConsumed=true; + } + } else { + printf("Clipboard text is empty\n"); + } + SDL_free(text); + } + break; + default: + break; + } + } // Stop unprintable characters (ctrl+, alt+ and escape),