1 /* This is a small demo of the high-performance GUIX graphics framework. */
2
3 #include <stdio.h>
4 #include <math.h>
5 #include "tx_api.h"
6 #include "gx_api.h"
7 #include "demo_guix_widget_animation_resources.h"
8 #include "demo_guix_widget_animation_specifications.h"
9
10 #define DROP_LIST_TOTAL_ROWS 31
11 #define ANIMATION_TOTAL_STEPS 40
12 #define ANIMATION_ID 1
13 #define MAX_EASING_TYPE_NAME_LENGTH 30
14
15 /* Define prototypes. */
16 VOID populate_drop_list();
17 void animation_start();
18 extern UINT win32_graphics_driver_setup_24xrgb(GX_DISPLAY *display);
19 UINT string_length_get(GX_CONST GX_CHAR* input_string, UINT max_string_length);
20
21 /* Define easing function data structure. */
22 typedef struct EASING_FUNCTION_DATA_STRUCT{
23 INT type;
24 GX_RESOURCE_ID map_id;
25 GX_CHAR *type_text;
26 }EASING_FUNCTION_DATA;
27
28 /* A pointer to the root window. */
29 GX_WINDOW_ROOT *root;
30
31 /* GX_PROMPT control blocks that we will use to populate the drop list */
32 GX_PROMPT drop_list_items[DROP_LIST_TOTAL_ROWS];
33
34 /* A scrollbar control block */
35 GX_SCROLLBAR list_scroll;
36
37 GX_ANIMATION *animation = GX_NULL;
38 USHORT easing_function_id = 0;
39
40 GX_BOOL animation_back = GX_FALSE;
41 /* Define easing functions. */
42
43 /* Would it be difficult to draw the easing function graphi instead of
44 using pre-defined pixelmaps for each shape?
45 */
46 GX_CONST EASING_FUNCTION_DATA easing_function_list[] = {
47 { 0, GX_PIXELMAP_ID_LINEAR, "Linear" },
48 { GX_ANIMATION_BACK_EASE_IN, GX_PIXELMAP_ID_BACK_EASE_IN, "BackEaseIn" },
49 { GX_ANIMATION_BACK_EASE_OUT, GX_PIXELMAP_ID_BACK_EASE_OUT, "BackEaseOut" },
50 { GX_ANIMATION_BACK_EASE_IN_OUT, GX_PIXELMAP_ID_BACK_EASE_IN_OUT, "BackEaseInOut" },
51 { GX_ANIMATION_BOUNCE_EASE_IN, GX_PIXELMAP_ID_BOUNCE_EASE_IN, "BounceEaseIn" },
52 { GX_ANIMATION_BOUNCE_EASE_OUT, GX_PIXELMAP_ID_BOUNCE_EASE_OUT, "BounceEaseOut" },
53 { GX_ANIMATION_BOUNCE_EASE_IN_OUT, GX_PIXELMAP_ID_BOUNCE_EASE_IN_OUT, "BounceEaseInOut" },
54 { GX_ANIMATION_CIRC_EASE_IN, GX_PIXELMAP_ID_CIRC_EASE_IN, "CircEaseIn" },
55 { GX_ANIMATION_CIRC_EASE_OUT, GX_PIXELMAP_ID_CIRC_EASE_OUT, "CircEaseOut" },
56 { GX_ANIMATION_CIRC_EASE_IN_OUT, GX_PIXELMAP_ID_CIRC_EASE_IN_OUT, "CircEaseInOut" },
57 { GX_ANIMATION_CUBIC_EASE_IN, GX_PIXELMAP_ID_CUBIC_EASE_IN, "CubicEaseIn" },
58 { GX_ANIMATION_CUBIC_EASE_OUT, GX_PIXELMAP_ID_CUBIC_EASE_OUT, "CubicEaseOut" },
59 { GX_ANIMATION_CUBIC_EASE_IN_OUT, GX_PIXELMAP_ID_CUBIC_EASE_IN_OUT, "CubixEaseInOut" },
60 { GX_ANIMATION_ELASTIC_EASE_IN, GX_PIXELMAP_ID_ELASTIC_EASE_IN, "ElasticEaseIn" },
61 { GX_ANIMATION_ELASTIC_EASE_OUT, GX_PIXELMAP_ID_ELASTIC_EASE_OUT, "ElasticEaseOut" },
62 { GX_ANIMATION_ELASTIC_EASE_IN_OUT, GX_PIXELMAP_ID_ELASTIC_EASE_IN_OUT, "ElasticEaseInOut" },
63 { GX_ANIMATION_EXPO_EASE_IN, GX_PIXELMAP_ID_EXPO_EASE_IN, "ExpoEaseIn" },
64 { GX_ANIMATION_EXPO_EASE_OUT, GX_PIXELMAP_ID_EXPO_EASE_OUT, "ExpoEaseOut" },
65 { GX_ANIMATION_EXPO_EASE_IN_OUT, GX_PIXELMAP_ID_EXPO_EASE_IN_OUT, "ExpoEaseInOut" },
66 { GX_ANIMATION_QUAD_EASE_IN, GX_PIXELMAP_ID_QUAD_EASE_IN, "QuadEaseIn" },
67 { GX_ANIMATION_QUAD_EASE_OUT, GX_PIXELMAP_ID_QUAD_EASE_OUT, "QuadEaseOut" },
68 { GX_ANIMATION_QUAD_EASE_IN_OUT, GX_PIXELMAP_ID_QUAD_EASE_IN_OUT, "QuadEaseInOut" },
69 { GX_ANIMATION_QUART_EASE_IN, GX_PIXELMAP_ID_QUART_EASE_IN, "QuartEaseIn" },
70 { GX_ANIMATION_QUART_EASE_OUT, GX_PIXELMAP_ID_QUART_EASE_OUT, "QuartEaseOut" },
71 { GX_ANIMATION_QUART_EASE_IN_OUT, GX_PIXELMAP_ID_QUART_EASE_IN_OUT, "QuartEaseInOut" },
72 { GX_ANIMATION_QUINT_EASE_IN, GX_PIXELMAP_ID_QUINT_EASE_IN, "QuintEaseIn" },
73 { GX_ANIMATION_QUINT_EASE_OUT, GX_PIXELMAP_ID_QUINT_EASE_OUT, "QuintEaseOut" },
74 { GX_ANIMATION_QUINT_EASE_IN_OUT, GX_PIXELMAP_ID_QUINT_EASE_IN_OUT, "QuintEaseInOut" },
75 { GX_ANIMATION_SINE_EASE_IN, GX_PIXELMAP_ID_SINE_EASE_IN, "SineEaseIn" },
76 { GX_ANIMATION_SINE_EASE_OUT, GX_PIXELMAP_ID_SINE_EASE_OUT, "SineEaseOut" },
77 { GX_ANIMATION_SINE_EASE_IN_OUT, GX_PIXELMAP_ID_SINE_EASE_IN_OUT, "SineEaseInOut" },
78 { GX_NULL, 0, "" }
79 };
80
81 /******************************************************************************************/
82 /* Application entry. */
83 /******************************************************************************************/
main(int argc,char ** argv)84 int main(int argc, char ** argv)
85 {
86 tx_kernel_enter();
87 return(0);
88 }
89
90 /******************************************************************************************/
91 /* Define tx_application_define function. */
92 /******************************************************************************************/
tx_application_define(void * first_unused_memory)93 VOID tx_application_define(void *first_unused_memory)
94 {
95 /* Initialize GUIX. */
96 gx_system_initialize();
97
98 gx_studio_display_configure(PRIMARY, win32_graphics_driver_setup_24xrgb,
99 LANGUAGE_ENGLISH, PRIMARY_THEME_1, &root);
100
101 /* create the button screen */
102 gx_studio_named_widget_create("main_screen", (GX_WIDGET *)root, GX_NULL);
103
104 /* add selectable child items to the drop list */
105 populate_drop_list();
106
107 /* Show the root window to make it and patients screen visible. */
108 gx_widget_show(root);
109
110 animation_start();
111
112 /* start the GUIX thread */
113 gx_system_start();
114 }
115
116 /******************************************************************************************/
117 /* Start animation. */
118 /******************************************************************************************/
animation_start()119 void animation_start()
120 {
121 GX_ANIMATION_INFO animation_info;
122 GX_WINDOW *chart_win = &main_screen.main_screen_easing_function_chart_win;
123 GX_RECTANGLE *size = &chart_win->gx_widget_size;
124
125 if (animation)
126 {
127 gx_animation_stop(animation);
128 }
129 else
130 {
131 gx_system_animation_get(&animation);
132 }
133
134 if (animation)
135 {
136 memset(&animation_info, 0, sizeof(GX_ANIMATION_INFO));
137
138 animation_info.gx_animation_start_position.gx_point_x = size->gx_rectangle_left - 40;
139 animation_info.gx_animation_end_position.gx_point_x = size->gx_rectangle_left - 40;
140
141 if (animation_back)
142 {
143 animation_info.gx_animation_start_position.gx_point_y = size->gx_rectangle_top + 68;
144 animation_info.gx_animation_end_position.gx_point_y = size->gx_rectangle_bottom - 63;
145 }
146 else
147 {
148 animation_info.gx_animation_start_position.gx_point_y = size->gx_rectangle_bottom - 63;
149 animation_info.gx_animation_end_position.gx_point_y = size->gx_rectangle_top+ 68;
150 }
151
152 animation_info.gx_animation_id = ANIMATION_ID;
153 animation_info.gx_animation_frame_interval = 2;
154 animation_info.gx_animation_steps = ANIMATION_TOTAL_STEPS;
155 animation_info.gx_animation_start_alpha = 0xff;
156 animation_info.gx_animation_end_alpha = 0xff;
157 animation_info.gx_animation_target = (GX_WIDGET *)&main_screen.main_screen_animation_button;
158 animation_info.gx_animation_parent = (GX_WIDGET *)&main_screen;
159 animation_info.gx_animation_style = easing_function_id;
160
161 /* pass in parameter to fire off the animation sequence */
162 gx_animation_start(animation, &animation_info);
163 }
164 }
165
166 /******************************************************************************************/
167 /* Handle easing function drop list select event. */
168 /******************************************************************************************/
easing_function_drop_list_select_event_handler()169 VOID easing_function_drop_list_select_event_handler()
170 {
171 GX_VERTICAL_LIST *list;
172 INT selected_index;
173
174 /* Get popup list of the drop list. */
175 gx_drop_list_popup_get(&main_screen.main_screen_easing_function_drop_list, &list);
176
177 /* Get the selected index of the popup list. */
178 gx_vertical_list_selected_index_get(list, &selected_index);
179
180 gx_window_wallpaper_set(&main_screen.main_screen_easing_function_chart_win, easing_function_list[selected_index].map_id, GX_FALSE);
181
182 easing_function_id = easing_function_list[selected_index].type;
183 animation_start();
184 }
185
186 /******************************************************************************************/
187 /* Override the default event processing of "main_screen" to handle signals from my child */
188 /* widgets. */
189 /******************************************************************************************/
main_screen_event_process(GX_WINDOW * window,GX_EVENT * event_ptr)190 UINT main_screen_event_process(GX_WINDOW *window, GX_EVENT *event_ptr)
191 {
192 switch (event_ptr->gx_event_type)
193 {
194 case GX_SIGNAL(ID_EASING_FUNCTION_DROP_LIST, GX_EVENT_LIST_SELECT):
195 animation_back = GX_FALSE;
196 easing_function_drop_list_select_event_handler();
197 break;
198
199 case GX_EVENT_ANIMATION_COMPLETE:
200 /* The animation controller is retrieved from system, when animation complete,
201 it will be released. */
202 animation = GX_NULL;
203 if (animation_back)
204 {
205 animation_back = GX_FALSE;
206 }
207 else
208 {
209 animation_back = GX_TRUE;
210 }
211 animation_start();
212 break;
213
214 default:
215 return gx_window_event_process(window, event_ptr);
216 }
217
218 return 0;
219 }
220
221 /*****************************************************************************/
222 /* Create one item for the specified popup list. */
223 /*****************************************************************************/
drop_list_row_create(GX_VERTICAL_LIST * list,GX_WIDGET * widget,INT index)224 VOID drop_list_row_create(GX_VERTICAL_LIST *list, GX_WIDGET *widget, INT index)
225 {
226 GX_RECTANGLE size;
227 GX_PROMPT *prompt = (GX_PROMPT *)widget;
228 GX_STRING string;
229
230 /* Define prompt size. */
231 gx_utility_rectangle_define(&size, 0, 0, 100, 20);
232
233 /* Create prompt. */
234 gx_prompt_create(prompt, easing_function_list[index].type_text, list, 0, GX_STYLE_ENABLED | GX_STYLE_TEXT_LEFT | GX_STYLE_BORDER_NONE, 0, &size);
235
236 /* Set prompt fill color. */
237 gx_widget_fill_color_set(prompt, GX_COLOR_ID_LIGHT_SLATE_GRAY, GX_COLOR_ID_SLATE_GRAY, GX_COLOR_ID_LIGHT_SLATE_GRAY);
238
239 /* Set prompt text color. */
240 gx_prompt_text_color_set(prompt, GX_COLOR_ID_WHITE, GX_COLOR_ID_WHITE, GX_COLOR_ID_WHITE);
241
242 /* Set prompt text. */
243 string.gx_string_ptr = easing_function_list[index].type_text;
244 string.gx_string_length = string_length_get(string.gx_string_ptr, MAX_EASING_TYPE_NAME_LENGTH);
245 gx_prompt_text_set_ext(prompt, &string);
246 }
247
248 /*****************************************************************************/
249 /* Create drop list items. */
250 /*****************************************************************************/
populate_drop_list(void)251 VOID populate_drop_list(void)
252 {
253 INT index;
254 GX_VERTICAL_LIST *list;
255 GX_SCROLLBAR_APPEARANCE scrollbar_appearance;
256
257 /* Get popup list of the drop list. */
258 gx_drop_list_popup_get(&main_screen.main_screen_easing_function_drop_list, &list);
259
260 for (index = 0; index < DROP_LIST_TOTAL_ROWS; index++)
261 {
262 /* Create row items. */
263 drop_list_row_create(list, (GX_WIDGET *)&drop_list_items[index], index);
264 }
265
266 /* Set scrollbar appearance. */
267 memset(&scrollbar_appearance, 0, sizeof(GX_SCROLLBAR_APPEARANCE));
268 scrollbar_appearance.gx_scroll_thumb_pixelmap = GX_PIXELMAP_ID_LIST_SCROLL_THUMB;
269 scrollbar_appearance.gx_scroll_thumb_travel_min = 4;
270 scrollbar_appearance.gx_scroll_thumb_travel_max = 4;
271 scrollbar_appearance.gx_scroll_thumb_width = 8;
272 scrollbar_appearance.gx_scroll_width = 10;
273
274 /* Create scrollbar for popup list. */
275 gx_vertical_scrollbar_create(&list_scroll, "list_scroll", list,
276 &scrollbar_appearance, GX_SCROLLBAR_VERTICAL | GX_STYLE_ENABLED);
277 }
278
279 /******************************************************************************************/
280 /* Calculate string length. */
281 /******************************************************************************************/
string_length_get(GX_CONST GX_CHAR * input_string,UINT max_string_length)282 UINT string_length_get(GX_CONST GX_CHAR* input_string, UINT max_string_length)
283 {
284 UINT length = 0;
285
286 if (input_string)
287 {
288 /* Traverse the string. */
289 for (length = 0; input_string[length]; length++)
290 {
291 /* Check if the string length is bigger than the max string length. */
292 if (length >= max_string_length)
293 {
294 break;
295 }
296 }
297 }
298
299 return length;
300 }
301
302