1 #include "demo_guix_smart_watch.h"
2 
3 #define CLOCK_SLIDE_SHIFT 30
4 
5 #define TARGET_XPOS_MIN 227
6 #define TARGET_XPOS_MAX (TARGET_XPOS_MIN + CLOCK_SLIDE_SHIFT)
7 
8 /* Define clock slide animation control blocks. */
9 static GX_ANIMATION clock_slide_animation[2];
10 
11 /******************************************************************************************/
12 /* Start clock slide animation.                                                           */
13 /******************************************************************************************/
clock_slide_animation_start()14 static void clock_slide_animation_start()
15 {
16     GX_ANIMATION_INFO info;
17     GX_WIDGET *target_hour = (GX_WIDGET*)&clock_4_screen.clock_4_screen_hour;
18     GX_WIDGET *target_minute = (GX_WIDGET*)&clock_4_screen.clock_4_screen_minute;
19     GX_VALUE hour_end_xpos;
20     GX_VALUE minute_end_xpos;
21 
22     if (target_hour->gx_widget_size.gx_rectangle_left < target_minute->gx_widget_size.gx_rectangle_left)
23     {
24         hour_end_xpos = TARGET_XPOS_MAX;
25         minute_end_xpos = TARGET_XPOS_MIN;
26     }
27     else
28     {
29         hour_end_xpos = TARGET_XPOS_MIN;
30         minute_end_xpos = TARGET_XPOS_MAX;
31     }
32 
33     memset(&info, 0, sizeof(GX_ANIMATION_INFO));
34     info.gx_animation_parent = (GX_WIDGET *)&clock_4_screen;
35     info.gx_animation_target = target_hour;
36     info.gx_animation_start_alpha = 255;
37     info.gx_animation_end_alpha = 255;
38     info.gx_animation_frame_interval = 40 / GX_SYSTEM_TIMER_MS;
39     info.gx_animation_id = CLOCK_SLIDE_ANIMATION_ID;
40     info.gx_animation_start_position.gx_point_x = target_hour->gx_widget_size.gx_rectangle_left;
41     info.gx_animation_end_position.gx_point_x = hour_end_xpos;
42     info.gx_animation_start_position.gx_point_y = target_hour->gx_widget_size.gx_rectangle_top;
43     info.gx_animation_end_position.gx_point_y = info.gx_animation_start_position.gx_point_y;
44     info.gx_animation_steps = GX_ABS(info.gx_animation_end_position.gx_point_x - info.gx_animation_start_position.gx_point_x);
45 
46     gx_animation_start(&clock_slide_animation[0], &info);
47 
48     info.gx_animation_target = target_minute;
49     info.gx_animation_start_position.gx_point_x = target_minute->gx_widget_size.gx_rectangle_left;
50     info.gx_animation_end_position.gx_point_x = minute_end_xpos;
51     info.gx_animation_start_position.gx_point_y = target_minute->gx_widget_size.gx_rectangle_top;
52     info.gx_animation_end_position.gx_point_y = info.gx_animation_start_position.gx_point_y;
53 
54     gx_animation_start(&clock_slide_animation[1], &info);
55 }
56 
57 /******************************************************************************************/
58 /* Stop clock slide animation.                                                            */
59 /******************************************************************************************/
clock_slide_animation_stop()60 static void clock_slide_animation_stop()
61 {
62     gx_animation_stop(&clock_slide_animation[0]);
63     gx_animation_stop(&clock_slide_animation[1]);
64 }
65 
66 /******************************************************************************************/
67 /* Override the default event processing of "clock_screen_template" to handle signals     */
68 /* from my child widgets.                                                                 */
69 /******************************************************************************************/
clock_4_screen_event_process(GX_WINDOW * window,GX_EVENT * event_ptr)70 UINT clock_4_screen_event_process(GX_WINDOW* window, GX_EVENT* event_ptr)
71 {
72     switch (event_ptr->gx_event_type)
73     {
74     case GX_EVENT_SHOW:
75         gx_animation_create(&clock_slide_animation[0]);
76         gx_animation_create(&clock_slide_animation[1]);
77         clear_screen_clock_record();
78         screen_clock_update(&clock_4_screen.clock_4_screen_hour, &clock_4_screen.clock_4_screen_minute, GX_NULL);
79         gx_system_timer_start(window, SCREEN_CLOCK_TIMER_ID, GX_TICKS_SECOND, GX_TICKS_SECOND);
80         return gx_window_event_process(window, event_ptr);
81 
82     case GX_EVENT_HIDE:
83         gx_system_timer_stop(window, SCREEN_CLOCK_TIMER_ID);
84         gx_system_timer_stop(window, SCREEN_ANIMATION_TIMER_ID);
85         return gx_window_event_process(window, event_ptr);
86 
87     case USER_EVENT_ANIMATION_START:
88         clock_slide_animation_start();
89         break;
90 
91     case USER_EVENT_ANIMATION_STOP:
92         clock_slide_animation_stop();
93         break;
94 
95     case GX_EVENT_ANIMATION_COMPLETE:
96         if (event_ptr->gx_event_sender == CLOCK_SLIDE_ANIMATION_ID)
97         {
98             clock_slide_animation_start();
99         }
100         break;
101 
102     case GX_EVENT_TIMER:
103         if (event_ptr->gx_event_payload.gx_event_timer_id == SCREEN_CLOCK_TIMER_ID)
104         {
105             screen_clock_update(&clock_4_screen.clock_4_screen_hour, &clock_4_screen.clock_4_screen_minute, GX_NULL);
106         }
107         break;
108 
109     default:
110         return gx_window_event_process(window, event_ptr);
111     }
112 
113     return 0;
114 }