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_synergy_24xrgb_rotated_cw_resources.h"
6 #include "all_widgets_synergy_24xrgb_rotated_cw_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__24XRGB, GX_PIXELMAP_ID__24XRGB_A,
30 GX_PIXELMAP_ID__24XRGB_C, GX_PIXELMAP_ID__24XRGB_C_A};
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 end_angle = 0;
195 }
196 gx_system_dirty_mark(pGraphicsWin);
197 }
198 else if (myevent->gx_event_payload.gx_event_timer_id == PIE_TIMER)
199 {
200 /* Update pie parameter. */
201 angle_off += 2;
202 if (angle_off >= 360)
203 {
204 angle_off = 0;
205 }
206 gx_system_dirty_mark(pGraphicsWin);
207 }
208 break;
209
210 default:
211 return next_button_handler(window, myevent);
212 break;
213 }
214 fill_pixelmap_index = alpha + compress;
215 return status;
216 }
217
218
219
graphics_draw(GX_WINDOW * window)220 VOID graphics_draw(GX_WINDOW *window)
221 {
222 ULONG brush_style = 0;
223 GX_RECTANGLE rect;
224 GX_POINT rectangle[4] = { { 188, 50 },{ 254, 50 },{ 254, 150 },{ 188, 150 } };
225 GX_POINT rectangle_1[4] = { { 300, 200 }, { 539, 200 }, { 530, 250 }, { 310, 250 } };
226 GX_POINT rectangle_2[4] = { { 300, 0 }, { 539, 0 }, { 530, 50 }, { 310, 50 } };
227 GX_POINT pentagon[5] = { { 310, 150 }, { 290, 90 },{ 335, 50 },{ 380, 90 },{ 360, 150 } };
228 GX_POINT concave[6] = { { 50, 50 },{ 90, 80 },{ 130, 50 },{ 130, 150 },{ 90, 110 },{ 50, 150 } };
229 GX_POINT star[10] = { { 173, 227 },{ 212, 227 },{ 223, 187 },{ 237, 227 },{ 273, 227 },{ 244, 253 },{ 256, 294 },{ 226, 270 },{ 192, 293 },{ 203, 253 } };
230 GX_POINT self_intersection[8] = { { 110, 321 },{ 189, 415 },{ 266, 321 },{ 334, 415 },{ 334, 321 },{ 264, 415 },{ 189, 321 },{ 110, 415 } };
231 GX_BRUSH *brush;
232
233 gx_context_brush_get(&brush);
234 gx_window_draw((GX_WINDOW*)window);
235 brush->gx_brush_alpha = brush_alpha;
236
237 if (anti_aliased)
238 {
239 brush_style |= GX_BRUSH_ALIAS;
240 }
241
242 if (solid_fill)
243 {
244 brush_style |= GX_BRUSH_SOLID_FILL;
245 }
246
247 if (pixelmap_fill)
248 {
249 brush_style |= GX_BRUSH_PIXELMAP_FILL;
250 gx_context_pixelmap_set(pixelmap_id[fill_pixelmap_index]);
251 }
252
253 if (round_end)
254 {
255 brush_style |= GX_BRUSH_ROUND;
256 }
257
258 gx_context_brush_define(line_color, fill_color, brush_style);
259 gx_context_brush_width_set(brush_width);
260
261
262 switch (draw_shape)
263 {
264
265 case CIRCLE:
266 gx_canvas_circle_draw(xcenter, ycenter, radius);
267 break;
268
269 case ARC:
270
271 gx_canvas_arc_draw(xcenter, ycenter, radius, start_angle, end_angle);
272 break;
273
274 case PIE:
275 gx_context_brush_define(GX_COLOR_ID_GRAY, GX_COLOR_ID_INDIAN_RED, brush_style);
276 gx_canvas_pie_draw(xcenter, ycenter, radius, 60 + angle_off, 150 + angle_off);
277
278 gx_context_brush_define(GX_COLOR_ID_GRAY, GX_COLOR_ID_YELLOW, brush_style);
279 gx_canvas_pie_draw(xcenter, ycenter, radius, 150 + angle_off, 200 + angle_off);
280
281 gx_context_brush_define(GX_COLOR_ID_GRAY, GX_COLOR_ID_PINK, brush_style);
282 gx_canvas_pie_draw(xcenter, ycenter, radius, 200 + angle_off, 280 + angle_off);
283
284 gx_context_brush_define(GX_COLOR_ID_GRAY, GX_COLOR_ID_PURPLE, brush_style);
285 gx_canvas_pie_draw(xcenter, ycenter, radius, 280 + angle_off, 60 + angle_off);
286 break;
287
288 case RECTANGLE:
289 gx_context_line_color_set(GX_COLOR_ID_INDIAN_RED);
290 gx_context_fill_color_set(GX_COLOR_ID_YELLOW);
291 rect = window->gx_widget_size;
292 gx_utility_rectangle_resize(&rect, -10);
293 gx_canvas_rectangle_draw(&rect);
294
295 gx_utility_rectangle_resize(&rect, -30);
296 gx_context_fill_color_set(GX_COLOR_ID_BROWN);
297 gx_canvas_rectangle_draw(&rect);
298
299 gx_utility_rectangle_resize(&rect, -30);
300 gx_context_line_color_set(GX_COLOR_ID_WHITE);
301 gx_context_fill_color_set(GX_COLOR_ID_BLACK);
302 gx_canvas_rectangle_draw(&rect);
303 break;
304
305 case POLYGON:
306 gx_context_brush_define(GX_COLOR_ID_GREEN, fill_color, brush_style);
307 gx_canvas_polygon_draw(rectangle, 4);
308 gx_canvas_polygon_draw(rectangle_1, 4);
309 gx_canvas_polygon_draw(rectangle_2, 4);
310 gx_canvas_polygon_draw(pentagon, 5);
311 gx_canvas_polygon_draw(concave, 6);
312 gx_canvas_polygon_draw(star, 10);
313 gx_canvas_polygon_draw(self_intersection, 8);
314 break;
315
316 case ELLIPSE:
317 gx_context_brush_define(GX_COLOR_ID_BROWN, GX_COLOR_ID_YELLOW, brush_style);
318 gx_canvas_ellipse_draw(xcenter, ycenter, radius, ellipse_b);
319 #if 0
320 if (radius > 50)
321 {
322 gx_context_brush_define(GX_COLOR_ID_BROWN, GX_COLOR_ID_WHITE, brush_style);
323 gx_canvas_ellipse_draw(xcenter, ycenter, radius - 50, ellipse_b);
324 }
325
326 if (radius > 100)
327 {
328 gx_context_brush_define(GX_COLOR_ID_BROWN, GX_COLOR_ID_YELLOW, brush_style);
329 gx_canvas_ellipse_draw(xcenter, ycenter, radius - 100, ellipse_b);
330 }
331 #endif
332 break;
333 }
334
335 }