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
159
160
161
162
|
#include "gfx.h"
#include "stdio.h"
static GListener gl;
static GHandle ghFrame1;
static GHandle ghSliderR, ghSliderG, ghSliderB;
static GHandle ghButton1, ghButton2, ghButton3;
static GHandle ghWindow1;
static void _updateColor(void) {
uint32_t color;
color = (unsigned)gwinSliderGetPosition(ghSliderR) << 16;
color |= (unsigned)gwinSliderGetPosition(ghSliderG) << 8;
color |= (unsigned)gwinSliderGetPosition(ghSliderB) << 0;
gwinSetBgColor(ghWindow1, HTML2COLOR(color));
gwinClear(ghWindow1);
}
static void _createWidgets(void) {
GWidgetInit wi;
// Apply some default values for GWIN
gwinWidgetClearInit(&wi);
wi.g.show = TRUE;
// Create a surprise label behind the frame window
wi.g.width = 100;
wi.g.height = 20;
wi.g.y = 100;
wi.g.x = 150;
wi.text = "Surprise!";
gwinLabelCreate(0, &wi);
// Apply the frame parameters
wi.g.width = 300;
wi.g.height = 200;
wi.g.y = 10;
wi.g.x = 10;
wi.text = "Colorpicker";
ghFrame1 = gwinFrameCreate(0, &wi, GWIN_FRAME_BORDER | GWIN_FRAME_CLOSE_BTN | GWIN_FRAME_MINMAX_BTN);
// Apply the button parameters
wi.g.width = 60;
wi.g.height = 20;
wi.g.x = 10;
wi.g.y = 10;
wi.text = "Random";
wi.g.parent = ghFrame1;
ghButton1 = gwinButtonCreate(0, &wi);
// Apply the slider parameters
wi.g.width = 200;
wi.g.height = 20;
wi.g.x = 80;
wi.g.y += 0;
wi.text = "Red";
wi.g.parent = ghFrame1;
ghSliderR = gwinSliderCreate(0, &wi);
gwinSliderSetRange(ghSliderR, 0, 255);
gwinSliderSetPosition(ghSliderR, 180);
// Apply the button parameters
wi.g.width = 60;
wi.g.height = 20;
wi.g.x = 10;
wi.g.y += 25;
wi.text = "Random";
wi.g.parent = ghFrame1;
ghButton2 = gwinButtonCreate(0, &wi);
// Apply the slider parameters
wi.g.width = 200;
wi.g.height = 20;
wi.g.x = 80;
wi.g.y += 0;
wi.text = "Green";
wi.g.parent = ghFrame1;
ghSliderG = gwinSliderCreate(0, &wi);
gwinSliderSetRange(ghSliderG, 0, 255);
gwinSliderSetPosition(ghSliderG, 60);
// Apply the button parameters
wi.g.width = 60;
wi.g.height = 20;
wi.g.x = 10;
wi.g.y += 25;
wi.text = "Random";
wi.g.parent = ghFrame1;
ghButton3 = gwinButtonCreate(0, &wi);
// Apply the slider parameters
wi.g.width = 200;
wi.g.height = 20;
wi.g.x = 80;
wi.g.y += 0;
wi.text = "Blue";
wi.g.parent = ghFrame1;
ghSliderB = gwinSliderCreate(0, &wi);
gwinSliderSetRange(ghSliderB, 0, 255);
gwinSliderSetPosition(ghSliderB, 235);
// Color Preview
wi.g.width = 270;
wi.g.height = 65;
wi.g.x = 10;
wi.g.y = 90;
ghWindow1 = gwinWindowCreate(0, &wi.g);
_updateColor();
}
int main(void) {
GEvent* pe;
// Initialize the display
gfxInit();
// 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);
while(1) {
// Get an Event
pe = geventEventWait(&gl, TIME_INFINITE);
switch(pe->type) {
case GEVENT_GWIN_SLIDER:
if (((GEventGWinSlider *)pe)->gwin == ghSliderR || \
ghSliderG || \
ghSliderB ) {
_updateColor();
}
break;
case GEVENT_GWIN_BUTTON:
if (((GEventGWinButton *)pe)->gwin == ghButton1) {
gwinSliderSetPosition(ghSliderR, rand() % 256);
} else if (((GEventGWinButton *)pe)->gwin == ghButton2) {
gwinSliderSetPosition(ghSliderG, rand() % 256);
} else if (((GEventGWinButton *)pe)->gwin == ghButton3) {
gwinSliderSetPosition(ghSliderB, rand() % 256);
}
_updateColor();
default:
break;
}
}
return 0;
}
|