diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-07-27 20:19:48 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-07-27 20:19:48 +0000 |
| commit | af204026313ece9a12ec89f59adf554e0639783b (patch) | |
| tree | 0fe1df635e39fa85c78cb0cdc92fc85c3f564d7c | |
| parent | 90ef234fb0602d80ed5416ab0492511b83ac6df5 (diff) | |
- novy vydget catchkey
- vo widget_textfield.c boli dve nepotrebne premnne a bola volana jedna nepotrebna funkcia
git-svn-id: http://opensvn.csie.org/tuxanci_ng@172 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
| -rw-r--r-- | config.h | 2 | ||||
| -rw-r--r-- | src/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/widget/widget_catchkey.c | 104 | ||||
| -rw-r--r-- | src/widget/widget_catchkey.h | 29 | ||||
| -rw-r--r-- | src/widget/widget_textfield.c | 4 |
5 files changed, 137 insertions, 4 deletions
@@ -1 +1 @@ -#define TUXANCI_NG_VERSION "svn171" +#define TUXANCI_NG_VERSION "svn172" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d8ed337..b89bd8d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,7 +13,7 @@ ${WORKDIR}/client/layer ${WORKDIR}/client/term ${WORKDIR}/client/screen ${WORKDI ${WORKDIR}/screen/screen_choiceArena ${WORKDIR}/screen/screen_table ${WORKDIR}/screen/screen_setting ${WORKDIR}/screen/screen_credits ${WORKDIR}/screen/screen_world ${WORKDIR}/screen/screen_analyze ${WORKDIR}/screen/screen_mainMenu ${WORKDIR}/screen/screen_browser ${WORKDIR}/screen/screen_gameType -${WORKDIR}/widget/widget_check ${WORKDIR}/widget/widget_button ${WORKDIR}/widget/widget_textfield ${WORKDIR}/widget/widget_label ${WORKDIR}/widget/widget_buttonimage ${WORKDIR}/widget/widget_image ${WORKDIR}/widget/widget_select +${WORKDIR}/widget/widget_check ${WORKDIR}/widget/widget_button ${WORKDIR}/widget/widget_textfield ${WORKDIR}/widget/widget_label ${WORKDIR}/widget/widget_buttonimage ${WORKDIR}/widget/widget_image ${WORKDIR}/widget/widget_select ${WORKDIR}/widget/widget_catchkey ) SET ( SRC_audio ${WORKDIR}/audio/audio ${WORKDIR}/audio/music ${WORKDIR}/audio/sound) diff --git a/src/widget/widget_catchkey.c b/src/widget/widget_catchkey.c new file mode 100644 index 0000000..7443358 --- /dev/null +++ b/src/widget/widget_catchkey.c @@ -0,0 +1,104 @@ + +#include <stdlib.h> + +#include "main.h" +#include "interface.h" +#include "font.h" +#include "widget_catchkey.h" + +widget_catchkey_t* newWidgetCatchkey(int x, int y, int key) +{ + widget_catchkey_t *new; + + new = malloc( sizeof(widget_catchkey_t) ); + + new->x = x; + new->y = y; + new->key = key; + + return new; +} + +int getWidgetCatchKey(widget_catchkey_t *p) +{ + return p->key; +} + +void setWidgetCatchKey(widget_catchkey_t *p, int key) +{ + p->key = key; +} + +void drawWidgetCatchkey(widget_catchkey_t *p) +{ + char *name; + + name = NULL; + + if( p->key != WIDGET_CATCHKEY_NOKEY ) + { + name = (char *) SDL_GetKeyName(p->key); + } + + if( name == NULL ) + { + name = "no key"; + } + + drawFont(name, p->x, p->y, COLOR_WHITE); +} + +static int getPessAnyKey() +{ + Uint8 *mapa; + int i; + + mapa = SDL_GetKeyState(NULL); + + for( i = SDLK_FIRST ; i <= SDLK_F15 ; i++ ) + { + if( mapa[i] == SDL_PRESSED ) + { + return i; + } + } + + return WIDGET_CATCHKEY_NOKEY; +} + +void eventWidgetCatchkey(widget_catchkey_t *p) +{ + int x, y; + + getMousePosition(&x, &y); + + if( isMouseClicked() ) + { + if( x >= p->x && x <= p->x+WIDGET_CATCHKEY_WIDTH && + y >= p->y && y <= p->y+WIDGET_CATCHKEY_HEIGHT ) + { + p->active = TRUE; + } + else + { + p->active = FALSE; + } + } + + if( p->active == TRUE ) + { + int key; + + key = getPessAnyKey(); + + if( key != WIDGET_CATCHKEY_NOKEY ) + { + p->key = key; + } + } +} + +void destroyWidgetCatchkey(widget_catchkey_t *p) +{ + free(p); +} diff --git a/src/widget/widget_catchkey.h b/src/widget/widget_catchkey.h new file mode 100644 index 0000000..ab95bbd --- /dev/null +++ b/src/widget/widget_catchkey.h @@ -0,0 +1,29 @@ + +#ifndef WIDGET_CATCHKEY_H + +#define WIDGET_CATCHKEY_H + +#include "main.h" + +#define WIDGET_CATCHKEY_WIDTH 64 +#define WIDGET_CATCHKEY_HEIGHT 32 + +#define WIDGET_CATCHKEY_NOKEY -1 + +typedef struct widget_catchkey_struct +{ + int x, y; + int w, h; + int key; + bool_t active; +} widget_catchkey_t; + +extern widget_catchkey_t* newWidgetCatchkey(int x, int y, int key); +extern int getWidgetCatchKey(widget_catchkey_t *p); +extern void setWidgetCatchKey(widget_catchkey_t *p, int key); +extern void drawWidgetCatchkey(widget_catchkey_t *p); +extern void eventWidgetCatchkey(widget_catchkey_t *p); +extern void destroyWidgetCatchkey(widget_catchkey_t *p); + +#endif + diff --git a/src/widget/widget_textfield.c b/src/widget/widget_textfield.c index 70e2a66..ee1cf76 100644 --- a/src/widget/widget_textfield.c +++ b/src/widget/widget_textfield.c @@ -32,9 +32,9 @@ static void drawBackground(widget_textfield_t *p) { static image_t *g_textfield0 = NULL; static image_t *g_textfield1 = NULL; - int x, y; + //int x, y; - getMousePosition(&x, &y); + //getMousePosition(&x, &y); if( g_textfield0 == NULL ) { |