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