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 "demo_guix_ml_text_input_resources.h"
6 #include "demo_guix_ml_text_input_specifications.h"
7 
8 #define MEMORY_POOL_SIZE (DISPLAY_1_X_RESOLUTION * DISPLAY_1_Y_RESOLUTION)
9 
10 /* Define variables.  */
11 TX_BYTE_POOL       memory_pool;
12 GX_COLOR           memory_pool_buffer[MEMORY_POOL_SIZE];
13 GX_WINDOW_ROOT    *root;
14 
15 /* Define prototypes.   */
16 VOID  start_guix();
17 extern UINT win32_graphics_driver_setup_565rgb(GX_DISPLAY *display);
18 
19 GX_CONST GX_CHAR test_text[] = "It is helpful to have some knowledge of the basic organization of a GUIX Studio project "
20                       "to understand how to use GUIX Studio effectively and to understand the information presented "
21                       "in the Project View of the GUIX Studio IDE. The Project View is a summary visual representation "
22                       "of all of the information contained in your project.\n"
23                       "Before describing the project, it is necessary to define few terms. First, we use the term Display "
24                       "to mean a physical display device. This is most often an LCD display device but it could be using other "
25                       "technology. The next term is Screen, which mean a top-level GUIX object, usually a GUIX Window, and all of "
26                       "its associated child elements. A Screen is a software construct that can be defined and modified at runtime."
27                       "Finally, a Theme is a collection of resources. A theme includes a table of color definitions,"
28                       "font definitions, and pixelmap definitions that are designed to work well together "
29                       "and present your end user with a consistent look and feel.\n"
30                       "The project first includes a set of global information such as the project name, "
31                       "number of displays supported, the resolution and color format of each display, the number "
32                       "of languages supported, the name of each supported language. The project name is the first node "
33                       "displayed in the Project View.\n"
34                       "The project next organizes all of the information required for up to 4 physical displays "
35                       "and the screens and resources available to each display. The display names are the next level "
36                       "nodes in the Project View tree.";
37 
38 
39 /******************************************************************************************/
40 /* Application entry.                                                                     */
41 /******************************************************************************************/
main(int argc,char ** argv)42 int main(int argc, char ** argv)
43 {
44   tx_kernel_enter();
45   return(0);
46 }
47 
48 /******************************************************************************************/
49 /* Application defined memory allocate function.                                          */
50 /******************************************************************************************/
memory_allocate(ULONG size)51 VOID *memory_allocate(ULONG size)
52 {
53     VOID *memptr;
54 
55     if (tx_byte_allocate(&memory_pool, &memptr, size, TX_NO_WAIT) == TX_SUCCESS)
56     {
57         return memptr;
58     }
59 
60     return NULL;
61 }
62 
63 /******************************************************************************************/
64 /* Application defined memory free function.                                              */
65 /******************************************************************************************/
memory_free(VOID * mem)66 VOID memory_free(VOID *mem)
67 {
68     tx_byte_release(mem);
69 }
70 
71 /******************************************************************************************/
72 /* Define tx_application_define function.                                                 */
73 /******************************************************************************************/
tx_application_define(void * first_unused_memory)74 VOID tx_application_define(void *first_unused_memory)
75 {
76     /* create byte pool for rotate to use */
77     tx_byte_pool_create(&memory_pool, "memory_pool", memory_pool_buffer, MEMORY_POOL_SIZE * sizeof(GX_COLOR));
78 
79     start_guix();
80 }
81 
82 /******************************************************************************************/
83 /* Initiate and run GUIX.                                                                 */
84 /******************************************************************************************/
start_guix()85 VOID  start_guix()
86 {
87     GX_STRING string;
88 
89     /* Initialize GUIX.  */
90     gx_system_initialize();
91 
92     /* install our memory allocator and de-allocator */
93     gx_system_memory_allocator_set(memory_allocate, memory_free);
94 
95     /* Configure display. */
96     gx_studio_display_configure(DISPLAY_1, win32_graphics_driver_setup_565rgb,
97                                 LANGUAGE_ENGLISH, DISPLAY_1_THEME_1, &root);
98 
99     /* create the MAIN screen */
100     gx_studio_named_widget_create("main_screen", (GX_WIDGET *) root, GX_NULL);
101 
102     /* Set multi line text input text. */
103     string.gx_string_ptr = test_text;
104     string.gx_string_length = sizeof(test_text) - 1;
105     gx_multi_line_text_input_text_set_ext(&main_screen.main_screen_ml_text_input, &string);
106 
107     /* Show the root window to make it visible.  */
108     gx_widget_show(root);
109 
110     /* let GUIX run.  */
111     gx_system_start();
112 }
113 
114 /******************************************************************************************/
115 /* Convert string to integer value.                                                       */
116 /******************************************************************************************/
string_to_int(char * str,int len,int * value)117 static void string_to_int(char *str, int len, int *value)
118 {
119     int index;
120 
121     *value = 0;
122 
123     for (index = 0; index < len; index++)
124     {
125         *value = *value * 10;
126         *value += str[index] - '0';
127     }
128 }
129 
130 /******************************************************************************************/
131 /* Set text alignment style.                                                              */
132 /******************************************************************************************/
set_alignment(int alignment)133 VOID set_alignment(int alignment)
134 {
135     gx_widget_style_remove((GX_WIDGET *)&main_screen.main_screen_ml_text_input, GX_STYLE_TEXT_ALIGNMENT_MASK);
136     gx_widget_style_add((GX_WIDGET *)&main_screen.main_screen_ml_text_input, alignment);
137 }
138 
139 /******************************************************************************************/
140 /* Set cursor width.                                                                      */
141 /******************************************************************************************/
set_cursor_width()142 VOID set_cursor_width()
143 {
144     GX_MULTI_LINE_TEXT_INPUT *ml_input;
145     GX_SINGLE_LINE_TEXT_INPUT *cursor_width_input;
146     GX_CHAR  *input_buffer;
147     UINT     string_size;
148     INT      value;
149 
150     ml_input = &main_screen.main_screen_ml_text_input;
151 
152     cursor_width_input = &main_screen.main_screen_cursor_width_input;
153 
154     /* Pick up buffer address and input string size. */
155     gx_single_line_text_input_buffer_get(cursor_width_input, &input_buffer, &string_size, GX_NULL);
156 
157     /* Convert string to integer. */
158     string_to_int(input_buffer, string_size, &value);
159 
160     if (value > 0)
161     {
162         /* Set cursor width. */
163         gx_text_input_cursor_width_set(&ml_input->gx_multi_line_text_input_cursor_instance, value);
164     }
165 }
166 
167 /******************************************************************************************/
168 /* Set cursor height.                                                                     */
169 /******************************************************************************************/
set_cursor_height()170 VOID set_cursor_height()
171 {
172     GX_MULTI_LINE_TEXT_INPUT *ml_input;
173     GX_SINGLE_LINE_TEXT_INPUT *cursor_height_input;
174     GX_CHAR  *input_buffer;
175     UINT     string_size;
176     INT      value;
177 
178     ml_input = &main_screen.main_screen_ml_text_input;
179 
180     cursor_height_input = &main_screen.main_screen_cursor_height_input;
181 
182     /* Pick up buffer address and input string size. */
183     gx_single_line_text_input_buffer_get(cursor_height_input, &input_buffer, &string_size, GX_NULL);
184 
185     /* Convert string to integer. */
186     string_to_int(input_buffer, string_size, &value);
187 
188     if (value >= 0)
189     {
190         /* Set cursor height, 0 means use font height as cursor height. */
191         gx_text_input_cursor_height_set(&ml_input->gx_multi_line_text_input_cursor_instance, value);
192     }
193 }
194 
195 /******************************************************************************************/
196 /* Set whitespace, the space from text draw area to the client boder.                     */
197 /******************************************************************************************/
set_whitespace(int value)198 VOID set_whitespace(int value)
199 {
200     /* Set prompt value. */
201     gx_numeric_prompt_value_set(&main_screen.main_screen_prompt_whitespace, value);
202 
203     /* Set multi line text view whitespace. */
204     gx_multi_line_text_view_whitespace_set((GX_MULTI_LINE_TEXT_VIEW *)&main_screen.main_screen_ml_text_input, value);
205 }
206 
207 /******************************************************************************************/
208 /* Set line space, the space between lines.                                               */
209 /******************************************************************************************/
set_line_space(int value)210 VOID set_line_space(int value)
211 {
212     /* Set prompt value. */
213     gx_numeric_prompt_value_set(&main_screen.main_screen_prompt_line_space, value);
214 
215     /* Set multi line text view line space. */
216     gx_multi_line_text_view_line_space_set((GX_MULTI_LINE_TEXT_VIEW *)&main_screen.main_screen_ml_text_input, value);
217 }
218 
219 /******************************************************************************************/
220 /* Highlight whole text.                                                                    */
221 /******************************************************************************************/
select_whole_text()222 VOID select_whole_text()
223 {
224     UINT     string_size;
225 
226     /* Pick up string size. */
227     gx_multi_line_text_input_buffer_get(&main_screen.main_screen_ml_text_input, GX_NULL, &string_size, GX_NULL);
228 
229     /* Select text[0: string_size - 1]. */
230     gx_multi_line_text_input_text_select(&main_screen.main_screen_ml_text_input, 0, string_size - 1);
231 }
232 
233 /******************************************************************************************/
234 /* Override the default event processing of "main_screen" to handle signals from my child */
235 /* widgets.                                                                               */
236 /******************************************************************************************/
main_screen_event_handler(GX_WINDOW * window,GX_EVENT * event_ptr)237 UINT main_screen_event_handler(GX_WINDOW *window, GX_EVENT *event_ptr)
238 {
239     switch(event_ptr->gx_event_type)
240     {
241     case GX_SIGNAL(ID_FONT_SMALL, GX_EVENT_RADIO_SELECT):
242         gx_multi_line_text_view_font_set((GX_MULTI_LINE_TEXT_VIEW *)&main_screen.main_screen_ml_text_input, GX_FONT_ID_SYSTEM);
243         break;
244 
245     case GX_SIGNAL(ID_FONT_MEDIUM, GX_EVENT_RADIO_SELECT):
246         gx_multi_line_text_view_font_set((GX_MULTI_LINE_TEXT_VIEW *)&main_screen.main_screen_ml_text_input, GX_FONT_ID_TITLE);
247         break;
248 
249     case GX_SIGNAL(ID_ALIGN_LEFT, GX_EVENT_RADIO_SELECT):
250         set_alignment(GX_STYLE_TEXT_LEFT);
251         break;
252 
253     case GX_SIGNAL(ID_ALIGN_CENTER, GX_EVENT_RADIO_SELECT):
254         set_alignment( GX_STYLE_TEXT_CENTER);
255         break;
256 
257     case GX_SIGNAL(ID_ALIGN_RIGHT, GX_EVENT_RADIO_SELECT):
258         set_alignment(GX_STYLE_TEXT_RIGHT);
259         break;
260 
261     case GX_SIGNAL(ID_CURSOR_WIDTH_INPUT, GX_EVENT_TEXT_EDITED):
262         set_cursor_width();
263         break;
264 
265     case GX_SIGNAL(ID_CURSOR_HEIGHT_INPUT, GX_EVENT_TEXT_EDITED):
266         set_cursor_height();
267         break;
268 
269     case GX_SIGNAL(ID_SLIDER_WHITESPACE, GX_EVENT_SLIDER_VALUE):
270         set_whitespace(event_ptr->gx_event_payload.gx_event_longdata);
271         break;
272 
273     case GX_SIGNAL(ID_SLIDER_LINE_SPACE, GX_EVENT_SLIDER_VALUE):
274         set_line_space(event_ptr->gx_event_payload.gx_event_longdata);
275         break;
276 
277     case GX_SIGNAL(ID_SCROLLBAR, GX_EVENT_TOGGLE_ON):
278         gx_widget_show((GX_WIDGET *)&main_screen.main_screen_input_scroll);
279         break;
280 
281     case GX_SIGNAL(ID_SCROLLBAR, GX_EVENT_TOGGLE_OFF):
282         gx_widget_hide((GX_WIDGET *)&main_screen.main_screen_input_scroll);
283         break;
284 
285     case GX_SIGNAL(ID_SELECT_ALL, GX_EVENT_CLICKED):
286         select_whole_text();
287         break;
288 
289     default:
290         return gx_window_event_process(window, event_ptr);
291     }
292     return GX_SUCCESS;
293 }
294 
295