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 /**************************************************************************/
_gx_sprite_start(GX_SPRITE * sprite,USHORT frame_number)79 UINT  _gx_sprite_start(GX_SPRITE *sprite, USHORT frame_number)
80 {
81 GX_WIDGET       *widget = (GX_WIDGET *)sprite;
82 GX_SPRITE_FRAME *frame;
83 UINT             delayval;
84 
85     if (sprite -> gx_sprite_run_state == GX_SPRITE_RUNNING)
86     {
87         _gx_system_timer_stop(widget, GX_SPRITE_TIMER);
88         sprite -> gx_sprite_run_state = GX_SPRITE_IDLE;
89     }
90 
91     if (sprite -> gx_sprite_frame_list &&
92         (widget -> gx_widget_status & GX_STATUS_VISIBLE))
93     {
94         if (frame_number < sprite -> gx_sprite_frame_count)
95         {
96             sprite -> gx_sprite_current_frame = frame_number;
97 
98             frame = &sprite -> gx_sprite_frame_list[sprite -> gx_sprite_current_frame];
99             if (frame -> gx_sprite_frame_delay > 0)
100             {
101                 delayval = frame -> gx_sprite_frame_delay;
102             }
103             else
104             {
105                 delayval = 1;
106             }
107             _gx_system_timer_start(widget, GX_SPRITE_TIMER, delayval, 0);
108             sprite -> gx_sprite_run_state = GX_SPRITE_RUNNING;
109             _gx_system_dirty_mark(widget);
110             return(GX_SUCCESS);
111         }
112     }
113     return(GX_FAILURE);
114 }
115 
116