/* ReadKeyboard.cpp Copyright (C) 2005 Poul Sander This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Poul Sander R�veh�jvej 36, V. 1111 2800 Kgs. Lyngby DENMARK blockattack@poulsander.com */ #include "ReadKeyboard.h" ReadKeyboard::ReadKeyboard(void) { length = 0; maxLength = 16; position = 0; strcpy(textstring," "); } ReadKeyboard::~ReadKeyboard(void) { } Uint8 ReadKeyboard::CharsBeforeCursor() { return position; } ReadKeyboard::ReadKeyboard(char *oldName) { length = 0; maxLength = 16; position = 0; strcpy(textstring," "); strcpy(textstring,oldName); char charecter = textstring[maxLength+1]; int i = maxLength+1; while ((charecter == ' ') && (i>0)) { i--; charecter = textstring[i]; } if (i>0)length = i+1; else if (charecter == ' ') length = 0; else length = 1; position = length; } void ReadKeyboard::putchar(char thing) { if (length < maxLength) { for (int i = 28; i>position;i--) { textstring[i]=textstring[i-1]; } textstring[position] = thing; length++; position++; } } void ReadKeyboard::removeChar() { for (int i = position;i<28;i++) { textstring[i]=textstring[i+1]; } textstring[28]=' '; if (length>0)length--; } bool ReadKeyboard::ReadKey(SDLKey keyPressed) { if (keyPressed == SDLK_SPACE) { ReadKeyboard::putchar(' '); return true; } if (keyPressed == SDLK_DELETE) { if ((length>0)&& (position0) { position--; ReadKeyboard::removeChar(); return true; } return false; } Uint8* keys; keys = SDL_GetKeyState(NULL); if (keyPressed == SDLK_HOME) { position=0; return true; } if (keyPressed == SDLK_END) { position=length; return true; } if ((keyPressed == SDLK_LEFT) && (position>0)) { position--; return true; } if ((keyPressed == SDLK_RIGHT) && (position