1 2 /*************************************************************************** 3 textfield.h - Single-line text input widget 4 ------------------- 5 begin : Thu Aug 28 2003 6 copyright : (C) 2003 by Gabor Torok 7 email : cctorok@yahoo.com 8 ***************************************************************************/ 9 10 /*************************************************************************** 11 * * 12 * This program is free software; you can redistribute it and/or modify * 13 * it under the terms of the GNU General Public License as published by * 14 * the Free Software Foundation; either version 2 of the License, or * 15 * (at your option) any later version. * 16 * * 17 ***************************************************************************/ 18 19 #ifndef TEXTFIELD_H 20 #define TEXTFIELD_H 21 #pragma once 22 23 #include "gui.h" 24 #include "widget.h" 25 #include "window.h" 26 #include "label.h" 27 28 /** 29 *@author Gabor Torok 30 */ 31 32 /// A single-line text input widget. 33 class TextField : public Widget { 34 private: 35 int numChars; 36 bool inside; // was the last event inside the button? 37 char *text; 38 int pos, maxPos; 39 int eventType; 40 41 public: 42 43 enum { 44 EVENT_KEYPRESS = 0, 45 EVENT_ACTION 46 }; 47 48 TextField( int x, int y, int numChars ); 49 ~TextField(); 50 bool handleEvent( Widget *parent, SDL_Event *event, int x, int y ); 51 void drawWidget( Widget *parent ); getText()52 inline char *getText() { 53 text[maxPos] = '\0'; return text; 54 } 55 void setText( const char *p ); setFocus(bool b)56 inline void setFocus( bool b ) { 57 Widget::setFocus( b ); inside = b; 58 } clearText()59 inline void clearText() { 60 pos = maxPos = 0; 61 } getEventType()62 inline int getEventType() { 63 return eventType; 64 } 65 // don't play sound when the value changes hasSound()66 virtual inline bool hasSound() { 67 return false; 68 } 69 }; 70 71 #endif 72 73