1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** GUIX Component                                                        */
17 /**                                                                       */
18 /**   Animation Management (Animation)                                    */
19 /**                                                                       */
20 /**************************************************************************/
21 
22 #define GX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "gx_api.h"
28 #include "gx_widget.h"
29 #include "gx_system.h"
30 #include "gx_canvas.h"
31 #include "gx_animation.h"
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _gx_animation_complete_event_send                   PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Kenneth Maxwell, Microsoft Corporation                              */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    Internal helper function to send an animation complete event.       */
46 /*                                                                        */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    animation                             Pointer to animation control  */
51 /*                                            block                       */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    None                                                                */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _gx_system_event_send                 Send GUIX event               */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    _gx_animation_complete                                              */
64 /*    _gx_animation_slide_landing                                         */
65 /*                                                                        */
66 /*  RELEASE HISTORY                                                       */
67 /*                                                                        */
68 /*    DATE              NAME                      DESCRIPTION             */
69 /*                                                                        */
70 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
71 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
72 /*                                            resulting in version 6.1    */
73 /*                                                                        */
74 /**************************************************************************/
_gx_animation_complete_event_send(GX_ANIMATION * animation)75 VOID _gx_animation_complete_event_send(GX_ANIMATION *animation)
76 {
77 GX_EVENT complete_event;
78 
79     if (animation -> gx_animation_info.gx_animation_id)
80     {
81         if (animation -> gx_animation_info.gx_animation_target)
82         {
83             complete_event.gx_event_target = animation -> gx_animation_info.gx_animation_target;
84         }
85         else
86         {
87             complete_event.gx_event_target = animation -> gx_animation_info.gx_animation_parent;
88         }
89 
90         /* send event to notify the animation has been completed */
91 
92         complete_event.gx_event_type = GX_EVENT_ANIMATION_COMPLETE;
93         complete_event.gx_event_sender = animation -> gx_animation_info.gx_animation_id;
94         _gx_system_event_send(&complete_event);
95     }
96 }
97 
98 
99 
100 /**************************************************************************/
101 /*                                                                        */
102 /*  FUNCTION                                               RELEASE        */
103 /*                                                                        */
104 /*    _gx_animation_complete                              PORTABLE C      */
105 /*                                                           6.1.3        */
106 /*  AUTHOR                                                                */
107 /*                                                                        */
108 /*    Kenneth Maxwell, Microsoft Corporation                              */
109 /*                                                                        */
110 /*  DESCRIPTION                                                           */
111 /*                                                                        */
112 /*    Called internally when an animation sequence is finished.           */
113 /*                                                                        */
114 /*                                                                        */
115 /*  INPUT                                                                 */
116 /*                                                                        */
117 /*    animation                             Pointer to window control     */
118 /*                                            block                       */
119 /*                                                                        */
120 /*  OUTPUT                                                                */
121 /*                                                                        */
122 /*    None                                                                */
123 /*                                                                        */
124 /*  CALLS                                                                 */
125 /*                                                                        */
126 /*    _gx_animation_stop                    Stop an animation             */
127 /*    _gx_widget_detach                     Detach a widget from its      */
128 /*                                            parent                      */
129 /*    _gx_widget_hide                       Hide a widget                 */
130 /*    _gx_widget_shift                      Shift a widget                */
131 /*    _gx_widget_attach                     Attach a widget to its parent */
132 /*    _gx_system_event_send                 Send GUIX event               */
133 /*                                                                        */
134 /*  CALLED BY                                                             */
135 /*                                                                        */
136 /*    _gx_animation_update                                                */
137 /*                                                                        */
138 /*  RELEASE HISTORY                                                       */
139 /*                                                                        */
140 /*    DATE              NAME                      DESCRIPTION             */
141 /*                                                                        */
142 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
143 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
144 /*                                            resulting in version 6.1    */
145 /*  12-31-2020     Kenneth Maxwell          Modified comment(s),          */
146 /*                                            improved logic,             */
147 /*                                            resulting in version 6.1.3  */
148 /*                                                                        */
149 /**************************************************************************/
150 
_gx_animation_complete(GX_ANIMATION * animation)151 VOID _gx_animation_complete(GX_ANIMATION *animation)
152 {
153 GX_WIDGET *target;
154 GX_VALUE   xshift;
155 GX_VALUE   yshift;
156 
157     /* Remove animation from active list and assign idle status */
158     _gx_animation_stop(animation);
159 
160     /* do final cleanup */
161     target = animation -> gx_animation_info.gx_animation_target;
162 
163     if (animation -> gx_animation_canvas)
164     {
165         /* hide the animation root */
166         if (target -> gx_widget_parent)
167         {
168             _gx_widget_hide(target -> gx_widget_parent);
169         }
170 
171         /* Hide animation target. */
172         _gx_widget_detach(target);
173 
174         if (animation -> gx_animation_info.gx_animation_style & GX_ANIMATION_PUSH_STACK)
175         {
176             /* Push animation target to system screen stack. */
177             _gx_system_screen_stack_push(target);
178         }
179         else if (animation -> gx_animation_info.gx_animation_style & GX_ANIMATION_DETACH)
180         {
181             if (target -> gx_widget_status & GX_STATUS_STUDIO_CREATED)
182             {
183                 _gx_widget_delete(target);
184                 animation -> gx_animation_info.gx_animation_target = GX_NULL;
185             }
186         }
187         else
188         {
189             /* shift the target into final position */
190             _gx_widget_shift(animation -> gx_animation_info.gx_animation_target,
191                              animation -> gx_animation_info.gx_animation_end_position.gx_point_x,
192                              animation -> gx_animation_info.gx_animation_end_position.gx_point_y, GX_FALSE);
193 
194             /* attach the widget to it's parent */
195             _gx_widget_attach(animation -> gx_animation_info.gx_animation_parent, target);
196         }
197         _gx_canvas_hide(animation -> gx_animation_canvas);
198         _gx_system_canvas_refresh();
199     }
200     else
201     {
202 #if defined(GX_BRUSH_ALPHA_SUPPORT)
203 
204         if (animation -> gx_animation_info.gx_animation_start_alpha !=
205             animation -> gx_animation_info.gx_animation_end_alpha)
206         {
207             animation -> gx_animation_info.gx_animation_target -> gx_widget_style &= ~GX_STYLE_USE_LOCAL_ALPHA;
208             _gx_system_dirty_mark(animation -> gx_animation_info.gx_animation_target);
209         }
210 #endif
211 
212         if (animation -> gx_animation_info.gx_animation_style & GX_ANIMATION_PUSH_STACK)
213         {
214             /* Push animation target to system screen stack. */
215             _gx_system_screen_stack_push(target);
216         }
217         else if (animation -> gx_animation_info.gx_animation_style & GX_ANIMATION_DETACH)
218         {
219             _gx_widget_hide(target);
220 
221             /* if this target was created by the Studio generated code, then delete the widget here */
222             if (target -> gx_widget_status & GX_STATUS_STUDIO_CREATED)
223             {
224                 _gx_widget_delete(target);
225                 animation -> gx_animation_info.gx_animation_target = GX_NULL;
226             }
227         }
228         else
229         {
230             /* test for shift translation */
231             xshift = (GX_VALUE)(animation -> gx_animation_info.gx_animation_end_position.gx_point_x -
232                                 animation -> gx_animation_info.gx_animation_start_position.gx_point_x);
233 
234             yshift = (GX_VALUE)(animation -> gx_animation_info.gx_animation_end_position.gx_point_y -
235                                 animation -> gx_animation_info.gx_animation_start_position.gx_point_y);
236 
237             if (xshift || yshift)
238             {
239                 xshift = (GX_VALUE)(animation -> gx_animation_info.gx_animation_end_position.gx_point_x -
240                                     target -> gx_widget_size.gx_rectangle_left);
241 
242                 yshift = (GX_VALUE)(animation -> gx_animation_info.gx_animation_end_position.gx_point_y -
243                                     target -> gx_widget_size.gx_rectangle_top);
244 
245                 /* shift the target into final position */
246                 _gx_widget_shift(target, xshift, yshift, GX_TRUE);
247             }
248         }
249     }
250 
251     _gx_animation_complete_event_send(animation);
252 
253     /* If this animation came from the system pool, return it */
254     if (animation -> gx_animation_system_allocated)
255     {
256         _gx_system_animation_free(animation);
257     }
258 }
259 
260