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 "alphamap_16bpp_resources.h"
8 #include "alphamap_16bpp_specifications.h"
9 
10 /* Define the ThreadX demo thread control block and stack.  */
11 
12 TX_THREAD          demo_thread;
13 UCHAR              demo_thread_stack[4096];
14 
15 GX_WINDOW_ROOT    *root;
16 #define            COLOR_ID_BLUE   0xf0
17 #define            COLOR_ID_RED 0xf0f0
18 #define            COLOR_ID_GREEN 0xf00
19 
20 GX_COLOR          fill_color = COLOR_ID_BLUE;
21 GX_UBYTE          alpha_value = 0xff;
22 /* Define prototypes.   */
23 VOID  demo_thread_entry(ULONG thread_input);
24 extern UINT win32_graphics_driver_setup_565rgb(GX_DISPLAY *display);
25 
26 
main(int argc,char ** argv)27 int main(int argc, char ** argv)
28 {
29   tx_kernel_enter();
30   return(0);
31 }
32 
33 
tx_application_define(void * first_unused_memory)34 VOID tx_application_define(void *first_unused_memory)
35 {
36 
37     /* Create the main demo thread.  */
38     tx_thread_create(&demo_thread, "GUIX Demo Thread", demo_thread_entry,
39                      0,  demo_thread_stack, sizeof(demo_thread_stack),
40                      1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
41 }
42 
43 
demo_thread_entry(ULONG thread_input)44 VOID  demo_thread_entry(ULONG thread_input)
45 {
46     /* Initialize GUIX.  */
47     gx_system_initialize();
48 
49 
50     gx_studio_display_configure(DISPLAY_1, win32_graphics_driver_setup_565rgb,
51                                 LANGUAGE_ENGLISH, DISPLAY_1_DEFAULT_THEME, &root);
52 
53     /* create the main screen */
54     gx_studio_named_widget_create("main_window", (GX_WIDGET *) root, NULL);
55 
56     /* Show the root window to make it and patients screen visible.  */
57     gx_widget_show(root);
58 
59     /* let GUIX run */
60     gx_system_start();
61 }
62 
pixelmap_wnd_draw(GX_WINDOW * widget)63 VOID pixelmap_wnd_draw(GX_WINDOW *widget)
64 {
65 GX_BRUSH    *brush;
66 GX_PIXELMAP *pixelmap = GX_NULL;
67 
68     gx_context_brush_get(&brush);
69     brush->gx_brush_fill_color = fill_color;
70     brush->gx_brush_alpha = alpha_value;
71 
72     gx_widget_pixelmap_get(widget, widget->gx_window_wallpaper, &pixelmap);
73     gx_canvas_pixelmap_draw(widget->gx_widget_size.gx_rectangle_left,
74                             widget->gx_widget_size.gx_rectangle_top,
75                             pixelmap);
76 }
77 
update_prompt_value(GX_PROMPT * pp,INT value)78 VOID update_prompt_value(GX_PROMPT *pp, INT value)
79 {
80     GX_STRING str;
81     static GX_CHAR str_buf[10];
82 
83     if (pp)
84     {
85         gx_utility_ltoa(value, str_buf, 10);
86         str.gx_string_ptr = str_buf;
87         str.gx_string_length = strnlen(str_buf, 10);
88         gx_prompt_text_set_ext(pp, &str);
89     }
90 }
91 
window_event_handler(GX_WINDOW * window,GX_EVENT * event_ptr)92 UINT window_event_handler(GX_WINDOW *window, GX_EVENT *event_ptr)
93 {
94 GX_PROMPT *prompt;
95 
96     switch (event_ptr->gx_event_type)
97     {
98     case GX_SIGNAL(ID_RADIO_BUTTON_BLUE, GX_EVENT_RADIO_SELECT):
99         fill_color = COLOR_ID_BLUE;
100         gx_system_dirty_mark((GX_WIDGET *)&main_window);
101         break;
102 
103     case GX_SIGNAL(ID_RADIO_BUTTON_RED, GX_EVENT_RADIO_SELECT):
104         fill_color = COLOR_ID_RED;
105         gx_system_dirty_mark((GX_WIDGET *)&main_window);
106         break;
107 
108     case GX_SIGNAL(ID_RADIO_BUTTON_GREEN, GX_EVENT_RADIO_SELECT):
109         fill_color = COLOR_ID_GREEN;
110         gx_system_dirty_mark((GX_WIDGET *)&main_window);
111         break;
112 
113     case GX_SIGNAL(ID_SLIDER_ALPHA, GX_EVENT_SLIDER_VALUE):
114         alpha_value = (GX_UBYTE)event_ptr->gx_event_payload.gx_event_longdata;
115         prompt = &(main_window.main_window_prompt_alpha);
116         update_prompt_value(prompt, alpha_value);
117         gx_system_dirty_mark((GX_WIDGET *)&main_window);
118         break;
119     }
120 
121     return gx_window_event_process(window, event_ptr);
122 }
123