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 "all_widgets_4bpp_resources.h"
6 #include "all_widgets_4bpp_specifications.h"
7
8 #define DROP_LIST_VISIBLE_ROWS 5
9 #define NUMBER_ANIMATION_TIMER 2
10
11 GX_WINDOW *pTextScreen;
12 GX_WINDOW *pWindowScreen;
13 GX_WINDOW *pButtonScreen;
14 GX_WINDOW *pIndicatorScreen;
15 GX_WINDOW *pShapesScreen;
16 GX_WINDOW *pGraphicsWin;
17 GX_WINDOW *pSpriteScreen;
18 GX_WINDOW *pLineScreen;
19 GX_WINDOW *pRotateScreen;
20 GX_WINDOW *pScrollWheelScreen;
21 GX_WINDOW *pRotateWin;
22 GX_SCROLLBAR list_scroll;
23
24 extern MENU_SCREEN_CONTROL_BLOCK menu_screen;
25
26 /* Define the ThreadX demo thread control block and stack. */
27
28 TX_THREAD demo_thread;
29 UCHAR demo_thread_stack[4096];
30 TX_BYTE_POOL rotate_pool;
31
32 GX_WINDOW NestedWindow;
33 GX_WINDOW_ROOT nested_root;
34
35 GX_BOOL day_wheel_selected_row_changed = GX_FALSE;/* Used for testing*/
36 GX_BOOL month_wheel_selected_row_changed = GX_FALSE;/* Used for testing*/
37 #define NESTED_WINDOW_WIDTH 94
38 #define NESTED_WINDOW_HEIGHT 73
39
40 GX_WINDOW_ROOT *root;
41
42 #define SCRATCHPAD_PIXELS (MAIN_DISPLAY_X_RESOLUTION * MAIN_DISPLAY_X_RESOLUTION)
43 GX_COLOR scratchpad[SCRATCHPAD_PIXELS];
44 GX_COLOR composite_canvas_memory[SCRATCHPAD_PIXELS];
45 GX_COLOR animation_canvas_memory[NESTED_WINDOW_WIDTH * NESTED_WINDOW_HEIGHT];
46
47 GX_CANVAS composite_canvas;
48 GX_CANVAS animation_canvas;
49
50 extern GX_STUDIO_DISPLAY_INFO all_widgets_4bpp_display_table[];
51
52 typedef struct {
53 GX_PROMPT prompt;
54 CHAR text[80];
55 } DROP_LIST_WIDGET;
56
57 DROP_LIST_WIDGET drop_list_widgets[DROP_LIST_VISIBLE_ROWS + 1];
58 INT numeric_prompt_value = 10000;
59
60
61 /* Define prototypes. */
62 VOID PopulateDropList();
63 VOID demo_thread_entry(ULONG thread_input);
64 VOID memory_free(VOID *mem);
65 extern UINT win32_graphics_driver_setup_4bpp_grayscale(GX_DISPLAY *display);
66
main(int argc,char ** argv)67 int main(int argc, char ** argv)
68 {
69 tx_kernel_enter();
70 return(0);
71 }
72
memory_allocate(ULONG size)73 VOID *memory_allocate(ULONG size)
74 {
75 VOID *memptr;
76
77 if (tx_byte_allocate(&rotate_pool, &memptr, size, TX_NO_WAIT) == TX_SUCCESS)
78 {
79 return memptr;
80 }
81
82 return NULL;
83 }
84
memory_free(VOID * mem)85 VOID memory_free(VOID *mem)
86 {
87 tx_byte_release(mem);
88 }
89
tx_application_define(void * first_unused_memory)90 VOID tx_application_define(void *first_unused_memory)
91 {
92
93 /* Create the main demo thread. */
94 tx_thread_create(&demo_thread, "GUIX Demo Thread", demo_thread_entry,
95 0, demo_thread_stack, sizeof(demo_thread_stack),
96 1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
97
98 }
99
100
demo_thread_entry(ULONG thread_input)101 VOID demo_thread_entry(ULONG thread_input)
102 {
103 GX_RECTANGLE winsize;
104
105 tx_byte_pool_create(&rotate_pool, "scratchpad", scratchpad,
106 SCRATCHPAD_PIXELS * sizeof(GX_COLOR));
107
108 /* Initialize GUIX. */
109 gx_system_initialize();
110
111 gx_system_memory_allocator_set(memory_allocate, memory_free);
112
113 gx_studio_display_configure(MAIN_DISPLAY, win32_graphics_driver_setup_4bpp_grayscale,
114 LANGUAGE_ENGLISH, MAIN_DISPLAY_THEME_1, &root);
115
116 /* create the button screen */
117 gx_studio_named_widget_create("button_screen", GX_NULL, (GX_WIDGET **) &pButtonScreen);
118
119 /* create the text widget screen */
120 gx_studio_named_widget_create("text_screen", GX_NULL, (GX_WIDGET **) &pTextScreen);
121
122 /* create the windows screen */
123 gx_studio_named_widget_create("window_screen", GX_NULL, (GX_WIDGET **) &pWindowScreen);
124 PopulateDropList();
125
126 /* create the indicator screen */
127 gx_studio_named_widget_create("indicator_screen", GX_NULL, (GX_WIDGET **) &pIndicatorScreen);
128
129 /* create the shapes screen */
130 gx_studio_named_widget_create("shapes_screen", GX_NULL, (GX_WIDGET **)&pShapesScreen);
131
132 /* create the sprite screen */
133 gx_studio_named_widget_create("sprite_screen", (GX_WIDGET *)root, (GX_WIDGET **)&pSpriteScreen);
134
135 /* create the rotate screen */
136 gx_studio_named_widget_create("rotate_screen", GX_NULL, (GX_WIDGET **)&pRotateScreen);
137 pRotateWin = &(((ROTATE_SCREEN_CONTROL_BLOCK *)pRotateScreen)->rotate_screen_pixelmap_window);
138
139 /* create the sprite screen */
140 gx_studio_named_widget_create("line_screen", (GX_WIDGET *)GX_NULL, (GX_WIDGET **)&pLineScreen);
141
142 /* create menu screen */
143 gx_studio_named_widget_create("menu_screen", GX_NULL, GX_NULL);
144
145 gx_studio_named_widget_create("image_convert_screen", GX_NULL, GX_NULL);
146
147 gx_studio_named_widget_create("resize_screen", GX_NULL, GX_NULL);
148
149 /* Show the root window to make it and patients screen visible. */
150 gx_widget_show(root);
151
152 /* create the composite canvas used during animations */
153 gx_canvas_create(&composite_canvas, GX_NULL,
154 all_widgets_4bpp_display_table[0].display,
155 GX_CANVAS_COMPOSITE,
156 root->gx_widget_size.gx_rectangle_right - root->gx_widget_size.gx_rectangle_left + 1,
157 root->gx_widget_size.gx_rectangle_bottom - root->gx_widget_size.gx_rectangle_top + 1,
158 composite_canvas_memory, SCRATCHPAD_PIXELS * sizeof(GX_COLOR));
159 gx_canvas_alpha_set(&composite_canvas, 255);
160
161 /* create the nested window shown on the window screen */
162
163 winsize.gx_rectangle_left = winsize.gx_rectangle_top = 0;
164 winsize.gx_rectangle_right = NESTED_WINDOW_WIDTH - 1;
165 winsize.gx_rectangle_bottom = NESTED_WINDOW_HEIGHT - 1;
166 gx_window_create(&NestedWindow, GX_NULL, GX_NULL, GX_STYLE_BORDER_THIN, 0, &winsize);
167 gx_widget_fill_color_set(&NestedWindow, GX_COLOR_ID_GRAY, GX_COLOR_ID_GRAY, GX_COLOR_ID_GRAY);
168
169 /* create the root window used for window blend animation */
170 gx_window_root_create(&nested_root, "nested_root", &animation_canvas, GX_STYLE_BORDER_NONE, GX_NULL, &NestedWindow.gx_widget_size);
171 gx_widget_attach((GX_WIDGET *)&nested_root, (GX_WIDGET *)&NestedWindow);
172
173 /* let GUIX run */
174 gx_system_start();
175 }
176
ToggleScreen(GX_WINDOW * new_win,GX_WINDOW * old_win)177 void ToggleScreen(GX_WINDOW *new_win, GX_WINDOW *old_win)
178 {
179 if (!new_win->gx_widget_parent)
180 {
181 gx_widget_attach(root, (GX_WIDGET *) new_win);
182 }
183 else
184 {
185 gx_widget_show((GX_WIDGET *) new_win);
186 }
187 gx_widget_hide((GX_WIDGET *) old_win);
188 }
189
next_button_handler(GX_WINDOW * window,GX_EVENT * event_ptr)190 UINT next_button_handler(GX_WINDOW *window, GX_EVENT *event_ptr)
191 {
192 switch(event_ptr->gx_event_type)
193 {
194 case GX_SIGNAL(IDB_NEXT, GX_EVENT_CLICKED):
195 switch(window ->gx_widget_id)
196 {
197 case ID_BUTTON_SCREEN:
198 /* we are on button window, switch to window */
199 ToggleScreen(pWindowScreen, window);
200 break;
201
202 case ID_WINDOW_SCREEN:
203 ToggleScreen(pTextScreen, window);
204 gx_system_timer_start(pTextScreen, NUMBER_ANIMATION_TIMER, 20, 20);
205 break;
206
207 case ID_TEXT_SCREEN:
208 ToggleScreen(pIndicatorScreen, window);
209 gx_system_timer_stop(window, NUMBER_ANIMATION_TIMER);
210 break;
211
212 case ID_INDICATOR_SCREEN:
213 ToggleScreen(pShapesScreen, window);
214 break;
215
216 case ID_SHAPES_SCREEN:
217 ToggleScreen(pSpriteScreen, window);
218 break;
219
220 case ID_SPRITE_SCREEN:
221 ToggleScreen(pRotateScreen, window);
222 break;
223
224 case ID_ROTATE_SCREEN:
225 gx_studio_named_widget_create("scroll_wheel_screen", GX_NULL, (GX_WIDGET **)&pScrollWheelScreen);
226 ToggleScreen((GX_WINDOW *)pScrollWheelScreen, window);
227 break;
228
229 case ID_SCROLL_WHEEL_SCREEN:
230 ToggleScreen((GX_WINDOW *)&menu_screen, window);
231 gx_tree_view_selected_set(&menu_screen.menu_screen_tree_view, (GX_WIDGET *)&menu_screen.menu_screen_tree_menu_2_2);
232 gx_widget_delete(window);
233 break;
234
235 case ID_MENU_SCREEN:
236 ToggleScreen((GX_WINDOW *)&image_convert_screen, window);
237 break;
238
239 case ID_IMAGE_CONVERT_SCREEN:
240 ToggleScreen(pLineScreen, window);
241 break;
242
243 case ID_LINE_SCREEN:
244 ToggleScreen((GX_WINDOW *)&resize_screen, window);
245 break;
246
247 case ID_RESIZE_SCREEN:
248 ToggleScreen(pButtonScreen, window);
249 break;
250 }
251 break;
252
253 case GX_EVENT_TIMER:
254 if (event_ptr->gx_event_payload.gx_event_timer_id == NUMBER_ANIMATION_TIMER)
255 {
256 numeric_prompt_value++;
257
258 if (numeric_prompt_value > 19999)
259 {
260 numeric_prompt_value = 10000;
261 }
262 gx_numeric_prompt_value_set(&text_screen.text_screen_numeric_prompt_1, numeric_prompt_value);
263 gx_numeric_pixelmap_prompt_value_set(&text_screen.text_screen_numeric_pixelmap_prompt_1, numeric_prompt_value);
264 }
265 break;
266
267 default:
268 return gx_window_event_process(window, event_ptr);
269 }
270 return 0;
271 }
272
window_screen_event_handler(GX_WINDOW * window,GX_EVENT * event_ptr)273 UINT window_screen_event_handler(GX_WINDOW *window, GX_EVENT *event_ptr)
274 {
275 switch (event_ptr->gx_event_type)
276 {
277 case GX_EVENT_SHOW:
278 /* Create new canvas to save the semi-transparent window,
279 Then set alpha to canvas and shift it. */
280 gx_canvas_create(&animation_canvas, GX_NULL,
281 all_widgets_4bpp_display_table[0].display,
282 GX_CANVAS_MANAGED_VISIBLE,
283 NESTED_WINDOW_WIDTH, NESTED_WINDOW_HEIGHT,
284 animation_canvas_memory, NESTED_WINDOW_WIDTH * NESTED_WINDOW_HEIGHT * sizeof(GX_COLOR));
285 gx_canvas_alpha_set(&animation_canvas, 255);
286 gx_canvas_offset_set(&animation_canvas, 94, 67);
287 gx_widget_show((GX_WIDGET *)&nested_root);
288 gx_window_event_process(window, event_ptr);
289
290 gx_window_client_scroll(&window_screen.window_screen_scroll_frame_1, 1, 1);
291 break;
292
293 case GX_EVENT_HIDE:
294 gx_widget_hide((GX_WIDGET *)&nested_root);
295 gx_canvas_delete(&animation_canvas);
296 gx_window_event_process(window, event_ptr);
297 break;
298
299 default:
300 return next_button_handler(window, event_ptr);
301 }
302 return 0;
303 }
304
drop_list_row_create(GX_VERTICAL_LIST * list,GX_WIDGET * widget,INT index)305 VOID drop_list_row_create(GX_VERTICAL_LIST *list, GX_WIDGET *widget, INT index)
306 {
307 GX_BOOL created;
308 GX_RECTANGLE size;
309 GX_CHAR temp[10];
310 GX_STRING string;
311
312 DROP_LIST_WIDGET *entry = (DROP_LIST_WIDGET *) widget;
313
314 GX_STRCPY(entry->text, "List Entry #");
315 gx_utility_ltoa(index + 1, temp, 10);
316 GX_STRCAT(entry->text, (char*)temp);
317
318 gx_widget_created_test(widget, &created);
319
320 if (!created)
321 {
322 gx_utility_rectangle_define(&size, 0, 0, 100, 30);
323 gx_prompt_create(&entry->prompt, entry->text, list, 0, GX_STYLE_ENABLED|GX_STYLE_TEXT_LEFT|GX_STYLE_BORDER_NONE, 0, &size);
324 gx_widget_fill_color_set(&entry->prompt, GX_COLOR_ID_BLACK, GX_COLOR_ID_BLUE, GX_COLOR_ID_BLACK);
325 gx_prompt_text_color_set(&entry->prompt, GX_COLOR_ID_WHITE, GX_COLOR_ID_WHITE, GX_COLOR_ID_WHITE);
326 }
327
328 string.gx_string_ptr = entry->text;
329 string.gx_string_length = strnlen(string.gx_string_ptr, sizeof(entry->text));
330 gx_prompt_text_set_ext(&entry->prompt, &string);
331 }
332
PopulateDropList(void)333 VOID PopulateDropList(void)
334 {
335 int index;
336 GX_VERTICAL_LIST *list;
337
338 WINDOW_SCREEN_CONTROL_BLOCK *control = (WINDOW_SCREEN_CONTROL_BLOCK *) pWindowScreen;
339 GX_DROP_LIST *drop = &control->window_screen_drop_list;
340 gx_drop_list_popup_get(drop, &list);
341
342 for (index = 0; index < DROP_LIST_VISIBLE_ROWS; index++)
343 {
344 drop_list_row_create(list, (GX_WIDGET *) &drop_list_widgets[index], index);
345 }
346
347 gx_vertical_scrollbar_create(&list_scroll, "list_scroll", list, GX_NULL,
348 GX_SCROLLBAR_VERTICAL | GX_SCROLLBAR_RELATIVE_THUMB | GX_SCROLLBAR_END_BUTTONS | GX_STYLE_ENABLED);
349
350 }
351
format_func(GX_NUMERIC_PROMPT * prompt,INT value)352 VOID format_func(GX_NUMERIC_PROMPT *prompt, INT value)
353 {
354 gx_utility_ltoa(value % 1000, prompt->gx_numeric_prompt_buffer, GX_NUMERIC_PROMPT_BUFFER_SIZE);
355 }
356
numeric_pixelmap_format_func(GX_NUMERIC_PIXELMAP_PROMPT * prompt,INT value)357 VOID numeric_pixelmap_format_func(GX_NUMERIC_PIXELMAP_PROMPT *prompt, INT value)
358 {
359 gx_utility_ltoa(value % 1000, prompt->gx_numeric_pixelmap_prompt_buffer, GX_NUMERIC_PROMPT_BUFFER_SIZE);
360 }
361