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