From 5855f591b6d509633e3730346e18122768ec6e04 Mon Sep 17 00:00:00 2001 From: Tomas Chvatal Date: Thu, 11 Dec 2008 22:34:18 +0100 Subject: First pass renaming sreen and widgets. --- src/widget/button.c | 103 ++++++++++ src/widget/button.h | 26 +++ src/widget/buttonimage.c | 86 ++++++++ src/widget/buttonimage.h | 27 +++ src/widget/catchkey.c | 140 +++++++++++++ src/widget/catchkey.h | 27 +++ src/widget/check.c | 118 +++++++++++ src/widget/check.h | 28 +++ src/widget/choicegroup.c | 147 +++++++++++++ src/widget/choicegroup.h | 33 +++ src/widget/image.c | 52 +++++ src/widget/image.h | 19 ++ src/widget/label.c | 64 ++++++ src/widget/label.h | 24 +++ src/widget/select.c | 150 ++++++++++++++ src/widget/select.h | 26 +++ src/widget/textfield.c | 444 ++++++++++++++++++++++++++++++++++++++++ src/widget/textfield.h | 41 ++++ src/widget/widget.c | 2 +- src/widget/widget_button.c | 103 ---------- src/widget/widget_button.h | 26 --- src/widget/widget_buttonimage.c | 86 -------- src/widget/widget_buttonimage.h | 27 --- src/widget/widget_catchkey.c | 140 ------------- src/widget/widget_catchkey.h | 27 --- src/widget/widget_check.c | 118 ----------- src/widget/widget_check.h | 28 --- src/widget/widget_choicegroup.c | 147 ------------- src/widget/widget_choicegroup.h | 33 --- src/widget/widget_image.c | 52 ----- src/widget/widget_image.h | 19 -- src/widget/widget_label.c | 64 ------ src/widget/widget_label.h | 24 --- src/widget/widget_select.c | 150 -------------- src/widget/widget_select.h | 26 --- src/widget/widget_textfield.c | 444 ---------------------------------------- src/widget/widget_textfield.h | 41 ---- 37 files changed, 1556 insertions(+), 1556 deletions(-) create mode 100644 src/widget/button.c create mode 100644 src/widget/button.h create mode 100644 src/widget/buttonimage.c create mode 100644 src/widget/buttonimage.h create mode 100644 src/widget/catchkey.c create mode 100644 src/widget/catchkey.h create mode 100644 src/widget/check.c create mode 100644 src/widget/check.h create mode 100644 src/widget/choicegroup.c create mode 100644 src/widget/choicegroup.h create mode 100644 src/widget/image.c create mode 100644 src/widget/image.h create mode 100644 src/widget/label.c create mode 100644 src/widget/label.h create mode 100644 src/widget/select.c create mode 100644 src/widget/select.h create mode 100644 src/widget/textfield.c create mode 100644 src/widget/textfield.h delete mode 100644 src/widget/widget_button.c delete mode 100644 src/widget/widget_button.h delete mode 100644 src/widget/widget_buttonimage.c delete mode 100644 src/widget/widget_buttonimage.h delete mode 100644 src/widget/widget_catchkey.c delete mode 100644 src/widget/widget_catchkey.h delete mode 100644 src/widget/widget_check.c delete mode 100644 src/widget/widget_check.h delete mode 100644 src/widget/widget_choicegroup.c delete mode 100644 src/widget/widget_choicegroup.h delete mode 100644 src/widget/widget_image.c delete mode 100644 src/widget/widget_image.h delete mode 100644 src/widget/widget_label.c delete mode 100644 src/widget/widget_label.h delete mode 100644 src/widget/widget_select.c delete mode 100644 src/widget/widget_select.h delete mode 100644 src/widget/widget_textfield.c delete mode 100644 src/widget/widget_textfield.h (limited to 'src/widget') diff --git a/src/widget/button.c b/src/widget/button.c new file mode 100644 index 0000000..e2db211 --- /dev/null +++ b/src/widget/button.c @@ -0,0 +1,103 @@ + +#include +#include + +#include "main.h" + +#include "interface.h" +#include "image.h" +#include "font.h" + +#include "widget.h" +#include "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; + + DEBUG_MSG(_("Event caught\n")); + + 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/button.h b/src/widget/button.h new file mode 100644 index 0000000..ac238be --- /dev/null +++ b/src/widget/button.h @@ -0,0 +1,26 @@ + +#ifndef WIDGET_BUTTON_H + +# define WIDGET_BUTTON_H + +# include "main.h" +# include "widget.h" + +# define WIDGET_BUTTON_TIME 10 + +# define WIDGET_BUTTON_WIDTH 125 +# define WIDGET_BUTTON_HEIGHT 36 + +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 *)); +extern void drawWidgetButton(widget_t * widget); +extern void eventWidgetButton(widget_t * widget); +extern void destroyWidgetButton(widget_t * widget); + +#endif diff --git a/src/widget/buttonimage.c b/src/widget/buttonimage.c new file mode 100644 index 0000000..1859ef0 --- /dev/null +++ b/src/widget/buttonimage.c @@ -0,0 +1,86 @@ + +#include +#include + +#include "main.h" +#include "interface.h" +#include "font.h" +#include "image.h" + +#include "widget.h" +#include "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/buttonimage.h b/src/widget/buttonimage.h new file mode 100644 index 0000000..5a0ab7c --- /dev/null +++ b/src/widget/buttonimage.h @@ -0,0 +1,27 @@ + +#ifndef WIDGET_BUTTONIMAGE_H + +# include "main.h" + +# define WIDGET_BUTTONIMAGE_H + +# define WIDGET_BUTTONIMAGE_TIME 10 + +# include "widget.h" + +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 *)); + +extern void setWidgetButtonimageActive(widget_t * widget, bool_t active); +extern void drawWidgetButtonimage(widget_t * widget); +extern void eventWidgetButtonimage(widget_t * widget); +extern void destroyWidgetButtonimage(widget_t * widget); + +#endif diff --git a/src/widget/catchkey.c b/src/widget/catchkey.c new file mode 100644 index 0000000..ecfb993 --- /dev/null +++ b/src/widget/catchkey.c @@ -0,0 +1,140 @@ + +#include +#include + +#include "main.h" +#include "interface.h" +#include "font.h" + +#include "widget.h" +#include "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/catchkey.h b/src/widget/catchkey.h new file mode 100644 index 0000000..106bc92 --- /dev/null +++ b/src/widget/catchkey.h @@ -0,0 +1,27 @@ +#ifndef WIDGET_CATCHKEY_H + +# define WIDGET_CATCHKEY_H + +# include "main.h" +# include "widget.h" + +# define WIDGET_CATCHKEY_WIDTH 110 +# define WIDGET_CATCHKEY_HEIGHT 12 + +# define WIDGET_CATCHKEY_NOKEY -1 + +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); +extern int getWidgetCatchKey(widget_t * p); +extern void setWidgetCatchKey(widget_t * p, int key); +extern void drawWidgetCatchkey(widget_t * p); +extern void eventWidgetCatchkey(widget_t * p); +extern void destroyWidgetCatchkey(widget_t * p); + +#endif diff --git a/src/widget/check.c b/src/widget/check.c new file mode 100644 index 0000000..7ef4b8b --- /dev/null +++ b/src/widget/check.c @@ -0,0 +1,118 @@ + +#include +#include + +#include "main.h" +#include "interface.h" +#include "image.h" + +#include "widget.h" +#include "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(widget); + } + } +} + +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/check.h b/src/widget/check.h new file mode 100644 index 0000000..007e82c --- /dev/null +++ b/src/widget/check.h @@ -0,0 +1,28 @@ + +#ifndef WIDGET_CHECK_H + +# define WIDGET_CHECK_H + +# include "main.h" +# include "widget.h" + +# define WIDGET_CHECK_TIME_SWITCH_STATUS 5 + +# define WIDGET_CHECK_WIDTH 25 +# define WIDGET_CHECK_HEIGHT 25 + +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 *)); +extern void drawWidgetCheck(widget_t * widget); +extern void eventWidgetCheck(widget_t * widget); +extern bool_t getWidgetCheckStatus(widget_t * widget); +extern void setWidgetCheckStatus(widget_t * widget, bool_t status); +extern void destroyWidgetCheck(widget_t * widget); + +#endif diff --git a/src/widget/choicegroup.c b/src/widget/choicegroup.c new file mode 100644 index 0000000..0eb562a --- /dev/null +++ b/src/widget/choicegroup.c @@ -0,0 +1,147 @@ + +#include +#include + +#include "main.h" +#include "interface.h" +#include "image.h" + +#include "widget.h" +#include "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/choicegroup.h b/src/widget/choicegroup.h new file mode 100644 index 0000000..a892d74 --- /dev/null +++ b/src/widget/choicegroup.h @@ -0,0 +1,33 @@ + +#ifndef WIDGET_CHOICEGROUP_H + +# define WIDGET_CHOICEGROUP_H + +# include "main.h" +# include "list.h" +# include "widget.h" + +# define WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS 5 + +# 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; +} widget_choicegroup_t; + +extern widget_t *newWidgetChoicegroup(int x, int y, bool_t status, + list_t * list, + void (*fce_event) (void *)); + +extern void drawWidgetChoicegroup(widget_t * p); +extern void setWidgetChoiceActive(widget_t * widget); +extern bool_t getWidgetChoiceStatus(widget_t * widget); +extern void setWidgetChoiceStatus(widget_t * widget, bool_t status); +extern void eventWidgetChoicegroup(widget_t * p); +extern void destroyWidgetChoicegroup(widget_t * p); + +#endif diff --git a/src/widget/image.c b/src/widget/image.c new file mode 100644 index 0000000..2c9702f --- /dev/null +++ b/src/widget/image.c @@ -0,0 +1,52 @@ + +#include +#include + +#include +#include "main.h" +#include "image.h" +#include "interface.h" +#include "font.h" + +#include "widget.h" +#include "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/image.h b/src/widget/image.h new file mode 100644 index 0000000..61bf89a --- /dev/null +++ b/src/widget/image.h @@ -0,0 +1,19 @@ + +#ifndef WIDGET_IMAGE_H + +# define WIDGET_IMAGE_H + +# include "main.h" +# include "interface.h" +# include "widget.h" + +typedef struct widget_image { + image_t *widget_image; +} widget_image_t; + +extern widget_t *newWidgetImage(int x, int y, image_t * image); +extern void drawWidgetImage(widget_t * p); +extern void eventWidgetImage(widget_t * p); +extern void destroyWidgetImage(widget_t * p); + +#endif diff --git a/src/widget/label.c b/src/widget/label.c new file mode 100644 index 0000000..a2d0a48 --- /dev/null +++ b/src/widget/label.c @@ -0,0 +1,64 @@ + +#include +#include + +#include "main.h" +#include "interface.h" +#include "font.h" +#include "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/label.h b/src/widget/label.h new file mode 100644 index 0000000..743db7e --- /dev/null +++ b/src/widget/label.h @@ -0,0 +1,24 @@ + +#ifndef WIDGET_LABEL_H + +# define WIDGET_LABEL_H + +# include "main.h" +# include "widget.h" + +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 + +extern widget_t *newWidgetLabel(char *text, int x, int y, int bind); +extern void drawWidgetLabel(widget_t * widget); +extern void eventWidgetLabel(widget_t * widget); +extern void destroyWidgetLabel(widget_t * widget); + +#endif diff --git a/src/widget/select.c b/src/widget/select.c new file mode 100644 index 0000000..5e290e2 --- /dev/null +++ b/src/widget/select.c @@ -0,0 +1,150 @@ + +#include +#include + +#include "main.h" +#include "interface.h" +#include "font.h" + +#include "widget.h" +#include "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/select.h b/src/widget/select.h new file mode 100644 index 0000000..9d772cc --- /dev/null +++ b/src/widget/select.h @@ -0,0 +1,26 @@ + +#ifndef WIDGET_SELECT_H + +# define WIDGET_SELECT_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 *); +} widget_select_t; + +extern widget_t *newWidgetSelect(int x, int y, void (*fce_event) (void *)); +extern char *getWidgetSelectItem(widget_t * widget); +extern int getWidgetSelectIndex(widget_t * widget); +extern void addToWidgetSelect(widget_t * widget, char *s); +extern void removeAllFromWidgetSelect(widget_t * widget); +extern void drawWidgetSelect(widget_t * widget); +extern void eventWidgetSelect(widget_t * widget); +extern void destroyWidgetSelect(widget_t * widget); + +#endif diff --git a/src/widget/textfield.c b/src/widget/textfield.c new file mode 100644 index 0000000..edc74a8 --- /dev/null +++ b/src/widget/textfield.c @@ -0,0 +1,444 @@ + +#include +#include + +#include "main.h" +#include "interface.h" +#include "font.h" +#include "image.h" + +#include "widget.h" +#include "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(widthtext, " "); + 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); +} diff --git a/src/widget/textfield.h b/src/widget/textfield.h new file mode 100644 index 0000000..7991deb --- /dev/null +++ b/src/widget/textfield.h @@ -0,0 +1,41 @@ + +#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; +} widget_textfield_t; + +extern widget_t *newWidgetTextfield(char *text, int filter, int x, int y); +extern void setWidgetTextFiledText(widget_t * widget, char *text); +extern char *getTextFromWidgetTextfield(widget_t * widget); +extern void drawWidgetTextfield(widget_t * widget); +extern void eventWidgetTextfield(widget_t * widget); +extern void destroyWidgetTextfield(widget_t * widget); + +#endif diff --git a/src/widget/widget.c b/src/widget/widget.c index b72a463..f33e643 100644 --- a/src/widget/widget.c +++ b/src/widget/widget.c @@ -5,7 +5,7 @@ #include "main.h" #include "widget.h" -#include "widget_label.h" +#include "label.h" widget_t *newWidget(int type, int x, int y, int w, int h, void *private_data) { diff --git a/src/widget/widget_button.c b/src/widget/widget_button.c deleted file mode 100644 index c2afcad..0000000 --- a/src/widget/widget_button.c +++ /dev/null @@ -1,103 +0,0 @@ - -#include -#include - -#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; - - DEBUG_MSG(_("Event caught\n")); - - 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_button.h b/src/widget/widget_button.h deleted file mode 100644 index ac238be..0000000 --- a/src/widget/widget_button.h +++ /dev/null @@ -1,26 +0,0 @@ - -#ifndef WIDGET_BUTTON_H - -# define WIDGET_BUTTON_H - -# include "main.h" -# include "widget.h" - -# define WIDGET_BUTTON_TIME 10 - -# define WIDGET_BUTTON_WIDTH 125 -# define WIDGET_BUTTON_HEIGHT 36 - -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 *)); -extern void drawWidgetButton(widget_t * widget); -extern void eventWidgetButton(widget_t * widget); -extern void destroyWidgetButton(widget_t * widget); - -#endif diff --git a/src/widget/widget_buttonimage.c b/src/widget/widget_buttonimage.c deleted file mode 100644 index dd20e62..0000000 --- a/src/widget/widget_buttonimage.c +++ /dev/null @@ -1,86 +0,0 @@ - -#include -#include - -#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_buttonimage.h b/src/widget/widget_buttonimage.h deleted file mode 100644 index 5a0ab7c..0000000 --- a/src/widget/widget_buttonimage.h +++ /dev/null @@ -1,27 +0,0 @@ - -#ifndef WIDGET_BUTTONIMAGE_H - -# include "main.h" - -# define WIDGET_BUTTONIMAGE_H - -# define WIDGET_BUTTONIMAGE_TIME 10 - -# include "widget.h" - -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 *)); - -extern void setWidgetButtonimageActive(widget_t * widget, bool_t active); -extern void drawWidgetButtonimage(widget_t * widget); -extern void eventWidgetButtonimage(widget_t * widget); -extern void destroyWidgetButtonimage(widget_t * widget); - -#endif diff --git a/src/widget/widget_catchkey.c b/src/widget/widget_catchkey.c deleted file mode 100644 index b213890..0000000 --- a/src/widget/widget_catchkey.c +++ /dev/null @@ -1,140 +0,0 @@ - -#include -#include - -#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_catchkey.h b/src/widget/widget_catchkey.h deleted file mode 100644 index 106bc92..0000000 --- a/src/widget/widget_catchkey.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef WIDGET_CATCHKEY_H - -# define WIDGET_CATCHKEY_H - -# include "main.h" -# include "widget.h" - -# define WIDGET_CATCHKEY_WIDTH 110 -# define WIDGET_CATCHKEY_HEIGHT 12 - -# define WIDGET_CATCHKEY_NOKEY -1 - -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); -extern int getWidgetCatchKey(widget_t * p); -extern void setWidgetCatchKey(widget_t * p, int key); -extern void drawWidgetCatchkey(widget_t * p); -extern void eventWidgetCatchkey(widget_t * p); -extern void destroyWidgetCatchkey(widget_t * p); - -#endif diff --git a/src/widget/widget_check.c b/src/widget/widget_check.c deleted file mode 100644 index e574211..0000000 --- a/src/widget/widget_check.c +++ /dev/null @@ -1,118 +0,0 @@ - -#include -#include - -#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(widget); - } - } -} - -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_check.h b/src/widget/widget_check.h deleted file mode 100644 index 007e82c..0000000 --- a/src/widget/widget_check.h +++ /dev/null @@ -1,28 +0,0 @@ - -#ifndef WIDGET_CHECK_H - -# define WIDGET_CHECK_H - -# include "main.h" -# include "widget.h" - -# define WIDGET_CHECK_TIME_SWITCH_STATUS 5 - -# define WIDGET_CHECK_WIDTH 25 -# define WIDGET_CHECK_HEIGHT 25 - -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 *)); -extern void drawWidgetCheck(widget_t * widget); -extern void eventWidgetCheck(widget_t * widget); -extern bool_t getWidgetCheckStatus(widget_t * widget); -extern void setWidgetCheckStatus(widget_t * widget, bool_t status); -extern void destroyWidgetCheck(widget_t * widget); - -#endif diff --git a/src/widget/widget_choicegroup.c b/src/widget/widget_choicegroup.c deleted file mode 100644 index 1045f81..0000000 --- a/src/widget/widget_choicegroup.c +++ /dev/null @@ -1,147 +0,0 @@ - -#include -#include - -#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_choicegroup.h b/src/widget/widget_choicegroup.h deleted file mode 100644 index a892d74..0000000 --- a/src/widget/widget_choicegroup.h +++ /dev/null @@ -1,33 +0,0 @@ - -#ifndef WIDGET_CHOICEGROUP_H - -# define WIDGET_CHOICEGROUP_H - -# include "main.h" -# include "list.h" -# include "widget.h" - -# define WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS 5 - -# 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; -} widget_choicegroup_t; - -extern widget_t *newWidgetChoicegroup(int x, int y, bool_t status, - list_t * list, - void (*fce_event) (void *)); - -extern void drawWidgetChoicegroup(widget_t * p); -extern void setWidgetChoiceActive(widget_t * widget); -extern bool_t getWidgetChoiceStatus(widget_t * widget); -extern void setWidgetChoiceStatus(widget_t * widget, bool_t status); -extern void eventWidgetChoicegroup(widget_t * p); -extern void destroyWidgetChoicegroup(widget_t * p); - -#endif diff --git a/src/widget/widget_image.c b/src/widget/widget_image.c deleted file mode 100644 index ad49f9e..0000000 --- a/src/widget/widget_image.c +++ /dev/null @@ -1,52 +0,0 @@ - -#include -#include - -#include -#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_image.h b/src/widget/widget_image.h deleted file mode 100644 index 081fbda..0000000 --- a/src/widget/widget_image.h +++ /dev/null @@ -1,19 +0,0 @@ - -#ifndef WIDGET_IMAGE_H - -# define WIDGET_IMAGE_H - -# include "main.h" -# include "interface.h" -# include "widget.h" - -typedef struct widget_image { - image_t *image; -} widget_image_t; - -extern widget_t *newWidgetImage(int x, int y, image_t * image); -extern void drawWidgetImage(widget_t * p); -extern void eventWidgetImage(widget_t * p); -extern void destroyWidgetImage(widget_t * p); - -#endif diff --git a/src/widget/widget_label.c b/src/widget/widget_label.c deleted file mode 100644 index e3c907c..0000000 --- a/src/widget/widget_label.c +++ /dev/null @@ -1,64 +0,0 @@ - -#include -#include - -#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_label.h b/src/widget/widget_label.h deleted file mode 100644 index 743db7e..0000000 --- a/src/widget/widget_label.h +++ /dev/null @@ -1,24 +0,0 @@ - -#ifndef WIDGET_LABEL_H - -# define WIDGET_LABEL_H - -# include "main.h" -# include "widget.h" - -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 - -extern widget_t *newWidgetLabel(char *text, int x, int y, int bind); -extern void drawWidgetLabel(widget_t * widget); -extern void eventWidgetLabel(widget_t * widget); -extern void destroyWidgetLabel(widget_t * widget); - -#endif diff --git a/src/widget/widget_select.c b/src/widget/widget_select.c deleted file mode 100644 index f53e583..0000000 --- a/src/widget/widget_select.c +++ /dev/null @@ -1,150 +0,0 @@ - -#include -#include - -#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_select.h b/src/widget/widget_select.h deleted file mode 100644 index 9d772cc..0000000 --- a/src/widget/widget_select.h +++ /dev/null @@ -1,26 +0,0 @@ - -#ifndef WIDGET_SELECT_H - -# define WIDGET_SELECT_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 *); -} widget_select_t; - -extern widget_t *newWidgetSelect(int x, int y, void (*fce_event) (void *)); -extern char *getWidgetSelectItem(widget_t * widget); -extern int getWidgetSelectIndex(widget_t * widget); -extern void addToWidgetSelect(widget_t * widget, char *s); -extern void removeAllFromWidgetSelect(widget_t * widget); -extern void drawWidgetSelect(widget_t * widget); -extern void eventWidgetSelect(widget_t * widget); -extern void destroyWidgetSelect(widget_t * widget); - -#endif diff --git a/src/widget/widget_textfield.c b/src/widget/widget_textfield.c deleted file mode 100644 index 6a8824a..0000000 --- a/src/widget/widget_textfield.c +++ /dev/null @@ -1,444 +0,0 @@ - -#include -#include - -#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(widthtext, " "); - 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); -} diff --git a/src/widget/widget_textfield.h b/src/widget/widget_textfield.h deleted file mode 100644 index 7991deb..0000000 --- a/src/widget/widget_textfield.h +++ /dev/null @@ -1,41 +0,0 @@ - -#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; -} widget_textfield_t; - -extern widget_t *newWidgetTextfield(char *text, int filter, int x, int y); -extern void setWidgetTextFiledText(widget_t * widget, char *text); -extern char *getTextFromWidgetTextfield(widget_t * widget); -extern void drawWidgetTextfield(widget_t * widget); -extern void eventWidgetTextfield(widget_t * widget); -extern void destroyWidgetTextfield(widget_t * widget); - -#endif -- cgit v1.2.3