1 /* This is a demo of the high-performance GUIX graphics framework. */
2
3 #include <stdio.h>
4 #include "gx_api.h"
5 #include "all_widgets_8bpp_rotated_cw_binary_resources.h"
6 #include "all_widgets_8bpp_rotated_cw_binary_specifications.h"
7
8 extern GX_WINDOW *pShapesScreen;
9
10 GX_RESOURCE_ID line_color = GX_COLOR_ID_GRAY;
11 GX_RESOURCE_ID fill_color = GX_COLOR_ID_PURPLE;
12 INT xcenter = 213;
13 INT ycenter = 230;
14 INT radius = 160;
15 GX_BOOL round_end = GX_TRUE;
16 GX_BOOL solid_fill = GX_TRUE;
17 GX_BOOL pixelmap_fill = GX_FALSE;
18 INT brush_width = 2;
19 INT start_angle = 60;
20 INT end_angle = 90;
21 INT angle_off = 0;
22 INT ellipse_b = 100;
23 GX_UBYTE brush_alpha = 255;
24 INT fill_pixelmap_index = 0;
25 INT transparent = 0;
26 INT compress = 0;
27
28 GX_RESOURCE_ID pixelmap_id[4] = {
29 GX_PIXELMAP_ID__RAW,
30 GX_PIXELMAP_ID__TRANS,
31 GX_PIXELMAP_ID__COMPRESS,
32 GX_PIXELMAP_ID__COMPRESS_TRANS
33 };
34
35 #define CIRCLE 0
36 #define ARC 1
37 #define PIE 2
38 #define POLYGON 3
39 #define ELLIPSE 4
40 #define RECTANGLE 5
41
42 #define ARC_TIMER 5
43 #define PIE_TIMER 6
44
45 #define ARC_TICKS 2
46 #define PIE_TICKS 10
47
48 INT draw_shape = CIRCLE;
49 INT pre_shape;
50
update_prompt_value(GX_PROMPT * pp,INT value)51 VOID update_prompt_value(GX_PROMPT *pp, INT value)
52 {
53 static GX_CHAR str[10];
54
55 if (pp)
56 {
57 gx_utility_ltoa(value, str, 10);
58 gx_prompt_text_set(pp, str);
59 }
60 }
61
shapesscreen_event_handler(GX_WINDOW * window,GX_EVENT * myevent)62 UINT shapesscreen_event_handler(GX_WINDOW *window, GX_EVENT *myevent)
63 {
64 UINT status = 0;
65 GX_PROMPT *prompt;
66 GX_WINDOW *pGraphicsWin = &(((SHAPES_SCREEN_CONTROL_BLOCK *)pShapesScreen)->shapes_screen_graphics_window);
67
68 switch (myevent->gx_event_type)
69 {
70 case GX_EVENT_SHOW:
71 gx_window_event_process(window, myevent);
72 break;
73
74 case GX_SIGNAL(ID_BRUSH_ALPHA_SLIDER, GX_EVENT_SLIDER_VALUE):
75 brush_alpha = (GX_UBYTE )myevent->gx_event_payload.gx_event_longdata;
76 prompt = &(((SHAPES_SCREEN_CONTROL_BLOCK *)pShapesScreen) ->shapes_screen_prompt_12);
77 update_prompt_value(prompt, brush_alpha);
78 gx_system_dirty_mark(pGraphicsWin);
79 break;
80
81 case GX_SIGNAL(ID_RADIUS_SLIDER, GX_EVENT_SLIDER_VALUE):
82 radius = myevent->gx_event_payload.gx_event_longdata;
83 prompt = &(((SHAPES_SCREEN_CONTROL_BLOCK *)pShapesScreen)->shapes_screen_prompt_6);
84 update_prompt_value(prompt, radius);
85 gx_system_dirty_mark(pGraphicsWin);
86 break;
87
88 case GX_SIGNAL(ID_BRUSH_WIDTH, GX_EVENT_SLIDER_VALUE):
89 brush_width = myevent->gx_event_payload.gx_event_longdata;
90 prompt = &(((SHAPES_SCREEN_CONTROL_BLOCK *)pShapesScreen)->shapes_screen_prompt_7);
91 update_prompt_value(prompt, brush_width);
92 gx_system_dirty_mark(pGraphicsWin);
93 break;
94
95 case GX_SIGNAL(ID_ROUND_END, GX_EVENT_TOGGLE_ON):
96 round_end = GX_TRUE;
97 gx_system_dirty_mark(pGraphicsWin);
98 break;
99
100 case GX_SIGNAL(ID_ROUND_END, GX_EVENT_TOGGLE_OFF):
101 round_end = GX_FALSE;
102 gx_system_dirty_mark(pGraphicsWin);
103 break;
104
105 case GX_SIGNAL(ID_SOLID_FILL, GX_EVENT_TOGGLE_ON):
106 solid_fill = GX_TRUE;
107 gx_system_dirty_mark(pGraphicsWin);
108 break;
109
110 case GX_SIGNAL(ID_SOLID_FILL, GX_EVENT_TOGGLE_OFF):
111 solid_fill = GX_FALSE;
112 gx_system_dirty_mark(pGraphicsWin);
113 break;
114
115 case GX_SIGNAL(ID_PIXELMAP_FILL, GX_EVENT_TOGGLE_ON):
116 pixelmap_fill = GX_TRUE;
117 gx_system_dirty_mark(pGraphicsWin);
118 break;
119
120 case GX_SIGNAL(ID_PIXELMAP_FILL, GX_EVENT_TOGGLE_OFF):
121 pixelmap_fill = GX_FALSE;
122 gx_system_dirty_mark(pGraphicsWin);
123 break;
124
125 case GX_SIGNAL(ID_COMPRESS, GX_EVENT_TOGGLE_ON):
126 compress = 2;
127 gx_system_dirty_mark(pGraphicsWin);
128 break;
129
130 case GX_SIGNAL(ID_COMPRESS, GX_EVENT_TOGGLE_OFF):
131 compress = 0;
132 gx_system_dirty_mark(pGraphicsWin);
133 break;
134
135 case GX_SIGNAL(ID_TRANSPARENT, GX_EVENT_TOGGLE_ON):
136 transparent = 1;
137 gx_system_dirty_mark(pGraphicsWin);
138 break;
139
140 case GX_SIGNAL(ID_TRANSPARENT, GX_EVENT_TOGGLE_OFF):
141 transparent = 0;
142 gx_system_dirty_mark(pGraphicsWin);
143 break;
144
145 case GX_SIGNAL(ID_CIRCLE, GX_EVENT_RADIO_SELECT):
146 draw_shape = CIRCLE;
147 gx_system_dirty_mark(pGraphicsWin);
148 break;
149
150 case GX_SIGNAL(ID_ELLIPSE, GX_EVENT_RADIO_SELECT):
151 draw_shape = ELLIPSE;
152 gx_system_dirty_mark(pGraphicsWin);
153 break;
154
155 case GX_SIGNAL(ID_ARC, GX_EVENT_RADIO_SELECT):
156 draw_shape = ARC;
157 end_angle = start_angle;
158 gx_system_timer_start(pGraphicsWin, ARC_TIMER, ARC_TICKS, ARC_TICKS);
159 gx_system_dirty_mark(pGraphicsWin);
160 break;
161
162 case GX_SIGNAL(ID_PIE, GX_EVENT_RADIO_SELECT):
163 draw_shape = PIE;
164 gx_system_timer_start(pGraphicsWin, PIE_TIMER, PIE_TICKS, PIE_TICKS);
165 gx_system_dirty_mark(pGraphicsWin);
166 break;
167
168 case GX_SIGNAL(ID_POLYGON, GX_EVENT_RADIO_SELECT):
169 draw_shape = POLYGON;
170 gx_system_dirty_mark(pGraphicsWin);
171 break;
172
173 case GX_SIGNAL(ID_RECTANGLE, GX_EVENT_RADIO_SELECT):
174 draw_shape = RECTANGLE;
175 gx_system_dirty_mark(pGraphicsWin);
176 break;
177
178 case GX_EVENT_TIMER:
179 if (myevent->gx_event_payload.gx_event_timer_id == ARC_TIMER)
180 {
181 /* Update arc parameter. */
182 end_angle += 2;
183 if (end_angle == 360)
184 {
185 gx_system_timer_stop(pGraphicsWin, ARC_TIMER);
186 }
187 }
188 else if (myevent->gx_event_payload.gx_event_timer_id == PIE_TIMER)
189 {
190 /* Update pie parameter. */
191 angle_off += 2;
192 if (angle_off >= 360)
193 {
194 angle_off = 0;
195 }
196 gx_system_dirty_mark(pGraphicsWin);
197 }
198 break;
199
200 default:
201 return next_button_handler(window, myevent);
202 break;
203 }
204
205 fill_pixelmap_index = transparent + compress;
206 return status;
207 }
208
209
210
graphics_draw(GX_WINDOW * window)211 VOID graphics_draw(GX_WINDOW *window)
212 {
213 ULONG brush_style = 0;
214 GX_RECTANGLE rect;
215 GX_POINT rectangle[4] = { { 188, 50 },{ 254, 50 },{ 254, 150 },{ 188, 150 } };
216 GX_POINT rectangle_1[4] = { { 300, 200 }, { 539, 200 }, { 530, 250 }, { 310, 250 } };
217 GX_POINT rectangle_2[4] = { { 300, 0 }, { 539, 0 }, { 530, 50 }, { 310, 50 } };
218 GX_POINT pentagon[5] = { { 310, 150 }, { 290, 90 },{ 335, 50 },{ 380, 90 },{ 360, 150 } };
219 GX_POINT concave[6] = { { 50, 50 },{ 90, 80 },{ 130, 50 },{ 130, 150 },{ 90, 110 },{ 50, 150 } };
220 GX_POINT star[10] = { { 173, 227 },{ 212, 227 },{ 223, 187 },{ 237, 227 },{ 273, 227 },{ 244, 253 },{ 256, 294 },{ 226, 270 },{ 192, 293 },{ 203, 253 } };
221 GX_POINT self_intersection[8] = { { 110, 321 },{ 189, 415 },{ 266, 321 },{ 334, 415 },{ 334, 321 },{ 264, 415 },{ 189, 321 },{ 110, 415 } };
222 GX_BRUSH *brush;
223
224 gx_context_brush_get(&brush);
225 gx_window_draw((GX_WINDOW*)window);
226 brush->gx_brush_alpha = brush_alpha;
227
228 if (solid_fill)
229 {
230 brush_style |= GX_BRUSH_SOLID_FILL;
231 }
232
233 if (pixelmap_fill)
234 {
235 brush_style |= GX_BRUSH_PIXELMAP_FILL;
236 gx_context_pixelmap_set(pixelmap_id[fill_pixelmap_index]);
237 }
238
239 if (round_end)
240 {
241 brush_style |= GX_BRUSH_ROUND;
242 }
243
244 gx_context_brush_define(line_color, fill_color, brush_style);
245 gx_context_brush_width_set(brush_width);
246
247
248 switch (draw_shape)
249 {
250
251 case CIRCLE:
252 gx_canvas_circle_draw(xcenter, ycenter, radius);
253 break;
254
255 case ARC:
256
257 gx_canvas_arc_draw(xcenter, ycenter, radius, start_angle, end_angle);
258 break;
259
260 case PIE:
261 gx_context_brush_define(GX_COLOR_ID_GRAY, GX_COLOR_ID_INDIAN_RED, brush_style);
262 gx_canvas_pie_draw(xcenter, ycenter, radius, 60 + angle_off, 150 + angle_off);
263
264 gx_context_brush_define(GX_COLOR_ID_GRAY, GX_COLOR_ID_YELLOW, brush_style);
265 gx_canvas_pie_draw(xcenter, ycenter, radius, 150 + angle_off, 200 + angle_off);
266
267 gx_context_brush_define(GX_COLOR_ID_GRAY, GX_COLOR_ID_PINK, brush_style);
268 gx_canvas_pie_draw(xcenter, ycenter, radius, 200 + angle_off, 280 + angle_off);
269
270 gx_context_brush_define(GX_COLOR_ID_GRAY, GX_COLOR_ID_PURPLE, brush_style);
271 gx_canvas_pie_draw(xcenter, ycenter, radius, 280 + angle_off, 60 + angle_off);
272 break;
273
274 case RECTANGLE:
275 gx_context_line_color_set(GX_COLOR_ID_INDIAN_RED);
276 gx_context_fill_color_set(GX_COLOR_ID_YELLOW);
277 rect = window->gx_widget_size;
278 gx_utility_rectangle_resize(&rect, -10);
279 gx_canvas_rectangle_draw(&rect);
280
281 gx_utility_rectangle_resize(&rect, -30);
282 gx_context_fill_color_set(GX_COLOR_ID_BROWN);
283 gx_canvas_rectangle_draw(&rect);
284
285 gx_utility_rectangle_resize(&rect, -30);
286 gx_context_line_color_set(GX_COLOR_ID_WHITE);
287 gx_context_fill_color_set(GX_COLOR_ID_BLACK);
288 gx_canvas_rectangle_draw(&rect);
289 break;
290
291 case POLYGON:
292 gx_context_brush_define(GX_COLOR_ID_GREEN, fill_color, brush_style);
293 gx_canvas_polygon_draw(rectangle, 4);
294 gx_canvas_polygon_draw(rectangle_1, 4);
295 gx_canvas_polygon_draw(rectangle_2, 4);
296 gx_canvas_polygon_draw(pentagon, 5);
297 gx_canvas_polygon_draw(concave, 6);
298 gx_canvas_polygon_draw(star, 10);
299 gx_canvas_polygon_draw(self_intersection, 8);
300 break;
301
302 case ELLIPSE:
303 gx_context_brush_define(GX_COLOR_ID_BROWN, GX_COLOR_ID_YELLOW, brush_style);
304 gx_canvas_ellipse_draw(xcenter, ycenter, radius, ellipse_b);
305 break;
306 }
307
308 }