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