1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
#include <stdlib.h>
#include <assert.h>
#include "main.h"
#include "interface.h"
#include "image.h"
#include "widget.h"
#include "widget_choicegroup.h"
widget_t *choiceGroup_new(int x, int y, bool_t status, list_t * list, void (*fce_event) (void *))
{
widget_choicegroup_t *new;
widget_t *widget;
new = malloc(sizeof(widget_choicegroup_t));
new->time = 0;
new->status = status;
new->fce_event = fce_event;
new->list = list;
widget = widget_new(WIDGET_TYPE_CHOICE, x, y, WIDGET_CHOICEGROUP_WIDTH, WIDGET_CHOICEGROUP_HEIGHT, new);
list_add(new->list, widget);
return widget;
}
void choiceGroup_draw(widget_t * widget)
{
widget_choicegroup_t *p;
static image_t *g_choicegroup = NULL;
int x, y;
int offset;
assert(widget != NULL);
assert(widget->type == WIDGET_TYPE_CHOICE);
p = (widget_choicegroup_t *) widget->private_data;
interface_get_mouse_position(&x, &y);
if (g_choicegroup == NULL) {
g_choicegroup = image_add("choice.png", IMAGE_ALPHA, "choicegroup", IMAGE_GROUP_BASE);
}
if (p->status == TRUE) {
offset = 0;
} else {
offset = WIDGET_CHOICEGROUP_WIDTH;
}
image_draw(g_choicegroup, widget->x, widget->y, offset, 0,
WIDGET_CHOICEGROUP_WIDTH, WIDGET_CHOICEGROUP_HEIGHT);
}
void choiceGroup_set_active(widget_t * widget)
{
widget_choicegroup_t *p;
int i;
assert(widget != NULL);
assert(widget->type == WIDGET_TYPE_CHOICE);
p = (widget_choicegroup_t *) widget->private_data;
for (i = 0; i < p->list->count; i++) {
widget_t *this;
widget_choicegroup_t *thisChoice;
this = (widget_t *) p->list->list[i];
thisChoice = (widget_choicegroup_t *) this->private_data;
if (widget == this) {
thisChoice->status = TRUE;
thisChoice->time = WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS;
thisChoice->fce_event(p);
} else {
thisChoice->status = FALSE;
}
}
}
bool_t choiceGroup_get_status(widget_t * widget)
{
widget_choicegroup_t *p;
assert(widget != NULL);
assert(widget->type == WIDGET_TYPE_CHOICE);
p = (widget_choicegroup_t *) widget->private_data;
return p->status;
}
void choiceGroup_set_status(widget_t * widget, bool_t status)
{
widget_choicegroup_t *p;
assert(widget != NULL);
assert(widget->type == WIDGET_TYPE_CHOICE);
p = (widget_choicegroup_t *) widget->private_data;
p->status = status;
}
void choiceGroup_event(widget_t * widget)
{
widget_choicegroup_t *p;
int x, y;
assert(widget != NULL);
assert(widget->type == WIDGET_TYPE_CHOICE);
p = (widget_choicegroup_t *) widget->private_data;
if (p->time > 0) {
p->time--;
return;
}
interface_get_mouse_position(&x, &y);
if (x >= widget->x && x <= widget->x + WIDGET_CHOICEGROUP_WIDTH &&
y >= widget->y && y <= widget->y + WIDGET_CHOICEGROUP_HEIGHT &&
interface_is_mouse_clicket()) {
choiceGroup_set_active(widget);
}
}
void choiceGroup_destroy(widget_t * widget)
{
widget_choicegroup_t *p;
int my_index;
assert(widget != NULL);
assert(widget->type == WIDGET_TYPE_CHOICE);
p = (widget_choicegroup_t *) widget->private_data;
my_index = list_search(p->list, widget);
assert(my_index != -1);
list_del(p->list, my_index);
free(p);
widget_destroy(widget);
}
|