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