GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_animation_start.c Lines: 46 46 100.0 %
Date: 2026-03-06 19:21:09 Branches: 24 24 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
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
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _gx_animation_start                                 PORTABLE C      */
39
/*                                                           6.1.3        */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Kenneth Maxwell, Microsoft Corporation                              */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This function starts an animation sequence.                         */
47
/*                                                                        */
48
/*                                                                        */
49
/*  INPUT                                                                 */
50
/*                                                                        */
51
/*    animation                             Pointer to animation control  */
52
/*                                            block                       */
53
/*    info                                  Animation information         */
54
/*                                                                        */
55
/*  OUTPUT                                                                */
56
/*                                                                        */
57
/*    status                                Completion status             */
58
/*                                                                        */
59
/*  CALLS                                                                 */
60
/*                                                                        */
61
/*    _gx_widget_detach                     Detach a widget from its      */
62
/*                                            parent                      */
63
/*    _gx_widget_shift                      Shift a widget                */
64
/*    _gx_canvas_offset_set                 Set the offset of canvas      */
65
/*    _gx_canvas_alpha_set                  Set the alpha of canvas       */
66
/*    _gx_widget_attach                     Attach a widget to its parent */
67
/*    _gx_widget_show                       Show a widget                 */
68
/*    tx_timer_info_get                     Get the information of        */
69
/*                                            ThreadX timer               */
70
/*    tx_timer_activate                     Start the ThreadX timer       */
71
/*                                                                        */
72
/*  CALLED BY                                                             */
73
/*                                                                        */
74
/*    Application Code                                                    */
75
/*                                                                        */
76
/**************************************************************************/
77
#if (GX_ANIMATION_POOL_SIZE > 0)
78
62
UINT _gx_animation_start(GX_ANIMATION *animation, GX_ANIMATION_INFO *info)
79
{
80
62
UINT            status = GX_SUCCESS;
81
GX_WINDOW_ROOT *root;
82
83
#ifdef GX_THREADX_BINDING
84
#ifndef GX_DISABLE_THREADX_TIMER_SOURCE
85
UINT     tx_timer_active;
86
#endif
87
#endif
88
GX_VALUE left;
89
GX_VALUE top;
90
91
62
    animation -> gx_animation_total_steps = info -> gx_animation_steps;
92
93
62
    if (animation -> gx_animation_canvas)
94
    {
95
        /* Make sure the widget is not attached to any parent */
96
7
        _gx_widget_detach(info -> gx_animation_target);
97
98
        /* position the target widget at 0,0 within the animation canvas */
99
7
        left = info -> gx_animation_target -> gx_widget_size.gx_rectangle_left;
100
7
        top = info -> gx_animation_target -> gx_widget_size.gx_rectangle_top;
101
102

7
        if (left || top)
103
        {
104
2
            _gx_widget_shift(info -> gx_animation_target, (GX_VALUE)-left, (GX_VALUE)-top, GX_FALSE);
105
        }
106
107
        /* position the canvas at the animation starting position */
108
7
        _gx_canvas_offset_set(animation -> gx_animation_canvas,
109
7
                              info -> gx_animation_start_position.gx_point_x,
110
7
                              info -> gx_animation_start_position.gx_point_y);
111
112
        /* link the target to the animation root window */
113
7
        root = _gx_system_root_window_created_list;
114

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

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