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