summaryrefslogtreecommitdiff
path: root/src/widget/check.c
diff options
context:
space:
mode:
authorTomas Chvatal <scarabeus@gentoo.org>2008-12-11 22:34:18 +0100
committerTomas Chvatal <scarabeus@gentoo.org>2008-12-11 22:34:18 +0100
commit5855f591b6d509633e3730346e18122768ec6e04 (patch)
treecd98fd39a789464294fd05ae00eeea5bd9411138 /src/widget/check.c
parenta83321436c8d40210bbbd0a44fe1290ed71638af (diff)
First pass renaming sreen and widgets.
Diffstat (limited to 'src/widget/check.c')
-rw-r--r--src/widget/check.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/widget/check.c b/src/widget/check.c
new file mode 100644
index 0000000..7ef4b8b
--- /dev/null
+++ b/src/widget/check.c
@@ -0,0 +1,118 @@
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include "main.h"
+#include "interface.h"
+#include "image.h"
+
+#include "widget.h"
+#include "check.h"
+
+widget_t *newWidgetCheck(int x, int y, bool_t status, void (*fce_event) (void *))
+{
+ widget_check_t *new;
+
+ new = malloc(sizeof(widget_check_t));
+ new->time = 0;
+ new->status = status;
+ new->fce_event = fce_event;
+
+ return newWidget(WIDGET_TYPE_CHECK, x, y, WIDGET_CHECK_WIDTH, WIDGET_CHECK_HEIGHT, new);
+}
+
+void drawWidgetCheck(widget_t * widget)
+{
+ widget_check_t *p;
+ static image_t *g_check = NULL;
+ int x, y;
+ int offset;
+
+ assert(widget != NULL);
+ assert(widget->type == WIDGET_TYPE_CHECK);
+
+ p = (widget_check_t *) widget->private_data;
+
+ getMousePosition(&x, &y);
+
+ if (g_check == NULL) {
+ g_check = addImageData("check.png", IMAGE_ALPHA, "check", IMAGE_GROUP_BASE);
+ }
+
+ if (p->status == TRUE) {
+ offset = 0;
+ } else {
+ offset = WIDGET_CHECK_WIDTH;
+ }
+
+ drawImage(g_check, widget->x, widget->y, offset, 0, WIDGET_CHECK_WIDTH, WIDGET_CHECK_HEIGHT);
+}
+
+void eventWidgetCheck(widget_t * widget)
+{
+ widget_check_t *p;
+ int x, y;
+
+ assert(widget != NULL);
+ assert(widget->type == WIDGET_TYPE_CHECK);
+
+ p = (widget_check_t *) widget->private_data;
+
+ if (p->time > 0) {
+ p->time--;
+ return;
+ }
+
+ getMousePosition(&x, &y);
+
+ if (x >= widget->x && x <= widget->x + WIDGET_CHECK_WIDTH &&
+ y >= widget->y && y <= widget->y + WIDGET_CHECK_HEIGHT &&
+ isMouseClicked()) {
+ if (p->status == TRUE) {
+ p->status = FALSE;
+ p->time = WIDGET_CHECK_TIME_SWITCH_STATUS;
+ } else {
+ p->status = TRUE;
+ p->time = WIDGET_CHECK_TIME_SWITCH_STATUS;
+ }
+
+ if (p->fce_event != NULL) {
+ p->fce_event(widget);
+ }
+ }
+}
+
+bool_t getWidgetCheckStatus(widget_t * widget)
+{
+ widget_check_t *p;
+
+ assert(widget != NULL);
+ assert(widget->type == WIDGET_TYPE_CHECK);
+
+ p = (widget_check_t *) widget->private_data;
+
+ return p->status;
+}
+
+void setWidgetCheckStatus(widget_t * widget, bool_t status)
+{
+ widget_check_t *p;
+
+ assert(widget != NULL);
+ assert(widget->type == WIDGET_TYPE_CHECK);
+
+ p = (widget_check_t *) widget->private_data;
+ p->status = status;
+}
+
+void destroyWidgetCheck(widget_t * widget)
+{
+ widget_check_t *p;
+
+ assert(widget != NULL);
+ assert(widget->type == WIDGET_TYPE_CHECK);
+
+ p = (widget_check_t *) widget->private_data;
+ free(p);
+ destroyWidget(widget);
+}