summaryrefslogtreecommitdiff
path: root/src/widget/widget_buttonimage.c~
diff options
context:
space:
mode:
authorTomas Chvatal (scarabeus) <tomas.chvatal@gmail.com>2008-10-22 22:50:54 +0200
committerTomas Chvatal (scarabeus) <tomas.chvatal@gmail.com>2008-10-22 22:50:54 +0200
commite12753d2ec9db83ec08bb9db63902a82fb245cdd (patch)
tree6e4a63b790d6335f969f88b797a927e0fb25f37a /src/widget/widget_buttonimage.c~
parent0b4d9821c7333b8c4bdf7e0eeb750aef502a1137 (diff)
X
Diffstat (limited to 'src/widget/widget_buttonimage.c~')
-rw-r--r--src/widget/widget_buttonimage.c~88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/widget/widget_buttonimage.c~ b/src/widget/widget_buttonimage.c~
new file mode 100644
index 0000000..27e94a3
--- /dev/null
+++ b/src/widget/widget_buttonimage.c~
@@ -0,0 +1,88 @@
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include "main.h"
+#include "interface.h"
+#include "font.h"
+#include "image.h"
+
+#include "widget.h"
+#include "widget_buttonimage.h"
+
+widget_t* newWidgetButtonimage(image_t *image, int x, int y, void (*fce_event)(void *))
+{
+ widget_buttonimage_t *new;
+
+ new = malloc( sizeof(widget_buttonimage_t) );
+ new->image = image;
+ new->w = image->w/2;
+ new->h = image->h;
+ new->active = 0;
+ new->fce_event = fce_event;
+
+ return newWidget(WIDGET_TYPE_BUTTONIMAGE, x, y, new->w, new->h, new);
+}
+
+void setWidgetButtonimageActive(widget_t *widget, bool_t active)
+{
+ widget_buttonimage_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_BUTTONIMAGE );
+
+ p = (widget_buttonimage_t *)widget->private_data;
+ p->active = active;
+}
+
+void drawWidgetButtonimage(widget_t *widget)
+{
+ widget_buttonimage_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_BUTTONIMAGE );
+
+ p = (widget_buttonimage_t *)widget->private_data;
+ drawImage(p->image, widget->x, widget->y, p->active*p->w, 0, p->w, p->h);
+}
+
+void eventWidgetButtonimage(widget_t *widget)
+{
+ widget_buttonimage_t *p;
+ static int time = 0;
+ int x, y;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_BUTTONIMAGE );
+
+ p = (widget_buttonimage_t *) widget->private_data;
+ if( time > 0)
+ {
+ time--;
+ return;
+ }
+
+ getMousePosition(&x, &y);
+
+ if( x >= widget->x && x <= widget->x+p->w &&
+ y >= widget->y && y <= widget->y+p->h &&
+ isMouseClicked() )
+ {
+ time = WIDGET_BUTTONIMAGE_TIME;
+ p->active = 1;
+ p->fce_event(widget);
+ }
+}
+
+void destroyWidgetButtonimage(widget_t *widget)
+{
+ widget_buttonimage_t *p;
+
+ assert( widget != NULL );
+ assert( widget->type == WIDGET_TYPE_BUTTONIMAGE );
+
+ p = (widget_buttonimage_t *) widget->private_data;
+
+ free(p);
+ destroyWidget(widget);
+}