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 "ml_text_input_16bpp_resources.h"
6 #include "ml_text_input_16bpp_specifications.h"
7 
8 WINDOW_CONTROL_BLOCK *pMainScreen;
9 
10 /* Define the ThreadX demo thread control block and stack.  */
11 
12 GX_BOOL APP_CTRL_FLAG = GX_FALSE;
13 GX_BOOL APP_SHIFT_FLAG = GX_FALSE;
14 
15 TX_BYTE_POOL       memory_pool;
16 
17 #define SCRATCHPAD_PIXELS (DISPLAY_1_X_RESOLUTION * DISPLAY_1_Y_RESOLUTION)
18 GX_COLOR           scratchpad[SCRATCHPAD_PIXELS];
19 
20 TX_THREAD          demo_thread;
21 UCHAR              demo_thread_stack[4096];
22 
23 GX_WINDOW_ROOT    *root;
24 GX_RESOURCE_ID font[3][2] = {{GX_FONT_ID_TEXT_INPUT_1BPP_18PIX, GX_FONT_ID_TEXT_INPUT_1BPP_24PIX},
25                              {GX_FONT_ID_TEXT_INPUT_4BPP_18PIX, GX_FONT_ID_TEXT_INPUT_4BPP_24PIX},
26                              {GX_FONT_ID_TEXT_INPUT_8BPP_18PIX, GX_FONT_ID_TEXT_INPUT_8BPP_24PIX}};
27 GX_BOOL scrollbar = GX_TRUE;
28 GX_BOOL cursor_blink = GX_TRUE;
29 GX_BOOL cursor_always = GX_FALSE;
30 UINT    cursor_height;
31 UINT    cursor_width;
32 UINT    font_depth = 2;
33 UINT    font_size = 0;
34 
35 GX_CHAR line_space[3];
36 GX_CHAR whitespace[3];
37 
38 /* Define prototypes.   */
39 VOID  demo_thread_entry(ULONG thread_input);
40 extern UINT win32_graphics_driver_setup_565rgb(GX_DISPLAY *display);
41 
main(int argc,char ** argv)42 int main(int argc, char ** argv)
43 {
44   tx_kernel_enter();
45   return(0);
46 }
47 
memory_allocate(ULONG size)48 VOID *memory_allocate(ULONG size)
49 {
50     VOID *memptr;
51 
52     if (tx_byte_allocate(&memory_pool, &memptr, size, TX_NO_WAIT) == TX_SUCCESS)
53     {
54         return memptr;
55     }
56 
57     return NULL;
58 }
59 
memory_free(VOID * mem)60 VOID memory_free(VOID *mem)
61 {
62     tx_byte_release(mem);
63 }
64 
tx_application_define(void * first_unused_memory)65 VOID tx_application_define(void *first_unused_memory)
66 {
67     /* create byte pool for rotate to use */
68     tx_byte_pool_create(&memory_pool, "scratchpad", scratchpad,
69         SCRATCHPAD_PIXELS * sizeof(GX_COLOR));
70 
71 
72     /* Create the main demo thread.  */
73     tx_thread_create(&demo_thread, "GUIX Demo Thread", demo_thread_entry,
74                      0,  demo_thread_stack, sizeof(demo_thread_stack),
75                      1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
76 }
77 
78 
79 GX_STUDIO_DISPLAY_INFO display_info;
80 
demo_thread_entry(ULONG thread_input)81 VOID  demo_thread_entry(ULONG thread_input)
82 {
83     /* Initialize GUIX.  */
84     gx_system_initialize();
85 
86     /* install our memory allocator and de-allocator */
87     gx_system_memory_allocator_set(memory_allocate, memory_free);
88 
89     gx_studio_display_configure(DISPLAY_1, win32_graphics_driver_setup_565rgb,
90                                 LANGUAGE_ENGLISH, DISPLAY_1_THEME_1, &root);
91 
92     /* create the button screen */
93     gx_studio_named_widget_create("window", (GX_WIDGET *) root, (GX_WIDGET **) &pMainScreen);
94 
95     /* Show the root window to make it and patients screen visible.  */
96     gx_widget_show(root);
97 
98     /* let GUIX run */
99     gx_system_start();
100 }
101 
string_to_int(char * str,int len,int * value)102 void string_to_int(char *str, int len, int *value)
103 {
104 int i;
105 
106     *value = 0;
107 
108     for(i = 0; i < len; i++)
109     {
110         *value = *value * 10;
111         *value += str[i] - '0';
112     }
113 }
114 
main_event_handler(GX_WINDOW * window,GX_EVENT * event_ptr)115 UINT main_event_handler(GX_WINDOW *window, GX_EVENT *event_ptr)
116 {
117 GX_MULTI_LINE_TEXT_INPUT *ml_input;
118 GX_MULTI_LINE_TEXT_VIEW *ml_view;
119 GX_SINGLE_LINE_TEXT_INPUT *cursor_width_input;
120 GX_SINGLE_LINE_TEXT_INPUT *cursor_height_input;
121 GX_CHAR  *input_buffer;
122 UINT     string_size;
123 INT      value;
124 GX_STRING str;
125 
126     ml_input = &pMainScreen->window_ml_text_input;
127     ml_view = (GX_MULTI_LINE_TEXT_VIEW *)ml_input;
128 
129     switch(event_ptr->gx_event_type)
130     {
131     case GX_SIGNAL(ID_SCROLLBAR, GX_EVENT_TOGGLE_ON):
132         gx_widget_show((GX_WIDGET *)&pMainScreen->window_input_scroll);
133         break;
134 
135     case GX_SIGNAL(ID_SCROLLBAR, GX_EVENT_TOGGLE_OFF):
136         gx_widget_hide((GX_WIDGET *)&pMainScreen->window_input_scroll);
137         break;
138 
139     case GX_SIGNAL(ID_CURSOR_BLINK, GX_EVENT_TOGGLE_ON):
140         gx_multi_line_text_input_style_add(ml_input, GX_STYLE_CURSOR_BLINK);
141         break;
142 
143     case GX_SIGNAL(ID_CURSOR_BLINK, GX_EVENT_TOGGLE_OFF):
144         gx_multi_line_text_input_style_remove(ml_input, GX_STYLE_CURSOR_BLINK);
145         break;
146 
147     case GX_SIGNAL(ID_CURSOR_ALWAYS, GX_EVENT_TOGGLE_ON):
148         gx_multi_line_text_input_style_add(ml_input, GX_STYLE_CURSOR_ALWAYS);
149         break;
150 
151     case GX_SIGNAL(ID_CURSOR_ALWAYS, GX_EVENT_TOGGLE_OFF):
152         gx_multi_line_text_input_style_remove(ml_input, GX_STYLE_CURSOR_ALWAYS);
153         break;
154 
155     case GX_SIGNAL(ID_FONT_1BPP, GX_EVENT_RADIO_SELECT):
156         font_depth = 0;
157         gx_multi_line_text_view_font_set(ml_view, font[font_depth][font_size]);
158         break;
159 
160     case GX_SIGNAL(ID_FONT_4BPP, GX_EVENT_RADIO_SELECT):
161         font_depth = 1;
162         gx_multi_line_text_view_font_set(ml_view, font[font_depth][font_size]);
163         break;
164 
165     case GX_SIGNAL(ID_FONT_8BPP, GX_EVENT_RADIO_SELECT):
166         font_depth = 2;
167         gx_multi_line_text_view_font_set(ml_view, font[font_depth][font_size]);
168         break;
169 
170     case GX_SIGNAL(ID_SIZE_18PIX, GX_EVENT_RADIO_SELECT):
171         font_size = 0;
172         gx_multi_line_text_view_font_set(ml_view, font[font_depth][font_size]);
173         break;
174 
175     case GX_SIGNAL(ID_SIZE_24PIX, GX_EVENT_RADIO_SELECT):
176         font_size = 1;
177         gx_multi_line_text_view_font_set(ml_view, font[font_depth][font_size]);
178         break;
179 
180     case GX_SIGNAL(ID_ALIGN_LEFT, GX_EVENT_RADIO_SELECT):
181         gx_widget_style_add((GX_WIDGET *)ml_input, GX_STYLE_TEXT_LEFT);
182         break;
183 
184     case GX_SIGNAL(ID_ALIGN_LEFT, GX_EVENT_RADIO_DESELECT):
185         gx_widget_style_remove((GX_WIDGET *)ml_input, GX_STYLE_TEXT_LEFT);
186         break;
187 
188     case GX_SIGNAL(ID_ALIGN_CENTER, GX_EVENT_RADIO_SELECT):
189         gx_widget_style_add((GX_WIDGET *)ml_input, GX_STYLE_TEXT_CENTER);
190         break;
191 
192     case GX_SIGNAL(ID_ALIGN_CENTER, GX_EVENT_RADIO_DESELECT):
193         gx_widget_style_remove((GX_WIDGET *)ml_input, GX_STYLE_TEXT_CENTER);
194         break;
195 
196     case GX_SIGNAL(ID_ALIGN_RIGHT, GX_EVENT_RADIO_SELECT):
197         gx_widget_style_add((GX_WIDGET *)ml_input, GX_STYLE_TEXT_RIGHT);
198         break;
199 
200     case GX_SIGNAL(ID_ALIGN_RIGHT, GX_EVENT_RADIO_DESELECT):
201         gx_widget_style_remove((GX_WIDGET *)ml_input, GX_STYLE_TEXT_RIGHT);
202         break;
203 
204     case GX_SIGNAL(ID_CURSOR_WIDTH_INPUT, GX_EVENT_TEXT_EDITED):
205         cursor_width_input = &pMainScreen->window_cursor_width_input;
206 
207         /* Pick up buffer address and input string size. */
208         gx_single_line_text_input_buffer_get(cursor_width_input, &input_buffer, &string_size, GX_NULL);
209 
210         /* Convert string to integer. */
211         string_to_int(input_buffer, string_size, &value);
212 
213         if(value > 0)
214         {
215             gx_text_input_cursor_width_set(&ml_input->gx_multi_line_text_input_cursor_instance, value);
216             gx_system_dirty_mark((GX_WIDGET *)ml_input);
217         }
218         break;
219 
220     case GX_SIGNAL(ID_CURSOR_HEIGHT_INPUT, GX_EVENT_TEXT_EDITED):
221         cursor_height_input = &pMainScreen->window_cursor_height_input;
222 
223         /* Pick up buffer address and input string size. */
224         gx_single_line_text_input_buffer_get(cursor_height_input, &input_buffer, &string_size, GX_NULL);
225 
226         /* Convert string to integer. */
227         string_to_int(input_buffer, string_size, &value);
228 
229         if(value > 0)
230         {
231             gx_text_input_cursor_height_set(&ml_input->gx_multi_line_text_input_cursor_instance, value);
232             gx_system_dirty_mark((GX_WIDGET *)ml_input);
233         }
234         break;
235 
236     case GX_SIGNAL(ID_SLIDER_WHITESPACE, GX_EVENT_SLIDER_VALUE):
237         value = event_ptr->gx_event_payload.gx_event_longdata;
238         gx_utility_ltoa(value, whitespace, 3);
239         str.gx_string_ptr = whitespace;
240         str.gx_string_length = strnlen(whitespace, 3);
241         gx_prompt_text_set_ext(&pMainScreen->window_prompt_whitespace, &str);
242         gx_multi_line_text_view_whitespace_set(ml_view, value);
243         break;
244 
245     case GX_SIGNAL(ID_SLIDER_LINE_SPACE, GX_EVENT_SLIDER_VALUE):
246         value = event_ptr->gx_event_payload.gx_event_longdata;
247         gx_utility_ltoa(value, line_space, 3);
248         str.gx_string_ptr = line_space;
249         str.gx_string_length = strnlen(line_space, 3);
250         gx_prompt_text_set_ext(&pMainScreen->window_prompt_line_space, &str);
251         gx_multi_line_text_view_line_space_set(ml_view, value);
252         break;
253 
254     default:
255         return gx_window_event_process(window, event_ptr);
256     }
257     return GX_SUCCESS;
258 }
259 
260