1 /* This is a small demo of the high-performance GUIX graphics framework. */
2
3 #include <stdio.h>
4 #include "gx_api.h"
5
6 #include "demo_guix_circular_gauge_resources.h"
7 #include "demo_guix_circular_gauge_specifications.h"
8
9 /* Define the ThreadX demo thread control block and stack. */
10
11 TX_THREAD demo_thread;
12 UCHAR demo_thread_stack[4096];
13 TX_BYTE_POOL memory_pool;
14
15 #define SCRATCHPAD_PIXELS (DISPLAY_1_X_RESOLUTION * DISPLAY_1_Y_RESOLUTION)
16 GX_COLOR scratchpad[SCRATCHPAD_PIXELS];
17
18 GX_WINDOW_ROOT *root;
19
20
21 /* Define prototypes. */
22 VOID guix_setup(void);
23 extern UINT win32_graphics_driver_setup_24xrgb(GX_DISPLAY *display);
24 UINT string_length_get(GX_CONST GX_CHAR* input_string, UINT max_string_length);
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 /******************************************************************************************/
memory_allocate(ULONG size)34 VOID *memory_allocate(ULONG size)
35 {
36 VOID *memptr;
37
38 if (tx_byte_allocate(&memory_pool, &memptr, size, TX_NO_WAIT) == TX_SUCCESS)
39 {
40 return memptr;
41 }
42 return NULL;
43 }
44
45 /******************************************************************************************/
memory_free(VOID * mem)46 void memory_free(VOID *mem)
47 {
48 tx_byte_release(mem);
49 }
50
51 /******************************************************************************************/
tx_application_define(void * first_unused_memory)52 VOID tx_application_define(void *first_unused_memory)
53 {
54
55 /* create byte pool for needle rotation to use */
56 tx_byte_pool_create(&memory_pool, "scratchpad", scratchpad,
57 SCRATCHPAD_PIXELS * sizeof(GX_COLOR));
58
59 guix_setup();
60
61 /* install our memory allocator and de-allocator */
62 gx_system_memory_allocator_set(memory_allocate, memory_free);
63 }
64
65 /******************************************************************************************/
guix_setup()66 VOID guix_setup()
67 {
68
69 /* Initialize GUIX. */
70 gx_system_initialize();
71
72 gx_studio_display_configure(DISPLAY_1, win32_graphics_driver_setup_24xrgb,
73 LANGUAGE_ENGLISH, DISPLAY_1_THEME_1, &root);
74
75 /* create the gauge_window */
76 gx_studio_named_widget_create("gauge_window", (GX_WIDGET *)root, GX_NULL);
77
78 /* Show the root window to make it and patients screen visible. */
79 gx_widget_show(root);
80
81 /* let GUIX run */
82 gx_system_start();
83 }
84
85
86 /******************************************************************************************/
set_speed_value(int id,int value)87 void set_speed_value(int id, int value)
88 {
89 GX_PROMPT *prompt;
90 static GX_CHAR str_value1[10];
91 static GX_CHAR str_value2[10];
92 GX_STRING string;
93
94 if (id == 1)
95 {
96 prompt = &gauge_window.gauge_window_speed_value_1;
97 string.gx_string_ptr = str_value1;
98 }
99 else
100 {
101 prompt = &gauge_window.gauge_window_speed_value_2;
102 string.gx_string_ptr = str_value2;
103 }
104
105 gx_utility_ltoa(value, (GX_CHAR *)string.gx_string_ptr, 10);
106 string.gx_string_length = string_length_get(string.gx_string_ptr, sizeof(str_value1) - 1);
107 gx_prompt_text_set_ext(prompt, &string);
108 }
109
110
111 /******************************************************************************************/
window_event_handle(GX_WINDOW * win,GX_EVENT * event_ptr)112 UINT window_event_handle(GX_WINDOW *win, GX_EVENT *event_ptr)
113 {
114 int pos;
115 GX_CIRCULAR_GAUGE *gauge;
116
117 switch (event_ptr->gx_event_type)
118 {
119 case GX_SIGNAL(ID_POS_1, GX_EVENT_SLIDER_VALUE):
120 /* Change needle position. */
121 pos = event_ptr->gx_event_payload.gx_event_longdata;
122 set_speed_value(1, pos);
123 gx_widget_find(win, ID_GAUGE_1, GX_SEARCH_DEPTH_INFINITE, &gauge);
124 gx_circular_gauge_angle_set(gauge, pos);
125 break;
126
127 case GX_SIGNAL(ID_POS_2, GX_EVENT_SLIDER_VALUE):
128 /* Change needle position of gauge 1*/
129 pos = event_ptr->gx_event_payload.gx_event_longdata;
130 set_speed_value(2, pos);
131 gx_widget_find(win, ID_GAUGE_2, GX_SEARCH_DEPTH_INFINITE, &gauge);
132 gx_circular_gauge_angle_set(gauge, pos);
133 break;
134 }
135
136 return gx_window_event_process(win, event_ptr);
137 }
138
139 /******************************************************************************************/
string_length_get(GX_CONST GX_CHAR * input_string,UINT max_string_length)140 UINT string_length_get(GX_CONST GX_CHAR* input_string, UINT max_string_length)
141 {
142 UINT length = 0;
143
144 if (input_string)
145 {
146 /* Traverse the string. */
147 for (length = 0; input_string[length]; length++)
148 {
149 /* Check if the string length is bigger than the max string length. */
150 if (length >= max_string_length)
151 {
152 break;
153 }
154 }
155 }
156
157 return length;
158 }
159