1 
2 #include "demo_guix_home_automation.h"
3 
4 /* Define future weather information structure. */
5 typedef struct WEATHER_7DAY_INFO_STRUCT{
6     GX_RESOURCE_ID icon; /* ID of the weather icon. */
7     INT hi_value; /* Highest temperature. */
8     INT low_value; /* Lowest temperature. */
9 }WEATHER_7DAY_INFO;
10 
11 /* Define weather information structure. */
12 typedef struct WEATHER_INFO_STRUCT{
13     WEATHER_BASE_CONTROL_BLOCK *widget; /* Pointer to the weather display widget. */
14     GX_RESOURCE_ID city_name_id; /* City name. */
15     INT temperature; /* Current temperature. */
16     INT hi_value; /* Highest temperature. */
17     INT low_value; /* Lowest temperature. */
18     INT rain_value; /* Probability of rain. */
19     GX_RESOURCE_ID weather_icon; /* ID of the weather icon. */
20     GX_RESOURCE_ID weather_text_id; /* Weather description text. */
21     INT wind_speed; /* Wind speed. */
22     INT humidity_value; /* Humidity value. */
23     WEATHER_7DAY_INFO *weather_7day_info_list; /* Weather information for next 7 days. */
24 }WEATHER_INFO;
25 
26 /* This is a list of weather information for next 7 days in San Diego. */
27 static WEATHER_7DAY_INFO San_Diego_weather_7day_info_list[] = {
28     { GX_PIXELMAP_ID_WEATHER_7DAY_ICON_SUN, 81, 70},
29     { GX_PIXELMAP_ID_WEATHER_7DAY_ICON_SUN, 80, 70},
30     { GX_PIXELMAP_ID_WEATHER_7DAY_ICON_CLOUDY, 79, 65 },
31     { GX_PIXELMAP_ID_WEATHER_7DAY_ICON_CLOUDY, 79, 65 },
32     { GX_PIXELMAP_ID_WEATHER_7DAY_ICON_SUN, 76, 64 },
33     { GX_PIXELMAP_ID_WEATHER_7DAY_ICON_SUN, 85, 72 },
34     { GX_PIXELMAP_ID_WEATHER_7DAY_ICON_SUN, 80, 70 }
35 };
36 
37 /* This is a list of weather information for next 7 days in New York. */
38 static WEATHER_7DAY_INFO New_York_weather_7day_info_list[] = {
39     { GX_PIXELMAP_ID_WEATHER_7DAY_ICON_RAIN, 68, 79 },
40     { GX_PIXELMAP_ID_WEATHER_7DAY_ICON_RAIN, 69, 58 },
41     { GX_PIXELMAP_ID_WEATHER_7DAY_ICON_CLOUDY, 69, 55 },
42     { GX_PIXELMAP_ID_WEATHER_7DAY_ICON_CLOUDY, 69, 55 },
43     { GX_PIXELMAP_ID_WEATHER_7DAY_ICON_CLOUDY, 71, 64 },
44     { GX_PIXELMAP_ID_WEATHER_7DAY_ICON_SUN, 65, 52 },
45     { GX_PIXELMAP_ID_WEATHER_7DAY_ICON_CLOUDY,70, 60 }
46 };
47 
48 /* This is a list of weather information for next 7 days in Las Vegas. */
49 static WEATHER_7DAY_INFO Las_Vegas_weather_7day_info_list[] = {
50     { GX_PIXELMAP_ID_WEATHER_7DAY_ICON_SUN, 85, 72 },
51     { GX_PIXELMAP_ID_WEATHER_7DAY_ICON_CLOUDY, 82, 65 },
52     { GX_PIXELMAP_ID_WEATHER_7DAY_ICON_SUN, 82, 68 },
53     { GX_PIXELMAP_ID_WEATHER_7DAY_ICON_SUN, 80, 68 },
54     { GX_PIXELMAP_ID_WEATHER_7DAY_ICON_CLOUDY, 76, 67 },
55     { GX_PIXELMAP_ID_WEATHER_7DAY_ICON_SUN, 85, 72 },
56     { GX_PIXELMAP_ID_WEATHER_7DAY_ICON_SUN, 80, 70 }
57 };
58 
59 /* This is a list of weather information of 3 cities. */
60 static WEATHER_INFO weather_info_list[] = {
61     { &win_San_Diego.base, GX_STRING_ID_SANDIEGO, 75, 82, 70, 0, GX_PIXELMAP_ID_WEATHER_ICON_CLOUDY, GX_STRING_ID_PARTLY_CLOUDY, 19, 58, San_Diego_weather_7day_info_list},
62     { &win_New_York.base, GX_STRING_ID_NEW_YORK, 67, 71, 52, 90, GX_PIXELMAP_ID_WEATHER_ICON_RAIN, GX_STRING_ID_RAIN, 11, 64, New_York_weather_7day_info_list },
63     { &win_Las_Vegas.base, GX_STRING_ID_LAS_VEGAS, 80, 85, 68, 0, GX_PIXELMAP_ID_WEATHER_ICON_SUN, GX_STRING_ID_SUNNY, 5, 14, Las_Vegas_weather_7day_info_list},
64     { GX_NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
65 };
66 
67 /* Define child widget animation information structure. */
68 typedef struct WEATHER_ANIMATION_INFO_STRUCT{
69     INT target_id; /* Widget id of animation target. */
70     INT delay; /* Delay time of animation. */
71     GX_VALUE start_x_offset; /* The x offset from current position to start position. */
72     GX_VALUE end_x_offset; /* The x offset from current position  to end position. */
73     GX_VALUE start_y_offset; /* The y offset from current position to start position. */
74     GX_VALUE end_y_offset; /* The y offset from current position to end position. */
75 }WEATHER_ANIMATION_INFO;
76 
77 /* This is a list of animation informations.
78    This list is used to run child widget animations when
79    weather information page switches. */
80 WEATHER_ANIMATION_INFO animation_info_list[] = {
81     { ID_WEATHER_WIN, 0, -128, 28, 23, 23 },
82     { ID_WIND_WIN, 5, -128, 28, 110, 110 },
83     { ID_HUMIDITY_WIN, 10, -128, 28, 197, 197 },
84     { ID_THU_WIN, 0, 611, 434, 15, 15 },
85     { ID_FRI_WIN, 5, 611, 434, 53, 53 },
86     { ID_SAT_WIN, 10, 611, 434, 91, 91 },
87     { ID_SUN_WIN, 15, 611, 434, 130, 130 },
88     { ID_MON_WIN, 20, 611, 434, 168, 168 },
89     { ID_TUE_WIN, 25, 611, 434, 206, 206 },
90     { ID_WED_WIN, 30, 611, 434, 243, 243 },
91     { ID_TITLE, 0, 200, 200, -42, 24 },
92     { 0, 0, 0, 0, 0, 0 }
93 };
94 
95 /* This variable is ued to count the number of in process animation in current screen. */
96 extern int screen_animation_count;
97 
98 /* This variable is used to run screen slide animation. */
99 extern GX_ANIMATION slide_animation;
100 
101 /******************************************************************************************/
102 /* Initiate weather information.                                                          */
103 /******************************************************************************************/
init_weather_info(WEATHER_INFO * info)104 static VOID init_weather_info(WEATHER_INFO *info)
105 {
106     int index;
107     GX_ICON *icon;
108     GX_NUMERIC_PROMPT *hi;
109     GX_NUMERIC_PROMPT *low;
110     WEATHER_7DAY_INFO *seven_day_info;
111     WEATHER_BASE_CONTROL_BLOCK *base = info->widget;
112 
113     /* Set city name. */
114     gx_prompt_text_id_set(&base->weather_base_city_name, info->city_name_id);
115 
116     /* Set current temperature. */
117     gx_numeric_prompt_value_set(&base->weather_base_temperature, info->temperature);
118 
119     /* Set highest temperature. */
120     gx_numeric_prompt_value_set(&base->weather_base_hi_value, info->hi_value);
121 
122     /* Set probability of rain. */
123     gx_numeric_prompt_value_set(&base->weather_base_rain_value, info->rain_value);
124 
125     /* Set weather icon. */
126     gx_icon_pixelmap_set(&base->weather_base_weather_icon, info->weather_icon, info->weather_icon);
127 
128     /* Set weather text. */
129     gx_prompt_text_id_set(&base->weather_base_weather_text, info->weather_text_id);
130 
131     /* Set wind speed. */
132     gx_numeric_prompt_value_set(&base->weather_base_wind_speed, info->wind_speed);
133 
134     /* Set humidity value. */
135     gx_numeric_prompt_value_set(&base->weather_base_humidity_value, info->humidity_value);
136 
137     /* Set weather information for next 7 days. */
138     for (index = 0; index < 7; index++)
139     {
140         switch (index)
141         {
142         case 0:
143             icon = &base->weather_base_thu_wicon;
144             hi = &base->weather_base_thu_hi_value;
145             low = &base->weather_base_thu_low_value;
146             break;
147         case 1:
148             icon = &base->weather_base_fri_wicon;
149             hi = &base->weather_base_fri_hi_value;
150             low = &base->weather_base_fri_low_value;
151             break;
152         case 2:
153             icon = &base->weather_base_sat_wicon;
154             hi = &base->weather_base_sat_hi_value;
155             low = &base->weather_base_sat_low_value;
156             break;
157         case 3:
158             icon = &base->weather_base_sun_wicon;
159             hi = &base->weather_base_sun_hi_value;
160             low = &base->weather_base_sun_low_value;
161             break;
162         case 4:
163             icon = &base->weather_base_mon_wicon;
164             hi = &base->weather_base_mon_hi_value;
165             low = &base->weather_base_mon_low_value;
166             break;
167         case 5:
168             icon = &base->weather_base_tue_wicon;
169             hi = &base->weather_base_tue_hi_value;
170             low = &base->weather_base_tue_low_value;
171             break;
172         case 6:
173             icon = &base->weather_base_wed_wicon;
174             hi = &base->weather_base_wed_hi_value;
175             low = &base->weather_base_wed_low_value;
176             break;
177 
178         }
179         seven_day_info = &info->weather_7day_info_list[index];
180 
181         gx_icon_pixelmap_set(icon, seven_day_info->icon, seven_day_info->icon);
182         gx_numeric_prompt_value_set(hi, seven_day_info->hi_value);
183         gx_numeric_prompt_value_set(low, seven_day_info->low_value);
184     }
185 }
186 
187 /******************************************************************************************/
188 /* Hide some children of weather window.                                                  */
189 /******************************************************************************************/
hide_weather_children(WEATHER_INFO * info)190 static VOID hide_weather_children(WEATHER_INFO *info)
191 {
192     WEATHER_BASE_CONTROL_BLOCK *base = info->widget;
193     GX_WIDGET *child;
194     GX_WIDGET *next;
195 
196     child = base->gx_widget_first_child;
197 
198     /* Hide some child widgets. */
199     while (child)
200     {
201         next = child->gx_widget_next;
202 
203         if (child->gx_widget_id != ID_V_LINE &&
204             child->gx_widget_id != ID_WEATHER_BG)
205         {
206             gx_widget_hide(child);
207         }
208         child = next;
209     }
210 }
211 
212 /******************************************************************************************/
213 /* Start children animation for specified weather window.                                 */
214 /******************************************************************************************/
start_weather_children_animation(WEATHER_INFO * info)215 static VOID start_weather_children_animation(WEATHER_INFO *info)
216 {
217     WEATHER_BASE_CONTROL_BLOCK *base = info->widget;
218     GX_ANIMATION *animation;
219     GX_ANIMATION_INFO animation_info;
220     GX_WIDGET *target;
221     WEATHER_ANIMATION_INFO *w_aninfo = animation_info_list;
222 
223     memset(&animation_info, 0, sizeof(GX_ANIMATION_INFO));
224 
225     animation_info.gx_animation_parent = (GX_WIDGET *)base;
226     animation_info.gx_animation_id = ANIMATION_ID_SCREEN_CHILDREN;
227     animation_info.gx_animation_style = 0;
228     animation_info.gx_animation_start_alpha = 255;
229     animation_info.gx_animation_end_alpha = 255;
230     animation_info.gx_animation_steps = 400 / GX_SYSTEM_TIMER_MS;
231     animation_info.gx_animation_frame_interval = 1;
232 
233     /* Start animations descriped in animation information list. */
234     while (w_aninfo->target_id)
235     {
236         gx_widget_find(base, w_aninfo->target_id, 1, &target);
237 
238         if (target && (gx_system_animation_get(&animation) == GX_SUCCESS))
239         {
240             animation_info.gx_animation_target = target;
241             animation_info.gx_animation_start_delay = w_aninfo->delay;
242             animation_info.gx_animation_start_position.gx_point_x = base->gx_widget_size.gx_rectangle_left + w_aninfo->start_x_offset;
243             animation_info.gx_animation_start_position.gx_point_y = base->gx_widget_size.gx_rectangle_top + w_aninfo->start_y_offset;
244             animation_info.gx_animation_end_position.gx_point_x = base->gx_widget_size.gx_rectangle_left + w_aninfo->end_x_offset;
245             animation_info.gx_animation_end_position.gx_point_y = base->gx_widget_size.gx_rectangle_top + w_aninfo->end_y_offset;
246 
247             gx_animation_start(animation, &animation_info);
248             screen_animation_count++;
249         }
250 
251         w_aninfo++;
252     }
253 
254     gx_widget_attach(base, &base->weather_base_temperature);
255     gx_widget_attach(base, &base->weather_base_bottom_info_win);
256     gx_widget_attach(base, &base->weather_base_degree_lable);
257 }
258 
259 /******************************************************************************************/
260 /* Reset weather screen.                                                                  */
261 /******************************************************************************************/
weather_screen_reset()262 VOID weather_screen_reset()
263 {
264     WEATHER_INFO *info = weather_info_list;
265 
266     while (info->widget)
267     {
268         if (info->widget->gx_widget_status & GX_STATUS_VISIBLE)
269         {
270             hide_weather_children(info);
271         }
272 
273         info++;
274     }
275 }
276 
277 /******************************************************************************************/
278 /* Start animation for weather screen.                                                    */
279 /******************************************************************************************/
weather_screen_animation_start()280 VOID weather_screen_animation_start()
281 {
282     WEATHER_INFO *info = weather_info_list;
283 
284     while (info->widget)
285     {
286         if (info->widget->gx_widget_status & GX_STATUS_VISIBLE)
287         {
288             if (!(info->widget->weather_base_temperature.gx_widget_status & GX_STATUS_VISIBLE))
289             {
290                 /* Disable drag slide animation before weather screen item animations complete. */
291                 gx_animation_drag_disable(&slide_animation, (GX_WIDGET *)&weather_screen.base.screen_base_slide_win);
292 
293                 /* Disable pagination buttons before weather screen item animations complete. */
294                 pagination_button_enable_disable((GX_WINDOW *)&weather_screen.base, GX_FALSE);
295 
296                 start_weather_children_animation(info);
297             }
298         }
299         else
300         {
301             hide_weather_children(info);
302         }
303 
304         info++;
305     }
306 }
307 
308 /******************************************************************************************/
309 /* Stop all animations in weather screen.                                                 */
310 /******************************************************************************************/
weather_screen_animation_stop()311 VOID weather_screen_animation_stop()
312 {
313     WEATHER_INFO* info = weather_info_list;
314 
315     while (info->widget)
316     {
317         if (info->widget->gx_widget_status & GX_STATUS_VISIBLE)
318         {
319             gx_animation_delete(GX_NULL, (GX_WIDGET *)info->widget);
320         }
321 
322         info++;
323     }
324 
325     screen_animation_count = 0;
326 }
327 
328 /******************************************************************************************/
329 /* Initiate weather screen information.                                                   */
330 /******************************************************************************************/
weather_screen_init()331 VOID weather_screen_init()
332 {
333     WEATHER_INFO *info = weather_info_list;
334 
335     while (info->widget)
336     {
337         /* Initialize weather information. */
338         init_weather_info(info);
339 
340         /* Hide child widgets.
341            Next time the weather screen been visible, those child widgets will get visible with animation. */
342         hide_weather_children(info);
343 
344         info++;
345     }
346 
347     /* Set "Add City" widget text. */
348     gx_prompt_text_id_set(&weather_screen.base.screen_base_add_text, GX_STRING_ID_ADD_CITY);
349 }
350