summaryrefslogtreecommitdiff
path: root/src/widget
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-08-14 14:47:44 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-08-14 14:47:44 +0000
commit50ba3d5e1e9f9eeda049a348efa4645af07610bc (patch)
tree3a41428f4ce755e596a4d5c2c69668515935e5b0 /src/widget
parent5b67651831ad9b160b41990288c938c7a05c1db1 (diff)
- 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
Diffstat (limited to 'src/widget')
-rw-r--r--src/widget/widget_choicegroup.c103
-rw-r--r--src/widget/widget_choicegroup.h31
-rw-r--r--src/widget/widget_select.c12
-rw-r--r--src/widget/widget_select.h1
4 files changed, 146 insertions, 1 deletions
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 <stdlib.h>
+#include <assert.h>
+
+#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);
+}
diff --git a/src/widget/widget_choicegroup.h b/src/widget/widget_choicegroup.h
new file mode 100644
index 0000000..93d88fc
--- /dev/null
+++ b/src/widget/widget_choicegroup.h
@@ -0,0 +1,31 @@
+
+#ifndef WIDGET_CHOICEGROUP_H
+
+#define WIDGET_CHOICEGROUP_H
+
+#include "main.h"
+#include "list.h"
+
+#define WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS 5
+
+#define WIDGET_CHOICEGROUP_WIDTH 25
+#define WIDGET_CHOICEGROUP_HEIGHT 25
+
+typedef struct widget_choicegroup
+{
+ int x, y;
+ bool_t status;
+ int time;
+ void (*fce_event)(void *);
+ list_t *list;
+} widget_choicegroup_t;
+
+extern widget_choicegroup_t* newWidgetChoicegroup(int x, int y, bool_t status,
+ list_t *list, void (*fce_event)(void *));
+
+extern void drawWidgetChoicegroup(widget_choicegroup_t *p);
+extern void eventWidgetChoicegroup(widget_choicegroup_t *p);
+extern void destroyWidgetChoicegroup(widget_choicegroup_t *p);
+
+#endif
+
diff --git a/src/widget/widget_select.c b/src/widget/widget_select.c
index 35a462b..3ab5638 100644
--- a/src/widget/widget_select.c
+++ b/src/widget/widget_select.c
@@ -22,13 +22,23 @@ widget_select_t* newWidgetSelect(int x, int y, void (*fce_event)(void *))
new = malloc( sizeof(widget_select_t) );
new->x = x;
new->y = y;
- new->select = 0;
+ new->select = -1;
new->fce_event = fce_event;
new->list = newList();
return new;
}
+char* getWidgetSelectItem(widget_select_t *p)
+{
+ if( p->select == -1 )
+ {
+ return NULL;
+ }
+
+ return (char *)p->list->list[p->select];
+}
+
void addToWidgetSelect(widget_select_t *p, char *s)
{
addList(p->list, strdup(s) );
diff --git a/src/widget/widget_select.h b/src/widget/widget_select.h
index a0bb795..0f5f712 100644
--- a/src/widget/widget_select.h
+++ b/src/widget/widget_select.h
@@ -17,6 +17,7 @@ typedef struct widget_select
} widget_select_t;
extern widget_select_t* newWidgetSelect(int x, int y, void (*fce_event)(void *));
+extern char* getWidgetSelectItem(widget_select_t *p);
extern void addToWidgetSelect(widget_select_t *p, char *s);
extern void removeAllFromWidgetSelect(widget_select_t *p);
extern void drawWidgetSelect(widget_select_t *p);