r130 - trunk/src
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Wed Aug 31 20:01:51 EDT 2005
Author: jonas
Date: 2005-08-31 20:01:51 -0400 (Wed, 31 Aug 2005)
New Revision: 130
Modified:
trunk/src/common.h
trunk/src/editor.cpp
trunk/src/editor.h
trunk/src/input.cpp
Log:
fixed Editor::update() to always perform an update, added TextInputBox to read text input...
Modified: trunk/src/common.h
===================================================================
--- trunk/src/common.h 2005-08-31 20:41:43 UTC (rev 129)
+++ trunk/src/common.h 2005-09-01 00:01:51 UTC (rev 130)
@@ -68,6 +68,7 @@
#define GAME_MENU 0x00000004
#define GAME_EDIT 0x00000008
#define GAME_EDIT_NOANIM 0x00000010
+#define GAME_TEXT_INPUT 0x00000020
enum ConfigKey {
KEY_START,
Modified: trunk/src/editor.cpp
===================================================================
--- trunk/src/editor.cpp 2005-08-31 20:41:43 UTC (rev 129)
+++ trunk/src/editor.cpp 2005-09-01 00:01:51 UTC (rev 130)
@@ -137,44 +137,44 @@
void Box::update() {
gfxeng->update(UPDATE_ALL);
- if (surface==NULL) {
- getArea();
- SDL_Surface* tmp=SDL_CreateRGBSurface(vflags, area.w, area.h, 32, rmask, gmask, bmask, amask);
- surface=SDL_DisplayFormatAlpha(tmp);
- SDL_FreeSurface(tmp);
- SDL_FillRect(surface,0,SDL_MapRGBA(surface->format,200,200,200,180));
+ getArea();
- /* create a border */
- Sint16 tmph=0;
- SDL_Rect line;
- line.x=0;
- line.y=0;
- line.w=BORDERSIZE;
- line.h=area.h;
- SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255));
- line.x=area.w-BORDERSIZE;
- SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255));
- line.x=0;
- line.y=0;
- line.w=area.w;
- line.h=BORDERSIZE;
- SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255));
- line.y=area.h-BORDERSIZE;
- SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255));
+ if (surface!=NULL) SDL_FreeSurface(surface);
+ SDL_Surface* tmp=SDL_CreateRGBSurface(vflags, area.w, area.h, 32, rmask, gmask, bmask, amask);
+ surface=SDL_DisplayFormatAlpha(tmp);
+ SDL_FreeSurface(tmp);
- /* write title */
- font_title->writeCenter(surface,title,WFONT);
- line.y=font_title->getHeight()+(int)((DFONT-line.h)/2);
- SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255));
- line.h=LINESIZE;
+ SDL_FillRect(surface,0,SDL_MapRGBA(surface->format,200,200,200,180));
+ /* create a border */
+ Sint16 tmph=0;
+ SDL_Rect line;
+ line.x=0;
+ line.y=0;
+ line.w=BORDERSIZE;
+ line.h=area.h;
+ SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255));
+ line.x=area.w-BORDERSIZE;
+ SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255));
+ line.x=0;
+ line.y=0;
+ line.w=area.w;
+ line.h=BORDERSIZE;
+ SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255));
+ line.y=area.h-BORDERSIZE;
+ SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255));
- /* write entries */
- for (Uint8 i=0; i<entries.size(); i++) {
- tmph=DFONT*(i+1)+font->getHeight()*i+WFONT+font_title->getHeight();
- font->writeCenter(surface,entries[i],tmph);
- line.y=tmph+font->getHeight()+(int)((DFONT-line.h)/2);
- SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,180));
- }
+ /* write title */
+ font_title->writeCenter(surface,title,WFONT);
+ line.y=font_title->getHeight()+(int)((DFONT-line.h)/2);
+ SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255));
+ line.h=LINESIZE;
+
+ /* write entries */
+ for (Uint8 i=0; i<entries.size(); i++) {
+ tmph=DFONT*(i+1)+font->getHeight()*i+WFONT+font_title->getHeight();
+ font->writeCenter(surface,entries[i],tmph);
+ line.y=tmph+font->getHeight()+(int)((DFONT-line.h)/2);
+ SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,180));
}
}
@@ -257,3 +257,38 @@
editor->closeBox();
}
}
+
+TextInputBox::TextInputBox(Sint16 x,Sint16 y): Box(x,y),
+ currententry(-1) {
+ SDL_EnableUNICODE(1);
+ SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL);
+ addGameMode(GAME_TEXT_INPUT);
+}
+TextInputBox::~TextInputBox() {
+ SDL_EnableUNICODE(0);
+ SDL_EnableKeyRepeat(0,SDL_DEFAULT_REPEAT_INTERVAL);
+ removeGameMode(GAME_TEXT_INPUT);
+ editor->run_action(EDIT_RESET_ACTIONS);
+}
+
+void TextInputBox::act(Sint8 button) {
+ if (button>=0 && (Uint8)button<entries.size()) currententry=button;
+}
+void TextInputBox::input(Uint16 akey) {
+ if (currententry==-1) {
+ } else if (akey==(Uint16)config.keybind[KEY_ACT]) {
+ editor->closeBox();
+ // Backspace
+ } else if (akey==8) {
+ if ( entries[currententry].begin() != entries[currententry].end() ) {
+ entries[currententry].erase(entries[currententry].end()-1);
+ gfxeng->update(UPDATE_ALL);
+ update();
+ }
+ } else if ((Uint16)akey<32 || (Uint16)akey>126) {
+ } else {
+ entries[currententry]+=(char)akey;
+ gfxeng->update(UPDATE_ALL);
+ update();
+ }
+}
Modified: trunk/src/editor.h
===================================================================
--- trunk/src/editor.h 2005-08-31 20:41:43 UTC (rev 129)
+++ trunk/src/editor.h 2005-09-01 00:01:51 UTC (rev 130)
@@ -15,10 +15,11 @@
public:
Box(Sint16,Sint16);
virtual ~Box();
- /// Name of the menu
+ /// Name of the box
string title;
- /// Main menu function, depends on currententry (changed by input), overload this.
+ /// Activate specified entry, if no entry is selected this is -1
virtual void act(Sint8) = 0;
+ virtual void input(Uint16) { }
Uint8 getSize() {
return entries.size();
}
@@ -47,6 +48,17 @@
virtual void act(Sint8);
};
+class TextInputBox : public Box {
+ public:
+ TextInputBox(Sint16,Sint16);
+ virtual ~TextInputBox();
+ virtual void act(Sint8);
+ virtual void input(Uint16);
+ protected:
+ Sint8 currententry;
+};
+
+
/** \brief Handels editor specific tasks
*/
Modified: trunk/src/input.cpp
===================================================================
--- trunk/src/input.cpp 2005-08-31 20:41:43 UTC (rev 129)
+++ trunk/src/input.cpp 2005-09-01 00:01:51 UTC (rev 130)
@@ -203,21 +203,26 @@
case SDL_KEYDOWN: {
SDLKey key=event.key.keysym.sym;
keypressed[key]=true;
- if (key==config.keybind[KEY_FULL]) {
- gfxeng->toggleFullScreen();
- } else if (key==config.keybind[KEY_MENU]) {
- sfxeng->pauseMusic();
- setMenu(new EditMenu());
- gfxeng->update(UPDATE_ALL);
- } else if (key==config.keybind[KEY_QUIT]) {
- quitGame(0);
- } else if (key==config.keybind[KEY_NOANIM]) {
- gfxeng->update(UPDATE_ALL);
- if (game_mode&GAME_EDIT_NOANIM) {
- removeGameMode(GAME_EDIT_NOANIM);
- } else {
- scenario->reloadMap();
- addGameMode(GAME_EDIT_NOANIM);
+ if (game_mode&GAME_TEXT_INPUT) {
+ Uint16 unikey=event.key.keysym.unicode;
+ if (unikey<127) editor->box->input(unikey);
+ } else {
+ if (key==config.keybind[KEY_FULL]) {
+ gfxeng->toggleFullScreen();
+ } else if (key==config.keybind[KEY_MENU]) {
+ sfxeng->pauseMusic();
+ setMenu(new EditMenu());
+ gfxeng->update(UPDATE_ALL);
+ } else if (key==config.keybind[KEY_QUIT]) {
+ quitGame(0);
+ } else if (key==config.keybind[KEY_NOANIM]) {
+ gfxeng->update(UPDATE_ALL);
+ if (game_mode&GAME_EDIT_NOANIM) {
+ removeGameMode(GAME_EDIT_NOANIM);
+ } else {
+ scenario->reloadMap();
+ addGameMode(GAME_EDIT_NOANIM);
+ }
}
}
break;
More information about the lostpenguins-commits
mailing list