1 /* This is a small demo of the high-performance GUIX graphics framework. */
2 
3 #include <stdio.h>
4 #include <string.h>
5 #include "gx_api.h"
6 #include "gx_canvas.h"
7 
8 #include "graphics_palette_resources.h"
9 #include "graphics_palette_specifications.h"
10 
11 MAIN_WINDOW_CONTROL_BLOCK     *pMainWin;
12 ELLIPSE_WINDOW_CONTROL_BLOCK  *pEllipseWin;
13 GX_WINDOW                     *pGraphicsWin;
14 GX_RESOURCE_ID    line_color = GX_COLOR_ID_CANVAS;
15 GX_RESOURCE_ID    fill_color = GX_COLOR_ID_SCROLL_BUTTON;
16 INT               start_angle = 0;
17 INT               end_angle = 90;
18 INT               radius = 100;
19 GX_BOOL           anti_aliased = GX_TRUE;
20 GX_BOOL           solid_fill = GX_TRUE;
21 GX_BOOL           round_end = GX_TRUE;
22 GX_BOOL           pixelmap_fill = GX_FALSE;
23 INT               transparent = 0;
24 INT               compress = 0;
25 INT               brush_width = 1;
26 
27 GX_RESOURCE_ID    pixelmap_id= 2;
28 GX_RESOURCE_ID    fill_map[4] = { GX_PIXELMAP_ID_RAW, GX_PIXELMAP_ID_COMPRESSED, GX_PIXELMAP_ID_TRANSPARENT, GX_PIXELMAP_ID_CMOPRESSED_TRANSPARENT };
29 #define CIRCLE    0
30 #define ARC       1
31 #define PIE       2
32 #define POLYGON   3
33 #define ELLIPSE   4
34 
35 INT               draw_shape = CIRCLE;
36 INT               pre_shape;
37 INT               a = 100;
38 INT               b = 50;
39 
40 /* Define the ThreadX demo thread control block and stack.  */
41 
42 TX_THREAD          demo_thread;
43 UCHAR              demo_thread_stack[4096];
44 
45 GX_WINDOW_ROOT    *root;
46 
47 /* Define prototypes.   */
48 VOID  demo_thread_entry(ULONG thread_input);
49 extern UINT win32_graphics_driver_setup_8bit_palette(GX_DISPLAY *display);
50 
main(int argc,char ** argv)51 int main(int argc, char ** argv)
52 {
53   tx_kernel_enter();
54   return(0);
55 }
56 
57 
tx_application_define(void * first_unused_memory)58 VOID tx_application_define(void *first_unused_memory)
59 {
60 
61     /* Create the main demo thread.  */
62     tx_thread_create(&demo_thread, "GUIX Demo Thread", demo_thread_entry,
63                      0,  demo_thread_stack, sizeof(demo_thread_stack),
64                      1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
65 }
66 
67 
demo_thread_entry(ULONG thread_input)68 VOID  demo_thread_entry(ULONG thread_input)
69 {
70     /* Initialize GUIX.  */
71     gx_system_initialize();
72 
73 
74     gx_studio_display_configure(DISPLAY_1, win32_graphics_driver_setup_8bit_palette,
75                                 LANGUAGE_ENGLISH, DISPLAY_1_DEFAULT_THEME, &root);
76 
77     /* create the main screen */
78     gx_studio_named_widget_create("main_window", (GX_WIDGET *) root, (GX_WIDGET **) &pMainWin);
79 
80     /* create the ellipse screen */
81     gx_studio_named_widget_create("ellipse_window", GX_NULL, (GX_WIDGET **) &pEllipseWin);
82 
83     /* get a pointer to polygon window */
84     pGraphicsWin = &pMainWin -> main_window_graphics_window;
85 
86     /* Show the root window to make it and patients screen visible.  */
87     gx_widget_show(root);
88 
89     /* let GUIX run */
90     gx_system_start();
91 }
92 
update_prompt_value(GX_PROMPT * pp,INT value)93 VOID update_prompt_value(GX_PROMPT *pp, INT value)
94 {
95 GX_STRING str;
96 static GX_CHAR str_buf[10];
97 
98     if(pp)
99     {
100         gx_utility_ltoa(value, str_buf, 10);
101         str.gx_string_ptr = str_buf;
102         str.gx_string_length = strnlen(str_buf, 10);
103         gx_prompt_text_set_ext(pp, &str);
104     }
105 }
106 
ToggleScreen(GX_WINDOW * new_win,GX_WINDOW * old_win)107 void ToggleScreen(GX_WINDOW *new_win, GX_WINDOW *old_win)
108 {
109     if (!new_win->gx_widget_parent)
110     {
111         gx_widget_attach(root, (GX_WIDGET *) new_win);
112     }
113     else
114     {
115         gx_widget_show((GX_WIDGET *) new_win);
116     }
117     gx_widget_hide((GX_WIDGET *) old_win);
118 }
119 
main_event_handler(GX_WINDOW * window,GX_EVENT * myevent)120 UINT main_event_handler(GX_WINDOW *window, GX_EVENT *myevent)
121 {
122 UINT status = 0;
123 GX_PROMPT *prompt;
124 
125     switch(myevent -> gx_event_type)
126     {
127 
128     case GX_SIGNAL(ID_NEXT_PAGE, GX_EVENT_CLICKED):
129          switch(window ->gx_widget_id)
130             {
131             case ID_CIRCLE_SCREEN:
132                 /* we are on button window, switch to window */
133                 ToggleScreen((GX_WINDOW *)pEllipseWin, window);
134                 pGraphicsWin = &pEllipseWin -> ellipse_window_graphics_window;
135                 pre_shape = draw_shape;
136                 draw_shape = ELLIPSE;
137                 break;
138 
139             case ID_ELLIPSE_SCREEN:
140                 ToggleScreen((GX_WINDOW *)pMainWin, window);
141                 pGraphicsWin = &pMainWin -> main_window_graphics_window;
142                 draw_shape = pre_shape;
143                 break;
144             }
145             break;
146 
147     case GX_SIGNAL(ID_A_SLIDER, GX_EVENT_SLIDER_VALUE):
148         a = myevent ->gx_event_payload.gx_event_longdata;
149         prompt = &pEllipseWin->ellipse_window_a_prompt;
150         update_prompt_value(prompt, a);
151         gx_system_dirty_mark(pGraphicsWin);
152         break;
153 
154     case GX_SIGNAL(ID_B_SLIDER, GX_EVENT_SLIDER_VALUE):
155         b = myevent ->gx_event_payload.gx_event_longdata;
156         prompt = &pEllipseWin->ellipse_window_b_prompt;
157         update_prompt_value(prompt, b);
158         gx_system_dirty_mark(pGraphicsWin);
159         break;
160 
161     case GX_SIGNAL(ID_START_ANGLE_SLIDER, GX_EVENT_SLIDER_VALUE):
162         start_angle = myevent ->gx_event_payload.gx_event_longdata;
163         prompt = &pMainWin->main_window_start_angle_prompt;
164         update_prompt_value(prompt, start_angle);
165         gx_system_dirty_mark(pGraphicsWin);
166         break;
167 
168     case GX_SIGNAL(ID_END_ANGLE_SLIDER, GX_EVENT_SLIDER_VALUE):
169         end_angle = myevent ->gx_event_payload.gx_event_longdata;
170         prompt = &pMainWin->main_window_end_angle_prompt;
171         update_prompt_value(prompt, end_angle);
172         gx_system_dirty_mark(pGraphicsWin);
173         break;
174 
175     case GX_SIGNAL(ID_RADIUS_SLIDER, GX_EVENT_SLIDER_VALUE):
176         radius = myevent ->gx_event_payload.gx_event_longdata;
177         prompt = &pMainWin->main_window_radius_prompt;
178         update_prompt_value(prompt, radius);
179         gx_system_dirty_mark(pGraphicsWin);
180         break;
181 
182     case GX_SIGNAL(ID_BRUSH_WIDTH, GX_EVENT_SLIDER_VALUE):
183         brush_width = myevent->gx_event_payload.gx_event_longdata;
184         prompt = &pMainWin->main_window_brush_width_prompt;
185         update_prompt_value(prompt, brush_width);
186         gx_system_dirty_mark(pGraphicsWin);
187         break;
188 
189     case GX_SIGNAL(ID_ANTI_ALIASED, GX_EVENT_TOGGLE_ON):
190         anti_aliased = GX_TRUE;
191         gx_system_dirty_mark(pGraphicsWin);
192         break;
193 
194     case GX_SIGNAL(ID_ANTI_ALIASED, GX_EVENT_TOGGLE_OFF):
195         anti_aliased = GX_FALSE;
196         gx_system_dirty_mark(pGraphicsWin);
197         break;
198 
199     case GX_SIGNAL(ID_ROUND_END, GX_EVENT_TOGGLE_ON):
200         round_end = GX_TRUE;
201         gx_system_dirty_mark(pGraphicsWin);
202         break;
203 
204     case GX_SIGNAL(ID_ROUND_END, GX_EVENT_TOGGLE_OFF):
205         round_end = GX_FALSE;
206         gx_system_dirty_mark(pGraphicsWin);
207         break;
208 
209     case GX_SIGNAL(ID_SOLID_FILL, GX_EVENT_TOGGLE_ON):
210         solid_fill = GX_TRUE;
211         gx_system_dirty_mark(pGraphicsWin);
212         break;
213 
214     case GX_SIGNAL(ID_SOLID_FILL, GX_EVENT_TOGGLE_OFF):
215         solid_fill = GX_FALSE;
216         gx_system_dirty_mark(pGraphicsWin);
217         break;
218 
219     case GX_SIGNAL(ID_PIXELMAP_FILL, GX_EVENT_TOGGLE_ON):
220         pixelmap_fill = GX_TRUE;
221         gx_system_dirty_mark(pGraphicsWin);
222         break;
223 
224     case GX_SIGNAL(ID_PIXELMAP_FILL, GX_EVENT_TOGGLE_OFF):
225         pixelmap_fill = GX_FALSE;
226         gx_system_dirty_mark(pGraphicsWin);
227         break;
228 
229     case GX_SIGNAL(ID_WALLPAPER, GX_EVENT_TOGGLE_ON):
230         gx_window_wallpaper_set(pGraphicsWin, GX_PIXELMAP_ID_CHECKBOX_OFF, GX_TRUE);
231         break;
232 
233     case GX_SIGNAL(ID_WALLPAPER, GX_EVENT_TOGGLE_OFF):
234         gx_window_wallpaper_set(pGraphicsWin, GX_NULL, GX_TRUE);
235         break;
236 
237     case GX_SIGNAL(ID_BLACK, GX_EVENT_RADIO_SELECT):
238         fill_color = GX_COLOR_ID_CANVAS;
239         gx_system_dirty_mark(pGraphicsWin);
240         break;
241 
242     case GX_SIGNAL(ID_FRESHCOLOR, GX_EVENT_RADIO_SELECT):
243         fill_color = GX_COLOR_ID_SCROLL_BUTTON;
244         gx_system_dirty_mark(pGraphicsWin);
245         break;
246 
247     case GX_SIGNAL(ID_CIRCLE, GX_EVENT_RADIO_SELECT):
248         draw_shape = CIRCLE;
249         gx_system_dirty_mark(pGraphicsWin);
250         break;
251 
252     case GX_SIGNAL(ID_ARC, GX_EVENT_RADIO_SELECT):
253         draw_shape = ARC;
254         gx_system_dirty_mark(pGraphicsWin);
255         break;
256 
257     case GX_SIGNAL(ID_PIE, GX_EVENT_RADIO_SELECT):
258         draw_shape = PIE;
259         gx_system_dirty_mark(pGraphicsWin);
260         break;
261 
262     case GX_SIGNAL(ID_POLYGON, GX_EVENT_RADIO_SELECT):
263         draw_shape = POLYGON;
264         gx_system_dirty_mark(pGraphicsWin);
265         break;
266 
267     default:
268         status = gx_window_event_process(window, myevent);
269         break;
270     }
271     return status;
272 }
273 
graphics_draw(GX_WINDOW * window)274 VOID graphics_draw(GX_WINDOW *window)
275 {
276 ULONG brush_style = 0;
277 GX_POINT rectangle[4] = {{188, 50}, {254, 50}, {254, 150}, {188, 150}};
278 GX_POINT pentagon[5] = {{290, 90}, {335, 50}, {380, 90}, {360, 150}, {310, 150}};
279 GX_POINT concave[6] = {{50, 50}, {90, 80}, {130, 50}, {130, 150}, {90, 110}, {50, 150}};
280 GX_POINT star[10] = {{173, 232}, {212, 232}, {223, 192}, {237, 232}, {273, 232}, {244, 258}, {256, 299}, {226, 275}, {192, 298}, {203, 258}};
281 GX_POINT self_intersection[8] = {{110, 326}, {189, 420}, {266, 326}, {334, 420}, {334, 326}, {264, 420}, {189, 326}, {110, 420}};
282 
283     gx_window_draw((GX_WINDOW*) window);
284 
285     if(anti_aliased)
286     {
287         brush_style |= GX_BRUSH_ALIAS;
288     }
289 
290     if(round_end)
291     {
292         brush_style |= GX_BRUSH_ROUND;
293     }
294 
295     if(solid_fill)
296     {
297         brush_style |= GX_BRUSH_SOLID_FILL;
298     }
299 
300     if (pixelmap_fill)
301     {
302         brush_style |= GX_BRUSH_PIXELMAP_FILL;
303         gx_context_pixelmap_set(fill_map[pixelmap_id]);
304         /* Set same brush color and style with function gx_context_brush_define().
305         Just add this to test more functions. */
306         gx_context_raw_line_color_set(0);
307         gx_context_brush_style_set(brush_style);
308     }
309     else
310     {
311         gx_context_brush_define(line_color, fill_color, brush_style);
312     }
313 
314     gx_context_brush_width_set(brush_width);
315 
316     switch(draw_shape)
317     {
318     case CIRCLE:
319         if (!pixelmap_fill)
320         {
321             gx_context_raw_fill_color_set(GX_COLOR_GREEN);
322             gx_context_raw_line_color_set(GX_COLOR_YELLOW);
323         }
324         gx_canvas_circle_draw(213, 230, radius);
325         break;
326 
327     case ARC:
328         gx_canvas_arc_draw(213, 230, radius, start_angle, end_angle);
329         break;
330 
331     case PIE:
332         gx_canvas_pie_draw(213, 230, radius, start_angle, end_angle);
333         gx_context_fill_color_set(GX_COLOR_ID_SHINE);
334         if (pixelmap_fill)
335         {
336             gx_context_pixelmap_set(GX_PIXELMAP_ID_CHECKBOX_ON);
337         }
338         gx_canvas_pie_draw(213, 230, radius, end_angle, end_angle + 30);
339         break;
340 
341     case POLYGON:
342         gx_canvas_polygon_draw(rectangle, 4);
343         gx_canvas_polygon_draw(pentagon, 5);
344         gx_canvas_polygon_draw(concave, 6);
345         gx_canvas_polygon_draw(star, 10);
346         gx_canvas_polygon_draw(self_intersection, 8);
347         break;
348 
349     case ELLIPSE:
350         gx_canvas_ellipse_draw(213, 230, a, b);
351         break;
352     }
353 }
354