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
148
149
150
151
152
153
154
155
156
157
158
|
#include "gfx.h"
static GListener gl;
static GHandle ghContainer1, ghContainer2, ghContainer3;
static GHandle ghButton1, ghButton2, ghButton3, ghButton4;
static GHandle ghCheckbox1, ghCheckbox2, ghCheckbox3;
static void createWidgets(void) {
GWidgetInit wi;
// Apply some default values for GWIN
gwinWidgetClearInit(&wi);
wi.g.show = FALSE;
// Container 1
wi.g.width = 300;
wi.g.height = 220;
wi.g.y = 40;
wi.g.x = 10;
wi.text = "Container 1";
ghContainer1 = gwinContainerCreate(0, &wi, GWIN_CONTAINER_BORDER);
wi.g.show = TRUE;
// Container 2
wi.g.width = 100;
wi.g.height = 150;
wi.g.y = 55;
wi.g.x = 10;
wi.g.parent = ghContainer1;
wi.text = "Container 2";
ghContainer2 = gwinContainerCreate(0, &wi, GWIN_CONTAINER_BORDER);
// Container 3
wi.g.width = 100;
wi.g.height = 150;
wi.g.y = 55;
wi.g.x = 185;
wi.g.parent = ghContainer1;
wi.text = "Container 3";
ghContainer3 = gwinContainerCreate(0, &wi, GWIN_CONTAINER_BORDER);
// Button 1
wi.g.width = 80;
wi.g.height = 20;
wi.g.y = 10;
wi.g.x = 10;
wi.text = "Button 1";
wi.g.parent = ghContainer2;
ghButton1 = gwinButtonCreate(0, &wi);
// Button 2
wi.g.width = 80;
wi.g.height = 20;
wi.g.y = 40;
wi.g.x = 10;
wi.text = "Button 2";
wi.g.parent = ghContainer2;
ghButton2 = gwinButtonCreate(0, &wi);
// Button 3
wi.g.width = 80;
wi.g.height = 20;
wi.g.y = 10;
wi.g.x = 10;
wi.text = "Button 3";
wi.g.parent = ghContainer3;
ghButton3 = gwinButtonCreate(0, &wi);
// Button 4
wi.g.width = 80;
wi.g.height = 20;
wi.g.y = 40;
wi.g.x = 10;
wi.text = "Button 4";
wi.g.parent = ghContainer3;
ghButton4 = gwinButtonCreate(0, &wi);
// Checkbox 1
wi.g.width = 80;
wi.g.height = 20;
wi.g.y = 25;
wi.g.x = 10;
wi.text = " Visible C2";
wi.g.parent = ghContainer1;
ghCheckbox1 = gwinCheckboxCreate(0, &wi);
// Checkbox 2
wi.g.width = 80;
wi.g.height = 20;
wi.g.y = 25;
wi.g.x = 185;
wi.text = " Visible C3";
wi.g.parent = ghContainer1;
ghCheckbox2 = gwinCheckboxCreate(0, &wi);
// Checkbox 3
wi.g.width = 80;
wi.g.height = 20;
wi.g.y = 10;
wi.g.x = 10;
wi.text = " Visible C1";
wi.g.parent = 0;
ghCheckbox3 = gwinCheckboxCreate(0, &wi);
// Make the container become visible - therefore all its children
// become visible as well
gwinShow(ghContainer1);
}
int main(void) {
GEvent* pe;
// Initialize the display
gfxInit();
// Attach the mouse input
gwinAttachMouse(0);
// Set the widget defaults
gwinSetDefaultFont(gdispOpenFont("*"));
gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE);
gdispClear(White);
// Create the widget
createWidgets();
// We want to listen for widget events
geventListenerInit(&gl);
gwinAttachListener(&gl);
// Set the initial state of the checkboxes
gwinCheckboxCheck(ghCheckbox1, TRUE);
gwinCheckboxCheck(ghCheckbox2, TRUE);
gwinCheckboxCheck(ghCheckbox3, TRUE);
while(1) {
// Get an Event
pe = geventEventWait(&gl, TIME_INFINITE);
switch(pe->type) {
case GEVENT_GWIN_CHECKBOX:
if (((GEventGWinCheckbox*)pe)->gwin == ghCheckbox1) {
gwinSetVisible(ghContainer2, gwinCheckboxIsChecked(ghCheckbox1));
}
else if (((GEventGWinCheckbox*)pe)->gwin == ghCheckbox2) {
gwinSetVisible(ghContainer3, gwinCheckboxIsChecked(ghCheckbox2));
}
else if (((GEventGWinCheckbox*)pe)->gwin == ghCheckbox3) {
gwinSetVisible(ghContainer1, gwinCheckboxIsChecked(ghCheckbox3));
}
break;
}
}
return 0;
}
|