From 55d229c2b70ec3a1dc6c51974331271fa9f8d5b5 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 15 Jun 2008 16:11:03 +0100 Subject: [PATCH] Make shift key work in high score name input --- src/AnimatedImage.cpp | 1 - src/Input.cpp | 15 ++++++++++++++- src/Input.hpp | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/AnimatedImage.cpp b/src/AnimatedImage.cpp index f459aca..013e415 100644 --- a/src/AnimatedImage.cpp +++ b/src/AnimatedImage.cpp @@ -43,7 +43,6 @@ void AnimatedImage::Draw(int x, int y, double rotate, double scale, int width = Texture::GetWidth(); int height = Texture::GetHeight(); - //cout << width << endl; glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, GetGLTexture()); diff --git a/src/Input.cpp b/src/Input.cpp index 0fad804..9985e44 100644 --- a/src/Input.cpp +++ b/src/Input.cpp @@ -86,12 +86,24 @@ void Input::Update() if (textinput) { if ((e.key.keysym.sym >= SDLK_a && e.key.keysym.sym <= SDLK_z) || (e.key.keysym.sym == SDLK_SPACE)) { - text += (char)e.key.keysym.sym; + char ch = (char)e.key.keysym.sym; + text += shift ? toupper(ch) : ch; + } + else if (e.key.keysym.sym == SDLK_LSHIFT + || e.key.keysym.sym == SDLK_RSHIFT) { + shift = true; } else if (e.key.keysym.sym == SDLK_BACKSPACE && text.length() > 0) { text.erase(text.length() - 1, 1); } } + break; + + case SDL_KEYUP: + if (e.key.keysym.sym == SDLK_LSHIFT + || e.key.keysym.sym == SDLK_RSHIFT) { + shift = false; + } break; case SDL_JOYAXISMOTION: @@ -173,6 +185,7 @@ void Input::OpenCharBuffer(int max) { assert(!textinput); + shift = false; maxchar = max; text = ""; textinput = true; diff --git a/src/Input.hpp b/src/Input.hpp index b13761c..45e9c55 100644 --- a/src/Input.hpp +++ b/src/Input.hpp @@ -53,6 +53,7 @@ private: int ignore[NUM_KEYS]; // Timeout for keys being ignored int jignore[NUM_BUTTONS]; // Timeout for buttons being ignored + bool shift; bool textinput; // Is a character buffer open? string text; // Text read so far int maxchar; // Maximum number of characters to read -- 2.39.2