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