GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_sprite_start.c Lines: 18 18 100.0 %
Date: 2024-12-05 08:52:37 Branches: 10 10 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
/**   Sprite Management (Sprite)                                          */
18
/**                                                                       */
19
/**************************************************************************/
20
21
#define GX_SOURCE_CODE
22
23
24
/* Include necessary system files.  */
25
26
#include "gx_api.h"
27
#include "gx_system.h"
28
#include "gx_display.h"
29
#include "gx_context.h"
30
#include "gx_canvas.h"
31
#include "gx_widget.h"
32
#include "gx_sprite.h"
33
34
35
/**************************************************************************/
36
/*                                                                        */
37
/*  FUNCTION                                               RELEASE        */
38
/*                                                                        */
39
/*    _gx_sprite_start                                    PORTABLE C      */
40
/*                                                           6.1          */
41
/*  AUTHOR                                                                */
42
/*                                                                        */
43
/*    Kenneth Maxwell, Microsoft Corporation                              */
44
/*                                                                        */
45
/*  DESCRIPTION                                                           */
46
/*                                                                        */
47
/*    This service starts the sprite widget from a given frame number.    */
48
/*                                                                        */
49
/*  INPUT                                                                 */
50
/*                                                                        */
51
/*    sprite                                Pointer to sprite widget      */
52
/*                                           control block                */
53
/*    frame_number                          The frame number to start     */
54
/*                                            with                        */
55
/*                                                                        */
56
/*  OUTPUT                                                                */
57
/*                                                                        */
58
/*    status                                Completion status             */
59
/*                                                                        */
60
/*  CALLS                                                                 */
61
/*                                                                        */
62
/*    _gx_system_timer_stop                 Stop an active GUIX timer     */
63
/*    _gx_system_timer_start                Start a GUIX timer            */
64
/*    _gx_system_dirty_mark                 Mark the widget as dirty      */
65
/*                                                                        */
66
/*  CALLED BY                                                             */
67
/*                                                                        */
68
/*    Application Code                                                    */
69
/*                                                                        */
70
/*  RELEASE HISTORY                                                       */
71
/*                                                                        */
72
/*    DATE              NAME                      DESCRIPTION             */
73
/*                                                                        */
74
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
75
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
76
/*                                            resulting in version 6.1    */
77
/*                                                                        */
78
/**************************************************************************/
79
242
UINT  _gx_sprite_start(GX_SPRITE *sprite, USHORT frame_number)
80
{
81
242
GX_WIDGET       *widget = (GX_WIDGET *)sprite;
82
GX_SPRITE_FRAME *frame;
83
UINT             delayval;
84
85
242
    if (sprite -> gx_sprite_run_state == GX_SPRITE_RUNNING)
86
    {
87
154
        _gx_system_timer_stop(widget, GX_SPRITE_TIMER);
88
154
        sprite -> gx_sprite_run_state = GX_SPRITE_IDLE;
89
    }
90
91
242
    if (sprite -> gx_sprite_frame_list &&
92
241
        (widget -> gx_widget_status & GX_STATUS_VISIBLE))
93
    {
94
240
        if (frame_number < sprite -> gx_sprite_frame_count)
95
        {
96
239
            sprite -> gx_sprite_current_frame = frame_number;
97
98
239
            frame = &sprite -> gx_sprite_frame_list[sprite -> gx_sprite_current_frame];
99
239
            if (frame -> gx_sprite_frame_delay > 0)
100
            {
101
237
                delayval = frame -> gx_sprite_frame_delay;
102
            }
103
            else
104
            {
105
2
                delayval = 1;
106
            }
107
239
            _gx_system_timer_start(widget, GX_SPRITE_TIMER, delayval, 0);
108
239
            sprite -> gx_sprite_run_state = GX_SPRITE_RUNNING;
109
239
            _gx_system_dirty_mark(widget);
110
239
            return(GX_SUCCESS);
111
        }
112
    }
113
3
    return(GX_FAILURE);
114
}
115