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 "radial_progress_bar_resources.h"
8 #include "radial_progress_bar_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 TX_BYTE_POOL       memory_pool;
15 
16 GX_WINDOW_ROOT    *root;
17 GX_RADIAL_PROGRESS_BAR *progress_bar = &progress_bar_window.progress_bar_window_radial_progress_bar;
18 GX_RADIAL_PROGRESS_BAR_INFO  *info = &progress_bar_window.progress_bar_window_radial_progress_bar.gx_radial_progress_bar_info;
19 
20 #define            SCRATCHPAD_PIXELS (DISPLAY_1_X_RESOLUTION * DISPLAY_1_Y_RESOLUTION)
21 GX_COLOR           scratchpad[SCRATCHPAD_PIXELS];
22 
23 /* Define prototypes.   */
24 extern UINT win32_graphics_driver_setup_24xrgb(GX_DISPLAY *display);
25 
26 GX_CHAR anchor_value[5];
27 GX_CHAR normal_width[5];
28 GX_CHAR selected_width[5];
29 GX_CHAR radius[5];
30 INT     radial_progress_bar_alpha = 255;
31 
memory_allocate(ULONG size)32 VOID *memory_allocate(ULONG size)
33 {
34     VOID *memptr;
35 
36     if (tx_byte_allocate(&memory_pool, &memptr, size, TX_NO_WAIT) == TX_SUCCESS)
37     {
38         return memptr;
39     }
40 
41     return NULL;
42 }
43 
memory_free(VOID * mem)44 VOID memory_free(VOID *mem)
45 {
46     tx_byte_release(mem);
47 }
48 
49 /******************************************************************************************/
main(int argc,char ** argv)50 int main(int argc, char ** argv)
51 {
52   tx_kernel_enter();
53   return(0);
54 }
55 
56 /******************************************************************************************/
tx_application_define(void * first_unused_memory)57 VOID tx_application_define(void *first_unused_memory)
58 {
59     /* create byte pool for rotate to use */
60     tx_byte_pool_create(&memory_pool, "scratchpad", scratchpad,
61         SCRATCHPAD_PIXELS * sizeof(GX_COLOR));
62 
63     /* Initialize GUIX.  */
64     gx_system_initialize();
65 
66     /* install our memory allocator and de-allocator */
67     gx_system_memory_allocator_set(memory_allocate, memory_free);
68 
69     gx_studio_display_configure(DISPLAY_1, win32_graphics_driver_setup_24xrgb,
70         LANGUAGE_ENGLISH, DISPLAY_1_THEME_1, &root);
71 
72     /* create the gauge_window */
73     gx_studio_named_widget_create("progress_bar_window", (GX_WIDGET *)root, GX_NULL);
74 
75     /* Show the root window to make it and patients screen visible.  */
76     gx_widget_show(root);
77 
78     /* let GUIX run */
79     gx_system_start();
80 }
81 
82 
83 /******************************************************************************************/
window_event_handle(GX_WINDOW * win,GX_EVENT * event_ptr)84 UINT window_event_handle(GX_WINDOW *win, GX_EVENT *event_ptr)
85 {
86 int pos;
87 GX_STRING str;
88 
89     switch (event_ptr->gx_event_type)
90     {
91     case GX_SIGNAL(ID_POS, GX_EVENT_SLIDER_VALUE):
92         pos = event_ptr->gx_event_payload.gx_event_longdata;
93         gx_radial_progress_bar_value_set(progress_bar, -pos);
94         break;
95 
96     case GX_SIGNAL(ID_SHOW_TEXT, GX_EVENT_TOGGLE_ON):
97         gx_widget_style_add((GX_WIDGET *)progress_bar, GX_STYLE_PROGRESS_TEXT_DRAW);
98         break;
99 
100     case GX_SIGNAL(ID_SHOW_TEXT, GX_EVENT_TOGGLE_OFF):
101         gx_widget_style_remove((GX_WIDGET *)progress_bar, GX_STYLE_PROGRESS_TEXT_DRAW);
102         break;
103 
104     case GX_SIGNAL(ID_SHOW_PERCENT, GX_EVENT_TOGGLE_ON):
105         gx_widget_style_add((GX_WIDGET *)progress_bar, GX_STYLE_PROGRESS_PERCENT);
106         break;
107 
108     case GX_SIGNAL(ID_SHOW_PERCENT, GX_EVENT_TOGGLE_OFF):
109         gx_widget_style_remove((GX_WIDGET *)progress_bar, GX_STYLE_PROGRESS_PERCENT);
110         break;
111 
112     case GX_SIGNAL(ID_TRANSPARENT, GX_EVENT_TOGGLE_ON):
113         gx_widget_style_add((GX_WIDGET *)progress_bar, GX_STYLE_TRANSPARENT);
114         break;
115 
116     case GX_SIGNAL(ID_TRANSPARENT, GX_EVENT_TOGGLE_OFF):
117         gx_widget_style_remove((GX_WIDGET *)progress_bar, GX_STYLE_TRANSPARENT);
118         break;
119 
120     case GX_SIGNAL(ID_ALIAS, GX_EVENT_TOGGLE_ON):
121         gx_widget_style_add((GX_WIDGET *)progress_bar, GX_STYLE_RADIAL_PROGRESS_ALIAS);
122         break;
123 
124     case GX_SIGNAL(ID_ALIAS, GX_EVENT_TOGGLE_OFF):
125         gx_widget_style_remove((GX_WIDGET *)progress_bar, GX_STYLE_RADIAL_PROGRESS_ALIAS);
126         break;
127 
128     case GX_SIGNAL(ID_ROUND_END, GX_EVENT_TOGGLE_ON):
129         gx_widget_style_add((GX_WIDGET *)progress_bar, GX_STYLE_RADIAL_PROGRESS_ROUND);
130         break;
131 
132     case GX_SIGNAL(ID_ROUND_END, GX_EVENT_TOGGLE_OFF):
133         gx_widget_style_remove((GX_WIDGET *)progress_bar, GX_STYLE_RADIAL_PROGRESS_ROUND);
134         break;
135 
136     case GX_SIGNAL(ID_NORMAL_WIDTH_SLIDER, GX_EVENT_SLIDER_VALUE):
137         pos = event_ptr->gx_event_payload.gx_event_longdata;
138         gx_utility_ltoa(pos, normal_width, 5);
139         str.gx_string_ptr = normal_width;
140         str.gx_string_length = strnlen(normal_width, sizeof(normal_width) - 1);
141         gx_prompt_text_set_ext(&progress_bar_window.progress_bar_window_normal_width_prompt, &str);
142         info->gx_radial_progress_bar_info_normal_brush_width = pos;
143         gx_radial_progress_bar_info_set(progress_bar, info);
144         break;
145 
146     case GX_SIGNAL(ID_SELECTED_WIDTH_SLIDER, GX_EVENT_SLIDER_VALUE):
147         pos = event_ptr->gx_event_payload.gx_event_longdata;
148         gx_utility_ltoa(pos, selected_width, 5);
149         str.gx_string_ptr = selected_width;
150         str.gx_string_length = strnlen(selected_width, sizeof(selected_width) - 1);
151         gx_prompt_text_set_ext(&progress_bar_window.progress_bar_window_selected_width_prompt, &str);
152         info->gx_radial_progress_bar_info_selected_brush_width = pos;
153         gx_radial_progress_bar_info_set(progress_bar, info);
154         break;
155 
156     case GX_SIGNAL(ID_RADIUS_SLIDER, GX_EVENT_SLIDER_VALUE):
157         pos = event_ptr->gx_event_payload.gx_event_longdata;
158         gx_utility_ltoa(pos, radius, 5);
159         str.gx_string_ptr = radius;
160         str.gx_string_length = strnlen(radius, sizeof(radius) - 1);
161         gx_prompt_text_set_ext(&progress_bar_window.progress_bar_window_radius_prompt, &str);
162         info->gx_radial_progress_bar_info_radius = pos;
163         gx_radial_progress_bar_info_set(progress_bar, info);
164         break;
165 
166     case GX_SIGNAL(ID_ANCHOR_SLIDER, GX_EVENT_SLIDER_VALUE):
167         pos = event_ptr->gx_event_payload.gx_event_longdata;
168         gx_utility_ltoa(pos, anchor_value, 5);
169         str.gx_string_ptr = anchor_value;
170         str.gx_string_length = strnlen(anchor_value, sizeof(anchor_value) - 1);
171         gx_prompt_text_set_ext(&progress_bar_window.progress_bar_window_anchor_prompt, &str);
172         gx_radial_progress_bar_anchor_set(progress_bar, pos);
173         break;
174 
175     case GX_SIGNAL(ID_ALPHA_SLIDER, GX_EVENT_SLIDER_VALUE):
176         radial_progress_bar_alpha = event_ptr->gx_event_payload.gx_event_longdata;
177         gx_numeric_prompt_value_set(&progress_bar_window.progress_bar_window_alpha_prompt, radial_progress_bar_alpha);
178         gx_system_dirty_mark((GX_WIDGET *)&progress_bar_window.progress_bar_window_radial_progress_bar);
179         break;
180     }
181 
182     return gx_window_event_process(win, event_ptr);
183 }
184 
185 
radial_progress_bar_draw(GX_RADIAL_PROGRESS_BAR * progress_bar)186 VOID radial_progress_bar_draw(GX_RADIAL_PROGRESS_BAR *progress_bar)
187 {
188 GX_BRUSH *brush;
189 
190     gx_context_brush_get(&brush);
191     brush->gx_brush_alpha = radial_progress_bar_alpha;
192 
193     gx_radial_progress_bar_draw(progress_bar);
194 }
195