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