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_332rgb_resources.h"
6 #include "all_widgets_332rgb_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 GX_BOOL day_wheel_selected_row_changed;
14 extern GX_BOOL month_wheel_selected_row_changed;
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
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 gx_window_event_process(window, event_ptr);
67 animation_speed_set();
68 break;
69
70 case GX_SIGNAL(ID_DAY_WHEEL, GX_EVENT_LIST_SELECT):
71 day_wheel_selected_row_changed = GX_TRUE;
72 break;
73
74 case GX_SIGNAL(ID_MONTH_WHEEL, GX_EVENT_LIST_SELECT):
75 month_wheel_selected_row_changed = GX_TRUE;
76 day_count_update();
77 break;
78
79 case GX_SIGNAL(ID_YEAR_WHEEL, GX_EVENT_LIST_SELECT):
80 day_count_update();
81 break;
82
83 case GX_SIGNAL(ID_DAY_SELECT, GX_EVENT_CLICKED):
84 select_day();
85 break;
86
87 default:
88 return next_button_handler(window, event_ptr);
89 }
90
91 return 0;
92 }
93
animation_speed_set()94 VOID animation_speed_set()
95 {
96 GX_NUMERIC_SCROLL_WHEEL *day_wheel;
97 GX_NUMERIC_SCROLL_WHEEL *year_wheel;
98 GX_STRING_SCROLL_WHEEL *month_wheel;
99
100 gx_widget_find(pScrollWheelScreen, ID_DAY_WHEEL, GX_SEARCH_DEPTH_INFINITE, &day_wheel);
101 gx_widget_find(pScrollWheelScreen, ID_YEAR_WHEEL, GX_SEARCH_DEPTH_INFINITE, &year_wheel);
102 gx_widget_find(pScrollWheelScreen, ID_MONTH_WHEEL, GX_SEARCH_DEPTH_INFINITE, &month_wheel);
103
104 gx_scroll_wheel_speed_set(day_wheel, GX_FIXED_VAL_MAKE(1), 100, 10, 2);
105 gx_scroll_wheel_speed_set(month_wheel, (GX_FIXED_VAL_MAKE(1) / 2), 100, 10, 2);
106 gx_scroll_wheel_speed_set(year_wheel, GX_FIXED_VAL_MAKE(2), 100, 10, 2);
107 }
108
day_count_update()109 VOID day_count_update()
110 {
111 int year;
112 int month;
113 int day_count;
114 int new_day_count;
115
116 GX_NUMERIC_SCROLL_WHEEL *day_wheel;
117 GX_NUMERIC_SCROLL_WHEEL *year_wheel;
118 GX_STRING_SCROLL_WHEEL *month_wheel;
119
120 gx_widget_find(pScrollWheelScreen, ID_DAY_WHEEL, GX_SEARCH_DEPTH_INFINITE, &day_wheel);
121 gx_widget_find(pScrollWheelScreen, ID_YEAR_WHEEL, GX_SEARCH_DEPTH_INFINITE, &year_wheel);
122 gx_widget_find(pScrollWheelScreen, ID_MONTH_WHEEL, GX_SEARCH_DEPTH_INFINITE, &month_wheel);
123
124 year = year_wheel->gx_numeric_scroll_wheel_start_val;
125 year += year_wheel->gx_scroll_wheel_selected_row;
126
127 month = month_wheel->gx_scroll_wheel_selected_row + 1;
128 day_count = GX_ABS(day_wheel->gx_numeric_scroll_wheel_end_val - day_wheel->gx_numeric_scroll_wheel_start_val) + 1;
129
130 switch (month)
131 {
132 case 1:
133 case 3:
134 case 5:
135 case 7:
136 case 8:
137 case 10:
138 case 12:
139 new_day_count = 31;
140 break;
141
142 case 2:
143 if ((!(year % 400)) ||
144 (!(year % 4) && (year % 400)))
145 {
146 new_day_count = 29;
147 }
148 else
149 {
150 new_day_count = 28;
151 }
152 break;
153
154 default:
155 new_day_count = 30;
156 break;
157 }
158
159 if (new_day_count != day_count)
160 {
161 gx_numeric_scroll_wheel_range_set(day_wheel, 1, new_day_count);
162 }
163 }
164