GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_animation_start.c Lines: 46 46 100.0 %
Date: 2024-12-05 08:52:37 Branches: 24 24 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 *
4
 * This program and the accompanying materials are made available under the
5
 * terms of the MIT License which is available at
6
 * https://opensource.org/licenses/MIT.
7
 *
8
 * SPDX-License-Identifier: MIT
9
 **************************************************************************/
10
11
12
/**************************************************************************/
13
/**************************************************************************/
14
/**                                                                       */
15
/** GUIX Component                                                        */
16
/**                                                                       */
17
/**   Animation Management (Animation)                                    */
18
/**                                                                       */
19
/**************************************************************************/
20
21
#define GX_SOURCE_CODE
22
23
24
/* Include necessary system files.  */
25
26
#include "gx_api.h"
27
#include "gx_widget.h"
28
#include "gx_system.h"
29
#include "gx_canvas.h"
30
#include "gx_animation.h"
31
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _gx_animation_start                                 PORTABLE C      */
38
/*                                                           6.1.3        */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Kenneth Maxwell, Microsoft Corporation                              */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function starts an animation sequence.                         */
46
/*                                                                        */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    animation                             Pointer to animation control  */
51
/*                                            block                       */
52
/*    info                                  Animation information         */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    status                                Completion status             */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    _gx_widget_detach                     Detach a widget from its      */
61
/*                                            parent                      */
62
/*    _gx_widget_shift                      Shift a widget                */
63
/*    _gx_canvas_offset_set                 Set the offset of canvas      */
64
/*    _gx_canvas_alpha_set                  Set the alpha of canvas       */
65
/*    _gx_widget_attach                     Attach a widget to its parent */
66
/*    _gx_widget_show                       Show a widget                 */
67
/*    tx_timer_info_get                     Get the information of        */
68
/*                                            ThreadX timer               */
69
/*    tx_timer_activate                     Start the ThreadX timer       */
70
/*                                                                        */
71
/*  CALLED BY                                                             */
72
/*                                                                        */
73
/*    Application Code                                                    */
74
/*                                                                        */
75
/*  RELEASE HISTORY                                                       */
76
/*                                                                        */
77
/*    DATE              NAME                      DESCRIPTION             */
78
/*                                                                        */
79
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
80
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
81
/*                                            resulting in version 6.1    */
82
/*  12-31-2020     Kenneth Maxwell          Modified comment(s),          */
83
/*                                            added GX_DISABLE_THREADX_   */
84
/*                                            TIMER_SOURCE configuration, */
85
/*                                            resulting in version 6.1.3  */
86
/*                                                                        */
87
/**************************************************************************/
88
62
UINT _gx_animation_start(GX_ANIMATION *animation, GX_ANIMATION_INFO *info)
89
{
90
62
UINT            status = GX_SUCCESS;
91
GX_WINDOW_ROOT *root;
92
93
#ifdef GX_THREADX_BINDING
94
#ifndef GX_DISABLE_THREADX_TIMER_SOURCE
95
UINT     tx_timer_active;
96
#endif
97
#endif
98
GX_VALUE left;
99
GX_VALUE top;
100
101
62
    animation -> gx_animation_total_steps = info -> gx_animation_steps;
102
103
62
    if (animation -> gx_animation_canvas)
104
    {
105
        /* Make sure the widget is not attached to any parent */
106
7
        _gx_widget_detach(info -> gx_animation_target);
107
108
        /* position the target widget at 0,0 within the animation canvas */
109
7
        left = info -> gx_animation_target -> gx_widget_size.gx_rectangle_left;
110
7
        top = info -> gx_animation_target -> gx_widget_size.gx_rectangle_top;
111
112

7
        if (left || top)
113
        {
114
2
            _gx_widget_shift(info -> gx_animation_target, (GX_VALUE)-left, (GX_VALUE)-top, GX_FALSE);
115
        }
116
117
        /* position the canvas at the animation starting position */
118
7
        _gx_canvas_offset_set(animation -> gx_animation_canvas,
119
7
                              info -> gx_animation_start_position.gx_point_x,
120
7
                              info -> gx_animation_start_position.gx_point_y);
121
122
        /* link the target to the animation root window */
123
7
        root = _gx_system_root_window_created_list;
124

9
        while (root && root -> gx_window_root_canvas != animation -> gx_animation_canvas)
125
        {
126
2
            root = (GX_WINDOW_ROOT *)root -> gx_widget_next;
127
        }
128
7
        if (root)
129
        {
130
6
            _gx_widget_attach((GX_WIDGET *)root, info -> gx_animation_target);
131
132
            /* and show the animation root window to make everything visible */
133
6
            _gx_widget_show((GX_WIDGET *)root);
134
6
            _gx_canvas_drawing_initiate(animation -> gx_animation_canvas, (GX_WIDGET *) root, &root -> gx_widget_size);
135
6
            _gx_widget_children_draw((GX_WIDGET *)root);
136
6
            _gx_canvas_drawing_complete(animation -> gx_animation_canvas, GX_FALSE);
137
138
            /* set the initial alpha and make our canvas visible */
139
6
            _gx_canvas_alpha_set(animation -> gx_animation_canvas, info -> gx_animation_start_alpha);
140
6
            _gx_canvas_show(animation -> gx_animation_canvas);
141
        }
142
        else
143
        {
144
1
            status = GX_FAILURE;
145
        }
146
    }
147
    else
148
    {
149
55
        if (info -> gx_animation_start_alpha != info -> gx_animation_end_alpha)
150
        {
151
#ifdef GX_BRUSH_ALPHA_SUPPORT
152
16
            info -> gx_animation_target -> gx_widget_style |= GX_STYLE_USE_LOCAL_ALPHA;
153
16
            info -> gx_animation_target -> gx_widget_alpha = info -> gx_animation_start_alpha;
154
#else
155
            status = GX_INVALID_VALUE;
156
#endif
157
        }
158
159
        /* position the target at the starting position */
160
55
        left = (GX_VALUE)(info -> gx_animation_start_position.gx_point_x -
161
55
                          info -> gx_animation_target -> gx_widget_size.gx_rectangle_left);
162
55
        top =  (GX_VALUE)(info -> gx_animation_start_position.gx_point_y -
163
55
                          info -> gx_animation_target -> gx_widget_size.gx_rectangle_top);
164
165

55
        if (left || top)
166
        {
167
44
            _gx_widget_shift(info -> gx_animation_target,
168
                             left, top, GX_TRUE);
169
        }
170
171
        /* link the target to the animation root window */
172
55
        _gx_widget_attach(info -> gx_animation_parent, info -> gx_animation_target);
173
    }
174
175
    /* If we were able to start this animation, link it into the active list */
176
62
    if (status == GX_SUCCESS)
177
    {
178
        /* save the animation parameters */
179
61
        animation -> gx_animation_info = *info;
180
61
        if (info -> gx_animation_start_delay)
181
        {
182
2
            animation -> gx_animation_timer = info -> gx_animation_start_delay;
183
        }
184
        else
185
        {
186
59
            animation -> gx_animation_timer = animation -> gx_animation_info.gx_animation_frame_interval;
187
        }
188
61
        animation -> gx_animation_status = GX_ANIMATION_ACTIVE;
189
61
        animation -> gx_animation_next = _gx_system_animation_list;
190
61
        _gx_system_animation_list = animation;
191
192
#ifdef GX_THREADX_BINDING
193
#ifndef GX_DISABLE_THREADX_TIMER_SOURCE
194
        /* if the low-level timer is not active, start it */
195
61
        tx_timer_info_get(&_gx_system_timer, (CHAR **)TX_NULL, &tx_timer_active,
196
                          (ULONG *)TX_NULL, (ULONG *)TX_NULL, (TX_TIMER **)TX_NULL);
197
198
61
        if (!tx_timer_active)
199
        {
200
47
            tx_timer_activate(&_gx_system_timer);
201
        }
202
#endif
203
#else
204
        GX_TIMER_START;
205
#endif
206
    }
207
208
62
    return(status);
209
}
210