diff options
| author | Dusan Durech <dusan.d@Centrum.sk> | 2009-06-15 14:49:04 +0200 |
|---|---|---|
| committer | Dusan Durech <dusan.d@Centrum.sk> | 2009-06-15 14:49:04 +0200 |
| commit | 9b7a6f66182020913cd9b5b1205634dabbcf081e (patch) | |
| tree | 1d21745d28f559a1c1f13be4bdaaf8ef0cc7ba56 /src/widget | |
| parent | 20def950be569ed6c6e9887f80dc3beca27765d8 (diff) | |
add widget container, hi is use in mainMenu and small diff
Diffstat (limited to 'src/widget')
| -rw-r--r-- | src/widget/widget.c | 43 | ||||
| -rw-r--r-- | src/widget/widget.h | 17 | ||||
| -rw-r--r-- | src/widget/widget_buttonimage.h | 1 | ||||
| -rw-r--r-- | src/widget/widget_container.c | 110 | ||||
| -rw-r--r-- | src/widget/widget_container.h | 20 |
5 files changed, 185 insertions, 6 deletions
diff --git a/src/widget/widget.c b/src/widget/widget.c index 4e4143e..57c247b 100644 --- a/src/widget/widget.c +++ b/src/widget/widget.c @@ -5,6 +5,15 @@ #include "widget.h" #include "widget_label.h" +#include "widget_button.h" +#include "widget_buttonimage.h" +#include "widget_textfield.h" +#include "widget_catchkey.h" +#include "widget_check.h" +#include "widget_choicegroup.h" +#include "widget_image.h" +#include "widget_select.h" +#include "widget_statusbar.h" widget_t *widget_new(int type, int x, int y, int w, int h, void *private_data) { @@ -55,6 +64,40 @@ void widget_set_size(widget_t *p, int *w, int *h) } } +void widget_draw(widget_t *p) +{ + switch (p->type) + { + case WIDGET_TYPE_LABEL: label_draw(p); break; + case WIDGET_TYPE_BUTTON: button_draw(p); break; + case WIDGET_TYPE_BUTTONIMAGE: button_image_draw(p); break; + case WIDGET_TYPE_TEXTFILED: text_field_draw(p); break; + case WIDGET_TYPE_CATCHKEY: catch_key_draw(p); break; + case WIDGET_TYPE_CHECK: check_draw(p); break; + case WIDGET_TYPE_CHOICE: choice_group_draw(p); break; + case WIDGET_TYPE_IMAGE: wid_image_draw(p); break; + case WIDGET_TYPE_SELECT: select_draw(p); break; + case WIDGET_TYPE_STATUSBAR: statusbar_draw(p); break; + } +} + +void widget_event(widget_t *p) +{ + switch (p->type) + { + case WIDGET_TYPE_LABEL: label_event(p); break; + case WIDGET_TYPE_BUTTON: button_event(p); break; + case WIDGET_TYPE_BUTTONIMAGE: button_image_event(p); break; + case WIDGET_TYPE_TEXTFILED: text_field_event(p); break; + case WIDGET_TYPE_CATCHKEY: catch_key_event(p); break; + case WIDGET_TYPE_CHECK: check_event(p); break; + case WIDGET_TYPE_CHOICE: choice_group_event(p); break; + case WIDGET_TYPE_IMAGE: wid_image_event(p); break; + case WIDGET_TYPE_SELECT: select_event(p); break; + case WIDGET_TYPE_STATUSBAR: statusbar_event(p); break; + } +} + void widget_destroy(widget_t *p) { free(p); diff --git a/src/widget/widget.h b/src/widget/widget.h index 2d6b717..2f20c90 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -7,12 +7,15 @@ #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_STATUSBAR 9 +#define WIDGET_TYPE_CATCHKEY 5 +#define WIDGET_TYPE_CHECK 6 +#define WIDGET_TYPE_CHOICE 7 +#define WIDGET_TYPE_IMAGE 8 +#define WIDGET_TYPE_SELECT 9 +#define WIDGET_TYPE_STATUSBAR 10 +#define WIDGET_TYPE_CONTAINER 11 + +#define WIDGET_NONE_VALUE -1 typedef struct widget_struct { int type; @@ -26,6 +29,8 @@ extern void widget_set_location(widget_t *p, int x, int y); extern void widget_get_location(widget_t *p, int *x, int *y); extern void widget_get_size(widget_t *p, int w, int h); extern void widget_set_size(widget_t *p, int *w, int *h); +extern void widget_draw(widget_t *p); +extern void widget_event(widget_t *p); extern void widget_destroy(widget_t *p); #endif /* WIDGET_H */ diff --git a/src/widget/widget_buttonimage.h b/src/widget/widget_buttonimage.h index 197b79b..fff2658 100644 --- a/src/widget/widget_buttonimage.h +++ b/src/widget/widget_buttonimage.h @@ -2,6 +2,7 @@ #define WIDGET_BUTTONIMAGE_H #include "main.h" +#include "image.h" #include "widget.h" #define WIDGET_BUTTONIMAGE_TIME 10 diff --git a/src/widget/widget_container.c b/src/widget/widget_container.c new file mode 100644 index 0000000..3e0888c --- /dev/null +++ b/src/widget/widget_container.c @@ -0,0 +1,110 @@ + +#include <stdlib.h> +#include <assert.h> + +#include "main.h" +#include "widget.h" +#include "widget_container.h" + +widget_t* widget_container_new(int x, int y, int w, int h) +{ + widget_container_t *new; + + new = malloc(sizeof(widget_container_t)); + new->listWidget = list_new(); + + return widget_new(WIDGET_TYPE_CONTAINER, x, y, w, h, new); +} + +void widget_container_add(widget_t *widget, widget_t *widget_add) +{ + widget_container_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CONTAINER); + + p = (widget_container_t *) widget->private_data; + list_add(p->listWidget, widget_add); +} + +void widget_set_layout_table(widget_t *widget, int countW, int countH, int w, int h) +{ + widget_container_t *p; + int i, j; + int count; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CONTAINER); + + p = (widget_container_t *) widget->private_data; + + count = 0; + + for (i = 0; i < countH; i++) { + for (j = 0; j < countW; j++) { + widget_t *widget_tmp; + + if( count >= p->listWidget->count ) + { + break; + } + + widget_tmp = (widget_t*)p->listWidget->list[count]; + + widget_set_location(widget_tmp, widget->x+j*w, widget->y+i*h); + count++; + } + } +} + +void widget_container_draw(widget_t *widget) +{ + widget_container_t *p; + int i; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CONTAINER); + + p = (widget_container_t *) widget->private_data; + + for (i = 0; i < p->listWidget->count; i++) { + widget_t *widget; + + widget = (widget_t*)p->listWidget->list[i]; + + widget_draw(widget); + } +} + +void widget_container_event(widget_t *widget) +{ + widget_container_t *p; + int i; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CONTAINER); + + p = (widget_container_t *) widget->private_data; + + for (i = 0; i < p->listWidget->count; i++) { + widget_t *widget; + + widget = (widget_t*)p->listWidget->list[i]; + + widget_event(widget); + } +} + +void widget_container_destroy(widget_t *widget) +{ + widget_container_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CONTAINER); + + p = (widget_container_t *) widget->private_data; + list_destroy(p->listWidget); + free(p); + + widget_destroy(widget); +} diff --git a/src/widget/widget_container.h b/src/widget/widget_container.h new file mode 100644 index 0000000..7b7708d --- /dev/null +++ b/src/widget/widget_container.h @@ -0,0 +1,20 @@ +#ifndef WIDGET_CONTAINER_H + +#define WIDGET_CONTAINER_H + +#include "list.h" +#include "widget.h" + +typedef struct widget_container { + + list_t *listWidget; +} widget_container_t; + +extern widget_t* widget_container_new(int x, int y, int w, int h); +extern void widget_container_add(widget_t *widget, widget_t *widget_add); +extern void widget_set_layout_table(widget_t *widget, int countW, int countH, int w, int h); +extern void widget_container_draw(widget_t *widget); +extern void widget_container_event(widget_t *widget); +extern void widget_container_destroy(widget_t *widget); + +#endif /* WIDGET_CONTAINER_H */ |