From 7386e93e32575bae21006d0300cbff4cf7a40926 Mon Sep 17 00:00:00 2001 From: oroborus Date: Tue, 8 Jul 2008 16:35:02 +0000 Subject: - oprava chyby v configFile.h - chat sa zapina/vypina ENTERom - prepisany readKey() - widget_textfiled obsahuje filter na znaky :) - lasser je netrhany ale prestreluje pen v arene "na dobru noc", ked sa uplne priblizite git-svn-id: http://opensvn.csie.org/tuxanci_ng@124 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e --- config.h | 2 +- data/image/lasserX.png | Bin 167 -> 92 bytes data/image/lasserY.png | Bin 163 -> 92 bytes src/base/arena.c | 4 +- src/base/gun.c | 27 ++----- src/base/gun.h | 2 +- src/base/item.c | 35 +++------ src/base/item.h | 1 - src/base/main.h | 1 + src/client/chat.c | 151 +++++++++++++++---------------------- src/client/chat.h | 2 + src/screen/screen_gameType.c | 17 ++++- src/screen/screen_setting.c | 44 ++++++----- src/screen/screen_setting.h | 4 +- src/screen/screen_world.c | 4 +- src/widget/widget_textfield.c | 168 ++++++++++++++++++++++++++++++++++++++++-- src/widget/widget_textfield.h | 9 ++- 17 files changed, 293 insertions(+), 178 deletions(-) diff --git a/config.h b/config.h index cc0be28..588c690 100644 --- a/config.h +++ b/config.h @@ -1 +1 @@ -#define TUXANCI_NG_VERSION "svn123" +#define TUXANCI_NG_VERSION "svn124" diff --git a/data/image/lasserX.png b/data/image/lasserX.png index 191af4d..a9be26a 100644 Binary files a/data/image/lasserX.png and b/data/image/lasserX.png differ diff --git a/data/image/lasserY.png b/data/image/lasserY.png index b64a346..cff390f 100644 Binary files a/data/image/lasserY.png and b/data/image/lasserY.png differ diff --git a/src/base/arena.c b/src/base/arena.c index 7358e41..2fe18b7 100644 --- a/src/base/arena.c +++ b/src/base/arena.c @@ -204,10 +204,12 @@ void eventArena(arena_t *arena) for( i = 0 ; i < 8 ; i++) { checkShotIsInTuxScreen(arena); - eventMoveListShot(arena); + eventConflictShotWithItem(arena); eventConflictTuxWithShot(arena); eventModule(); + + eventMoveListShot(arena); } eventListItem(arena->spaceItem); diff --git a/src/base/gun.c b/src/base/gun.c index f905efd..aeb2478 100644 --- a/src/base/gun.c +++ b/src/base/gun.c @@ -85,31 +85,13 @@ static void addShotTrivial(tux_t *tux, int x, int y, int px, int py, int gun) shot = newShot(tux->x + dest_x, tux->y + dest_y, dest_px, dest_py, gun, tux->id); -/* - if( isFreeSpace( getCurrentArena(), shot->x, shot->y, shot->w, shot->h ) == 0 ) + if(1)// isFreeSpace(getCurrentArena(), shot->x, shot->y, shot->w, shot->h) ) { - destroyShot(shot); + addObjectToSpace(getCurrentArena()->spaceShot, shot); return; } -*/ - //addList( getCurrentArena()->listShot, shot ); - addObjectToSpace(getCurrentArena()->spaceShot, shot); -/* - if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) - { - client_t *thisClient; - - thisClient = getClientFromTux(tux); - - if( thisClient != NULL ) - { - proto_send_shot_server(PROTO_SEND_ONE, thisClient, shot); - } - - proto_send_shot_server(PROTO_SEND_ALL_SEES_TUX, thisClient, shot); - } -*/ + destroyShot(shot); } static void addShot(tux_t *tux,int x, int y, int px, int py) @@ -232,7 +214,10 @@ static void timer_addLaserTimer(void *p) gun = tux->gun; tux->gun = GUN_LASSER; + addShot(tux, 0, 0, +10, 0); + addShot(tux, +40, 0, +10, 0); + //addShot(tux, +40, 0, +10, 0); tux->gun = gun; } diff --git a/src/base/gun.h b/src/base/gun.h index 4986660..835c2c8 100644 --- a/src/base/gun.h +++ b/src/base/gun.h @@ -8,7 +8,7 @@ #define GUN_SHOT_WIDTH 5 #define GUN_SHOT_HEIGHT 5 -#define GUN_LASSER_HORIZONTAL 50 +#define GUN_LASSER_HORIZONTAL 40 #define GUN_SHOT_VERTICAL 5 #define GUN_BOMBBALL_WIDTH 20 diff --git a/src/base/item.c b/src/base/item.c index 7f12ce7..842da13 100644 --- a/src/base/item.c +++ b/src/base/item.c @@ -133,29 +133,6 @@ item_t* newItem(int x, int y, int type, int author_id) return new; } -/* -item_t* getItemID(list_t *listItem, int id) -{ - item_t *thisItem; - int i; - - assert( listItem != NULL ); - - for( i = 0 ; i < listItem->count ; i++ ) - { - thisItem = (item_t *)listItem->list[i]; - assert( thisItem != NULL ); - - if( thisItem->id == id ) - { - return thisItem; - } - } - - return NULL; -} -*/ - void getStatusItem(void *p, int *id, int *x, int *y ,int *w, int *h) { item_t *item; @@ -353,7 +330,7 @@ void eventListItem(space_t *spaceItem) } } -void mineExplosion(space_t *spaceItem, item_t *item) +static void mineExplosion(space_t *spaceItem, item_t *item) { if( getNetTypeGame() != NET_GAME_TYPE_CLIENT ) { @@ -378,7 +355,10 @@ void mineExplosion(space_t *spaceItem, item_t *item) proto_send_del_server(PROTO_SEND_ALL, NULL, item->id); } - delObjectFromSpaceWithObject(spaceItem, item, destroyItem); + if( getNetTypeGame() != NET_GAME_TYPE_CLIENT ) + { + delObjectFromSpaceWithObject(spaceItem, item, destroyItem); + } } void eventConflictShotWithItem(arena_t *arena) @@ -547,7 +527,10 @@ void eventGiveTuxItem(tux_t *tux, item_t *item, space_t *spaceItem) case ITEM_EXPLOSION : case ITEM_BIG_EXPLOSION : - eventTuxIsDeadWithItem(tux, item); + if( tux->bonus != BONUS_GHOST ) + { + eventTuxIsDeadWithItem(tux, item); + } break; case BONUS_SPEED : diff --git a/src/base/item.h b/src/base/item.h index c23e7d7..110c044 100644 --- a/src/base/item.h +++ b/src/base/item.h @@ -68,7 +68,6 @@ extern void addNewItem(space_t *spaceItem, int author_id); extern void drawListItem(list_t *listItem); #endif extern void eventListItem(space_t *listSpace); -extern void mineExplosion(space_t *spaceItem, item_t *item); extern void eventConflictShotWithItem(arena_t *arena); extern void eventGiveTuxItem(tux_t *tux, item_t *item, space_t *spaceItem); extern void eventGiveTuxListItem(tux_t *tux, space_t *spaceItem); diff --git a/src/base/main.h b/src/base/main.h index b8f988b..d0b11e6 100644 --- a/src/base/main.h +++ b/src/base/main.h @@ -23,5 +23,6 @@ extern bool_t isParamFlag(char *s); extern char *getString(int n); extern int* newInt(int x); extern void accessExistFile(const char *s); +extern int tryExistFile (const char *s); #endif diff --git a/src/client/chat.c b/src/client/chat.c index 7d425dd..b599853 100644 --- a/src/client/chat.c +++ b/src/client/chat.c @@ -26,6 +26,8 @@ static int timeBlick; static bool_t chat_active; static bool_t revicedNewMsg; +static my_time_t lastActive; + void initChat() { g_chat = addImageData("chat.png", IMAGE_NO_ALPHA, "chat", IMAGE_GROUP_USER); @@ -37,6 +39,7 @@ void initChat() line_time = 0; line_atime = 0; timeBlick = 0; + lastActive = 0; } void drawChat() @@ -84,8 +87,8 @@ void drawChat() static void readKey() { Uint8 *mapa; - int len; int w, h; + int len; int i; if (line_atime < 100) @@ -93,134 +96,96 @@ static void readKey() mapa = SDL_GetKeyState(NULL); len = strlen(line); - getTextSize(line, &w, &h); - - // mazanie posledneho klavesu - if( mapa[SDLK_BACKSPACE] == SDL_PRESSED ) + + for( i = SDLK_FIRST ; i <= SDLK_F15 ; i++ ) { - if( len > 0 ) + if( mapa[i] == SDL_PRESSED && len < STR_SIZE ) { - line_time = 0; - line[len-1]='\0'; - } + char *name = (char *) SDL_GetKeyName(i); + char c = '\0'; - return; - } + if( name == NULL )continue; - if( w > CHAT_LINE_WIDTH-40 ) - { - return; - } + if( strlen(name) == 1 )c = name[0]; + if( strlen(name) == 3 )c = name[1]; + if( strcmp(name, "space") == 0 )c = ' '; - // klavesy abecedy - for(i=SDLK_SPACE /*SDLK_a*/;i<=SDLK_z;i++) - { - //if(width 0 ) { - strcat( line, " " ); + line_time = 0; + line[len-1]='\0'; return; } - const char *c = (const char *) SDL_GetKeyName(i); + if( c == '\0' || w > CHAT_SIZE_X-40 ) + { + continue; + } - if (len) { - if (line[len-1] == *c) { - line_time ++; + if( len > 0 ) + { + if( line[len-1] == c ) + { + line_time++; - if ( line_time < CHAT_TIME_MULTIPLE) { - if ( line_atime < 3) - return; + if( line_time < CHAT_TIME_MULTIPLE ) + { + if( line_atime < 3 )return; } - } else + } + else + { line_time = 0; + } } line_atime = 0; - strcat( line, c ); - getTextSize(line, &w, &h); - + line[len] = c; + if( mapa[SDLK_LSHIFT] == SDL_PRESSED || mapa[SDLK_RSHIFT] == SDL_PRESSED) { - line[ strlen( line ) - 1 ] -= 32; - return; + line[len] -= 32; } + + return; } } +} - // aby ve jmene bulanka fungovaly take cislice alfanumericke klavesnice - for( i = SDLK_0 ; i <= SDLK_9 ; i++ ) +static void switchChatActive() +{ + if( chat_active == TRUE ) { - if( mapa[i] == SDL_PRESSED && len < STR_SIZE ) - { - const char *c = (const char *) SDL_GetKeyName(i); - - if (len) { - if (line[len-1] == *c) { - line_time ++; - - if (line_time < CHAT_TIME_MULTIPLE) { - if (line_atime < 3) - return; - } - } else - line_time = 0; - } - - line_atime = 0; - - strcat( line, c ); - return; - } + chat_active = FALSE; } - - // aby ve jmene bulanka fungovaly take cislice napsane na numericke klavesnici - for( i=SDLK_KP0 ; i<=SDLK_KP9 ; i++ ) + else { - if( mapa[i] == SDL_PRESSED && len < STR_SIZE ) - { - const char *c = (const char *) SDL_GetKeyName(i)+1; - - if (len) { - if (line[len-1] == *c) { - line_time ++; - - if (line_time < CHAT_TIME_MULTIPLE) { - if (line_atime < 3) - return; - } - } else - line_time = 0; - } - - line_atime = 0; - - strncat( line, c, 1 ); // napr. "[4]" - return; - } + chat_active = TRUE; } } void eventChat() { Uint8 *mapa; - - mapa = SDL_GetKeyState(NULL); + my_time_t currentTime; - if( mapa[SDLK_RETURN] == SDL_PRESSED && chat_active == FALSE ) + mapa = SDL_GetKeyState(NULL); + currentTime = getMyTime(); + + if( mapa[SDLK_RETURN] == SDL_PRESSED && + strcmp(line, "") == 0 && + currentTime - lastActive > CHAT_LAST_ENTER_INTERVAL ) { + lastActive = getMyTime(); revicedNewMsg = FALSE; - chat_active = TRUE; - } - - if( mapa[SDLK_ESCAPE] == SDL_PRESSED && chat_active == TRUE ) - { - chat_active = FALSE; + switchChatActive(); + memset(line, '\0', STR_SIZE); + return; } if( chat_active == FALSE ) @@ -245,7 +210,7 @@ void eventChat() proto_send_chat_server(PROTO_SEND_ALL, NULL, out); } - strcpy(line, ""); + memset(line, '\0', STR_SIZE); return; } diff --git a/src/client/chat.h b/src/client/chat.h index fc6abc3..f2e1770 100644 --- a/src/client/chat.h +++ b/src/client/chat.h @@ -14,6 +14,8 @@ #define CHAT_LOCATION_X (WINDOW_SIZE_X/2 - CHAT_SIZE_X/2) #define CHAT_LOCATION_Y (WINDOW_SIZE_Y/2 - CHAT_SIZE_Y/2) +#define CHAT_LAST_ENTER_INTERVAL 50 + extern void initChat(); extern void drawChat(); extern void eventChat(); diff --git a/src/screen/screen_gameType.c b/src/screen/screen_gameType.c index e512b28..fb971db 100644 --- a/src/screen/screen_gameType.c +++ b/src/screen/screen_gameType.c @@ -73,11 +73,13 @@ void drawScreenGameType() drawWidgetTextfield(textfield_ip); } +#if 0 if( check_server->status == TRUE ) { setSettingIP (getParamElse ("--ip", "127.0.0.1")); setSettingPort (atoi (getParamElse("--port", "2200"))); } +#endif if( check_client->status == TRUE ) drawWidgetButton(button_browser); @@ -102,7 +104,9 @@ void eventScreenGameType() eventWidgetButton(button_back); eventWidgetButton(button_play); - eventWidgetButton(button_browser); + + if( check_client->status == TRUE ) + eventWidgetButton(button_browser); } void stopScreenGameType() @@ -199,8 +203,15 @@ void initScreenGameType() label_ip = newWidgetLabel(getMyText("IP_ADDR"), 300, 145, WIDGET_LABEL_LEFT); label_port = newWidgetLabel(getMyText("NET_PORT"), 300, 245, WIDGET_LABEL_LEFT); - textfield_ip = newWidgetTextfield(getParamElse("--ip", "127.0.0.1"), 300, 180); - textfield_port = newWidgetTextfield(getParamElse("--port", "2200"), 300, 280); + textfield_ip = newWidgetTextfield( + getParamElse("--ip", "127.0.0.1"), + WIDGET_TEXTFIELD_FILTER_IP_OR_DOMAIN, + 300, 180); + + textfield_port = newWidgetTextfield( + getParamElse("--port", "2200"), + WIDGET_TEXTFIELD_FILTER_NUM, + 300, 280); registerScreen( newScreen("gameType", startScreenGameType, eventScreenGameType, drawScreenGameType, stopScreenGameType) ); diff --git a/src/screen/screen_setting.c b/src/screen/screen_setting.c index d853265..876c464 100644 --- a/src/screen/screen_setting.c +++ b/src/screen/screen_setting.c @@ -141,16 +141,7 @@ void drawScreenSetting() void eventScreenSetting() { int i; -/* - int x, y; - getMousePosition(&x, &y); - - if( isMouseClicked() ) - { - printf("x = %d y = %d\n", x, y); - } -*/ eventWidgetTextfield(textfield_count_cound); eventWidgetTextfield(textfield_name_player1); @@ -233,11 +224,13 @@ static void initSettingFile() } loadValueFromConfigFile(configFile, "COUNT_ROUND", val, STR_SIZE, "15"); - strcpy(textfield_count_cound->text, val); - loadValueFromConfigFile(configFile, "NAME_PLAYER_RIGHT", val, STR_SIZE, "TUX Warrior #01"); - strcpy(textfield_name_player1->text, val); - loadValueFromConfigFile(configFile, "NAME_PLAYER_LEFT", val, STR_SIZE, "TUX Warrior #02"); - strcpy(textfield_name_player2->text, val); + setWidgetTextFiledText(textfield_count_cound, val); + + loadValueFromConfigFile(configFile, "NAME_PLAYER_RIGHT", val, STR_SIZE, NAME_PLAYER_RIGHT); + setWidgetTextFiledText(textfield_name_player1, val); + + loadValueFromConfigFile(configFile, "NAME_PLAYER_LEFT", val, STR_SIZE, NAME_PLAYER_LEFT); + setWidgetTextFiledText(textfield_name_player2, val); loadValueFromConfigFile(configFile, "GUN_DUAL_SIMPLE", val, STR_SIZE, "YES"); check[GUN_DUAL_SIMPLE]->status = isYesOrNO(val); @@ -281,8 +274,6 @@ static void initSettingFile() static void saveAndDestroyConfigFile() { - char val[STR_SIZE], name2[STR_SIZE]; - if( configFile == NULL ) { fprintf(stderr, "i can't save configure, " @@ -349,10 +340,23 @@ void initScreenSetting() label_name_player1 = newWidgetLabel(getMyText("NAME_PLAYER1"), 100, WINDOW_SIZE_Y-160, WIDGET_LABEL_LEFT); label_name_player2 = newWidgetLabel(getMyText("NAME_PLAYER2"), 100, WINDOW_SIZE_Y-120, WIDGET_LABEL_LEFT); - textfield_count_cound = newWidgetTextfield(getParamElse("--count", "15"), 110+label_count_round->w, WINDOW_SIZE_Y-200); + textfield_count_cound = newWidgetTextfield( + getParamElse("--count", "15"), + WIDGET_TEXTFIELD_FILTER_NUM, + 110+label_count_round->w, + WINDOW_SIZE_Y-200); - textfield_name_player1 = newWidgetTextfield(getParamElse("--name1", NAME_PLAYER_RIGHT), 110+label_name_player1->w, WINDOW_SIZE_Y-160); - textfield_name_player2 = newWidgetTextfield(getParamElse("--name2", NAME_PLAYER_LEFT), 110+label_name_player2->w, WINDOW_SIZE_Y-120); + textfield_name_player1 = newWidgetTextfield( + getParamElse("--name1", NAME_PLAYER_RIGHT), + WIDGET_TEXTFIELD_FILTER_ALPHANUM, + 110+label_name_player1->w, + WINDOW_SIZE_Y-160); + + textfield_name_player2 = newWidgetTextfield( + getParamElse("--name2", NAME_PLAYER_LEFT), + WIDGET_TEXTFIELD_FILTER_ALPHANUM, + 110+label_name_player2->w, + WINDOW_SIZE_Y-120); for( i = GUN_DUAL_SIMPLE ; i <= GUN_BOMBBALL ; i++ ) { @@ -458,7 +462,7 @@ bool_t isSettingAnyItem() } } - for( i = BONUS_SPEED ; i <= BONUS_HIDDEN ; i++ ) + for( i = BONUS_SPEED ; i < BONUS_HIDDEN ; i++ ) { if( check[i]->status == TRUE ) { diff --git a/src/screen/screen_setting.h b/src/screen/screen_setting.h index d80a7a5..2dfb897 100644 --- a/src/screen/screen_setting.h +++ b/src/screen/screen_setting.h @@ -6,8 +6,8 @@ #include "main.h" #define NAME_AI "tuxAI" -#define NAME_PLAYER_RIGHT "TUX Warrior #01" -#define NAME_PLAYER_LEFT "TUX Warrior #02" +#define NAME_PLAYER_RIGHT "name1" +#define NAME_PLAYER_LEFT "name2" extern void initScreenSetting(); extern void drawScreenSetting(); diff --git a/src/screen/screen_world.c b/src/screen/screen_world.c index f5556c9..030c690 100644 --- a/src/screen/screen_world.c +++ b/src/screen/screen_world.c @@ -365,7 +365,7 @@ static void eventEsc() Uint8 *mapa; mapa = SDL_GetKeyState(NULL); - if( mapa[(SDLKey)SDLK_ESCAPE] == SDL_PRESSED && isChatActive() == FALSE ) + if( mapa[(SDLKey)SDLK_ESCAPE] == SDL_PRESSED ) { setWorldEnd(); return; @@ -471,7 +471,7 @@ void eventWorld() addToRadar(thisTux->id, thisTux->x, thisTux->y, - RADAR_TYPE_YOU); + RADAR_TYPE_TUX); } eventTerm(); diff --git a/src/widget/widget_textfield.c b/src/widget/widget_textfield.c index 6b9a6c0..3ea7900 100644 --- a/src/widget/widget_textfield.c +++ b/src/widget/widget_textfield.c @@ -6,7 +6,7 @@ #include "image.h" #include "widget_textfield.h" -widget_textfield_t* newWidgetTextfield(char *text, int x, int y) +widget_textfield_t* newWidgetTextfield(char *text, int filter, int x, int y) { widget_textfield_t *new; @@ -18,6 +18,7 @@ widget_textfield_t* newWidgetTextfield(char *text, int x, int y) new->timeBlick = 0; new->atime = 0; new->active = FALSE; + new->filter = filter; getTextSize(text, &new->w, &new->h); return new; @@ -82,12 +83,86 @@ void drawWidgetTextfield(widget_textfield_t *p) drawText(p); } +void setWidgetTextFiledText(widget_textfield_t *p, char *text) +{ + strcpy(p->text, text); + getTextSize(text, &p->w, &p->h); +} + +static void checkText(widget_textfield_t *p) +{ + int len; + int i; + + //printf("check\n"); + + len = strlen(p->text); + + for( i = 0 ; i < len ; i++ ) + { + char c; + bool_t isDel; + + c = p->text[i]; + isDel = TRUE; + + switch( p->filter ) + { + case WIDGET_TEXTFIELD_FILTER_ALL : + isDel = FALSE; + break; + + case WIDGET_TEXTFIELD_FILTER_NUM : + if( c >= '0' && c <= '9' ) + { + isDel = FALSE; + } + break; + + case WIDGET_TEXTFIELD_FILTER_ALPHANUM : + if( ( c >= '0' && c <= '9' ) || + ( c >= 'a' && c <= 'z' ) || + ( c >= 'A' && c <= 'Z' ) || + c == '-' ) + { + isDel = FALSE; + } + break; + + case WIDGET_TEXTFIELD_FILTER_IP_OR_DOMAIN : + if( ( c >= '0' && c <= '9' ) || + ( c == '.' || c == ':' || c == '-' ) ) + { + isDel = FALSE; + } + break; + + default : + assert( ! "bad filter" ); + break; + } + + if( isDel ) + { + memmove(p->text+i, p->text+i+1, len - i ); + len = strlen(p->text); + i--; + } + } + + getTextSize(p->text, &p->w, &p->h); + +} + +#if 0 static void readKey(widget_textfield_t *p) { Uint8 *mapa; int len; int i; + //printf("readKey w=%d\n", p->w); + if( p->active == FALSE ) { return; @@ -126,7 +201,7 @@ static void readKey(widget_textfield_t *p) if (i == SDLK_SPACE) { strcat( p->text, " " ); - getTextSize(p->text, &p->w, &p->h); + checkText(p); return; } @@ -147,13 +222,13 @@ static void readKey(widget_textfield_t *p) p->atime = 0; strcat( p->text, c ); - getTextSize(p->text, &p->w, &p->h); + checkText(p); if( mapa[SDLK_LSHIFT] == SDL_PRESSED || mapa[SDLK_RSHIFT] == SDL_PRESSED) { p->text[ strlen( p->text ) - 1 ] -= 32; - getTextSize(p->text, &p->w, &p->h); + checkText(p); return; } } @@ -181,7 +256,7 @@ static void readKey(widget_textfield_t *p) p->atime = 0; strcat( p->text, c ); - getTextSize(p->text, &p->w, &p->h); + checkText(p); return; } } @@ -208,11 +283,92 @@ static void readKey(widget_textfield_t *p) p->atime = 0; strncat( p->text, c, 1 ); // napr. "[4]" - getTextSize(p->text, &p->w, &p->h); + checkText(p); + return; + } + } +} +#endif + +#if 1 +static void readKey(widget_textfield_t *p) +{ + Uint8 *mapa; + int len; + int i; + + if( p->active == FALSE ) + { + return; + } + + if (p->atime < 100) + p->atime ++; + + mapa = SDL_GetKeyState(NULL); + len = strlen(p->text); + + for( i = SDLK_FIRST ; i <= SDLK_F15 ; i++ ) + { + if( mapa[i] == SDL_PRESSED && len < STR_SIZE ) + { + char *name = (char *) SDL_GetKeyName(i); + char c = '\0'; + + if( name == NULL )continue; + + if( strlen(name) == 1 )c = name[0]; + if( strlen(name) == 3 )c = name[1]; + if( strcmp(name, "space") == 0 )c = ' '; + + //printf("name %s\n", name); + + if( strcmp(name, "backspace") == 0 && len > 0 ) + { + p->time = 0; + p->text[len-1]='\0'; + checkText(p); + return; + } + + if( c == '\0' || p->w > WIDGET_TEXTFIELD_WIDTH-40 ) + { + continue; + } + + if( len > 0 ) + { + if( p->text[len-1] == c ) + { + p->time++; + + if( p->time < WIDGET_TEXTFIELD_TIME_MULTIPLE ) + { + if( p->atime < 3 )return; + } + } + else + { + p->time = 0; + } + } + + p->atime = 0; + + p->text[len] = c; + + if( mapa[SDLK_LSHIFT] == SDL_PRESSED || + mapa[SDLK_RSHIFT] == SDL_PRESSED) + { + p->text[len] -= 32; + } + + checkText(p); return; } } } +#endif void eventWidgetTextfield(widget_textfield_t *p) { diff --git a/src/widget/widget_textfield.h b/src/widget/widget_textfield.h index fc41826..0de3c96 100644 --- a/src/widget/widget_textfield.h +++ b/src/widget/widget_textfield.h @@ -14,6 +14,11 @@ #define WIDGET_TEXTFIELD_TIME_READ_KEY 2 #define WIDGET_TEXTFIELD_TIME_BLICK_CURSOR 20 +#define WIDGET_TEXTFIELD_FILTER_ALL 0 +#define WIDGET_TEXTFIELD_FILTER_NUM 2 +#define WIDGET_TEXTFIELD_FILTER_ALPHANUM 3 +#define WIDGET_TEXTFIELD_FILTER_IP_OR_DOMAIN 4 + typedef struct widget_textfield { int x, y; @@ -22,11 +27,13 @@ typedef struct widget_textfield int timeBlick; int time; int atime; + int filter; char text[STR_SIZE]; bool_t active; } widget_textfield_t; -extern widget_textfield_t* newWidgetTextfield(char *text, int x, int y); +extern widget_textfield_t* newWidgetTextfield(char *text, int filter, int x, int y); +extern void setWidgetTextFiledText(widget_textfield_t *p, char *text); extern void drawWidgetTextfield(widget_textfield_t *p); extern void eventWidgetTextfield(widget_textfield_t *p); extern void destroyWidgetTextfield(widget_textfield_t *p); -- cgit v1.2.3