1 /* This is a small demo of the high-performance GUIX graphics framework. */
2 
3 #include <stdio.h>
4 #include "gx_api.h"
5 
6 #include "polygon_32bpp_resources.h"
7 #include "polygon_32bpp_specifications.h"
8 
9 MAIN_WINDOW_CONTROL_BLOCK *pMainWin;
10 GX_WINDOW      *pPolygonWin;
11 int            line_width = 1;
12 GX_RESOURCE_ID line_color = GX_COLOR_ID_CANVAS;
13 GX_RESOURCE_ID fill_color = GX_COLOR_ID_SCROLL_BUTTON;
14 
15 GX_BOOL    anti_aliased = GX_TRUE;
16 GX_BOOL    style_round = GX_TRUE;
17 GX_BOOL    solid_fill = GX_TRUE;
18 GX_CHAR    vertex_num_val[10];
19 GX_BOOL    pixelmap_fill = GX_FALSE;
20 int        alpha = 0;
21 int        compress = 0;
22 
23 GX_RESOURCE_ID pixelmap_id[2][2] = {{GX_PIXELMAP_ID_RADIOBUTTON_RAW, GX_PIXELMAP_ID_RADIOBUTTON_COMPRESS},
24                                     {GX_PIXELMAP_ID_RADIOBUTTON_ALPHA, GX_PIXELMAP_ID_RADIOBUTTON_ALPHA_COMPRESS}};
25 
26 /* Define the ThreadX demo thread control block and stack.  */
27 
28 TX_THREAD          demo_thread;
29 UCHAR              demo_thread_stack[4096];
30 
31 GX_WINDOW_ROOT    *root;
32 
33 /* Define prototypes.   */
34 VOID  demo_thread_entry(ULONG thread_input);
35 extern UINT win32_graphics_driver_setup_24xrgb(GX_DISPLAY *display);
36 
main(int argc,char ** argv)37 int main(int argc, char ** argv)
38 {
39   tx_kernel_enter();
40   return(0);
41 }
42 
43 
tx_application_define(void * first_unused_memory)44 VOID tx_application_define(void *first_unused_memory)
45 {
46 
47     /* Create the main demo thread.  */
48     tx_thread_create(&demo_thread, "GUIX Demo Thread", demo_thread_entry,
49                      0,  demo_thread_stack, sizeof(demo_thread_stack),
50                      1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
51 }
52 
53 
demo_thread_entry(ULONG thread_input)54 VOID  demo_thread_entry(ULONG thread_input)
55 {
56     /* Initialize GUIX.  */
57     gx_system_initialize();
58 
59 
60     gx_studio_display_configure(DISPLAY_1, win32_graphics_driver_setup_24xrgb,
61                                 LANGUAGE_ENGLISH, DISPLAY_1_DEFAULT_THEME, &root);
62 
63     /* create the main screen */
64     gx_studio_named_widget_create("main_window", (GX_WIDGET *) root, (GX_WIDGET **) &pMainWin);
65 
66     /* get a pointer to polygon window */
67     pPolygonWin = &pMainWin -> main_window_polygon_window;
68 
69     /* Show the root window to make it and patients screen visible.  */
70     gx_widget_show(root);
71 
72     /* let GUIX run */
73     gx_system_start();
74 }
75 
update_line_width_prompt()76 VOID update_line_width_prompt()
77 {
78 GX_PROMPT *pp;
79 static GX_CHAR width[10];
80 
81     gx_widget_find(pMainWin, ID_LINE_WIDTH_DISPLAY, 0, &pp);
82 
83     if(pp)
84     {
85         gx_utility_ltoa(line_width, width, 10);
86         gx_prompt_text_set(pp, width);
87     }
88 }
89 
main_event_handler(GX_WINDOW * window,GX_EVENT * myevent)90 UINT main_event_handler(GX_WINDOW *window, GX_EVENT *myevent)
91 {
92     UINT status = 0;
93 
94     switch(myevent -> gx_event_type)
95     {
96     case GX_SIGNAL(ID_LINE_WIDTH, GX_EVENT_SLIDER_VALUE):
97         line_width = myevent ->gx_event_payload.gx_event_longdata;
98         update_line_width_prompt();
99         gx_system_dirty_mark(pPolygonWin);
100         break;
101 
102     case GX_SIGNAL(ID_ANTI_ALIASED, GX_EVENT_TOGGLE_ON):
103         anti_aliased = GX_TRUE;
104         gx_system_dirty_mark(pPolygonWin);
105         break;
106 
107     case GX_SIGNAL(ID_ANTI_ALIASED, GX_EVENT_TOGGLE_OFF):
108         anti_aliased = GX_FALSE;
109         gx_system_dirty_mark(pPolygonWin);
110         break;
111 
112     case GX_SIGNAL(ID_ROUND, GX_EVENT_TOGGLE_ON):
113         style_round = GX_TRUE;
114         gx_system_dirty_mark(pPolygonWin);
115         break;
116 
117     case GX_SIGNAL(ID_ROUND, GX_EVENT_TOGGLE_OFF):
118         style_round = GX_FALSE;
119         gx_system_dirty_mark(pPolygonWin);
120         break;
121 
122     case GX_SIGNAL(ID_SOLID_FILL, GX_EVENT_TOGGLE_ON):
123         solid_fill = GX_TRUE;
124         gx_system_dirty_mark(pPolygonWin);
125         break;
126 
127     case GX_SIGNAL(ID_SOLID_FILL, GX_EVENT_TOGGLE_OFF):
128         solid_fill = GX_FALSE;
129         gx_system_dirty_mark(pPolygonWin);
130         break;
131 
132     case GX_SIGNAL(ID_PIXELMAP_FILL, GX_EVENT_TOGGLE_ON):
133         pixelmap_fill = GX_TRUE;
134         gx_system_dirty_mark(pPolygonWin);
135         break;
136 
137     case GX_SIGNAL(ID_PIXELMAP_FILL, GX_EVENT_TOGGLE_OFF):
138         pixelmap_fill = GX_FALSE;
139         gx_system_dirty_mark(pPolygonWin);
140         break;
141 
142     case GX_SIGNAL(ID_ALPHA, GX_EVENT_TOGGLE_ON):
143         alpha = 1;
144         gx_system_dirty_mark(pPolygonWin);
145         break;
146 
147     case GX_SIGNAL(ID_ALPHA, GX_EVENT_TOGGLE_OFF):
148         alpha = 0;
149         gx_system_dirty_mark(pPolygonWin);
150         break;
151 
152     case GX_SIGNAL(ID_COMPRESS, GX_EVENT_TOGGLE_ON):
153         compress = 1;
154         gx_system_dirty_mark(pPolygonWin);
155         break;
156 
157     case GX_SIGNAL(ID_COMPRESS, GX_EVENT_TOGGLE_OFF):
158         compress = 0;
159         gx_system_dirty_mark(pPolygonWin);
160         break;
161 
162     case GX_SIGNAL(ID_WALLPAPER, GX_EVENT_TOGGLE_ON):
163         gx_window_wallpaper_set(&pMainWin->main_window_polygon_window, GX_PIXELMAP_ID_CHECKBOX_OFF, GX_TRUE);
164         break;
165 
166     case GX_SIGNAL(ID_WALLPAPER, GX_EVENT_TOGGLE_OFF):
167         gx_window_wallpaper_set(&pMainWin->main_window_polygon_window, GX_NULL, GX_TRUE);
168         break;
169 
170     case GX_SIGNAL(ID_COLOR_BLACK, GX_EVENT_RADIO_SELECT):
171         fill_color = GX_COLOR_ID_CANVAS;
172         gx_system_dirty_mark(pPolygonWin);
173         break;
174 
175     case GX_SIGNAL(ID_COLOR_BLUE, GX_EVENT_RADIO_SELECT):
176         fill_color = GX_COLOR_ID_SCROLL_BUTTON;
177         gx_system_dirty_mark(pPolygonWin);
178         break;
179     default:
180         status = gx_window_event_process(window, myevent);
181         break;
182     }
183     return status;
184 }
185 
polygon_draw(GX_WINDOW * window)186 VOID polygon_draw(GX_WINDOW *window)
187 {
188 GX_POINT rectangle[4] = {{188, 50}, {254, 50}, {254, 150}, {188, 150}};
189 GX_POINT pentagon[5] = {{290, 90}, {335, 50}, {380, 90}, {360, 150}, {310, 150}};
190 GX_POINT concave[6] = {{50, 50}, {90, 80}, {130, 50}, {130, 150}, {90, 110}, {50, 150}};
191 GX_POINT star[10] = {{173, 232}, {212, 232}, {223, 192}, {237, 232}, {273, 232}, {244, 258}, {256, 299}, {226, 275}, {192, 298}, {203, 258}};
192 GX_POINT self_intersection[8] = {{110, 330}, {189, 420}, {266, 330}, {334, 424}, {334, 330}, {264, 424}, {189, 330}, {110, 424}};
193 ULONG brush_style = 0;
194 
195     gx_window_draw((GX_WINDOW*) window);
196 
197     if(anti_aliased)
198     {
199         brush_style |= GX_BRUSH_ALIAS;
200     }
201 
202     if(style_round)
203     {
204         brush_style |= GX_BRUSH_ROUND;
205     }
206 
207     if(solid_fill)
208     {
209         brush_style |= GX_BRUSH_SOLID_FILL;
210     }
211 
212     if(pixelmap_fill)
213     {
214         brush_style |= GX_BRUSH_PIXELMAP_FILL;
215         gx_context_pixelmap_set(pixelmap_id[alpha][compress]);
216     }
217 
218     gx_context_brush_define(line_color, fill_color, brush_style);
219     gx_context_brush_width_set(line_width);
220 
221     gx_canvas_polygon_draw(rectangle, 4);
222     gx_canvas_polygon_draw(pentagon, 5);
223     gx_canvas_polygon_draw(concave, 6);
224     gx_canvas_polygon_draw(star, 10);
225     gx_canvas_polygon_draw(self_intersection, 8);
226 }
227