1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** GUIX Component                                                        */
17 /**                                                                       */
18 /**   Sprite Management (Sprite)                                          */
19 /**                                                                       */
20 /**************************************************************************/
21 
22 #define GX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "gx_api.h"
28 #include "gx_system.h"
29 #include "gx_display.h"
30 #include "gx_context.h"
31 #include "gx_canvas.h"
32 #include "gx_widget.h"
33 #include "gx_sprite.h"
34 
35 
36 /**************************************************************************/
37 /*                                                                        */
38 /*  FUNCTION                                               RELEASE        */
39 /*                                                                        */
40 /*    _gx_sprite_draw                                     PORTABLE C      */
41 /*                                                           6.1.9        */
42 /*  AUTHOR                                                                */
43 /*                                                                        */
44 /*    Kenneth Maxwell, Microsoft Corporation                              */
45 /*                                                                        */
46 /*  DESCRIPTION                                                           */
47 /*                                                                        */
48 /*    This service draws a sprite widget.                                 */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    sprite                                Pointer to sprite widget      */
53 /*                                            control block               */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    None                                                                */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    _gx_context_pixelmap_get              Get the pixelmap in the       */
62 /*                                            current context             */
63 /*    _gx_canvas_pixelmap_blend             Blend pixelmap                */
64 /*    _gx_canvas_pixelmap_draw              Draw pixelmap                 */
65 /*    _gx_widget_children_draw              Draw the children of a widget */
66 /*                                                                        */
67 /*                                                                        */
68 /*  CALLED BY                                                             */
69 /*                                                                        */
70 /*    Application Code                                                    */
71 /*    GUIX Internal Code                                                  */
72 /*                                                                        */
73 /*  RELEASE HISTORY                                                       */
74 /*                                                                        */
75 /*    DATE              NAME                      DESCRIPTION             */
76 /*                                                                        */
77 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
78 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
79 /*                                            resulting in version 6.1    */
80 /*  10-15-2021     Ting Zhu                 Modified comment(s),          */
81 /*                                            supported alphamap draw,    */
82 /*                                            resulting in version 6.1.9  */
83 /*                                                                        */
84 /**************************************************************************/
_gx_sprite_draw(GX_SPRITE * sprite)85 VOID  _gx_sprite_draw(GX_SPRITE *sprite)
86 {
87 GX_SPRITE_FRAME *frame;
88 GX_PIXELMAP     *map;
89 GX_VALUE         xpos;
90 GX_VALUE         ypos;
91 
92     /* Draw sprite background.  */
93     _gx_widget_background_draw((GX_WIDGET *)sprite);
94 
95     if (sprite -> gx_sprite_frame_list)
96     {
97         if (sprite -> gx_sprite_current_frame < sprite -> gx_sprite_frame_count)
98         {
99             frame = &sprite -> gx_sprite_frame_list[sprite -> gx_sprite_current_frame];
100             if (frame -> gx_sprite_frame_pixelmap)
101             {
102                 _gx_widget_context_fill_set((GX_WIDGET *)sprite);
103 
104                 _gx_context_pixelmap_get(frame -> gx_sprite_frame_pixelmap, &map);
105                 if (map)
106                 {
107                     xpos = (GX_VALUE)(sprite -> gx_widget_size.gx_rectangle_left + frame -> gx_sprite_frame_x_offset);
108                     ypos = (GX_VALUE)(sprite -> gx_widget_size.gx_rectangle_top + frame -> gx_sprite_frame_y_offset);
109 
110                     if (frame -> gx_sprite_frame_alpha != GX_ALPHA_VALUE_OPAQUE)
111                     {
112                         _gx_canvas_pixelmap_blend(xpos, ypos, map, frame -> gx_sprite_frame_alpha);
113                     }
114                     else
115                     {
116                         _gx_canvas_pixelmap_draw(xpos, ypos, map);
117                     }
118                 }
119             }
120         }
121     }
122 
123     /* Draw children widgets of prompt widget.  */
124     _gx_widget_children_draw((GX_WIDGET *)sprite);
125 }
126 
127