diff options
| author | Tomas Chvatal (scarabeus) <tomas.chvatal@gmail.com> | 2008-10-22 22:51:24 +0200 |
|---|---|---|
| committer | Tomas Chvatal (scarabeus) <tomas.chvatal@gmail.com> | 2008-10-22 22:51:24 +0200 |
| commit | 44daf03024fbf7cbffa10349044786f6ab784821 (patch) | |
| tree | fe311eb22e2d853dfc18fde1a9e55d21815f4f82 /src/widget | |
| parent | e12753d2ec9db83ec08bb9db63902a82fb245cdd (diff) | |
Revert "X"
This reverts commit e12753d2ec9db83ec08bb9db63902a82fb245cdd.
Diffstat (limited to 'src/widget')
| -rw-r--r-- | src/widget/widget.c | 58 | ||||
| -rw-r--r-- | src/widget/widget.c~ | 52 | ||||
| -rw-r--r-- | src/widget/widget_button.c | 149 | ||||
| -rw-r--r-- | src/widget/widget_button.c~ | 109 | ||||
| -rw-r--r-- | src/widget/widget_buttonimage.c | 109 | ||||
| -rw-r--r-- | src/widget/widget_buttonimage.c~ | 88 | ||||
| -rw-r--r-- | src/widget/widget_catchkey.c | 219 | ||||
| -rw-r--r-- | src/widget/widget_catchkey.c~ | 154 | ||||
| -rw-r--r-- | src/widget/widget_check.c | 171 | ||||
| -rw-r--r-- | src/widget/widget_check.c~ | 128 | ||||
| -rw-r--r-- | src/widget/widget_choicegroup.c | 209 | ||||
| -rw-r--r-- | src/widget/widget_choicegroup.c~ | 155 | ||||
| -rw-r--r-- | src/widget/widget_image.c | 46 | ||||
| -rw-r--r-- | src/widget/widget_image.c~ | 52 | ||||
| -rw-r--r-- | src/widget/widget_label.c | 74 | ||||
| -rw-r--r-- | src/widget/widget_label.c~ | 65 | ||||
| -rw-r--r-- | src/widget/widget_select.c | 204 | ||||
| -rw-r--r-- | src/widget/widget_select.c~ | 160 | ||||
| -rw-r--r-- | src/widget/widget_textfield.c | 813 | ||||
| -rw-r--r-- | src/widget/widget_textfield.c~ | 487 |
20 files changed, 1022 insertions, 2480 deletions
diff --git a/src/widget/widget.c b/src/widget/widget.c index 3c437b4..2d9ee19 100644 --- a/src/widget/widget.c +++ b/src/widget/widget.c @@ -7,56 +7,46 @@ #include "widget.h" #include "widget_label.h" -widget_t * -newWidget(int type, int x, int y, int w, int h, void *private_data) +widget_t* newWidget(int type, int x, int y, int w, int h, void *private_data) { - widget_t *new; + widget_t *new; - new = malloc(sizeof(widget_t)); - new->type = type; - new->x = x; - new->y = y; - new->w = w; - new->h = h; - new->private_data = private_data; + new = malloc( sizeof(widget_t) ); + new->type = type; + new->x = x; + new->y = y; + new->w = w; + new->h = h; + new->private_data = private_data; - return new; + return new; } -void -widgetSetLocation(widget_t * p, int x, int y) +void widgetSetLocation(widget_t *p, int x, int y) { - p->x = x; - p->y = y; + p->x = x; + p->y = y; } -void -widgetGetLocation(widget_t * p, int *x, int *y) +void widgetGetLocation(widget_t *p, int *x, int *y) { - if (x != NULL) - *x = p->x; - if (y != NULL) - *y = p->y; + if( x != NULL )*x = p->x; + if( y != NULL )*y = p->y; } -void -widgetSetSize(widget_t * p, int w, int h) +void widgetSetSize(widget_t *p, int w, int h) { - p->w = w; - p->h = h; + p->w = w; + p->h = h; } -void -widgetGetSize(widget_t * p, int *w, int *h) +void widgetGetSize(widget_t *p, int *w, int *h) { - if (w != NULL) - *w = p->w; - if (h != NULL) - *h = p->h; + if( w != NULL )*w = p->w; + if( h != NULL )*h = p->h; } -void -destroyWidget(widget_t * p) +void destroyWidget(widget_t *p) { - free(p); + free(p); } diff --git a/src/widget/widget.c~ b/src/widget/widget.c~ deleted file mode 100644 index 2d9ee19..0000000 --- a/src/widget/widget.c~ +++ /dev/null @@ -1,52 +0,0 @@ - -#include <stdlib.h> -#include <assert.h> - -#include "main.h" - -#include "widget.h" -#include "widget_label.h" - -widget_t* newWidget(int type, int x, int y, int w, int h, void *private_data) -{ - widget_t *new; - - new = malloc( sizeof(widget_t) ); - new->type = type; - new->x = x; - new->y = y; - new->w = w; - new->h = h; - new->private_data = private_data; - - return new; -} - -void widgetSetLocation(widget_t *p, int x, int y) -{ - p->x = x; - p->y = y; -} - -void widgetGetLocation(widget_t *p, int *x, int *y) -{ - if( x != NULL )*x = p->x; - if( y != NULL )*y = p->y; -} - -void widgetSetSize(widget_t *p, int w, int h) -{ - p->w = w; - p->h = h; -} - -void widgetGetSize(widget_t *p, int *w, int *h) -{ - if( w != NULL )*w = p->w; - if( h != NULL )*h = p->h; -} - -void destroyWidget(widget_t *p) -{ - free(p); -} diff --git a/src/widget/widget_button.c b/src/widget/widget_button.c index 4e6414f..d52be75 100644 --- a/src/widget/widget_button.c +++ b/src/widget/widget_button.c @@ -11,104 +11,99 @@ #include "widget.h" #include "widget_button.h" -widget_t * -newWidgetButton(char *text, int x, int y, void (*fce_event) (void *)) +widget_t* newWidgetButton(char *text, int x, int y, void (*fce_event)(void *)) { - widget_button_t *new; + widget_button_t *new; - new = malloc(sizeof(widget_button_t)); - new->text = strdup(text); - new->fce_event = fce_event; - getTextSize(text, &(new->w), &(new->h)); + new = malloc( sizeof(widget_button_t) ); + new->text = strdup(text); + new->fce_event = fce_event; + getTextSize(text, &(new->w), &(new->h)); - return newWidget(WIDGET_TYPE_BUTTON, x, y, WIDGET_BUTTON_WIDTH, - WIDGET_BUTTON_HEIGHT, new); + return newWidget(WIDGET_TYPE_BUTTON, x, y, WIDGET_BUTTON_WIDTH, WIDGET_BUTTON_HEIGHT, new); } -void -drawWidgetButton(widget_t * widget) +void drawWidgetButton(widget_t *widget) { - widget_button_t *p; - static image_t *g_button0 = NULL; - static image_t *g_button1 = NULL; - int x, y; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_BUTTON); - - p = (widget_button_t *) widget->private_data; - getMousePosition(&x, &y); - - if (g_button0 == NULL) { - g_button0 = - addImageData("button0.png", IMAGE_ALPHA, "button0", - IMAGE_GROUP_BASE); - } - - if (g_button1 == NULL) { - g_button1 = - addImageData("button1.png", IMAGE_ALPHA, "button1", - IMAGE_GROUP_BASE); - } - - if (x >= widget->x && x <= widget->x + WIDGET_BUTTON_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_BUTTON_HEIGHT) { - drawImage(g_button1, widget->x, widget->y, 0, 0, g_button0->w, - g_button0->h); - } - else { - drawImage(g_button0, widget->x, widget->y, 0, 0, g_button0->w, - g_button0->h); - } - - //drawFont(p->text, p->x+WIDGET_BUTTON_WIDTH/2-p->w/2, p->y+p->h/2, COLOR_WHITE); - drawFont(p->text, - widget->x + WIDGET_BUTTON_WIDTH / 2 - p->w / 2, - widget->y + WIDGET_BUTTON_HEIGHT / 2 - p->h / 2, COLOR_WHITE); + widget_button_t *p; + static image_t *g_button0 = NULL; + static image_t *g_button1 = NULL; + int x, y; + + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_BUTTON ); + + p = (widget_button_t *) widget->private_data; + getMousePosition(&x, &y); + + if( g_button0 == NULL ) + { + g_button0 = addImageData("button0.png", IMAGE_ALPHA, "button0", IMAGE_GROUP_BASE); + } + + if( g_button1 == NULL ) + { + g_button1 = addImageData("button1.png", IMAGE_ALPHA, "button1", IMAGE_GROUP_BASE); + } + + if( x >= widget->x && x <= widget->x+WIDGET_BUTTON_WIDTH && + y >= widget->y && y <= widget->y+WIDGET_BUTTON_HEIGHT ) + { + drawImage(g_button1, widget->x, widget->y, 0, 0, g_button0->w, g_button0->h); + } + else + { + drawImage(g_button0, widget->x, widget->y, 0, 0, g_button0->w, g_button0->h); + } + + //drawFont(p->text, p->x+WIDGET_BUTTON_WIDTH/2-p->w/2, p->y+p->h/2, COLOR_WHITE); + drawFont(p->text, + widget->x + WIDGET_BUTTON_WIDTH/2 - p->w/2, + widget->y + WIDGET_BUTTON_HEIGHT/2 - p->h/2, COLOR_WHITE); } -void -eventWidgetButton(widget_t * widget) +void eventWidgetButton(widget_t *widget) { - widget_button_t *p; - static int time = 0; - int x, y; + widget_button_t *p; + static int time = 0; + int x, y; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_BUTTON); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_BUTTON ); - p = (widget_button_t *) widget->private_data; + p = (widget_button_t *) widget->private_data; - if (time > 0) { - time--; - return; - } + if( time > 0) + { + time--; + return; + } - getMousePosition(&x, &y); + getMousePosition(&x, &y); - if (x >= widget->x && x <= widget->x + WIDGET_BUTTON_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_BUTTON_HEIGHT && - isMouseClicked()) { - time = WIDGET_BUTTON_TIME; + if( x >= widget->x && x <= widget->x+WIDGET_BUTTON_WIDTH && + y >= widget->y && y <= widget->y+WIDGET_BUTTON_HEIGHT && + isMouseClicked() ) + { + time = WIDGET_BUTTON_TIME; #ifdef DEBUG - printf(_("Event caught\n")); + printf(_("Event caught\n")); #endif - p->fce_event(widget); - } + p->fce_event(widget); + } } -void -destroyWidgetButton(widget_t * widget) +void destroyWidgetButton(widget_t *widget) { - widget_button_t *p; + widget_button_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_BUTTON); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_BUTTON ); - p = (widget_button_t *) widget->private_data; + p = (widget_button_t *) widget->private_data; - free(p->text); - free(p); + free(p->text); + free(p); - destroyWidget(widget); + destroyWidget(widget); } diff --git a/src/widget/widget_button.c~ b/src/widget/widget_button.c~ deleted file mode 100644 index d52be75..0000000 --- a/src/widget/widget_button.c~ +++ /dev/null @@ -1,109 +0,0 @@ - -#include <stdlib.h> -#include <assert.h> - -#include "main.h" - -#include "interface.h" -#include "image.h" -#include "font.h" - -#include "widget.h" -#include "widget_button.h" - -widget_t* newWidgetButton(char *text, int x, int y, void (*fce_event)(void *)) -{ - widget_button_t *new; - - new = malloc( sizeof(widget_button_t) ); - new->text = strdup(text); - new->fce_event = fce_event; - getTextSize(text, &(new->w), &(new->h)); - - return newWidget(WIDGET_TYPE_BUTTON, x, y, WIDGET_BUTTON_WIDTH, WIDGET_BUTTON_HEIGHT, new); -} - -void drawWidgetButton(widget_t *widget) -{ - widget_button_t *p; - static image_t *g_button0 = NULL; - static image_t *g_button1 = NULL; - int x, y; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_BUTTON ); - - p = (widget_button_t *) widget->private_data; - getMousePosition(&x, &y); - - if( g_button0 == NULL ) - { - g_button0 = addImageData("button0.png", IMAGE_ALPHA, "button0", IMAGE_GROUP_BASE); - } - - if( g_button1 == NULL ) - { - g_button1 = addImageData("button1.png", IMAGE_ALPHA, "button1", IMAGE_GROUP_BASE); - } - - if( x >= widget->x && x <= widget->x+WIDGET_BUTTON_WIDTH && - y >= widget->y && y <= widget->y+WIDGET_BUTTON_HEIGHT ) - { - drawImage(g_button1, widget->x, widget->y, 0, 0, g_button0->w, g_button0->h); - } - else - { - drawImage(g_button0, widget->x, widget->y, 0, 0, g_button0->w, g_button0->h); - } - - //drawFont(p->text, p->x+WIDGET_BUTTON_WIDTH/2-p->w/2, p->y+p->h/2, COLOR_WHITE); - drawFont(p->text, - widget->x + WIDGET_BUTTON_WIDTH/2 - p->w/2, - widget->y + WIDGET_BUTTON_HEIGHT/2 - p->h/2, COLOR_WHITE); -} - -void eventWidgetButton(widget_t *widget) -{ - widget_button_t *p; - static int time = 0; - int x, y; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_BUTTON ); - - p = (widget_button_t *) widget->private_data; - - if( time > 0) - { - time--; - return; - } - - getMousePosition(&x, &y); - - if( x >= widget->x && x <= widget->x+WIDGET_BUTTON_WIDTH && - y >= widget->y && y <= widget->y+WIDGET_BUTTON_HEIGHT && - isMouseClicked() ) - { - time = WIDGET_BUTTON_TIME; -#ifdef DEBUG - printf(_("Event caught\n")); -#endif - p->fce_event(widget); - } -} - -void destroyWidgetButton(widget_t *widget) -{ - widget_button_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_BUTTON ); - - p = (widget_button_t *) widget->private_data; - - free(p->text); - free(p); - - destroyWidget(widget); -} diff --git a/src/widget/widget_buttonimage.c b/src/widget/widget_buttonimage.c index a088a83..27e94a3 100644 --- a/src/widget/widget_buttonimage.c +++ b/src/widget/widget_buttonimage.c @@ -10,82 +10,79 @@ #include "widget.h" #include "widget_buttonimage.h" -widget_t * -newWidgetButtonimage(image_t * image, int x, int y, - void (*fce_event) (void *)) +widget_t* newWidgetButtonimage(image_t *image, int x, int y, void (*fce_event)(void *)) { - widget_buttonimage_t *new; + widget_buttonimage_t *new; - new = malloc(sizeof(widget_buttonimage_t)); - new->image = image; - new->w = image->w / 2; - new->h = image->h; - new->active = 0; - new->fce_event = fce_event; + new = malloc( sizeof(widget_buttonimage_t) ); + new->image = image; + new->w = image->w/2; + new->h = image->h; + new->active = 0; + new->fce_event = fce_event; - return newWidget(WIDGET_TYPE_BUTTONIMAGE, x, y, new->w, new->h, new); + return newWidget(WIDGET_TYPE_BUTTONIMAGE, x, y, new->w, new->h, new); } -void -setWidgetButtonimageActive(widget_t * widget, bool_t active) +void setWidgetButtonimageActive(widget_t *widget, bool_t active) { - widget_buttonimage_t *p; + widget_buttonimage_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_BUTTONIMAGE); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_BUTTONIMAGE ); - p = (widget_buttonimage_t *) widget->private_data; - p->active = active; + p = (widget_buttonimage_t *)widget->private_data; + p->active = active; } -void -drawWidgetButtonimage(widget_t * widget) +void drawWidgetButtonimage(widget_t *widget) { - widget_buttonimage_t *p; + widget_buttonimage_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_BUTTONIMAGE); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_BUTTONIMAGE ); - p = (widget_buttonimage_t *) widget->private_data; - drawImage(p->image, widget->x, widget->y, p->active * p->w, 0, p->w, p->h); + p = (widget_buttonimage_t *)widget->private_data; + drawImage(p->image, widget->x, widget->y, p->active*p->w, 0, p->w, p->h); } -void -eventWidgetButtonimage(widget_t * widget) +void eventWidgetButtonimage(widget_t *widget) { - widget_buttonimage_t *p; - static int time = 0; - int x, y; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_BUTTONIMAGE); - - p = (widget_buttonimage_t *) widget->private_data; - if (time > 0) { - time--; - return; - } - - getMousePosition(&x, &y); - - if (x >= widget->x && x <= widget->x + p->w && - y >= widget->y && y <= widget->y + p->h && isMouseClicked()) { - time = WIDGET_BUTTONIMAGE_TIME; - p->active = 1; - p->fce_event(widget); - } + widget_buttonimage_t *p; + static int time = 0; + int x, y; + + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_BUTTONIMAGE ); + + p = (widget_buttonimage_t *) widget->private_data; + if( time > 0) + { + time--; + return; + } + + getMousePosition(&x, &y); + + if( x >= widget->x && x <= widget->x+p->w && + y >= widget->y && y <= widget->y+p->h && + isMouseClicked() ) + { + time = WIDGET_BUTTONIMAGE_TIME; + p->active = 1; + p->fce_event(widget); + } } -void -destroyWidgetButtonimage(widget_t * widget) +void destroyWidgetButtonimage(widget_t *widget) { - widget_buttonimage_t *p; + widget_buttonimage_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_BUTTONIMAGE); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_BUTTONIMAGE ); - p = (widget_buttonimage_t *) widget->private_data; + p = (widget_buttonimage_t *) widget->private_data; - free(p); - destroyWidget(widget); + free(p); + destroyWidget(widget); } diff --git a/src/widget/widget_buttonimage.c~ b/src/widget/widget_buttonimage.c~ deleted file mode 100644 index 27e94a3..0000000 --- a/src/widget/widget_buttonimage.c~ +++ /dev/null @@ -1,88 +0,0 @@ - -#include <stdlib.h> -#include <assert.h> - -#include "main.h" -#include "interface.h" -#include "font.h" -#include "image.h" - -#include "widget.h" -#include "widget_buttonimage.h" - -widget_t* newWidgetButtonimage(image_t *image, int x, int y, void (*fce_event)(void *)) -{ - widget_buttonimage_t *new; - - new = malloc( sizeof(widget_buttonimage_t) ); - new->image = image; - new->w = image->w/2; - new->h = image->h; - new->active = 0; - new->fce_event = fce_event; - - return newWidget(WIDGET_TYPE_BUTTONIMAGE, x, y, new->w, new->h, new); -} - -void setWidgetButtonimageActive(widget_t *widget, bool_t active) -{ - widget_buttonimage_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_BUTTONIMAGE ); - - p = (widget_buttonimage_t *)widget->private_data; - p->active = active; -} - -void drawWidgetButtonimage(widget_t *widget) -{ - widget_buttonimage_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_BUTTONIMAGE ); - - p = (widget_buttonimage_t *)widget->private_data; - drawImage(p->image, widget->x, widget->y, p->active*p->w, 0, p->w, p->h); -} - -void eventWidgetButtonimage(widget_t *widget) -{ - widget_buttonimage_t *p; - static int time = 0; - int x, y; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_BUTTONIMAGE ); - - p = (widget_buttonimage_t *) widget->private_data; - if( time > 0) - { - time--; - return; - } - - getMousePosition(&x, &y); - - if( x >= widget->x && x <= widget->x+p->w && - y >= widget->y && y <= widget->y+p->h && - isMouseClicked() ) - { - time = WIDGET_BUTTONIMAGE_TIME; - p->active = 1; - p->fce_event(widget); - } -} - -void destroyWidgetButtonimage(widget_t *widget) -{ - widget_buttonimage_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_BUTTONIMAGE ); - - p = (widget_buttonimage_t *) widget->private_data; - - free(p); - destroyWidget(widget); -} diff --git a/src/widget/widget_catchkey.c b/src/widget/widget_catchkey.c index 19678a3..215e5b3 100644 --- a/src/widget/widget_catchkey.c +++ b/src/widget/widget_catchkey.c @@ -9,141 +9,146 @@ #include "widget.h" #include "widget_catchkey.h" -widget_t * -newWidgetCatchkey(int key, int x, int y, void *event) +widget_t* newWidgetCatchkey(int key, int x, int y, void *event) { - widget_catchkey_t *new; + widget_catchkey_t *new; - new = malloc(sizeof(widget_catchkey_t)); - new->key = key; - new->fce_event = event; - new->active = FALSE; + new = malloc( sizeof(widget_catchkey_t) ); + new->key = key; + new->fce_event = event; + new->active = FALSE; - return newWidget(WIDGET_TYPE_CATCHKEY, x, y, WIDGET_CATCHKEY_WIDTH, - WIDGET_CATCHKEY_HEIGHT, new); + return newWidget(WIDGET_TYPE_CATCHKEY, x, y, WIDGET_CATCHKEY_WIDTH, WIDGET_CATCHKEY_HEIGHT, new); } -int -getWidgetCatchKey(widget_t * widget) +int getWidgetCatchKey(widget_t *widget) { - widget_catchkey_t *p; + widget_catchkey_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CATCHKEY); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_CATCHKEY ); - p = (widget_catchkey_t *) widget->private_data; + p = (widget_catchkey_t *) widget->private_data; - return p->key; + return p->key; } -void -setWidgetCatchKey(widget_t * widget, int key) +void setWidgetCatchKey(widget_t *widget, int key) { - widget_catchkey_t *p; + widget_catchkey_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CATCHKEY); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_CATCHKEY ); - p = (widget_catchkey_t *) widget->private_data; + p = (widget_catchkey_t *) widget->private_data; - p->key = key; + p->key = key; } -void -drawWidgetCatchkey(widget_t * widget) +void drawWidgetCatchkey(widget_t *widget) { - widget_catchkey_t *p; - char *name; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CATCHKEY); - - p = (widget_catchkey_t *) widget->private_data; - name = NULL; - - if (p->key != WIDGET_CATCHKEY_NOKEY) { - name = (char *) SDL_GetKeyName(p->key); - } - - if (name == NULL) { - name = "no key"; - } - - if (p->active) { - drawFont(name, widget->x, widget->y, COLOR_RED); - } - else { - drawFont(name, widget->x, widget->y, COLOR_WHITE); - } + widget_catchkey_t *p; + char *name; + + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_CATCHKEY ); + + p = (widget_catchkey_t *) widget->private_data; + name = NULL; + + if( p->key != WIDGET_CATCHKEY_NOKEY ) + { + name = (char *) SDL_GetKeyName(p->key); + } + + if( name == NULL ) + { + name = "no key"; + } + + if( p->active ) + { + drawFont(name, widget->x, widget->y, COLOR_RED); + } + else + { + drawFont(name, widget->x, widget->y, COLOR_WHITE); + } } -static int -getPessAnyKey() +static int getPessAnyKey() { - Uint8 *mapa; - int i; - - mapa = SDL_GetKeyState(NULL); - - for (i = SDLK_FIRST; i <= SDLK_COMPOSE; i++) { - if (i == SDLK_NUMLOCK || // black key - i == SDLK_CAPSLOCK || i == SDLK_SCROLLOCK) { - continue; - } - - if (mapa[i] == SDL_PRESSED) { - return i; - } - } - - return WIDGET_CATCHKEY_NOKEY; + Uint8 *mapa; + int i; + + mapa = SDL_GetKeyState(NULL); + + for( i = SDLK_FIRST ; i <= SDLK_COMPOSE ; i++ ) + { + if( i == SDLK_NUMLOCK || // black key + i == SDLK_CAPSLOCK || + i == SDLK_SCROLLOCK ) + { + continue; + } + + if( mapa[i] == SDL_PRESSED ) + { + return i; + } + } + + return WIDGET_CATCHKEY_NOKEY; } -void -eventWidgetCatchkey(widget_t * widget) +void eventWidgetCatchkey(widget_t *widget) { - widget_catchkey_t *p; - int x, y; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CATCHKEY); - - p = (widget_catchkey_t *) widget->private_data; - - getMousePosition(&x, &y); - - if (isMouseClicked()) { - if (x >= widget->x && x <= widget->x + WIDGET_CATCHKEY_WIDTH && - y >= widget->y && y <= widget->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; - p->fce_event(widget); - } - } + widget_catchkey_t *p; + int x, y; + + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_CATCHKEY ); + + p = (widget_catchkey_t *) widget->private_data; + + getMousePosition(&x, &y); + + if( isMouseClicked() ) + { + if( x >= widget->x && x <= widget->x+WIDGET_CATCHKEY_WIDTH && + y >= widget->y && y <= widget->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; + p->fce_event(widget); + } + } } -void -destroyWidgetCatchkey(widget_t * widget) +void destroyWidgetCatchkey(widget_t *widget) { - widget_catchkey_t *p; + widget_catchkey_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CATCHKEY); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_CATCHKEY ); - p = (widget_catchkey_t *) widget->private_data; + p = (widget_catchkey_t *) widget->private_data; - free(p); - destroyWidget(widget); + free(p); + destroyWidget(widget); } diff --git a/src/widget/widget_catchkey.c~ b/src/widget/widget_catchkey.c~ deleted file mode 100644 index 215e5b3..0000000 --- a/src/widget/widget_catchkey.c~ +++ /dev/null @@ -1,154 +0,0 @@ - -#include <stdlib.h> -#include <assert.h> - -#include "main.h" -#include "interface.h" -#include "font.h" - -#include "widget.h" -#include "widget_catchkey.h" - -widget_t* newWidgetCatchkey(int key, int x, int y, void *event) -{ - widget_catchkey_t *new; - - new = malloc( sizeof(widget_catchkey_t) ); - new->key = key; - new->fce_event = event; - new->active = FALSE; - - return newWidget(WIDGET_TYPE_CATCHKEY, x, y, WIDGET_CATCHKEY_WIDTH, WIDGET_CATCHKEY_HEIGHT, new); -} - -int getWidgetCatchKey(widget_t *widget) -{ - widget_catchkey_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_CATCHKEY ); - - p = (widget_catchkey_t *) widget->private_data; - - return p->key; -} - -void setWidgetCatchKey(widget_t *widget, int key) -{ - widget_catchkey_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_CATCHKEY ); - - p = (widget_catchkey_t *) widget->private_data; - - p->key = key; -} - -void drawWidgetCatchkey(widget_t *widget) -{ - widget_catchkey_t *p; - char *name; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_CATCHKEY ); - - p = (widget_catchkey_t *) widget->private_data; - name = NULL; - - if( p->key != WIDGET_CATCHKEY_NOKEY ) - { - name = (char *) SDL_GetKeyName(p->key); - } - - if( name == NULL ) - { - name = "no key"; - } - - if( p->active ) - { - drawFont(name, widget->x, widget->y, COLOR_RED); - } - else - { - drawFont(name, widget->x, widget->y, COLOR_WHITE); - } -} - -static int getPessAnyKey() -{ - Uint8 *mapa; - int i; - - mapa = SDL_GetKeyState(NULL); - - for( i = SDLK_FIRST ; i <= SDLK_COMPOSE ; i++ ) - { - if( i == SDLK_NUMLOCK || // black key - i == SDLK_CAPSLOCK || - i == SDLK_SCROLLOCK ) - { - continue; - } - - if( mapa[i] == SDL_PRESSED ) - { - return i; - } - } - - return WIDGET_CATCHKEY_NOKEY; -} - -void eventWidgetCatchkey(widget_t *widget) -{ - widget_catchkey_t *p; - int x, y; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_CATCHKEY ); - - p = (widget_catchkey_t *) widget->private_data; - - getMousePosition(&x, &y); - - if( isMouseClicked() ) - { - if( x >= widget->x && x <= widget->x+WIDGET_CATCHKEY_WIDTH && - y >= widget->y && y <= widget->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; - p->fce_event(widget); - } - } -} - -void destroyWidgetCatchkey(widget_t *widget) -{ - widget_catchkey_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_CATCHKEY ); - - p = (widget_catchkey_t *) widget->private_data; - - free(p); - destroyWidget(widget); -} diff --git a/src/widget/widget_check.c b/src/widget/widget_check.c index caa937c..2d94238 100644 --- a/src/widget/widget_check.c +++ b/src/widget/widget_check.c @@ -9,121 +9,120 @@ #include "widget.h" #include "widget_check.h" -widget_t * -newWidgetCheck(int x, int y, bool_t status, void (*fce_event) (void *)) +widget_t* newWidgetCheck(int x, int y, bool_t status, void (*fce_event)(void *)) { - widget_check_t *new; + widget_check_t *new; - new = malloc(sizeof(widget_check_t)); - new->time = 0; - new->status = status; - new->fce_event = fce_event; + new = malloc( sizeof(widget_check_t) ); + new->time = 0; + new->status = status; + new->fce_event = fce_event; - return newWidget(WIDGET_TYPE_CHECK, x, y, WIDGET_CHECK_WIDTH, - WIDGET_CHECK_HEIGHT, new); + return newWidget(WIDGET_TYPE_CHECK, x, y, WIDGET_CHECK_WIDTH, WIDGET_CHECK_HEIGHT, new); } -void -drawWidgetCheck(widget_t * widget) +void drawWidgetCheck(widget_t *widget) { - widget_check_t *p; - static image_t *g_check = NULL; - int x, y; - int offset; + widget_check_t *p; + static image_t *g_check = NULL; + int x, y; + int offset; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHECK); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_CHECK ); - p = (widget_check_t *) widget->private_data; + p = (widget_check_t *) widget->private_data; - getMousePosition(&x, &y); + getMousePosition(&x, &y); - if (g_check == NULL) { - g_check = - addImageData("check.png", IMAGE_ALPHA, "check", IMAGE_GROUP_BASE); - } + if( g_check == NULL ) + { + g_check = addImageData("check.png", IMAGE_ALPHA, "check", IMAGE_GROUP_BASE); + } - if (p->status == TRUE) { - offset = 0; - } - else { - offset = WIDGET_CHECK_WIDTH; - } + if( p->status == TRUE ) + { + offset = 0; + } + else + { + offset = WIDGET_CHECK_WIDTH; + } - drawImage(g_check, widget->x, widget->y, offset, 0, WIDGET_CHECK_WIDTH, - WIDGET_CHECK_HEIGHT); + drawImage(g_check, widget->x, widget->y, offset, 0, WIDGET_CHECK_WIDTH, WIDGET_CHECK_HEIGHT); } -void -eventWidgetCheck(widget_t * widget) +void eventWidgetCheck(widget_t *widget) { - widget_check_t *p; - int x, y; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHECK); - - p = (widget_check_t *) widget->private_data; - - if (p->time > 0) { - p->time--; - return; - } - - getMousePosition(&x, &y); - - if (x >= widget->x && x <= widget->x + WIDGET_CHECK_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_CHECK_HEIGHT && - isMouseClicked()) { - if (p->status == TRUE) { - p->status = FALSE; - p->time = WIDGET_CHECK_TIME_SWITCH_STATUS; - } - else { - p->status = TRUE; - p->time = WIDGET_CHECK_TIME_SWITCH_STATUS; - } - - if (p->fce_event != NULL) { - p->fce_event(p); - } - } + widget_check_t *p; + int x, y; + + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_CHECK ); + + p = (widget_check_t *) widget->private_data; + + if( p->time > 0 ) + { + p->time--; + return; + } + + getMousePosition(&x, &y); + + if( x >= widget->x && x <= widget->x+WIDGET_CHECK_WIDTH && + y >= widget->y && y <= widget->y+WIDGET_CHECK_HEIGHT && + isMouseClicked() ) + { + if( p->status == TRUE ) + { + p->status = FALSE; + p->time = WIDGET_CHECK_TIME_SWITCH_STATUS; + } + else + { + p->status = TRUE; + p->time = WIDGET_CHECK_TIME_SWITCH_STATUS; + } + + if( p->fce_event != NULL ) + { + p->fce_event(p); + } + } } -bool_t -getWidgetCheckStatus(widget_t * widget) +bool_t getWidgetCheckStatus(widget_t *widget) { - widget_check_t *p; + widget_check_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHECK); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_CHECK ); - p = (widget_check_t *) widget->private_data; + p = (widget_check_t *) widget->private_data; - return p->status; + return p->status; } -void -setWidgetCheckStatus(widget_t * widget, bool_t status) +void setWidgetCheckStatus(widget_t *widget, bool_t status) { - widget_check_t *p; + widget_check_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHECK); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_CHECK ); - p = (widget_check_t *) widget->private_data; - p->status = status; + p = (widget_check_t *) widget->private_data; + p->status = status; } -void -destroyWidgetCheck(widget_t * widget) +void destroyWidgetCheck(widget_t *widget) { - widget_check_t *p; + widget_check_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHECK); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_CHECK ); - p = (widget_check_t *) widget->private_data; - free(p); - destroyWidget(widget); + p = (widget_check_t *) widget->private_data; + free(p); + destroyWidget(widget); } diff --git a/src/widget/widget_check.c~ b/src/widget/widget_check.c~ deleted file mode 100644 index 2d94238..0000000 --- a/src/widget/widget_check.c~ +++ /dev/null @@ -1,128 +0,0 @@ - -#include <stdlib.h> -#include <assert.h> - -#include "main.h" -#include "interface.h" -#include "image.h" - -#include "widget.h" -#include "widget_check.h" - -widget_t* newWidgetCheck(int x, int y, bool_t status, void (*fce_event)(void *)) -{ - widget_check_t *new; - - new = malloc( sizeof(widget_check_t) ); - new->time = 0; - new->status = status; - new->fce_event = fce_event; - - return newWidget(WIDGET_TYPE_CHECK, x, y, WIDGET_CHECK_WIDTH, WIDGET_CHECK_HEIGHT, new); -} - -void drawWidgetCheck(widget_t *widget) -{ - widget_check_t *p; - static image_t *g_check = NULL; - int x, y; - int offset; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_CHECK ); - - p = (widget_check_t *) widget->private_data; - - getMousePosition(&x, &y); - - if( g_check == NULL ) - { - g_check = addImageData("check.png", IMAGE_ALPHA, "check", IMAGE_GROUP_BASE); - } - - if( p->status == TRUE ) - { - offset = 0; - } - else - { - offset = WIDGET_CHECK_WIDTH; - } - - drawImage(g_check, widget->x, widget->y, offset, 0, WIDGET_CHECK_WIDTH, WIDGET_CHECK_HEIGHT); -} - -void eventWidgetCheck(widget_t *widget) -{ - widget_check_t *p; - int x, y; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_CHECK ); - - p = (widget_check_t *) widget->private_data; - - if( p->time > 0 ) - { - p->time--; - return; - } - - getMousePosition(&x, &y); - - if( x >= widget->x && x <= widget->x+WIDGET_CHECK_WIDTH && - y >= widget->y && y <= widget->y+WIDGET_CHECK_HEIGHT && - isMouseClicked() ) - { - if( p->status == TRUE ) - { - p->status = FALSE; - p->time = WIDGET_CHECK_TIME_SWITCH_STATUS; - } - else - { - p->status = TRUE; - p->time = WIDGET_CHECK_TIME_SWITCH_STATUS; - } - - if( p->fce_event != NULL ) - { - p->fce_event(p); - } - } -} - -bool_t getWidgetCheckStatus(widget_t *widget) -{ - widget_check_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_CHECK ); - - p = (widget_check_t *) widget->private_data; - - return p->status; -} - -void setWidgetCheckStatus(widget_t *widget, bool_t status) -{ - widget_check_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_CHECK ); - - p = (widget_check_t *) widget->private_data; - p->status = status; -} - -void destroyWidgetCheck(widget_t *widget) -{ - widget_check_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_CHECK ); - - p = (widget_check_t *) widget->private_data; - free(p); - destroyWidget(widget); -} diff --git a/src/widget/widget_choicegroup.c b/src/widget/widget_choicegroup.c index e68935d..fc4fd01 100644 --- a/src/widget/widget_choicegroup.c +++ b/src/widget/widget_choicegroup.c @@ -9,152 +9,147 @@ #include "widget.h" #include "widget_choicegroup.h" -widget_t * -newWidgetChoicegroup(int x, int y, bool_t status, list_t * list, - void (*fce_event) (void *)) +widget_t* newWidgetChoicegroup(int x, int y, bool_t status, list_t *list, void (*fce_event)(void *)) { - widget_choicegroup_t *new; - widget_t *widget; + widget_choicegroup_t *new; + widget_t *widget; - new = malloc(sizeof(widget_choicegroup_t)); - new->time = 0; - new->status = status; - new->fce_event = fce_event; - new->list = list; + new = malloc( sizeof(widget_choicegroup_t) ); + new->time = 0; + new->status = status; + new->fce_event = fce_event; + new->list = list; - widget = - newWidget(WIDGET_TYPE_CHOICE, x, y, WIDGET_CHOICEGROUP_WIDTH, - WIDGET_CHOICEGROUP_HEIGHT, new); - addList(new->list, widget); + widget = newWidget(WIDGET_TYPE_CHOICE, x, y, WIDGET_CHOICEGROUP_WIDTH, WIDGET_CHOICEGROUP_HEIGHT, new); + addList(new->list, widget); - return widget; + return widget; } -void -drawWidgetChoicegroup(widget_t * widget) +void drawWidgetChoicegroup(widget_t *widget) { - widget_choicegroup_t *p; - static image_t *g_choicegroup = NULL; - int x, y; - int offset; + widget_choicegroup_t *p; + static image_t *g_choicegroup = NULL; + int x, y; + int offset; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHOICE); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_CHOICE ); - p = (widget_choicegroup_t *) widget->private_data; + p = (widget_choicegroup_t *) widget->private_data; - getMousePosition(&x, &y); + getMousePosition(&x, &y); - if (g_choicegroup == NULL) { - g_choicegroup = - addImageData("choice.png", IMAGE_ALPHA, "choicegroup", - IMAGE_GROUP_BASE); - } + if( g_choicegroup == NULL ) + { + g_choicegroup = addImageData("choice.png", IMAGE_ALPHA, "choicegroup", IMAGE_GROUP_BASE); + } - if (p->status == TRUE) { - offset = 0; - } - else { - offset = WIDGET_CHOICEGROUP_WIDTH; - } + if( p->status == TRUE ) + { + offset = 0; + } + else + { + offset = WIDGET_CHOICEGROUP_WIDTH; + } - drawImage(g_choicegroup, widget->x, widget->y, offset, 0, - WIDGET_CHOICEGROUP_WIDTH, WIDGET_CHOICEGROUP_HEIGHT); + drawImage(g_choicegroup, widget->x, widget->y, offset, 0, WIDGET_CHOICEGROUP_WIDTH, WIDGET_CHOICEGROUP_HEIGHT); } -void -setWidgetChoiceActive(widget_t * widget) +void setWidgetChoiceActive(widget_t *widget) { - widget_choicegroup_t *p; - int i; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHOICE); - - p = (widget_choicegroup_t *) widget->private_data; - - for (i = 0; i < p->list->count; i++) { - widget_t *this; - widget_choicegroup_t *thisChoice; - - this = (widget_t *) p->list->list[i]; - thisChoice = (widget_choicegroup_t *) this->private_data; - - if (widget == this) { - thisChoice->status = TRUE; - thisChoice->time = WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS; - thisChoice->fce_event(p); - } - else { - thisChoice->status = FALSE; - } - } + widget_choicegroup_t *p; + int i; + + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_CHOICE ); + + p = (widget_choicegroup_t *) widget->private_data; + + for( i = 0 ; i < p->list->count ; i++ ) + { + widget_t *this; + widget_choicegroup_t *thisChoice; + + this = (widget_t *) p->list->list[i]; + thisChoice = (widget_choicegroup_t *) this->private_data; + + if( widget == this ) + { + thisChoice->status = TRUE; + thisChoice->time = WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS; + thisChoice->fce_event(p); + } + else + { + thisChoice->status = FALSE; + } + } } -bool_t -getWidgetChoiceStatus(widget_t * widget) +bool_t getWidgetChoiceStatus(widget_t *widget) { - widget_choicegroup_t *p; + widget_choicegroup_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHOICE); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_CHOICE ); - p = (widget_choicegroup_t *) widget->private_data; + p = (widget_choicegroup_t *) widget->private_data; - return p->status; + return p->status; } -void -setWidgetChoiceStatus(widget_t * widget, bool_t status) +void setWidgetChoiceStatus(widget_t *widget, bool_t status) { - widget_choicegroup_t *p; + widget_choicegroup_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHOICE); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_CHOICE ); - p = (widget_choicegroup_t *) widget->private_data; - p->status = status; + p = (widget_choicegroup_t *) widget->private_data; + p->status = status; } -void -eventWidgetChoicegroup(widget_t * widget) +void eventWidgetChoicegroup(widget_t *widget) { - widget_choicegroup_t *p; - int x, y; + widget_choicegroup_t *p; + int x, y; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHOICE); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_CHOICE ); - p = (widget_choicegroup_t *) widget->private_data; + p = (widget_choicegroup_t *) widget->private_data; - if (p->time > 0) { - p->time--; - return; - } + if( p->time > 0 ) + { + p->time--; + return; + } - getMousePosition(&x, &y); + getMousePosition(&x, &y); - if (x >= widget->x && x <= widget->x + WIDGET_CHOICEGROUP_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_CHOICEGROUP_HEIGHT && - isMouseClicked()) { - setWidgetChoiceActive(widget); - } + if( x >= widget->x && x <= widget->x+WIDGET_CHOICEGROUP_WIDTH && + y >= widget->y && y <= widget->y+WIDGET_CHOICEGROUP_HEIGHT && + isMouseClicked() ) + { + setWidgetChoiceActive(widget); + } } -void -destroyWidgetChoicegroup(widget_t * widget) +void destroyWidgetChoicegroup(widget_t *widget) { - widget_choicegroup_t *p; - int index; + widget_choicegroup_t *p; + int index; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHOICE); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_CHOICE ); - p = (widget_choicegroup_t *) widget->private_data; - index = searchListItem(p->list, widget); - assert(index != -1); - delList(p->list, index); + p = (widget_choicegroup_t *) widget->private_data; + index = searchListItem(p->list, widget); + assert( index != -1 ); + delList(p->list, index); - free(p); - destroyWidget(widget); + free(p); + destroyWidget(widget); } diff --git a/src/widget/widget_choicegroup.c~ b/src/widget/widget_choicegroup.c~ deleted file mode 100644 index fc4fd01..0000000 --- a/src/widget/widget_choicegroup.c~ +++ /dev/null @@ -1,155 +0,0 @@ - -#include <stdlib.h> -#include <assert.h> - -#include "main.h" -#include "interface.h" -#include "image.h" - -#include "widget.h" -#include "widget_choicegroup.h" - -widget_t* newWidgetChoicegroup(int x, int y, bool_t status, list_t *list, void (*fce_event)(void *)) -{ - widget_choicegroup_t *new; - widget_t *widget; - - new = malloc( sizeof(widget_choicegroup_t) ); - new->time = 0; - new->status = status; - new->fce_event = fce_event; - new->list = list; - - widget = newWidget(WIDGET_TYPE_CHOICE, x, y, WIDGET_CHOICEGROUP_WIDTH, WIDGET_CHOICEGROUP_HEIGHT, new); - addList(new->list, widget); - - return widget; -} - -void drawWidgetChoicegroup(widget_t *widget) -{ - widget_choicegroup_t *p; - static image_t *g_choicegroup = NULL; - int x, y; - int offset; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_CHOICE ); - - p = (widget_choicegroup_t *) widget->private_data; - - getMousePosition(&x, &y); - - if( g_choicegroup == NULL ) - { - g_choicegroup = addImageData("choice.png", IMAGE_ALPHA, "choicegroup", IMAGE_GROUP_BASE); - } - - if( p->status == TRUE ) - { - offset = 0; - } - else - { - offset = WIDGET_CHOICEGROUP_WIDTH; - } - - drawImage(g_choicegroup, widget->x, widget->y, offset, 0, WIDGET_CHOICEGROUP_WIDTH, WIDGET_CHOICEGROUP_HEIGHT); -} - -void setWidgetChoiceActive(widget_t *widget) -{ - widget_choicegroup_t *p; - int i; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_CHOICE ); - - p = (widget_choicegroup_t *) widget->private_data; - - for( i = 0 ; i < p->list->count ; i++ ) - { - widget_t *this; - widget_choicegroup_t *thisChoice; - - this = (widget_t *) p->list->list[i]; - thisChoice = (widget_choicegroup_t *) this->private_data; - - if( widget == this ) - { - thisChoice->status = TRUE; - thisChoice->time = WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS; - thisChoice->fce_event(p); - } - else - { - thisChoice->status = FALSE; - } - } -} - -bool_t getWidgetChoiceStatus(widget_t *widget) -{ - widget_choicegroup_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_CHOICE ); - - p = (widget_choicegroup_t *) widget->private_data; - - return p->status; -} - -void setWidgetChoiceStatus(widget_t *widget, bool_t status) -{ - widget_choicegroup_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_CHOICE ); - - p = (widget_choicegroup_t *) widget->private_data; - p->status = status; -} - -void eventWidgetChoicegroup(widget_t *widget) -{ - widget_choicegroup_t *p; - int x, y; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_CHOICE ); - - p = (widget_choicegroup_t *) widget->private_data; - - if( p->time > 0 ) - { - p->time--; - return; - } - - getMousePosition(&x, &y); - - if( x >= widget->x && x <= widget->x+WIDGET_CHOICEGROUP_WIDTH && - y >= widget->y && y <= widget->y+WIDGET_CHOICEGROUP_HEIGHT && - isMouseClicked() ) - { - setWidgetChoiceActive(widget); - } -} - -void destroyWidgetChoicegroup(widget_t *widget) -{ - widget_choicegroup_t *p; - int index; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_CHOICE ); - - p = (widget_choicegroup_t *) widget->private_data; - index = searchListItem(p->list, widget); - assert( index != -1 ); - delList(p->list, index); - - free(p); - destroyWidget(widget); -} diff --git a/src/widget/widget_image.c b/src/widget/widget_image.c index 0194364..926a714 100644 --- a/src/widget/widget_image.c +++ b/src/widget/widget_image.c @@ -11,46 +11,42 @@ #include "widget.h" #include "widget_image.h" -widget_t * -newWidgetImage(int x, int y, image_t * image) +widget_t* newWidgetImage(int x, int y, image_t *image) { - widget_image_t *new; + widget_image_t *new; - new = malloc(sizeof(widget_image_t)); - new->image = image; + new = malloc( sizeof(widget_image_t) ); + new->image = image; - return newWidget(WIDGET_TYPE_IMAGE, x, y, image->w, image->h, new); + return newWidget(WIDGET_TYPE_IMAGE, x, y, image->w, image->h, new); } -void -drawWidgetImage(widget_t * widget) +void drawWidgetImage(widget_t *widget) { - widget_image_t *p; + widget_image_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_IMAGE); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_IMAGE ); - p = (widget_image_t *) widget->private_data; - drawImage(p->image, widget->x, widget->y, 0, 0, p->image->w, p->image->h); + p = (widget_image_t *) widget->private_data; + drawImage(p->image, widget->x, widget->y, 0, 0, p->image->w, p->image->h); } -void -eventWidgetImage(widget_t * widget) +void eventWidgetImage(widget_t *widget) { - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_IMAGE); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_IMAGE ); } -void -destroyWidgetImage(widget_t * widget) +void destroyWidgetImage(widget_t *widget) { - widget_image_t *p; + widget_image_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_IMAGE); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_IMAGE ); - p = (widget_image_t *) widget->private_data; + p = (widget_image_t *) widget->private_data; - free(p); - destroyWidget(widget); + free(p); + destroyWidget(widget); } diff --git a/src/widget/widget_image.c~ b/src/widget/widget_image.c~ deleted file mode 100644 index 926a714..0000000 --- a/src/widget/widget_image.c~ +++ /dev/null @@ -1,52 +0,0 @@ - -#include <stdlib.h> -#include <assert.h> - -#include <stdlib.h> -#include "main.h" -#include "image.h" -#include "interface.h" -#include "font.h" - -#include "widget.h" -#include "widget_image.h" - -widget_t* newWidgetImage(int x, int y, image_t *image) -{ - widget_image_t *new; - - new = malloc( sizeof(widget_image_t) ); - new->image = image; - - return newWidget(WIDGET_TYPE_IMAGE, x, y, image->w, image->h, new); -} - -void drawWidgetImage(widget_t *widget) -{ - widget_image_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_IMAGE ); - - p = (widget_image_t *) widget->private_data; - drawImage(p->image, widget->x, widget->y, 0, 0, p->image->w, p->image->h); -} - -void eventWidgetImage(widget_t *widget) -{ - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_IMAGE ); -} - -void destroyWidgetImage(widget_t *widget) -{ - widget_image_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_IMAGE ); - - p = (widget_image_t *) widget->private_data; - - free(p); - destroyWidget(widget); -} diff --git a/src/widget/widget_label.c b/src/widget/widget_label.c index 132a26d..c0b3f35 100644 --- a/src/widget/widget_label.c +++ b/src/widget/widget_label.c @@ -8,62 +8,58 @@ #include "widget_label.h" #include "widget.h" -widget_t * -newWidgetLabel(char *text, int x, int y, int bind) +widget_t* newWidgetLabel(char *text, int x, int y, int bind) { - widget_label_t *new; + widget_label_t *new; - new = malloc(sizeof(widget_label_t)); - new->text = strdup(text); - new->bind = bind; - getTextSize(text, &(new->w), &(new->h)); + new = malloc( sizeof(widget_label_t) ); + new->text = strdup(text); + new->bind = bind; + getTextSize(text, &(new->w), &(new->h)); - return newWidget(WIDGET_TYPE_LABEL, x, y, new->w, new->h, new); + return newWidget(WIDGET_TYPE_LABEL, x, y, new->w, new->h, new); } -void -drawWidgetLabel(widget_t * widget) +void drawWidgetLabel(widget_t *widget) { - widget_label_t *p; + widget_label_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_LABEL); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_LABEL ); - p = (widget_label_t *) widget->private_data; + p = (widget_label_t *) widget->private_data; - switch (p->bind) { - case WIDGET_LABEL_RIGHT: - drawFont(p->text, widget->x + p->w, widget->y + p->h / 2, COLOR_WHITE); - break; - case WIDGET_LABEL_LEFT: - drawFont(p->text, widget->x, widget->y + widget->h / 2, COLOR_WHITE); - break; - case WIDGET_LABEL_CENTER: - drawFont(p->text, widget->x - p->w / 2, widget->y + p->h / 2, - COLOR_WHITE); - break; - } + switch( p->bind ) + { + case WIDGET_LABEL_RIGHT : + drawFont(p->text, widget->x+p->w, widget->y + p->h/2, COLOR_WHITE); + break; + case WIDGET_LABEL_LEFT : + drawFont(p->text, widget->x, widget->y + widget->h/2, COLOR_WHITE); + break; + case WIDGET_LABEL_CENTER : + drawFont(p->text, widget->x-p->w/2, widget->y + p->h/2, COLOR_WHITE); + break; + } } -void -eventWidgetLabel(widget_t * widget) +void eventWidgetLabel(widget_t *widget) { - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_LABEL); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_LABEL ); } -void -destroyWidgetLabel(widget_t * widget) +void destroyWidgetLabel(widget_t *widget) { - widget_label_t *p; + widget_label_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_LABEL); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_LABEL ); - p = (widget_label_t *) widget->private_data; + p = (widget_label_t *) widget->private_data; - free(p->text); - free(p); + free(p->text); + free(p); - destroyWidget(widget); + destroyWidget(widget); } diff --git a/src/widget/widget_label.c~ b/src/widget/widget_label.c~ deleted file mode 100644 index c0b3f35..0000000 --- a/src/widget/widget_label.c~ +++ /dev/null @@ -1,65 +0,0 @@ - -#include <stdlib.h> -#include <assert.h> - -#include "main.h" -#include "interface.h" -#include "font.h" -#include "widget_label.h" -#include "widget.h" - -widget_t* newWidgetLabel(char *text, int x, int y, int bind) -{ - widget_label_t *new; - - new = malloc( sizeof(widget_label_t) ); - new->text = strdup(text); - new->bind = bind; - getTextSize(text, &(new->w), &(new->h)); - - return newWidget(WIDGET_TYPE_LABEL, x, y, new->w, new->h, new); -} - -void drawWidgetLabel(widget_t *widget) -{ - widget_label_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_LABEL ); - - p = (widget_label_t *) widget->private_data; - - switch( p->bind ) - { - case WIDGET_LABEL_RIGHT : - drawFont(p->text, widget->x+p->w, widget->y + p->h/2, COLOR_WHITE); - break; - case WIDGET_LABEL_LEFT : - drawFont(p->text, widget->x, widget->y + widget->h/2, COLOR_WHITE); - break; - case WIDGET_LABEL_CENTER : - drawFont(p->text, widget->x-p->w/2, widget->y + p->h/2, COLOR_WHITE); - break; - } -} - -void eventWidgetLabel(widget_t *widget) -{ - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_LABEL ); -} - -void destroyWidgetLabel(widget_t *widget) -{ - widget_label_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_LABEL ); - - p = (widget_label_t *) widget->private_data; - - free(p->text); - free(p); - - destroyWidget(widget); -} diff --git a/src/widget/widget_select.c b/src/widget/widget_select.c index 0288f50..0ec90c1 100644 --- a/src/widget/widget_select.c +++ b/src/widget/widget_select.c @@ -9,152 +9,152 @@ #include "widget.h" #include "widget_select.h" -widget_t * -newWidgetSelect(int x, int y, void (*fce_event) (void *)) +widget_t* newWidgetSelect(int x, int y, void (*fce_event)(void *)) { - widget_select_t *new; + widget_select_t *new; - new = malloc(sizeof(widget_select_t)); - new->select = -1; - new->fce_event = fce_event; - new->list = newList(); + new = malloc( sizeof(widget_select_t) ); + new->select = -1; + new->fce_event = fce_event; + new->list = newList(); - return newWidget(WIDGET_TYPE_SELECT, x, y, 0, 0, new); + return newWidget(WIDGET_TYPE_SELECT, x, y, 0, 0, new); } -char * -getWidgetSelectItem(widget_t * widget) +char* getWidgetSelectItem(widget_t *widget) { - widget_select_t *p; + widget_select_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_SELECT); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_SELECT ); - p = (widget_select_t *) widget->private_data; + p = (widget_select_t *)widget->private_data; - if (p->select == -1) { - return NULL; - } + if( p->select == -1 ) + { + return NULL; + } - return (char *) p->list->list[p->select]; + return (char *)p->list->list[p->select]; } -int -getWidgetSelectIndex(widget_t * widget) +int getWidgetSelectIndex(widget_t *widget) { - widget_select_t *p; + widget_select_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_SELECT); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_SELECT ); - p = (widget_select_t *) widget->private_data; + p = (widget_select_t *)widget->private_data; - return p->select; + return p->select; } -void -addToWidgetSelect(widget_t * widget, char *s) +void addToWidgetSelect(widget_t *widget, char *s) { - widget_select_t *p; + widget_select_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_SELECT); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_SELECT ); - p = (widget_select_t *) widget->private_data; + p = (widget_select_t *)widget->private_data; - addList(p->list, strdup(s)); + addList(p->list, strdup(s) ); } -void -removeAllFromWidgetSelect(widget_t * widget) +void removeAllFromWidgetSelect(widget_t *widget) { - widget_select_t *p; + widget_select_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_SELECT); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_SELECT ); - p = (widget_select_t *) widget->private_data; + p = (widget_select_t *)widget->private_data; - while (p->list->count > 0) { - delListItem(p->list, 0, free); - } + while( p->list->count > 0 ) + { + delListItem(p->list, 0, free); + } } -void -drawWidgetSelect(widget_t * widget) +void drawWidgetSelect(widget_t *widget) { - widget_select_t *p; - int x, y, w, h; - int i; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_SELECT); - - getMousePosition(&x, &y); - p = (widget_select_t *) widget->private_data; - - for (i = 0; i < p->list->count; i++) { - char *line; - - line = (char *) p->list->list[i]; - - getTextSize(line, &w, &h); - - if (x > widget->x && y > widget->y + i * 20 && x < widget->x + w - && y < widget->y + i * 20 + h) { - drawFont(line, widget->x, widget->y + i * 20, COLOR_YELLOW); - } - else { - if (p->select == i) { - drawFont(line, widget->x, widget->y + i * 20, COLOR_RED); - } - else { - drawFont(line, widget->x, widget->y + i * 20, COLOR_WHITE); - } - } - } + widget_select_t *p; + int x, y, w, h; + int i; + + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_SELECT ); + + getMousePosition(&x, &y); + p = (widget_select_t *)widget->private_data; + + for( i = 0 ; i < p->list->count ; i++ ) + { + char *line; + + line = (char *)p->list->list[i]; + + getTextSize(line, &w, &h); + + if( x > widget->x && y > widget->y + i*20 && x < widget->x+w && y < widget->y + i*20 + h ) + { + drawFont(line, widget->x, widget->y + i*20, COLOR_YELLOW); + } + else + { + if( p->select == i ) + { + drawFont(line, widget->x, widget->y + i*20, COLOR_RED); + } + else + { + drawFont(line, widget->x, widget->y + i*20, COLOR_WHITE); + } + } + } } -void -eventWidgetSelect(widget_t * widget) +void eventWidgetSelect(widget_t *widget) { - widget_select_t *p; - int x, y, w, h; - int i; + widget_select_t *p; + int x, y, w, h; + int i; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_SELECT); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_SELECT ); - p = (widget_select_t *) widget->private_data; - getMousePosition(&x, &y); + p = (widget_select_t *)widget->private_data; + getMousePosition(&x, &y); - for (i = 0; i < p->list->count; i++) { - char *line; + for( i = 0 ; i < p->list->count ; i++ ) + { + char *line; - line = (char *) p->list->list[i]; + line = (char *)p->list->list[i]; - getTextSize(line, &w, &h); + getTextSize(line, &w, &h); - if (x > widget->x && y > widget->y + i * 20 && - x < widget->x + w && y < widget->y + i * 20 + h && - isMouseClicked()) { - p->select = i; - p->fce_event(p); - } - } + if( x > widget->x && y > widget->y + i*20 && + x < widget->x+w && y < widget->y + i*20 + h && + isMouseClicked() ) + { + p->select = i; + p->fce_event(p); + } + } } -void -destroyWidgetSelect(widget_t * widget) +void destroyWidgetSelect(widget_t *widget) { - widget_select_t *p; + widget_select_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_SELECT); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_SELECT ); - p = (widget_select_t *) widget->private_data; + p = (widget_select_t *)widget->private_data; - destroyListItem(p->list, free); - free(p); - destroyWidget(widget); + destroyListItem(p->list, free); + free(p); + destroyWidget(widget); } diff --git a/src/widget/widget_select.c~ b/src/widget/widget_select.c~ deleted file mode 100644 index 0ec90c1..0000000 --- a/src/widget/widget_select.c~ +++ /dev/null @@ -1,160 +0,0 @@ - -#include <stdlib.h> -#include <assert.h> - -#include "main.h" -#include "interface.h" -#include "font.h" - -#include "widget.h" -#include "widget_select.h" - -widget_t* newWidgetSelect(int x, int y, void (*fce_event)(void *)) -{ - widget_select_t *new; - - new = malloc( sizeof(widget_select_t) ); - new->select = -1; - new->fce_event = fce_event; - new->list = newList(); - - return newWidget(WIDGET_TYPE_SELECT, x, y, 0, 0, new); -} - -char* getWidgetSelectItem(widget_t *widget) -{ - widget_select_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_SELECT ); - - p = (widget_select_t *)widget->private_data; - - if( p->select == -1 ) - { - return NULL; - } - - return (char *)p->list->list[p->select]; -} - -int getWidgetSelectIndex(widget_t *widget) -{ - widget_select_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_SELECT ); - - p = (widget_select_t *)widget->private_data; - - return p->select; -} - -void addToWidgetSelect(widget_t *widget, char *s) -{ - widget_select_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_SELECT ); - - p = (widget_select_t *)widget->private_data; - - addList(p->list, strdup(s) ); -} - -void removeAllFromWidgetSelect(widget_t *widget) -{ - widget_select_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_SELECT ); - - p = (widget_select_t *)widget->private_data; - - while( p->list->count > 0 ) - { - delListItem(p->list, 0, free); - } -} - -void drawWidgetSelect(widget_t *widget) -{ - widget_select_t *p; - int x, y, w, h; - int i; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_SELECT ); - - getMousePosition(&x, &y); - p = (widget_select_t *)widget->private_data; - - for( i = 0 ; i < p->list->count ; i++ ) - { - char *line; - - line = (char *)p->list->list[i]; - - getTextSize(line, &w, &h); - - if( x > widget->x && y > widget->y + i*20 && x < widget->x+w && y < widget->y + i*20 + h ) - { - drawFont(line, widget->x, widget->y + i*20, COLOR_YELLOW); - } - else - { - if( p->select == i ) - { - drawFont(line, widget->x, widget->y + i*20, COLOR_RED); - } - else - { - drawFont(line, widget->x, widget->y + i*20, COLOR_WHITE); - } - } - } -} - -void eventWidgetSelect(widget_t *widget) -{ - widget_select_t *p; - int x, y, w, h; - int i; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_SELECT ); - - p = (widget_select_t *)widget->private_data; - getMousePosition(&x, &y); - - for( i = 0 ; i < p->list->count ; i++ ) - { - char *line; - - line = (char *)p->list->list[i]; - - getTextSize(line, &w, &h); - - if( x > widget->x && y > widget->y + i*20 && - x < widget->x+w && y < widget->y + i*20 + h && - isMouseClicked() ) - { - p->select = i; - p->fce_event(p); - } - } -} - -void destroyWidgetSelect(widget_t *widget) -{ - widget_select_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_SELECT ); - - p = (widget_select_t *)widget->private_data; - - destroyListItem(p->list, free); - free(p); - destroyWidget(widget); -} diff --git a/src/widget/widget_textfield.c b/src/widget/widget_textfield.c index be4562c..e44bcd6 100644 --- a/src/widget/widget_textfield.c +++ b/src/widget/widget_textfield.c @@ -12,457 +12,476 @@ //#define ZZEEXX86_READKEY -widget_t * -newWidgetTextfield(char *text, int filter, int x, int y) +widget_t* newWidgetTextfield(char *text, int filter, int x, int y) { - widget_textfield_t *new; + widget_textfield_t *new; - new = malloc(sizeof(widget_textfield_t)); - memset(new, 0, sizeof(widget_textfield_t)); + new = malloc( sizeof(widget_textfield_t) ); + memset(new, 0, sizeof(widget_textfield_t)); - strcpy(new->text, text); - new->time = 0; - new->timeBlick = 0; - new->atime = 0; - new->active = FALSE; - new->filter = filter; - getTextSize(text, &new->w, &new->h); + strcpy(new->text, text); + new->time = 0; + new->timeBlick = 0; + new->atime = 0; + new->active = FALSE; + new->filter = filter; + getTextSize(text, &new->w, &new->h); - return newWidget(WIDGET_TYPE_TEXTFILED, x, y, WIDGET_TEXTFIELD_WIDTH, - WIDGET_TEXTFIELD_HEIGHT, new); + return newWidget(WIDGET_TYPE_TEXTFILED, x, y, WIDGET_TEXTFIELD_WIDTH, WIDGET_TEXTFIELD_HEIGHT, new); } -static void -drawBackground(widget_t * widget) +static void drawBackground(widget_t *widget) { - static image_t *g_textfield0 = NULL; - static image_t *g_textfield1 = NULL; - widget_textfield_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_TEXTFILED); - - p = (widget_textfield_t *) widget->private_data; - - if (g_textfield0 == NULL) { - g_textfield0 = - addImageData("textfield0.png", IMAGE_ALPHA, "textfiled0", - IMAGE_GROUP_BASE); - } - - if (g_textfield1 == NULL) { - g_textfield1 = - addImageData("textfield1.png", IMAGE_ALPHA, "textfiled1", - IMAGE_GROUP_BASE); - } - - if (p->active) { - drawImage(g_textfield1, widget->x, widget->y, 0, 0, g_textfield1->w, - g_textfield1->h); - } - else { - drawImage(g_textfield0, widget->x, widget->y, 0, 0, g_textfield0->w, - g_textfield0->h); - } + static image_t *g_textfield0 = NULL; + static image_t *g_textfield1 = NULL; + widget_textfield_t *p; + + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_TEXTFILED ); + + p = (widget_textfield_t *) widget->private_data; + + if( g_textfield0 == NULL ) + { + g_textfield0 = addImageData("textfield0.png", IMAGE_ALPHA, "textfiled0", IMAGE_GROUP_BASE); + } + + if( g_textfield1 == NULL ) + { + g_textfield1 = addImageData("textfield1.png", IMAGE_ALPHA, "textfiled1", IMAGE_GROUP_BASE); + } + + if( p->active ) + { + drawImage(g_textfield1, widget->x, widget->y, 0, 0, g_textfield1->w, g_textfield1->h); + } + else + { + drawImage(g_textfield0, widget->x, widget->y, 0, 0, g_textfield0->w, g_textfield0->h); + } } -static void -drawText(widget_t * widget) +static void drawText(widget_t *widget) { - char str[STR_SIZE]; - widget_textfield_t *p; + char str[STR_SIZE]; + widget_textfield_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_TEXTFILED); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_TEXTFILED ); - p = (widget_textfield_t *) widget->private_data; + p = (widget_textfield_t *) widget->private_data; - strcpy(str, p->text); + strcpy(str, p->text); - if (p->timeBlick > WIDGET_TEXTFIELD_TIME_BLICK_CURSOR / 2 && - p->active == TRUE) { - //strcat(str, ">"); - strcat(str, "\f"); - } + if( p->timeBlick > WIDGET_TEXTFIELD_TIME_BLICK_CURSOR/2 && + p->active == TRUE ) + { + //strcat(str, ">"); + strcat(str, "\f"); + } - p->timeBlick++; + p->timeBlick++; - if (p->timeBlick == WIDGET_TEXTFIELD_TIME_BLICK_CURSOR) { - p->timeBlick = 0; - } + if( p->timeBlick == WIDGET_TEXTFIELD_TIME_BLICK_CURSOR ) + { + p->timeBlick = 0; + } - //drawFont(str, p->x+WIDGET_TEXTFIELD_TEXT_OFFSET_X, p->y+p->h/2, COLOR_WHITE); - //printf("p->y: %d\nheight: %d\n p->h: %d\n", p->y, WIDGET_TEXTFIELD_HEIGHT, p->h); + //drawFont(str, p->x+WIDGET_TEXTFIELD_TEXT_OFFSET_X, p->y+p->h/2, COLOR_WHITE); + //printf("p->y: %d\nheight: %d\n p->h: %d\n", p->y, WIDGET_TEXTFIELD_HEIGHT, p->h); - drawFont(str, - widget->x + WIDGET_TEXTFIELD_TEXT_OFFSET_X, - widget->y + WIDGET_TEXTFIELD_HEIGHT / 2 - p->h / 2, COLOR_WHITE); + drawFont(str, + widget->x+WIDGET_TEXTFIELD_TEXT_OFFSET_X, + widget->y+WIDGET_TEXTFIELD_HEIGHT/2-p->h/2, + COLOR_WHITE); } -void -drawWidgetTextfield(widget_t * widget) +void drawWidgetTextfield(widget_t *widget) { - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_TEXTFILED); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_TEXTFILED ); - drawBackground(widget); - drawText(widget); + drawBackground(widget); + drawText(widget); } -void -setWidgetTextFiledText(widget_t * widget, char *text) +void setWidgetTextFiledText(widget_t *widget, char *text) { - widget_textfield_t *p; + widget_textfield_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_TEXTFILED); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_TEXTFILED ); - p = (widget_textfield_t *) widget->private_data; + p = (widget_textfield_t *) widget->private_data; - memset(p->text, 0, STR_SIZE); - strcpy(p->text, text); - getTextSize(text, &p->w, &p->h); + memset(p->text, 0, STR_SIZE); + strcpy(p->text, text); + getTextSize(text, &p->w, &p->h); } -char * -getTextFromWidgetTextfield(widget_t * widget) +char* getTextFromWidgetTextfield(widget_t *widget) { - widget_textfield_t *p; + widget_textfield_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_TEXTFILED); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_TEXTFILED ); - p = (widget_textfield_t *) widget->private_data; - return p->text; + p = (widget_textfield_t *) widget->private_data; + return p->text; } -static void -checkText(widget_textfield_t * p) +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 == '_' || 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); + 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 == '_' || 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); } #ifdef ZZEEXX86_READKEY -static void -readKey(widget_textfield_t * p) +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; - } - - if (p->atime < 100) - p->atime++; - - mapa = SDL_GetKeyState(NULL); - len = strlen(p->text); - - // mazanie posledneho klavesu - if (mapa[SDLK_BACKSPACE] == SDL_PRESSED) { - if (len > 0) { - p->time = 0; - p->text[len - 1] = '\0'; - getTextSize(p->text, &p->w, &p->h); - } - - return; - } - - if (p->w > WIDGET_TEXTFIELD_WIDTH - 40) { - return; - } - - // klavesy abecedy - for (i = SDLK_SPACE /*SDLK_a */ ; i <= SDLK_z; i++) { - //if(width<TEXTFIELD_SIZE_X-20 && mapa[i]==SDL_PRESSED) - if (mapa[i] == SDL_PRESSED && len < STR_SIZE) { - if (i == SDLK_SPACE) { - strcat(p->text, " "); - checkText(p); - return; - } - - const char *c = (const char *) SDL_GetKeyName(i); - - if (len) { - 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; - - strcat(p->text, c); - checkText(p); - - if (mapa[SDLK_LSHIFT] == SDL_PRESSED || - mapa[SDLK_RSHIFT] == SDL_PRESSED) { - p->text[strlen(p->text) - 1] -= 32; - checkText(p); - return; - } - } - } - - // aby ve jmene bulanka fungovaly take cislice alfanumericke klavesnice - for (i = SDLK_0; i <= SDLK_9; i++) { - if (mapa[i] == SDL_PRESSED && len < STR_SIZE) { - const char *c = (const char *) SDL_GetKeyName(i); - - if (len) { - 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; - - strcat(p->text, c); - checkText(p); - return; - } - } - - // aby ve jmene bulanka fungovaly take cislice napsane na numericke klavesnici - for (i = SDLK_KP0; i <= SDLK_KP9; i++) { - if (mapa[i] == SDL_PRESSED && len < STR_SIZE) { - const char *c = (const char *) SDL_GetKeyName(i) + 1; - - if (len) { - 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; - - strncat(p->text, c, 1); // napr. "[4]" - checkText(p); - return; - } - } + Uint8 *mapa; + int len; + int i; + + //printf("readKey w=%d\n", p->w); + + if( p->active == FALSE ) + { + return; + } + + if (p->atime < 100) + p->atime ++; + + mapa = SDL_GetKeyState(NULL); + len = strlen(p->text); + + // mazanie posledneho klavesu + if( mapa[SDLK_BACKSPACE] == SDL_PRESSED ) + { + if( len > 0 ) + { + p->time = 0; + p->text[len-1]='\0'; + getTextSize(p->text, &p->w, &p->h); + } + + return; + } + + if( p->w > WIDGET_TEXTFIELD_WIDTH-40 ) + { + return; + } + + // klavesy abecedy + for(i=SDLK_SPACE /*SDLK_a*/;i<=SDLK_z;i++) + { + //if(width<TEXTFIELD_SIZE_X-20 && mapa[i]==SDL_PRESSED) + if( mapa[i] == SDL_PRESSED && len < STR_SIZE ) + { + if (i == SDLK_SPACE) + { + strcat( p->text, " " ); + checkText(p); + return; + } + + const char *c = (const char *) SDL_GetKeyName(i); + + if (len) { + 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; + + strcat( p->text, c ); + checkText(p); + + if( mapa[SDLK_LSHIFT] == SDL_PRESSED || + mapa[SDLK_RSHIFT] == SDL_PRESSED) + { + p->text[ strlen( p->text ) - 1 ] -= 32; + checkText(p); + return; + } + } + } + + // aby ve jmene bulanka fungovaly take cislice alfanumericke klavesnice + for( i = SDLK_0 ; i <= SDLK_9 ; i++ ) + { + if( mapa[i] == SDL_PRESSED && len < STR_SIZE ) + { + const char *c = (const char *) SDL_GetKeyName(i); + + if (len) { + 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; + + strcat( p->text, c ); + checkText(p); + return; + } + } + + // aby ve jmene bulanka fungovaly take cislice napsane na numericke klavesnici + for( i=SDLK_KP0 ; i<=SDLK_KP9 ; i++ ) + { + if( mapa[i] == SDL_PRESSED && len < STR_SIZE ) + { + const char *c = (const char *) SDL_GetKeyName(i)+1; + + if (len) { + 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; + + strncat( p->text, c, 1 ); // napr. "[4]" + checkText(p); + return; + } + } } #endif #ifndef ZZEEXX86_READKEY -static void -readKey(widget_textfield_t * p) +static void readKey(widget_textfield_t *p) { - Uint8 *mapa; - int len; - int i; - - const int len_shift_map = 20; - - char shift_map[] = { - '-', '_', - '=', '+', - '[', '{', - ']', '}', - ';', ':', - '/', '\"', - '\\', '|', - ',', '<', - '.', '>', - '/', '?' - }; - - 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; - //printf("name %s\n", name); - - if (strlen(name) == 1) - c = name[0]; - if (strlen(name) == 3) - c = name[1]; - if (strcmp(name, "space") == 0) - c = ' '; - - - 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) { - int i; - - for (i = 0; i < len_shift_map; i += 2) { - if (c == shift_map[i]) { - p->text[len] = shift_map[i + 1]; - } - } - - checkText(p); - return; - } - - if (mapa[SDLK_LSHIFT] == SDL_PRESSED || - mapa[SDLK_RSHIFT] == SDL_PRESSED) { - p->text[len] -= 32; - } - - checkText(p); - return; - } - } + Uint8 *mapa; + int len; + int i; + + const int len_shift_map = 20; + + char shift_map[] = + { + '-', '_', + '=', '+', + '[', '{', + ']', '}', + ';', ':', + '/', '\"', + '\\', '|', + ',', '<', + '.', '>', + '/', '?' + }; + + 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; + //printf("name %s\n", name); + + if( strlen(name) == 1 )c = name[0]; + if( strlen(name) == 3 )c = name[1]; + if( strcmp(name, "space") == 0 )c = ' '; + + + 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) + { + int i; + + for( i = 0 ; i < len_shift_map ; i+= 2 ) + { + if( c == shift_map[i] ) + { + p->text[len] = shift_map[i+1]; + } + } + + checkText(p); + return; + } + + if( mapa[SDLK_LSHIFT] == SDL_PRESSED || + mapa[SDLK_RSHIFT] == SDL_PRESSED) + { + p->text[len] -= 32; + } + + checkText(p); + return; + } + } } #endif -void -eventWidgetTextfield(widget_t * widget) +void eventWidgetTextfield(widget_t *widget) { - widget_textfield_t *p; - int x, y; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_TEXTFILED); - - p = (widget_textfield_t *) widget->private_data; - - getMousePosition(&x, &y); - - if (isMouseClicked()) { - if (x >= widget->x && x <= widget->x + WIDGET_TEXTFIELD_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_TEXTFIELD_HEIGHT) { - p->active = TRUE; - } - else { - p->active = FALSE; - } - } - - readKey(p); + widget_textfield_t *p; + int x, y; + + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_TEXTFILED ); + + p = (widget_textfield_t *) widget->private_data; + + getMousePosition(&x, &y); + + if( isMouseClicked() ) + { + if( x >= widget->x && x <= widget->x+WIDGET_TEXTFIELD_WIDTH && + y >= widget->y && y <= widget->y+WIDGET_TEXTFIELD_HEIGHT ) + { + p->active = TRUE; + } + else + { + p->active = FALSE; + } + } + + readKey(p); } -void -destroyWidgetTextfield(widget_t * widget) +void destroyWidgetTextfield(widget_t *widget) { - widget_textfield_t *p; + widget_textfield_t *p; - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_TEXTFILED); + assert( widget != NULL ); + assert( widget->type == WIDGET_TYPE_TEXTFILED ); - p = (widget_textfield_t *) widget->private_data; + p = (widget_textfield_t *) widget->private_data; - free(p); - destroyWidget(widget); + free(p); + destroyWidget(widget); } + diff --git a/src/widget/widget_textfield.c~ b/src/widget/widget_textfield.c~ deleted file mode 100644 index e44bcd6..0000000 --- a/src/widget/widget_textfield.c~ +++ /dev/null @@ -1,487 +0,0 @@ - -#include <stdlib.h> -#include <assert.h> - -#include "main.h" -#include "interface.h" -#include "font.h" -#include "image.h" - -#include "widget.h" -#include "widget_textfield.h" - -//#define ZZEEXX86_READKEY - -widget_t* newWidgetTextfield(char *text, int filter, int x, int y) -{ - widget_textfield_t *new; - - new = malloc( sizeof(widget_textfield_t) ); - memset(new, 0, sizeof(widget_textfield_t)); - - strcpy(new->text, text); - new->time = 0; - new->timeBlick = 0; - new->atime = 0; - new->active = FALSE; - new->filter = filter; - getTextSize(text, &new->w, &new->h); - - return newWidget(WIDGET_TYPE_TEXTFILED, x, y, WIDGET_TEXTFIELD_WIDTH, WIDGET_TEXTFIELD_HEIGHT, new); -} - -static void drawBackground(widget_t *widget) -{ - static image_t *g_textfield0 = NULL; - static image_t *g_textfield1 = NULL; - widget_textfield_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_TEXTFILED ); - - p = (widget_textfield_t *) widget->private_data; - - if( g_textfield0 == NULL ) - { - g_textfield0 = addImageData("textfield0.png", IMAGE_ALPHA, "textfiled0", IMAGE_GROUP_BASE); - } - - if( g_textfield1 == NULL ) - { - g_textfield1 = addImageData("textfield1.png", IMAGE_ALPHA, "textfiled1", IMAGE_GROUP_BASE); - } - - if( p->active ) - { - drawImage(g_textfield1, widget->x, widget->y, 0, 0, g_textfield1->w, g_textfield1->h); - } - else - { - drawImage(g_textfield0, widget->x, widget->y, 0, 0, g_textfield0->w, g_textfield0->h); - } -} - -static void drawText(widget_t *widget) -{ - char str[STR_SIZE]; - widget_textfield_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_TEXTFILED ); - - p = (widget_textfield_t *) widget->private_data; - - strcpy(str, p->text); - - if( p->timeBlick > WIDGET_TEXTFIELD_TIME_BLICK_CURSOR/2 && - p->active == TRUE ) - { - //strcat(str, ">"); - strcat(str, "\f"); - } - - p->timeBlick++; - - if( p->timeBlick == WIDGET_TEXTFIELD_TIME_BLICK_CURSOR ) - { - p->timeBlick = 0; - } - - //drawFont(str, p->x+WIDGET_TEXTFIELD_TEXT_OFFSET_X, p->y+p->h/2, COLOR_WHITE); - //printf("p->y: %d\nheight: %d\n p->h: %d\n", p->y, WIDGET_TEXTFIELD_HEIGHT, p->h); - - drawFont(str, - widget->x+WIDGET_TEXTFIELD_TEXT_OFFSET_X, - widget->y+WIDGET_TEXTFIELD_HEIGHT/2-p->h/2, - COLOR_WHITE); -} - -void drawWidgetTextfield(widget_t *widget) -{ - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_TEXTFILED ); - - drawBackground(widget); - drawText(widget); -} - -void setWidgetTextFiledText(widget_t *widget, char *text) -{ - widget_textfield_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_TEXTFILED ); - - p = (widget_textfield_t *) widget->private_data; - - memset(p->text, 0, STR_SIZE); - strcpy(p->text, text); - getTextSize(text, &p->w, &p->h); -} - -char* getTextFromWidgetTextfield(widget_t *widget) -{ - widget_textfield_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_TEXTFILED ); - - p = (widget_textfield_t *) widget->private_data; - return p->text; -} - -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 == '_' || 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); - -} - -#ifdef ZZEEXX86_READKEY -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; - } - - if (p->atime < 100) - p->atime ++; - - mapa = SDL_GetKeyState(NULL); - len = strlen(p->text); - - // mazanie posledneho klavesu - if( mapa[SDLK_BACKSPACE] == SDL_PRESSED ) - { - if( len > 0 ) - { - p->time = 0; - p->text[len-1]='\0'; - getTextSize(p->text, &p->w, &p->h); - } - - return; - } - - if( p->w > WIDGET_TEXTFIELD_WIDTH-40 ) - { - return; - } - - // klavesy abecedy - for(i=SDLK_SPACE /*SDLK_a*/;i<=SDLK_z;i++) - { - //if(width<TEXTFIELD_SIZE_X-20 && mapa[i]==SDL_PRESSED) - if( mapa[i] == SDL_PRESSED && len < STR_SIZE ) - { - if (i == SDLK_SPACE) - { - strcat( p->text, " " ); - checkText(p); - return; - } - - const char *c = (const char *) SDL_GetKeyName(i); - - if (len) { - 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; - - strcat( p->text, c ); - checkText(p); - - if( mapa[SDLK_LSHIFT] == SDL_PRESSED || - mapa[SDLK_RSHIFT] == SDL_PRESSED) - { - p->text[ strlen( p->text ) - 1 ] -= 32; - checkText(p); - return; - } - } - } - - // aby ve jmene bulanka fungovaly take cislice alfanumericke klavesnice - for( i = SDLK_0 ; i <= SDLK_9 ; i++ ) - { - if( mapa[i] == SDL_PRESSED && len < STR_SIZE ) - { - const char *c = (const char *) SDL_GetKeyName(i); - - if (len) { - 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; - - strcat( p->text, c ); - checkText(p); - return; - } - } - - // aby ve jmene bulanka fungovaly take cislice napsane na numericke klavesnici - for( i=SDLK_KP0 ; i<=SDLK_KP9 ; i++ ) - { - if( mapa[i] == SDL_PRESSED && len < STR_SIZE ) - { - const char *c = (const char *) SDL_GetKeyName(i)+1; - - if (len) { - 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; - - strncat( p->text, c, 1 ); // napr. "[4]" - checkText(p); - return; - } - } -} -#endif - -#ifndef ZZEEXX86_READKEY -static void readKey(widget_textfield_t *p) -{ - Uint8 *mapa; - int len; - int i; - - const int len_shift_map = 20; - - char shift_map[] = - { - '-', '_', - '=', '+', - '[', '{', - ']', '}', - ';', ':', - '/', '\"', - '\\', '|', - ',', '<', - '.', '>', - '/', '?' - }; - - 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; - //printf("name %s\n", name); - - if( strlen(name) == 1 )c = name[0]; - if( strlen(name) == 3 )c = name[1]; - if( strcmp(name, "space") == 0 )c = ' '; - - - 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) - { - int i; - - for( i = 0 ; i < len_shift_map ; i+= 2 ) - { - if( c == shift_map[i] ) - { - p->text[len] = shift_map[i+1]; - } - } - - checkText(p); - return; - } - - if( mapa[SDLK_LSHIFT] == SDL_PRESSED || - mapa[SDLK_RSHIFT] == SDL_PRESSED) - { - p->text[len] -= 32; - } - - checkText(p); - return; - } - } -} -#endif - -void eventWidgetTextfield(widget_t *widget) -{ - widget_textfield_t *p; - int x, y; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_TEXTFILED ); - - p = (widget_textfield_t *) widget->private_data; - - getMousePosition(&x, &y); - - if( isMouseClicked() ) - { - if( x >= widget->x && x <= widget->x+WIDGET_TEXTFIELD_WIDTH && - y >= widget->y && y <= widget->y+WIDGET_TEXTFIELD_HEIGHT ) - { - p->active = TRUE; - } - else - { - p->active = FALSE; - } - } - - readKey(p); -} - -void destroyWidgetTextfield(widget_t *widget) -{ - widget_textfield_t *p; - - assert( widget != NULL ); - assert( widget->type == WIDGET_TYPE_TEXTFILED ); - - p = (widget_textfield_t *) widget->private_data; - - free(p); - destroyWidget(widget); -} - |