diff options
Diffstat (limited to 'src/widget')
| -rw-r--r-- | src/widget/widget.c | 62 | ||||
| -rw-r--r-- | src/widget/widget.h | 35 | ||||
| -rw-r--r-- | src/widget/widget_button.c | 149 | ||||
| -rw-r--r-- | src/widget/widget_button.h | 23 | ||||
| -rw-r--r-- | src/widget/widget_buttonimage.c | 108 | ||||
| -rw-r--r-- | src/widget/widget_buttonimage.h | 21 | ||||
| -rw-r--r-- | src/widget/widget_catchkey.c | 173 | ||||
| -rw-r--r-- | src/widget/widget_catchkey.h | 23 | ||||
| -rw-r--r-- | src/widget/widget_check.c | 165 | ||||
| -rw-r--r-- | src/widget/widget_check.h | 23 | ||||
| -rw-r--r-- | src/widget/widget_choicegroup.c | 205 | ||||
| -rw-r--r-- | src/widget/widget_choicegroup.h | 29 | ||||
| -rw-r--r-- | src/widget/widget_image.c | 46 | ||||
| -rw-r--r-- | src/widget/widget_image.h | 13 | ||||
| -rw-r--r-- | src/widget/widget_label.c | 75 | ||||
| -rw-r--r-- | src/widget/widget_label.h | 21 | ||||
| -rw-r--r-- | src/widget/widget_select.c | 194 | ||||
| -rw-r--r-- | src/widget/widget_select.h | 19 | ||||
| -rw-r--r-- | src/widget/widget_textfield.c | 767 | ||||
| -rw-r--r-- | src/widget/widget_textfield.h | 57 |
20 files changed, 1059 insertions, 1149 deletions
diff --git a/src/widget/widget.c b/src/widget/widget.c index 4eaca17..0dcfb41 100644 --- a/src/widget/widget.c +++ b/src/widget/widget.c @@ -7,56 +7,50 @@ #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.h b/src/widget/widget.h index 05fce33..c18a687 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -1,30 +1,29 @@ #ifndef WIDGET_H -#define WIDGET_H +# define WIDGET_H -#include "main.h" +# include "main.h" -#define WIDGET_TYPE_LABEL 1 -#define WIDGET_TYPE_BUTTON 2 -#define WIDGET_TYPE_BUTTONIMAGE 3 -#define WIDGET_TYPE_TEXTFILED 4 -#define WIDGET_TYPE_CATCHKEY 4 -#define WIDGET_TYPE_CHECK 5 -#define WIDGET_TYPE_CHOICE 6 -#define WIDGET_TYPE_IMAGE 7 -#define WIDGET_TYPE_SELECT 8 +# define WIDGET_TYPE_LABEL 1 +# define WIDGET_TYPE_BUTTON 2 +# define WIDGET_TYPE_BUTTONIMAGE 3 +# define WIDGET_TYPE_TEXTFILED 4 +# define WIDGET_TYPE_CATCHKEY 4 +# define WIDGET_TYPE_CHECK 5 +# define WIDGET_TYPE_CHOICE 6 +# define WIDGET_TYPE_IMAGE 7 +# define WIDGET_TYPE_SELECT 8 -typedef struct widget_struct -{ - int type; - int x, y; - int w, h; - void *private_data; +typedef struct widget_struct { + int type; + int x, y; + int w, h; + void *private_data; } widget_t; extern widget_t *newWidget(int type, int x, int y, int w, int h, - void *private_data); + void *private_data); extern void widgetSetLocation(widget_t * p, int x, int y); extern void widgetGetLocation(widget_t * p, int *x, int *y); extern void widgetSetSize(widget_t * p, int w, int h); diff --git a/src/widget/widget_button.c b/src/widget/widget_button.c index 10391e7..d02a568 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.h b/src/widget/widget_button.h index a0e50db..ac238be 100644 --- a/src/widget/widget_button.h +++ b/src/widget/widget_button.h @@ -1,25 +1,24 @@ #ifndef WIDGET_BUTTON_H -#define WIDGET_BUTTON_H +# define WIDGET_BUTTON_H -#include "main.h" -#include "widget.h" +# include "main.h" +# include "widget.h" -#define WIDGET_BUTTON_TIME 10 +# define WIDGET_BUTTON_TIME 10 -#define WIDGET_BUTTON_WIDTH 125 -#define WIDGET_BUTTON_HEIGHT 36 +# define WIDGET_BUTTON_WIDTH 125 +# define WIDGET_BUTTON_HEIGHT 36 -typedef struct widget_button -{ - char *text; - int w, h; - void (*fce_event) (void *); +typedef struct widget_button { + char *text; + int w, h; + void (*fce_event) (void *); } widget_button_t; extern widget_t *newWidgetButton(char *text, int x, int y, - void (*fce_event) (void *)); + void (*fce_event) (void *)); extern void drawWidgetButton(widget_t * widget); extern void eventWidgetButton(widget_t * widget); extern void destroyWidgetButton(widget_t * widget); diff --git a/src/widget/widget_buttonimage.c b/src/widget/widget_buttonimage.c index 8c567a3..6c89d79 100644 --- a/src/widget/widget_buttonimage.c +++ b/src/widget/widget_buttonimage.c @@ -10,83 +10,77 @@ #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.h b/src/widget/widget_buttonimage.h index a607127..5a0ab7c 100644 --- a/src/widget/widget_buttonimage.h +++ b/src/widget/widget_buttonimage.h @@ -1,24 +1,23 @@ #ifndef WIDGET_BUTTONIMAGE_H -#include "main.h" +# include "main.h" -#define WIDGET_BUTTONIMAGE_H +# define WIDGET_BUTTONIMAGE_H -#define WIDGET_BUTTONIMAGE_TIME 10 +# define WIDGET_BUTTONIMAGE_TIME 10 -#include "widget.h" +# include "widget.h" -typedef struct widget_buttonimageimage -{ - int w, h; - int active; - image_t *image; - void (*fce_event) (void *); +typedef struct widget_buttonimageimage { + int w, h; + int active; + image_t *image; + void (*fce_event) (void *); } widget_buttonimage_t; extern widget_t *newWidgetButtonimage(image_t * image, int x, int y, - void (*fce_event) (void *)); + void (*fce_event) (void *)); extern void setWidgetButtonimageActive(widget_t * widget, bool_t active); extern void drawWidgetButtonimage(widget_t * widget); diff --git a/src/widget/widget_catchkey.c b/src/widget/widget_catchkey.c index fd3389e..37fab55 100644 --- a/src/widget/widget_catchkey.c +++ b/src/widget/widget_catchkey.c @@ -9,141 +9,132 @@ #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; + widget_catchkey_t *p; + char *name; - 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; - name = NULL; + p = (widget_catchkey_t *) widget->private_data; + name = NULL; - if (p->key != WIDGET_CATCHKEY_NOKEY) { - name = (char *) SDL_GetKeyName(p->key); - } + if (p->key != WIDGET_CATCHKEY_NOKEY) { + name = (char *) SDL_GetKeyName(p->key); + } - if (name == NULL) { - name = "no 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); - } + 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; + Uint8 *mapa; + int i; - mapa = SDL_GetKeyState(NULL); + 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; - } + 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; - } - } + if (mapa[i] == SDL_PRESSED) { + return i; + } + } - return WIDGET_CATCHKEY_NOKEY; + return WIDGET_CATCHKEY_NOKEY; } -void -eventWidgetCatchkey(widget_t * widget) +void eventWidgetCatchkey(widget_t * widget) { - widget_catchkey_t *p; - int x, y; + widget_catchkey_t *p; + int x, y; - 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; - getMousePosition(&x, &y); + 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 (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; + if (p->active == TRUE) { + int key; - key = getPessAnyKey(); + key = getPessAnyKey(); - if (key != WIDGET_CATCHKEY_NOKEY) { - p->key = key; - p->fce_event(widget); - } - } + 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.h b/src/widget/widget_catchkey.h index 1b318c6..106bc92 100644 --- a/src/widget/widget_catchkey.h +++ b/src/widget/widget_catchkey.h @@ -1,21 +1,20 @@ #ifndef WIDGET_CATCHKEY_H -#define WIDGET_CATCHKEY_H +# define WIDGET_CATCHKEY_H -#include "main.h" -#include "widget.h" +# include "main.h" +# include "widget.h" -#define WIDGET_CATCHKEY_WIDTH 110 -#define WIDGET_CATCHKEY_HEIGHT 12 +# define WIDGET_CATCHKEY_WIDTH 110 +# define WIDGET_CATCHKEY_HEIGHT 12 -#define WIDGET_CATCHKEY_NOKEY -1 +# define WIDGET_CATCHKEY_NOKEY -1 -typedef struct widget_catchkey_struct -{ - int w, h; - int key; - bool_t active; - void (*fce_event) (void *p); +typedef struct widget_catchkey_struct { + int w, h; + int key; + bool_t active; + void (*fce_event) (void *p); } widget_catchkey_t; extern widget_t *newWidgetCatchkey(int key, int x, int y, void *event); diff --git a/src/widget/widget_check.c b/src/widget/widget_check.c index 6ca1203..e57f151 100644 --- a/src/widget/widget_check.c +++ b/src/widget/widget_check.c @@ -9,121 +9,114 @@ #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(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(widget); + } + } } -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.h b/src/widget/widget_check.h index df42001..007e82c 100644 --- a/src/widget/widget_check.h +++ b/src/widget/widget_check.h @@ -1,25 +1,24 @@ #ifndef WIDGET_CHECK_H -#define WIDGET_CHECK_H +# define WIDGET_CHECK_H -#include "main.h" -#include "widget.h" +# include "main.h" +# include "widget.h" -#define WIDGET_CHECK_TIME_SWITCH_STATUS 5 +# define WIDGET_CHECK_TIME_SWITCH_STATUS 5 -#define WIDGET_CHECK_WIDTH 25 -#define WIDGET_CHECK_HEIGHT 25 +# define WIDGET_CHECK_WIDTH 25 +# define WIDGET_CHECK_HEIGHT 25 -typedef struct widget_check -{ - bool_t status; - int time; - void (*fce_event) (void *); +typedef struct widget_check { + bool_t status; + int time; + void (*fce_event) (void *); } widget_check_t; extern widget_t *newWidgetCheck(int x, int y, bool_t status, - void (*fce_event) (void *)); + void (*fce_event) (void *)); extern void drawWidgetCheck(widget_t * widget); extern void eventWidgetCheck(widget_t * widget); extern bool_t getWidgetCheckStatus(widget_t * widget); diff --git a/src/widget/widget_choicegroup.c b/src/widget/widget_choicegroup.c index 62eeb89..64533af 100644 --- a/src/widget/widget_choicegroup.c +++ b/src/widget/widget_choicegroup.c @@ -9,152 +9,143 @@ #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.h b/src/widget/widget_choicegroup.h index 8cc6764..a892d74 100644 --- a/src/widget/widget_choicegroup.h +++ b/src/widget/widget_choicegroup.h @@ -1,28 +1,27 @@ #ifndef WIDGET_CHOICEGROUP_H -#define WIDGET_CHOICEGROUP_H +# define WIDGET_CHOICEGROUP_H -#include "main.h" -#include "list.h" -#include "widget.h" +# include "main.h" +# include "list.h" +# include "widget.h" -#define WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS 5 +# define WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS 5 -#define WIDGET_CHOICEGROUP_WIDTH 25 -#define WIDGET_CHOICEGROUP_HEIGHT 25 +# define WIDGET_CHOICEGROUP_WIDTH 25 +# define WIDGET_CHOICEGROUP_HEIGHT 25 -typedef struct widget_choicegroup -{ - bool_t status; - int time; - void (*fce_event) (void *); - list_t *list; +typedef struct widget_choicegroup { + bool_t status; + int time; + void (*fce_event) (void *); + list_t *list; } widget_choicegroup_t; extern widget_t *newWidgetChoicegroup(int x, int y, bool_t status, - list_t * list, - void (*fce_event) (void *)); + list_t * list, + void (*fce_event) (void *)); extern void drawWidgetChoicegroup(widget_t * p); extern void setWidgetChoiceActive(widget_t * widget); diff --git a/src/widget/widget_image.c b/src/widget/widget_image.c index 2287541..ad49f9e 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.h b/src/widget/widget_image.h index 86cf6bc..081fbda 100644 --- a/src/widget/widget_image.h +++ b/src/widget/widget_image.h @@ -1,15 +1,14 @@ #ifndef WIDGET_IMAGE_H -#define WIDGET_IMAGE_H +# define WIDGET_IMAGE_H -#include "main.h" -#include "interface.h" -#include "widget.h" +# include "main.h" +# include "interface.h" +# include "widget.h" -typedef struct widget_image -{ - image_t *image; +typedef struct widget_image { + image_t *image; } widget_image_t; extern widget_t *newWidgetImage(int x, int y, image_t * image); diff --git a/src/widget/widget_label.c b/src/widget/widget_label.c index 449f916..d4bb813 100644 --- a/src/widget/widget_label.c +++ b/src/widget/widget_label.c @@ -8,63 +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.h b/src/widget/widget_label.h index 8ad29b5..743db7e 100644 --- a/src/widget/widget_label.h +++ b/src/widget/widget_label.h @@ -1,21 +1,20 @@ #ifndef WIDGET_LABEL_H -#define WIDGET_LABEL_H +# define WIDGET_LABEL_H -#include "main.h" -#include "widget.h" +# include "main.h" +# include "widget.h" -typedef struct widget_label -{ - int w, h; - char *text; - int bind; +typedef struct widget_label { + int w, h; + char *text; + int bind; } widget_label_t; -#define WIDGET_LABEL_RIGHT 1 -#define WIDGET_LABEL_LEFT 2 -#define WIDGET_LABEL_CENTER 3 +# define WIDGET_LABEL_RIGHT 1 +# define WIDGET_LABEL_LEFT 2 +# define WIDGET_LABEL_CENTER 3 extern widget_t *newWidgetLabel(char *text, int x, int y, int bind); extern void drawWidgetLabel(widget_t * widget); diff --git a/src/widget/widget_select.c b/src/widget/widget_select.c index 78877f0..2f89fe2 100644 --- a/src/widget/widget_select.c +++ b/src/widget/widget_select.c @@ -9,152 +9,142 @@ #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.h b/src/widget/widget_select.h index ba7b9d4..9d772cc 100644 --- a/src/widget/widget_select.h +++ b/src/widget/widget_select.h @@ -1,18 +1,17 @@ #ifndef WIDGET_SELECT_H -#define WIDGET_SELECT_H +# define WIDGET_SELECT_H -#include "main.h" -#include "list.h" -#include "widget.h" +# include "main.h" +# include "list.h" +# include "widget.h" -typedef struct widget_select -{ - int w, h; - list_t *list; - int select; - void (*fce_event) (void *); +typedef struct widget_select { + int w, h; + list_t *list; + int select; + void (*fce_event) (void *); } widget_select_t; extern widget_t *newWidgetSelect(int x, int y, void (*fce_event) (void *)); diff --git a/src/widget/widget_textfield.c b/src/widget/widget_textfield.c index 77abb40..b3aeeb3 100644 --- a/src/widget/widget_textfield.c +++ b/src/widget/widget_textfield.c @@ -12,457 +12,438 @@ //#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; + widget_textfield_t *p; + int x, y; - 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; - getMousePosition(&x, &y); + 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; - } - } + 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); + 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.h b/src/widget/widget_textfield.h index be46ea0..7991deb 100644 --- a/src/widget/widget_textfield.h +++ b/src/widget/widget_textfield.h @@ -1,35 +1,34 @@ #ifndef WIDGET_TEXTFIELD_H -#define WIDGET_TEXTFIELD_H - -#include "main.h" -#include "widget.h" - -#define WIDGET_TEXTFIELD_WIDTH 175 -#define WIDGET_TEXTFIELD_HEIGHT 36 - -#define WIDGET_TEXTFIELD_TEXT_OFFSET_X 10 - -#define WIDGET_TEXTFIELD_TIME_MULTIPLE 10 -#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 w, h; - int canWrite; - int timeBlick; - int time; - int atime; - int filter; - char text[STR_SIZE]; - bool_t active; +# define WIDGET_TEXTFIELD_H + +# include "main.h" +# include "widget.h" + +# define WIDGET_TEXTFIELD_WIDTH 175 +# define WIDGET_TEXTFIELD_HEIGHT 36 + +# define WIDGET_TEXTFIELD_TEXT_OFFSET_X 10 + +# define WIDGET_TEXTFIELD_TIME_MULTIPLE 10 +# 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 w, h; + int canWrite; + int timeBlick; + int time; + int atime; + int filter; + char text[STR_SIZE]; + bool_t active; } widget_textfield_t; extern widget_t *newWidgetTextfield(char *text, int filter, int x, int y); |