diff options
| author | Dusan Durech <dusan.d@centrum.sk> | 2008-11-15 16:08:21 +0100 |
|---|---|---|
| committer | Dusan Durech <dusan.d@centrum.sk> | 2008-11-15 16:08:21 +0100 |
| commit | 35084eaadf8b37f5c4a325f0d4b01767753ee9c3 (patch) | |
| tree | 8ca9a541783690eb6087a52faafa75e9a53d1521 /src/widget | |
| parent | 98875c5a636f50fe89b9394b8193e86094ae14e0 (diff) | |
modification coding stile
Diffstat (limited to 'src/widget')
| -rw-r--r-- | src/widget/widget.c | 2 | ||||
| -rw-r--r-- | src/widget/widget_button.c | 28 | ||||
| -rw-r--r-- | src/widget/widget_buttonimage.c | 6 | ||||
| -rw-r--r-- | src/widget/widget_catchkey.c | 8 | ||||
| -rw-r--r-- | src/widget/widget_check.c | 16 | ||||
| -rw-r--r-- | src/widget/widget_choicegroup.c | 16 | ||||
| -rw-r--r-- | src/widget/widget_label.c | 19 | ||||
| -rw-r--r-- | src/widget/widget_select.c | 8 | ||||
| -rw-r--r-- | src/widget/widget_textfield.c | 93 |
9 files changed, 89 insertions, 107 deletions
diff --git a/src/widget/widget.c b/src/widget/widget.c index 0dcfb41..b72a463 100644 --- a/src/widget/widget.c +++ b/src/widget/widget.c @@ -32,6 +32,7 @@ void widgetGetLocation(widget_t * p, int *x, int *y) { if (x != NULL) *x = p->x; + if (y != NULL) *y = p->y; } @@ -46,6 +47,7 @@ void widgetGetSize(widget_t * p, int *w, int *h) { if (w != NULL) *w = p->w; + if (h != NULL) *h = p->h; } diff --git a/src/widget/widget_button.c b/src/widget/widget_button.c index dbd7aa5..c2afcad 100644 --- a/src/widget/widget_button.c +++ b/src/widget/widget_button.c @@ -20,8 +20,8 @@ widget_t *newWidgetButton(char *text, int x, int y, void (*fce_event) (void *)) 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) @@ -38,30 +38,24 @@ void drawWidgetButton(widget_t * widget) getMousePosition(&x, &y); if (g_button0 == NULL) { - g_button0 = - addImageData("button0.png", IMAGE_ALPHA, "button0", - IMAGE_GROUP_BASE); + 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); + 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); + 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); + 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); + 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) @@ -83,8 +77,8 @@ void eventWidgetButton(widget_t * widget) getMousePosition(&x, &y); if (x >= widget->x && x <= widget->x + WIDGET_BUTTON_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_BUTTON_HEIGHT && - isMouseClicked()) { + y >= widget->y && y <= widget->y + WIDGET_BUTTON_HEIGHT && + isMouseClicked()) { time = WIDGET_BUTTON_TIME; DEBUG_MSG(_("Event caught\n")); diff --git a/src/widget/widget_buttonimage.c b/src/widget/widget_buttonimage.c index 6c89d79..dd20e62 100644 --- a/src/widget/widget_buttonimage.c +++ b/src/widget/widget_buttonimage.c @@ -10,8 +10,7 @@ #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; @@ -57,6 +56,7 @@ void eventWidgetButtonimage(widget_t * widget) assert(widget->type == WIDGET_TYPE_BUTTONIMAGE); p = (widget_buttonimage_t *) widget->private_data; + if (time > 0) { time--; return; @@ -65,7 +65,7 @@ void eventWidgetButtonimage(widget_t * widget) getMousePosition(&x, &y); if (x >= widget->x && x <= widget->x + p->w && - y >= widget->y && y <= widget->y + p->h && isMouseClicked()) { + y >= widget->y && y <= widget->y + p->h && isMouseClicked()) { time = WIDGET_BUTTONIMAGE_TIME; p->active = 1; p->fce_event(widget); diff --git a/src/widget/widget_catchkey.c b/src/widget/widget_catchkey.c index 37fab55..b213890 100644 --- a/src/widget/widget_catchkey.c +++ b/src/widget/widget_catchkey.c @@ -18,8 +18,7 @@ widget_t *newWidgetCatchkey(int key, int x, int y, void *event) 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) @@ -81,7 +80,8 @@ static int getPessAnyKey() for (i = SDLK_FIRST; i <= SDLK_COMPOSE; i++) { if (i == SDLK_NUMLOCK || // black key - i == SDLK_CAPSLOCK || i == SDLK_SCROLLOCK) { + i == SDLK_CAPSLOCK || + i == SDLK_SCROLLOCK) { continue; } @@ -107,7 +107,7 @@ void eventWidgetCatchkey(widget_t * widget) if (isMouseClicked()) { if (x >= widget->x && x <= widget->x + WIDGET_CATCHKEY_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_CATCHKEY_HEIGHT) { + y >= widget->y && y <= widget->y + WIDGET_CATCHKEY_HEIGHT) { p->active = TRUE; } else { p->active = FALSE; diff --git a/src/widget/widget_check.c b/src/widget/widget_check.c index e57f151..e574211 100644 --- a/src/widget/widget_check.c +++ b/src/widget/widget_check.c @@ -9,8 +9,7 @@ #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; @@ -19,8 +18,7 @@ widget_t *newWidgetCheck(int x, int y, bool_t status, 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) @@ -38,8 +36,7 @@ void drawWidgetCheck(widget_t * widget) getMousePosition(&x, &y); if (g_check == NULL) { - g_check = - addImageData("check.png", IMAGE_ALPHA, "check", IMAGE_GROUP_BASE); + g_check = addImageData("check.png", IMAGE_ALPHA, "check", IMAGE_GROUP_BASE); } if (p->status == TRUE) { @@ -48,8 +45,7 @@ void drawWidgetCheck(widget_t * widget) 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) @@ -70,8 +66,8 @@ void eventWidgetCheck(widget_t * widget) getMousePosition(&x, &y); if (x >= widget->x && x <= widget->x + WIDGET_CHECK_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_CHECK_HEIGHT && - isMouseClicked()) { + y >= widget->y && y <= widget->y + WIDGET_CHECK_HEIGHT && + isMouseClicked()) { if (p->status == TRUE) { p->status = FALSE; p->time = WIDGET_CHECK_TIME_SWITCH_STATUS; diff --git a/src/widget/widget_choicegroup.c b/src/widget/widget_choicegroup.c index 64533af..1045f81 100644 --- a/src/widget/widget_choicegroup.c +++ b/src/widget/widget_choicegroup.c @@ -9,8 +9,7 @@ #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; @@ -21,9 +20,8 @@ widget_t *newWidgetChoicegroup(int x, int y, bool_t status, list_t * list, new->fce_event = fce_event; new->list = list; - widget = - newWidget(WIDGET_TYPE_CHOICE, x, y, WIDGET_CHOICEGROUP_WIDTH, - WIDGET_CHOICEGROUP_HEIGHT, new); + widget = newWidget(WIDGET_TYPE_CHOICE, x, y, WIDGET_CHOICEGROUP_WIDTH, WIDGET_CHOICEGROUP_HEIGHT, new); + addList(new->list, widget); return widget; @@ -44,9 +42,7 @@ void drawWidgetChoicegroup(widget_t * widget) getMousePosition(&x, &y); if (g_choicegroup == NULL) { - g_choicegroup = - addImageData("choice.png", IMAGE_ALPHA, "choicegroup", - IMAGE_GROUP_BASE); + g_choicegroup = addImageData("choice.png", IMAGE_ALPHA, "choicegroup", IMAGE_GROUP_BASE); } if (p->status == TRUE) { @@ -56,7 +52,7 @@ void drawWidgetChoicegroup(widget_t * widget) } drawImage(g_choicegroup, widget->x, widget->y, offset, 0, - WIDGET_CHOICEGROUP_WIDTH, WIDGET_CHOICEGROUP_HEIGHT); + WIDGET_CHOICEGROUP_WIDTH, WIDGET_CHOICEGROUP_HEIGHT); } void setWidgetChoiceActive(widget_t * widget) @@ -127,7 +123,7 @@ void eventWidgetChoicegroup(widget_t * widget) getMousePosition(&x, &y); if (x >= widget->x && x <= widget->x + WIDGET_CHOICEGROUP_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_CHOICEGROUP_HEIGHT && + y >= widget->y && y <= widget->y + WIDGET_CHOICEGROUP_HEIGHT && isMouseClicked()) { setWidgetChoiceActive(widget); } diff --git a/src/widget/widget_label.c b/src/widget/widget_label.c index d4bb813..e3c907c 100644 --- a/src/widget/widget_label.c +++ b/src/widget/widget_label.c @@ -30,16 +30,15 @@ void drawWidgetLabel(widget_t * widget) 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; + 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; } } diff --git a/src/widget/widget_select.c b/src/widget/widget_select.c index 2f89fe2..f53e583 100644 --- a/src/widget/widget_select.c +++ b/src/widget/widget_select.c @@ -94,8 +94,8 @@ void drawWidgetSelect(widget_t * widget) getTextSize(line, &w, &h); - if (x > widget->x && y > widget->y + i * 20 && x < widget->x + w - && y < widget->y + i * 20 + 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) { @@ -127,8 +127,8 @@ void eventWidgetSelect(widget_t * widget) getTextSize(line, &w, &h); if (x > widget->x && y > widget->y + i * 20 && - x < widget->x + w && y < widget->y + i * 20 + h && - isMouseClicked()) { + x < widget->x + w && y < widget->y + i * 20 + h && + isMouseClicked()) { p->select = i; p->fce_event(p); } diff --git a/src/widget/widget_textfield.c b/src/widget/widget_textfield.c index b3aeeb3..6a8824a 100644 --- a/src/widget/widget_textfield.c +++ b/src/widget/widget_textfield.c @@ -27,8 +27,8 @@ widget_t *newWidgetTextfield(char *text, int filter, int x, int y) 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) @@ -43,23 +43,17 @@ static void drawBackground(widget_t * widget) p = (widget_textfield_t *) widget->private_data; if (g_textfield0 == NULL) { - g_textfield0 = - addImageData("textfield0.png", IMAGE_ALPHA, "textfiled0", - IMAGE_GROUP_BASE); + 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); + 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); + 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); + drawImage(g_textfield0, widget->x, widget->y, 0, 0, g_textfield0->w, g_textfield0->h); } } @@ -75,8 +69,8 @@ static void drawText(widget_t * widget) strcpy(str, p->text); - if (p->timeBlick > WIDGET_TEXTFIELD_TIME_BLICK_CURSOR / 2 && - p->active == TRUE) { + if (p->timeBlick > WIDGET_TEXTFIELD_TIME_BLICK_CURSOR / 2 && p->active == TRUE) + { //strcat(str, ">"); strcat(str, "\f"); } @@ -86,12 +80,12 @@ static void drawText(widget_t * widget) 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); + 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) @@ -145,33 +139,35 @@ static void checkText(widget_textfield_t * p) 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 == '-')) { + case WIDGET_TEXTFIELD_FILTER_ALL: 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; + 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) { @@ -182,7 +178,6 @@ static void checkText(widget_textfield_t * p) } getTextSize(p->text, &p->w, &p->h); - } #ifdef ZZEEXX86_READKEY @@ -351,8 +346,10 @@ static void readKey(widget_textfield_t * p) if (strlen(name) == 1) c = name[0]; + if (strlen(name) == 3) c = name[1]; + if (strcmp(name, "space") == 0) c = ' '; @@ -385,8 +382,7 @@ static void readKey(widget_textfield_t * p) p->text[len] = c; - if (mapa[SDLK_LSHIFT] == SDL_PRESSED || - mapa[SDLK_RSHIFT] == SDL_PRESSED) { + if (mapa[SDLK_LSHIFT] == SDL_PRESSED || mapa[SDLK_RSHIFT] == SDL_PRESSED) { int i; for (i = 0; i < len_shift_map; i += 2) { @@ -399,8 +395,7 @@ static void readKey(widget_textfield_t * p) return; } - if (mapa[SDLK_LSHIFT] == SDL_PRESSED || - mapa[SDLK_RSHIFT] == SDL_PRESSED) { + if (mapa[SDLK_LSHIFT] == SDL_PRESSED || mapa[SDLK_RSHIFT] == SDL_PRESSED) { p->text[len] -= 32; } @@ -425,7 +420,7 @@ void eventWidgetTextfield(widget_t * widget) if (isMouseClicked()) { if (x >= widget->x && x <= widget->x + WIDGET_TEXTFIELD_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_TEXTFIELD_HEIGHT) { + y >= widget->y && y <= widget->y + WIDGET_TEXTFIELD_HEIGHT) { p->active = TRUE; } else { p->active = FALSE; |