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_animation.h"
30 #include "gx_canvas.h"
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _gx_animation_drag_tracking                         PORTABLE C      */
37 /*                                                           6.1.11       */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Kenneth Maxwell, Microsoft Corporation                              */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function moves the animation screens according to current pen  */
45 /*      position.                                                         */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    animation                             Pointer to animation control  */
50 /*                                            block                       */
51 /*    penpos                                Current pen position          */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    status                                Completion status             */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _gx_widget_detach                     Detach a widget from its      */
60 /*                                            parent                      */
61 /*    _gx_widget_shift                      Change widget's position      */
62 /*    _gx_animation_drag_tracking_start     Prepare for screen draw       */
63 /*                                            animation                   */
64 /*                                                                        */
65 /*  CALLED BY                                                             */
66 /*                                                                        */
67 /*    _gx_animation_drag_event_check                                      */
68 /*                                                                        */
69 /*  RELEASE HISTORY                                                       */
70 /*                                                                        */
71 /*    DATE              NAME                      DESCRIPTION             */
72 /*                                                                        */
73 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
74 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
75 /*                                            resulting in version 6.1    */
76 /*  04-25-2022     Ting Zhu                 Modified comment(s),          */
77 /*                                            added canvas and block move */
78 /*                                            support,                    */
79 /*                                            resulting in version 6.1.11 */
80 /*                                                                        */
81 /**************************************************************************/
_gx_animation_drag_tracking(GX_ANIMATION * animation,GX_POINT penpos)82 UINT  _gx_animation_drag_tracking(GX_ANIMATION *animation, GX_POINT penpos)
83 {
84 GX_VALUE     delta_x = 0;
85 GX_VALUE     delta_y = 0;
86 GX_VALUE     shift_x = 0;
87 GX_VALUE     shift_y = 0;
88 GX_VALUE     last_pos;
89 GX_VALUE     start_pos;
90 GX_VALUE     pen_pos;
91 GX_WIDGET   *target_1 = GX_NULL;
92 GX_WIDGET   *target_2 = GX_NULL;
93 GX_WIDGET   *parent;
94 GX_RECTANGLE block;
95 GX_VALUE     border_width;
96 
97     if (animation -> gx_animation_slide_target_index_1 >= 0)
98     {
99         target_1 = animation -> gx_animation_info.gx_animation_slide_screen_list[animation -> gx_animation_slide_target_index_1];
100     }
101 
102     if (target_1 == GX_NULL)
103     {
104         return GX_SUCCESS;
105     }
106 
107     if (animation -> gx_animation_slide_target_index_2 >= 0)
108     {
109         target_2 = animation -> gx_animation_info.gx_animation_slide_screen_list[animation -> gx_animation_slide_target_index_2];
110     }
111 
112     last_pos = animation -> gx_animation_slide_tracking_current_pos;
113     if (animation -> gx_animation_info.gx_animation_style & GX_ANIMATION_VERTICAL)
114     {
115         pen_pos = penpos.gx_point_y;
116         delta_y = (GX_VALUE)(pen_pos - last_pos);
117     }
118     else
119     {
120         pen_pos = penpos.gx_point_x;
121         delta_x = (GX_VALUE)(pen_pos - last_pos);
122     }
123 
124     if (delta_x || delta_y)
125     {
126         /* Calculate sliding distance. */
127         start_pos = animation -> gx_animation_slide_tracking_start_pos;
128 
129         if (((animation -> gx_animation_slide_direction == GX_ANIMATION_SLIDE_LEFT) && (pen_pos > start_pos)) ||
130             ((animation -> gx_animation_slide_direction == GX_ANIMATION_SLIDE_RIGHT) && (pen_pos < start_pos)) ||
131             ((animation -> gx_animation_slide_direction == GX_ANIMATION_SLIDE_UP) && (pen_pos > start_pos)) ||
132             ((animation -> gx_animation_slide_direction == GX_ANIMATION_SLIDE_DOWN) && (pen_pos < start_pos)))
133         {
134             /* Sliding direction changed, detach the second animation target and
135                call tracking start again.  */
136             if (target_2)
137             {
138                 _gx_widget_detach(target_2);
139             }
140 
141             if (animation -> gx_animation_canvas)
142             {
143                 _gx_widget_shift(target_1,
144                                  animation -> gx_animation_canvas -> gx_canvas_display_offset_x,
145                                  animation -> gx_animation_canvas -> gx_canvas_display_offset_y, GX_TRUE);
146             }
147 
148             _gx_animation_drag_tracking_start(animation, penpos);
149 
150             if (animation -> gx_animation_slide_target_index_2 >= 0)
151             {
152                 target_2 = animation -> gx_animation_info.gx_animation_slide_screen_list[animation -> gx_animation_slide_target_index_2];
153             }
154             else
155             {
156                 target_2 = GX_NULL;
157             }
158 
159             if (animation -> gx_animation_info.gx_animation_style & GX_ANIMATION_VERTICAL)
160             {
161                 shift_y = (GX_VALUE)(start_pos - last_pos);
162                 delta_y = (GX_VALUE)(pen_pos - start_pos);
163             }
164             else
165             {
166                 shift_x = (GX_VALUE)(start_pos - last_pos);
167                 delta_x = (GX_VALUE)(pen_pos - start_pos);
168             }
169         }
170 
171         if (!target_2)
172         {
173             if (animation -> gx_animation_info.gx_animation_style & GX_ANIMATION_VERTICAL)
174             {
175                 animation -> gx_animation_slide_tracking_start_pos = (GX_VALUE)(animation -> gx_animation_slide_tracking_start_pos + ((delta_y + 1) >> 1));
176                 delta_y >>= 1;
177             }
178             else
179             {
180                 animation -> gx_animation_slide_tracking_start_pos = (GX_VALUE)(animation -> gx_animation_slide_tracking_start_pos + ((delta_x + 1) >> 1));
181                 delta_x >>= 1;
182             }
183         }
184 
185         if (animation -> gx_animation_canvas)
186         {
187             /* adjust canvas offset */
188             _gx_canvas_offset_set(animation -> gx_animation_canvas,
189                                   (GX_VALUE)(animation -> gx_animation_canvas -> gx_canvas_display_offset_x + shift_x + delta_x),
190                                   (GX_VALUE)(animation -> gx_animation_canvas -> gx_canvas_display_offset_y + shift_y + delta_y));
191         }
192         else
193         {
194             if (animation -> gx_animation_info.gx_animation_style & GX_ANIMATION_BLOCK_MOVE)
195             {
196                 if (target_2)
197                 {
198                     _gx_widget_scroll_shift(target_2, (GX_VALUE)(shift_x + delta_x), (GX_VALUE)(shift_y + delta_y), GX_TRUE);
199                 }
200 
201                 _gx_widget_scroll_shift(target_1, (GX_VALUE)(shift_x + delta_x), (GX_VALUE)(shift_y + delta_y), GX_TRUE);
202 
203                 parent = animation -> gx_animation_info.gx_animation_parent;
204                 _gx_widget_border_width_get(parent, &border_width);
205                 _gx_widget_client_get(parent, border_width, &block);
206                 _gx_widget_block_move(parent, &block, (GX_VALUE)(shift_x + delta_x), (GX_VALUE)(shift_y + delta_y));
207             }
208             else
209             {
210                 if (target_2)
211                 {
212                     _gx_widget_shift(target_2, (GX_VALUE)(shift_x + delta_x), (GX_VALUE)(shift_y + delta_y), GX_TRUE);
213                 }
214 
215                 _gx_widget_shift(target_1, (GX_VALUE)(shift_x + delta_x), (GX_VALUE)(shift_y + delta_y), GX_TRUE);
216             }
217         }
218 
219         animation -> gx_animation_slide_tracking_current_pos = pen_pos;
220     }
221 
222     /* Return completion status code. */
223     return(GX_SUCCESS);
224 }
225 
226