From 50ba3d5e1e9f9eeda049a348efa4645af07610bc Mon Sep 17 00:00:00 2001 From: oroborus Date: Thu, 14 Aug 2008 14:47:44 +0000 Subject: - novy widget widget_choicegroup - moznost ukladat a nacitavat rozohranu hru ( uklada sa pomocou F2) ( neda sa ulozit sietovy multiplayer, a este nie je dokonce ulozenie hranie s AI ) git-svn-id: http://opensvn.csie.org/tuxanci_ng@195 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e --- src/widget/widget_choicegroup.c | 103 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 src/widget/widget_choicegroup.c (limited to 'src/widget/widget_choicegroup.c') diff --git a/src/widget/widget_choicegroup.c b/src/widget/widget_choicegroup.c new file mode 100644 index 0000000..5404461 --- /dev/null +++ b/src/widget/widget_choicegroup.c @@ -0,0 +1,103 @@ + +#include +#include + +#include "main.h" +#include "interface.h" +#include "image.h" +#include "widget_choicegroup.h" + +widget_choicegroup_t* newWidgetChoicegroup(int x, int y, bool_t status, list_t *list, void (*fce_event)(void *)) +{ + widget_choicegroup_t *new; + + new = malloc( sizeof(widget_choicegroup_t) ); + new->x = x; + new->y = y; + new->time = 0; + new->status = status; + new->fce_event = fce_event; + new->list = list; + addList(new->list, new); + + return new; +} + +void drawWidgetChoicegroup(widget_choicegroup_t *p) +{ + static image_t *g_choicegroup = NULL; + int x, y; + int offset; + + getMousePosition(&x, &y); + + if( g_choicegroup == NULL ) + { + g_choicegroup = addImageData("check.png", IMAGE_ALPHA, "choicegroup", IMAGE_GROUP_BASE); + } + + if( p->status == TRUE ) + { + offset = 0; + } + else + { + offset = WIDGET_CHOICEGROUP_WIDTH; + } + + drawImage(g_choicegroup, p->x, p->y, offset, 0, WIDGET_CHOICEGROUP_WIDTH, WIDGET_CHOICEGROUP_HEIGHT); +} + +static void setActive(widget_choicegroup_t *p) +{ + int i; + + for( i = 0 ; i < p->list->count ; i++ ) + { + widget_choicegroup_t *this; + + this = (widget_choicegroup_t *) p->list->list[i]; + + if( this == p ) + { + this->status = TRUE; + this->time = WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS; + this->fce_event(p); + } + else + { + this->status = FALSE; + } + } +} + +void eventWidgetChoicegroup(widget_choicegroup_t *p) +{ + int x, y; + + if( p->time > 0 ) + { + p->time--; + return; + } + + getMousePosition(&x, &y); + + if( x >= p->x && x <= p->x+WIDGET_CHOICEGROUP_WIDTH && + y >= p->y && y <= p->y+WIDGET_CHOICEGROUP_HEIGHT && + isMouseClicked() ) + { + setActive(p); + } +} + +void destroyWidgetChoicegroup(widget_choicegroup_t *p) +{ + int index; + + index = searchListItem(p->list, p); + assert( index != -1 ); + delList(p->list, index); + + free(p); +} -- cgit v1.2.3