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