summaryrefslogtreecommitdiff
path: root/src/widget/widget_button.c
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-08-16 21:00:29 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-08-16 21:00:29 +0000
commitc68df329f2483d8fc9b75488c695787cd18c20a4 (patch)
tree18e11cd70360c77606ecdeafe5dbd8f9ff0c12d7 /src/widget/widget_button.c
parent753fde16397b5943091aa1e9112cea1e5ded0ca5 (diff)
- vsetky widegety pouzivaju widget_t
( priparava na kontajner s widgetmi ) git-svn-id: http://opensvn.csie.org/tuxanci_ng@201 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/widget/widget_button.c')
-rw-r--r--src/widget/widget_button.c55
1 files changed, 39 insertions, 16 deletions
diff --git a/src/widget/widget_button.c b/src/widget/widget_button.c
index 4cff900..add6adf 100644
--- a/src/widget/widget_button.c
+++ b/src/widget/widget_button.c
@@ -1,5 +1,6 @@
#include <stdlib.h>
+#include <assert.h>
#include "main.h"
@@ -7,28 +8,32 @@
#include "image.h"
#include "font.h"
+#include "widget.h"
#include "widget_button.h"
-widget_button_t* newWidgetButton(char *text, int x, int y, void (*fce_event)(void *))
+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->x = x;
- new->y = y;
new->fce_event = fce_event;
- getTextSize(text, &new->w, &new->h);
+ getTextSize(text, &(new->w), &(new->h));
- return new;
+ return newWidget(WIDGET_TYPE_BUTTON, x, y, WIDGET_BUTTON_WIDTH, WIDGET_BUTTON_HEIGHT, new);
}
-void drawWidgetButton(widget_button_t *p)
+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 )
@@ -41,25 +46,33 @@ void drawWidgetButton(widget_button_t *p)
g_button1 = addImageData("button1.png", IMAGE_ALPHA, "button1", IMAGE_GROUP_BASE);
}
- if( x >= p->x && x <= p->x+WIDGET_BUTTON_WIDTH &&
- y >= p->y && y <= p->y+WIDGET_BUTTON_HEIGHT )
+ if( x >= widget->x && x <= widget->x+WIDGET_BUTTON_WIDTH &&
+ y >= widget->y && y <= widget->y+WIDGET_BUTTON_HEIGHT )
{
- drawImage(g_button1, p->x, p->y, 0, 0, g_button0->w, g_button0->h);
+ drawImage(g_button1, widget->x, widget->y, 0, 0, g_button0->w, g_button0->h);
}
else
{
- drawImage(g_button0, p->x, p->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, p->x + WIDGET_BUTTON_WIDTH/2 - p->w/2, p->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_button_t *p)
+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--;
@@ -68,17 +81,27 @@ void eventWidgetButton(widget_button_t *p)
getMousePosition(&x, &y);
- if( x >= p->x && x <= p->x+WIDGET_BUTTON_WIDTH &&
- y >= p->y && y <= p->y+WIDGET_BUTTON_HEIGHT &&
+ if( x >= widget->x && x <= widget->x+WIDGET_BUTTON_WIDTH &&
+ y >= widget->y && y <= widget->y+WIDGET_BUTTON_HEIGHT &&
isMouseClicked() )
{
time = WIDGET_BUTTON_TIME;
- p->fce_event(p);
+ printf("event\n");
+ p->fce_event(widget);
}
}
-void destroyWidgetButton(widget_button_t *p)
+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);
}