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
7 #include "polygon_16bpp_resources.h"
8 #include "polygon_16bpp_specifications.h"
9
10 MAIN_WINDOW_CONTROL_BLOCK *pMainWin;
11 GX_WINDOW *pPolygonWin;
12 int line_width = 1;
13 GX_RESOURCE_ID line_color = GX_COLOR_ID_CANVAS;
14 GX_RESOURCE_ID fill_color = GX_COLOR_ID_SCROLL_BUTTON;
15
16 GX_BOOL anti_aliased = GX_TRUE;
17 GX_BOOL style_round = GX_TRUE;
18 GX_BOOL solid_fill = GX_TRUE;
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_565rgb(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_565rgb,
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_buf[10];
80 GX_STRING width;
81
82 gx_widget_find(pMainWin, ID_LINE_WIDTH_DISPLAY, 0, &pp);
83
84 if(pp)
85 {
86 gx_utility_ltoa(line_width, width_buf, 10);
87 width.gx_string_ptr = width_buf;
88 width.gx_string_length = strnlen(width_buf, sizeof(width_buf) - 1);
89 gx_prompt_text_set_ext(pp, &width);
90 }
91 }
92
main_event_handler(GX_WINDOW * window,GX_EVENT * myevent)93 UINT main_event_handler(GX_WINDOW *window, GX_EVENT *myevent)
94 {
95 UINT status = 0;
96
97 switch(myevent -> gx_event_type)
98 {
99 case GX_SIGNAL(ID_LINE_WIDTH, GX_EVENT_SLIDER_VALUE):
100 line_width = myevent ->gx_event_payload.gx_event_longdata;
101 update_line_width_prompt();
102 gx_system_dirty_mark(pPolygonWin);
103 break;
104
105 case GX_SIGNAL(ID_ANTI_ALIASED, GX_EVENT_TOGGLE_ON):
106 anti_aliased = GX_TRUE;
107 gx_system_dirty_mark(pPolygonWin);
108 break;
109
110 case GX_SIGNAL(ID_ANTI_ALIASED, GX_EVENT_TOGGLE_OFF):
111 anti_aliased = GX_FALSE;
112 gx_system_dirty_mark(pPolygonWin);
113 break;
114
115 case GX_SIGNAL(ID_ROUND, GX_EVENT_TOGGLE_ON):
116 style_round = GX_TRUE;
117 gx_system_dirty_mark(pPolygonWin);
118 break;
119
120 case GX_SIGNAL(ID_ROUND, GX_EVENT_TOGGLE_OFF):
121 style_round = GX_FALSE;
122 gx_system_dirty_mark(pPolygonWin);
123 break;
124
125 case GX_SIGNAL(ID_SOLID_FILL, GX_EVENT_TOGGLE_ON):
126 solid_fill = GX_TRUE;
127 gx_system_dirty_mark(pPolygonWin);
128 break;
129
130 case GX_SIGNAL(ID_SOLID_FILL, GX_EVENT_TOGGLE_OFF):
131 solid_fill = GX_FALSE;
132 gx_system_dirty_mark(pPolygonWin);
133 break;
134 case GX_SIGNAL(ID_PIXELMAP_FILL, GX_EVENT_TOGGLE_ON):
135 pixelmap_fill = GX_TRUE;
136 gx_system_dirty_mark(pPolygonWin);
137 break;
138
139 case GX_SIGNAL(ID_PIXELMAP_FILL, GX_EVENT_TOGGLE_OFF):
140 pixelmap_fill = GX_FALSE;
141 gx_system_dirty_mark(pPolygonWin);
142 break;
143
144 case GX_SIGNAL(ID_ALPHA, GX_EVENT_TOGGLE_ON):
145 alpha = 1;
146 gx_system_dirty_mark(pPolygonWin);
147 break;
148
149 case GX_SIGNAL(ID_ALPHA, GX_EVENT_TOGGLE_OFF):
150 alpha = 0;
151 gx_system_dirty_mark(pPolygonWin);
152 break;
153
154 case GX_SIGNAL(ID_COMPRESS, GX_EVENT_TOGGLE_ON):
155 compress = 1;
156 gx_system_dirty_mark(pPolygonWin);
157 break;
158
159 case GX_SIGNAL(ID_COMPRESS, GX_EVENT_TOGGLE_OFF):
160 compress = 0;
161 gx_system_dirty_mark(pPolygonWin);
162 break;
163
164 case GX_SIGNAL(ID_WALLPAPER, GX_EVENT_TOGGLE_ON):
165 gx_window_wallpaper_set(&pMainWin->main_window_polygon_window, GX_PIXELMAP_ID_CHECKBOX_OFF, GX_TRUE);
166 break;
167
168 case GX_SIGNAL(ID_WALLPAPER, GX_EVENT_TOGGLE_OFF):
169 gx_window_wallpaper_set(&pMainWin->main_window_polygon_window, GX_NULL, GX_TRUE);
170 break;
171
172 case GX_SIGNAL(ID_COLOR_BLACK, GX_EVENT_RADIO_SELECT):
173 fill_color = GX_COLOR_ID_CANVAS;
174 gx_system_dirty_mark(pPolygonWin);
175 break;
176
177 case GX_SIGNAL(ID_COLOR_BLUE, GX_EVENT_RADIO_SELECT):
178 fill_color = GX_COLOR_ID_SCROLL_BUTTON;
179 gx_system_dirty_mark(pPolygonWin);
180 break;
181
182 default:
183 status = gx_window_event_process(window, myevent);
184 break;
185 }
186 return status;
187 }
188
189
190 #define NUM_VERTICES 6
polygon_draw(GX_WINDOW * window)191 VOID polygon_draw(GX_WINDOW *window)
192 {
193 GX_POINT polygon_1[4] = { { 70, 162 }, { 116, 163 }, { 96, 264 }, { 50, 263 } };
194 GX_POINT polygon_2[4] = { { 300, 162 }, { 346, 163 }, { 326, 274 }, { 280, 263 } };
195 GX_POINT polygon_3[4] = { { 50, 302 }, { 96, 303 }, { 41, 434 }, { 40, 403 } };
196 GX_POINT rectangle[4] = {{188, 50}, {254, 50}, {254, 150}, {188, 150}};
197 GX_POINT pentagon[5] = {{290, 90}, {335, 50}, {380, 90}, {360, 150}, {310, 150}};
198 GX_POINT concave[6] = {{50, 50}, {90, 80}, {130, 50}, {130, 150}, {90, 110}, {50, 150}};
199 GX_POINT star[10] = {{173, 232}, {212, 232}, {223, 192}, {237, 232}, {273, 232}, {244, 258}, {256, 299}, {226, 275}, {192, 298}, {203, 258}};
200 GX_POINT self_intersection[8] = {{110, 330}, {189, 420}, {266, 330}, {334, 424}, {334, 330}, {264, 424}, {189, 330}, {110, 424}};
201 ULONG brush_style = 0;
202
203 gx_window_draw((GX_WINDOW*) window);
204
205 if(anti_aliased)
206 {
207 brush_style |= GX_BRUSH_ALIAS;
208 }
209
210 if(style_round)
211 {
212 brush_style |= GX_BRUSH_ROUND;
213 }
214
215 if(solid_fill)
216 {
217 brush_style |= GX_BRUSH_SOLID_FILL;
218 }
219
220 if(pixelmap_fill)
221 {
222 brush_style |= GX_BRUSH_PIXELMAP_FILL;
223 gx_context_pixelmap_set(pixelmap_id[alpha][compress]);
224 }
225
226 gx_context_brush_define(line_color, fill_color, brush_style);
227 gx_context_brush_width_set(line_width);
228
229 gx_canvas_polygon_draw(rectangle, 4);
230 gx_canvas_polygon_draw(pentagon, 5);
231 gx_canvas_polygon_draw(concave, 6);
232 gx_canvas_polygon_draw(star, 10);
233 gx_canvas_polygon_draw(self_intersection, 8);
234
235 gx_canvas_polygon_draw(polygon_1, 4);
236 gx_canvas_polygon_draw(polygon_2, 4);
237 gx_canvas_polygon_draw(polygon_3, 4);
238 }
239