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_update PORTABLE C */ 40 /* 6.1.10 */ 41 /* AUTHOR */ 42 /* */ 43 /* Kenneth Maxwell, Microsoft Corporation */ 44 /* */ 45 /* DESCRIPTION */ 46 /* */ 47 /* This service draws a sprite widget. */ 48 /* */ 49 /* INPUT */ 50 /* */ 51 /* sprite Pointer to the control block */ 52 /* of the sprite widget */ 53 /* */ 54 /* OUTPUT */ 55 /* */ 56 /* None */ 57 /* */ 58 /* CALLS */ 59 /* */ 60 /* _gx_widget_event_generate Generate an event */ 61 /* _gx_system_timer_start Allocate a free timer and */ 62 /* activate it */ 63 /* _gx_system_dirty_mark Mark widget as dirty */ 64 /* */ 65 /* CALLED BY */ 66 /* */ 67 /* _gx_sprite_event_process Event process routine for */ 68 /* the sprite widget */ 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 /* 01-31-2022 Kenneth Maxwell Modified comment(s), */ 78 /* fix logic for restarting */ 79 /* sprite timer, */ 80 /* resulting in version 6.1.10 */ 81 /* */ 82 /**************************************************************************/ _gx_sprite_update(GX_SPRITE * sprite)83VOID _gx_sprite_update(GX_SPRITE *sprite) 84 { 85 GX_WIDGET *widget = (GX_WIDGET *)sprite; 86 GX_SPRITE_FRAME *frame; 87 UINT delayval; 88 89 if (sprite->gx_sprite_run_state == GX_SPRITE_RUNNING) 90 { 91 if (sprite -> gx_sprite_frame_list) 92 { 93 if (sprite -> gx_sprite_current_frame + 1 >= sprite -> gx_sprite_frame_count) 94 { 95 if (sprite -> gx_widget_style & GX_STYLE_SPRITE_LOOP) 96 { 97 sprite -> gx_sprite_current_frame = 0; 98 } 99 else 100 { 101 sprite -> gx_sprite_run_state = GX_SPRITE_IDLE; 102 _gx_widget_event_generate(widget, GX_EVENT_SPRITE_COMPLETE, 0); 103 return; 104 } 105 } 106 else 107 { 108 sprite -> gx_sprite_current_frame++; 109 } 110 111 frame = &sprite -> gx_sprite_frame_list[sprite -> gx_sprite_current_frame]; 112 if (frame -> gx_sprite_frame_delay > 0) 113 { 114 delayval = frame -> gx_sprite_frame_delay; 115 } 116 else 117 { 118 delayval = 1; 119 } 120 _gx_system_timer_start(widget, GX_SPRITE_TIMER, delayval, 0); 121 _gx_system_dirty_mark(widget); 122 } 123 else 124 { 125 sprite -> gx_sprite_run_state = GX_SPRITE_IDLE; 126 } 127 } 128 } 129 130