1 /* This is a small demo of the high-performance GUIX graphics framework. */
2 #include <stdio.h>
3 #include "gx_api.h"
4 #include "folder_output_test_MAIN_DISPLAY_resources.h"
5 #include "folder_output_test_SECONDARY_resources.h"
6 #include "folder_output_test_specifications.h"
7
8 #define ID_SCROLL_WHEEL_DAY 0xf0
9 #define ID_SCROLL_WHEEL_MONTH 0xf1
10 #define ID_SCROLL_WHEEL_YEAR 0xf2
11
12 extern GX_WINDOW *pScrollWheelScreen;
13 extern int scroll_wheel_selected;
14 extern TX_SEMAPHORE *selected_semaphore;
15
16 VOID day_count_update();
17 VOID animation_speed_set();
18
19 /* Define day wheel callback function. */
day_wheel_value_format(GX_NUMERIC_SCROLL_WHEEL * wheel,INT row,GX_STRING * string)20 UINT day_wheel_value_format(GX_NUMERIC_SCROLL_WHEEL* wheel, INT row, GX_STRING *string)
21 {
22 sprintf(wheel->gx_numeric_scroll_wheel_string_buffer, "%02d", row + 1);
23 string->gx_string_ptr = wheel->gx_numeric_scroll_wheel_string_buffer;
24 string->gx_string_length = 2;
25
26 return GX_SUCCESS;
27 }
28
string_to_int(const char * string)29 int string_to_int(const char *string)
30 {
31 int value = 0;
32
33 while (string[0])
34 {
35 value = value * 10 + string[0] - '0';
36 string++;
37 }
38
39 return value;
40 }
41
select_day()42 VOID select_day()
43 {
44 int selected_day;
45 GX_SINGLE_LINE_TEXT_INPUT *input;
46 GX_NUMERIC_SCROLL_WHEEL *day_wheel;
47
48 gx_widget_find(pScrollWheelScreen, ID_DAY_WHEEL, GX_SEARCH_DEPTH_INFINITE, &day_wheel);
49
50 gx_widget_find(pScrollWheelScreen, ID_DAY_INPUT, GX_SEARCH_DEPTH_INFINITE, &input);
51
52 if (input && day_wheel)
53 {
54 selected_day = string_to_int(input->gx_single_line_text_input_buffer);
55 gx_scroll_wheel_selected_set(day_wheel, selected_day - 1);
56 }
57 }
58
59 /* Override default event processing of scroll wheel screen. */
scroll_wheel_screen_event_handler(GX_WINDOW * window,GX_EVENT * event_ptr)60 UINT scroll_wheel_screen_event_handler(GX_WINDOW *window, GX_EVENT *event_ptr)
61 {
62
63 switch (event_ptr->gx_event_type)
64 {
65 case GX_EVENT_SHOW:
66 pScrollWheelScreen = window;
67 gx_window_event_process(window, event_ptr);
68 animation_speed_set();
69 break;
70
71 case GX_SIGNAL(ID_DAY_WHEEL, GX_EVENT_LIST_SELECT):
72 if(selected_semaphore)
73 {
74 tx_semaphore_put(selected_semaphore);
75 }
76 break;
77
78 case GX_SIGNAL(ID_MONTH_WHEEL, GX_EVENT_LIST_SELECT):
79 if(selected_semaphore)
80 {
81 tx_semaphore_put(selected_semaphore);
82 }
83 break;
84
85 case GX_SIGNAL(ID_YEAR_WHEEL, GX_EVENT_LIST_SELECT):
86 day_count_update();
87 break;
88
89 case GX_SIGNAL(ID_DAY_SELECT, GX_EVENT_CLICKED):
90 select_day();
91 break;
92
93 default:
94 return gx_window_event_process(window, event_ptr);
95 }
96
97 return 0;
98 }
99
animation_speed_set()100 VOID animation_speed_set()
101 {
102 GX_NUMERIC_SCROLL_WHEEL *day_wheel;
103 GX_NUMERIC_SCROLL_WHEEL *year_wheel;
104 GX_STRING_SCROLL_WHEEL *month_wheel;
105
106 gx_widget_find(pScrollWheelScreen, ID_DAY_WHEEL, GX_SEARCH_DEPTH_INFINITE, &day_wheel);
107 gx_widget_find(pScrollWheelScreen, ID_YEAR_WHEEL, GX_SEARCH_DEPTH_INFINITE, &year_wheel);
108 gx_widget_find(pScrollWheelScreen, ID_MONTH_WHEEL, GX_SEARCH_DEPTH_INFINITE, &month_wheel);
109
110 gx_scroll_wheel_speed_set(day_wheel, GX_FIXED_VAL_MAKE(1), 100, 10, 2);
111 gx_scroll_wheel_speed_set(month_wheel, (GX_FIXED_VAL_MAKE(1) / 2), 100, 10, 2);
112 gx_scroll_wheel_speed_set(year_wheel, GX_FIXED_VAL_MAKE(2), 100, 10, 2);
113 }
114
day_count_update()115 VOID day_count_update()
116 {
117 int year;
118 int month;
119 int day_count;
120 int new_day_count;
121
122 GX_NUMERIC_SCROLL_WHEEL *day_wheel;
123 GX_NUMERIC_SCROLL_WHEEL *year_wheel;
124 GX_STRING_SCROLL_WHEEL *month_wheel;
125
126 gx_widget_find(pScrollWheelScreen, ID_DAY_WHEEL, GX_SEARCH_DEPTH_INFINITE, &day_wheel);
127 gx_widget_find(pScrollWheelScreen, ID_YEAR_WHEEL, GX_SEARCH_DEPTH_INFINITE, &year_wheel);
128 gx_widget_find(pScrollWheelScreen, ID_MONTH_WHEEL, GX_SEARCH_DEPTH_INFINITE, &month_wheel);
129
130 year = year_wheel->gx_numeric_scroll_wheel_start_val;
131 year += year_wheel->gx_scroll_wheel_selected_row;
132
133 month = month_wheel->gx_scroll_wheel_selected_row + 1;
134 day_count = GX_ABS(day_wheel->gx_numeric_scroll_wheel_end_val - day_wheel->gx_numeric_scroll_wheel_start_val) + 1;
135
136 switch (month)
137 {
138 case 1:
139 case 3:
140 case 5:
141 case 7:
142 case 8:
143 case 10:
144 case 12:
145 new_day_count = 31;
146 break;
147
148 case 2:
149 if ((!(year % 400)) ||
150 (!(year % 4) && (year % 400)))
151 {
152 new_day_count = 29;
153 }
154 else
155 {
156 new_day_count = 28;
157 }
158 break;
159
160 default:
161 new_day_count = 30;
162 break;
163 }
164
165 if (new_day_count != day_count)
166 {
167 gx_numeric_scroll_wheel_range_set(day_wheel, 1, new_day_count);
168 }
169 }
170