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