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