summaryrefslogtreecommitdiff
path: root/src/widget/widget_buttonimage.c
diff options
context:
space:
mode:
authorTomas Chvatal <scarabeus@gentoo.org>2008-12-11 19:39:49 +0100
committerTomas Chvatal <scarabeus@gentoo.org>2008-12-11 19:39:49 +0100
commita83321436c8d40210bbbd0a44fe1290ed71638af (patch)
tree02004c36772311bdc1ba6b9a2508b20691cca5c6 /src/widget/widget_buttonimage.c
parent3ba6105170ecac2fb124d9eb7e81ba72dd4700b8 (diff)
Revert "First pass for renaming screen/widget."
This reverts commit 3ba6105170ecac2fb124d9eb7e81ba72dd4700b8.
Diffstat (limited to 'src/widget/widget_buttonimage.c')
-rw-r--r--src/widget/widget_buttonimage.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/widget/widget_buttonimage.c b/src/widget/widget_buttonimage.c
new file mode 100644
index 0000000..dd20e62
--- /dev/null
+++ b/src/widget/widget_buttonimage.c
@@ -0,0 +1,86 @@
+
+#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);
+}