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_565rgb_synergy_resources.h"
8 #include "graphics_565rgb_synergy_specifications.h"
9 
10 MAIN_WINDOW_CONTROL_BLOCK     *pMainWin;
11 GX_WINDOW                     *pGraphicsWin;
12 GX_RESOURCE_ID    line_color = GX_COLOR_ID_CANVAS;
13 GX_RESOURCE_ID    fill_color = GX_COLOR_ID_SCROLL_BUTTON;
14 INT               start_angle = 0;
15 INT               end_angle = 90;
16 INT               radius = 100;
17 GX_BOOL           anti_aliased = GX_TRUE;
18 GX_BOOL           solid_fill = GX_TRUE;
19 GX_BOOL           pixelmap_fill = GX_FALSE;
20 INT               compress = 0;
21 INT               brush_width = 1;
22 
23 GX_RESOURCE_ID    pixelmap_id[2] = {GX_PIXELMAP_ID_PIXELMAP_RAW, GX_PIXELMAP_ID_PIXELMAP_COMPRESSED };
24 #define CIRCLE    0
25 #define ARC       1
26 #define PIE       2
27 #define POLYGON   3
28 #define ELLIPSE   4
29 
30 INT               draw_shape = CIRCLE;
31 INT               pre_shape;
32 INT               a = 100;
33 INT               b = 50;
34 
35 /* Define the ThreadX demo thread control block and stack.  */
36 
37 TX_THREAD          demo_thread;
38 UCHAR              demo_thread_stack[4096];
39 
40 GX_WINDOW_ROOT    *root;
41 
42 /* Define prototypes.   */
43 VOID  demo_thread_entry(ULONG thread_input);
44 extern UINT win32_dave2d_graphics_driver_setup_565rgb(GX_DISPLAY *display);
45 
main(int argc,char ** argv)46 int main(int argc, char ** argv)
47 {
48   tx_kernel_enter();
49   return(0);
50 }
51 
52 
tx_application_define(void * first_unused_memory)53 VOID tx_application_define(void *first_unused_memory)
54 {
55 
56     /* Create the main demo thread.  */
57     tx_thread_create(&demo_thread, "GUIX Demo Thread", demo_thread_entry,
58                      0,  demo_thread_stack, sizeof(demo_thread_stack),
59                      1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
60 }
61 
62 
demo_thread_entry(ULONG thread_input)63 VOID  demo_thread_entry(ULONG thread_input)
64 {
65     /* Initialize GUIX.  */
66     gx_system_initialize();
67 
68 
69     gx_studio_display_configure(DISPLAY_1, win32_dave2d_graphics_driver_setup_565rgb,
70                                 LANGUAGE_ENGLISH, DISPLAY_1_DEFAULT_THEME, &root);
71 
72     /* create the main screen */
73     gx_studio_named_widget_create("main_window", (GX_WIDGET *) root, (GX_WIDGET **) &pMainWin);
74 
75     /* get a pointer to polygon window */
76     pGraphicsWin = &pMainWin -> main_window_graphics_window;
77 
78     /* Show the root window to make it and patients screen visible.  */
79     gx_widget_show(root);
80 
81     /* let GUIX run */
82     gx_system_start();
83 }
84 
update_prompt_value(GX_PROMPT * pp,INT value)85 VOID update_prompt_value(GX_PROMPT *pp, INT value)
86 {
87 static GX_CHAR str[10];
88 
89     if(pp)
90     {
91         gx_utility_ltoa(value, str, 10);
92         gx_prompt_text_set(pp, str);
93     }
94 }
95 
ToggleScreen(GX_WINDOW * new_win,GX_WINDOW * old_win)96 void ToggleScreen(GX_WINDOW *new_win, GX_WINDOW *old_win)
97 {
98     if (!new_win->gx_widget_parent)
99     {
100         gx_widget_attach(root, (GX_WIDGET *) new_win);
101     }
102     else
103     {
104         gx_widget_show((GX_WIDGET *) new_win);
105     }
106     gx_widget_hide((GX_WIDGET *) old_win);
107 }
108 
main_event_handler(GX_WINDOW * window,GX_EVENT * myevent)109 UINT main_event_handler(GX_WINDOW *window, GX_EVENT *myevent)
110 {
111 UINT status = 0;
112 GX_PROMPT *prompt;
113 
114     switch(myevent -> gx_event_type)
115     {
116     case GX_SIGNAL(ID_START_ANGLE_SLIDER, GX_EVENT_SLIDER_VALUE):
117         start_angle = myevent ->gx_event_payload.gx_event_longdata;
118         prompt = &pMainWin->main_window_start_angle_prompt;
119         update_prompt_value(prompt, start_angle);
120         gx_system_dirty_mark(pGraphicsWin);
121         break;
122 
123     case GX_SIGNAL(ID_END_ANGLE_SLIDER, GX_EVENT_SLIDER_VALUE):
124         end_angle = myevent ->gx_event_payload.gx_event_longdata;
125         prompt = &pMainWin->main_window_end_angle_prompt;
126         update_prompt_value(prompt, end_angle);
127         gx_system_dirty_mark(pGraphicsWin);
128         break;
129 
130     case GX_SIGNAL(ID_RADIUS_SLIDER, GX_EVENT_SLIDER_VALUE):
131         radius = myevent ->gx_event_payload.gx_event_longdata;
132         prompt = &pMainWin->main_window_radius_prompt;
133         update_prompt_value(prompt, radius);
134         gx_system_dirty_mark(pGraphicsWin);
135         break;
136 
137     case GX_SIGNAL(ID_BRUSH_WIDTH, GX_EVENT_SLIDER_VALUE):
138         brush_width = myevent->gx_event_payload.gx_event_longdata;
139         prompt = &pMainWin->main_window_brush_width_prompt;
140         update_prompt_value(prompt, brush_width);
141         gx_system_dirty_mark(pGraphicsWin);
142         break;
143 
144     case GX_SIGNAL(ID_SOLID_FILL, GX_EVENT_TOGGLE_ON):
145         solid_fill = GX_TRUE;
146         gx_system_dirty_mark(pGraphicsWin);
147         break;
148 
149     case GX_SIGNAL(ID_SOLID_FILL, GX_EVENT_TOGGLE_OFF):
150         solid_fill = GX_FALSE;
151         gx_system_dirty_mark(pGraphicsWin);
152         break;
153 
154     case GX_SIGNAL(ID_PIXELMAP_FILL, GX_EVENT_TOGGLE_ON):
155         pixelmap_fill = GX_TRUE;
156         gx_system_dirty_mark(pGraphicsWin);
157         break;
158 
159     case GX_SIGNAL(ID_PIXELMAP_FILL, GX_EVENT_TOGGLE_OFF):
160         pixelmap_fill = GX_FALSE;
161         gx_system_dirty_mark(pGraphicsWin);
162         break;
163 
164     case GX_SIGNAL(ID_COMPRESS, GX_EVENT_TOGGLE_ON):
165         compress = 1;
166         gx_system_dirty_mark(pGraphicsWin);
167         break;
168 
169     case GX_SIGNAL(ID_COMPRESS, GX_EVENT_TOGGLE_OFF):
170         compress = 0;
171         gx_system_dirty_mark(pGraphicsWin);
172         break;
173 
174     case GX_SIGNAL(ID_WALLPAPER, GX_EVENT_TOGGLE_ON):
175         gx_window_wallpaper_set(pGraphicsWin, GX_PIXELMAP_ID_CHECKBOX_OFF, GX_TRUE);
176         break;
177 
178     case GX_SIGNAL(ID_WALLPAPER, GX_EVENT_TOGGLE_OFF):
179         gx_window_wallpaper_set(pGraphicsWin, GX_NULL, GX_TRUE);
180         break;
181 
182     case GX_SIGNAL(ID_BLACK, GX_EVENT_RADIO_SELECT):
183         fill_color = GX_COLOR_ID_CANVAS;
184         gx_system_dirty_mark(pGraphicsWin);
185         break;
186 
187     case GX_SIGNAL(ID_FRESHCOLOR, GX_EVENT_RADIO_SELECT):
188         fill_color = GX_COLOR_ID_SCROLL_BUTTON;
189         gx_system_dirty_mark(pGraphicsWin);
190         break;
191 
192     case GX_SIGNAL(ID_CIRCLE, GX_EVENT_RADIO_SELECT):
193         draw_shape = CIRCLE;
194         gx_system_dirty_mark(pGraphicsWin);
195         break;
196 
197     case GX_SIGNAL(ID_ARC, GX_EVENT_RADIO_SELECT):
198         draw_shape = ARC;
199         gx_system_dirty_mark(pGraphicsWin);
200         break;
201 
202     case GX_SIGNAL(ID_PIE, GX_EVENT_RADIO_SELECT):
203         draw_shape = PIE;
204         gx_system_dirty_mark(pGraphicsWin);
205         break;
206 
207     case GX_SIGNAL(ID_POLYGON, GX_EVENT_RADIO_SELECT):
208         draw_shape = POLYGON;
209         gx_system_dirty_mark(pGraphicsWin);
210         break;
211 
212     case GX_SIGNAL(ID_ELLIPSE, GX_EVENT_RADIO_SELECT):
213         draw_shape = ELLIPSE;
214         gx_system_dirty_mark(pGraphicsWin);
215         break;
216 
217     default:
218         status = gx_window_event_process(window, myevent);
219         break;
220     }
221     return status;
222 }
223 
graphics_draw(GX_WINDOW * window)224 VOID graphics_draw(GX_WINDOW *window)
225 {
226 ULONG brush_style = 0;
227 GX_POINT rectangle[4] = {{188, 50}, {254, 50}, {254, 150}, {188, 150}};
228 GX_POINT pentagon[5] = {{290, 90}, {335, 50}, {380, 90}, {360, 150}, {310, 150}};
229 GX_POINT concave[6] = {{50, 50}, {90, 80}, {130, 50}, {130, 150}, {90, 110}, {50, 150}};
230 GX_POINT star[10] = {{173, 232}, {212, 232}, {223, 192}, {237, 232}, {273, 232}, {244, 258}, {256, 299}, {226, 275}, {192, 298}, {203, 258}};
231 GX_POINT self_intersection[8] = {{110, 326}, {189, 420}, {266, 326}, {334, 420}, {334, 326}, {264, 420}, {189, 326}, {110, 420}};
232 
233     gx_window_draw((GX_WINDOW*) window);
234 
235     if(anti_aliased)
236     {
237         brush_style |= GX_BRUSH_ALIAS;
238     }
239 
240     if(solid_fill)
241     {
242         brush_style |= GX_BRUSH_SOLID_FILL;
243     }
244 
245     if(pixelmap_fill)
246     {
247         brush_style |= GX_BRUSH_PIXELMAP_FILL;
248         gx_context_pixelmap_set(pixelmap_id[compress]);
249     }
250 
251     gx_context_brush_define(line_color, fill_color, brush_style);
252     gx_context_brush_width_set(brush_width);
253 
254     switch(draw_shape)
255     {
256     case CIRCLE:
257         gx_canvas_circle_draw(213, 230, radius);
258         break;
259 
260     case ARC:
261         gx_canvas_arc_draw(213, 230, radius, start_angle, end_angle);
262         break;
263 
264     case PIE:
265         gx_canvas_pie_draw(213, 230, radius, start_angle, end_angle);
266         gx_context_fill_color_set(GX_COLOR_ID_SHINE);
267         if (pixelmap_fill)
268         {
269             gx_context_pixelmap_set(GX_PIXELMAP_ID_CHECKBOX_ON);
270         }
271         gx_canvas_pie_draw(213, 230, radius, end_angle, end_angle + 30);
272         break;
273 
274     case POLYGON:
275         gx_canvas_polygon_draw(rectangle, 4);
276         gx_canvas_polygon_draw(pentagon, 5);
277         gx_canvas_polygon_draw(concave, 6);
278         gx_canvas_polygon_draw(star, 10);
279         gx_canvas_polygon_draw(self_intersection, 8);
280         break;
281 
282     case ELLIPSE:
283         gx_canvas_ellipse_draw(213, 230, a, b);
284         break;
285     }
286 
287     gx_widget_children_draw(window);
288 }
289