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 /**   Pixelmap Prompt Management (Prompt)                                 */
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_canvas.h"
29 #include "gx_context.h"
30 #include "gx_widget.h"
31 #include "gx_prompt.h"
32 #include "gx_pixelmap_prompt.h"
33 
34 
35 /**************************************************************************/
36 /*                                                                        */
37 /*  FUNCTION                                               RELEASE        */
38 /*                                                                        */
39 /*    _gx_pixelmap_prompt_background_draw                 PORTABLE C      */
40 /*                                                           6.1          */
41 /*  AUTHOR                                                                */
42 /*                                                                        */
43 /*    Kenneth Maxwell, Microsoft Corporation                              */
44 /*                                                                        */
45 /*  DESCRIPTION                                                           */
46 /*                                                                        */
47 /*    This function draws the background of a pixelmap prompt widget.     */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    prompt                                Pixelmap prompt control block */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    None                                                                */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _gx_widget_background_draw            Draw the widget's background  */
60 /*    _gx_context_pixelmap_get              Retrieve pixelmap image       */
61 /*    _gx_canvas_pixelmap_draw              Draw a pixelmap               */
62 /*    _gx_canvas_pixelmap_tile              Tile a pixelmap               */
63 /*                                                                        */
64 /*  CALLED BY                                                             */
65 /*                                                                        */
66 /*    Application Code                                                    */
67 /*    GUIX Internal Code                                                  */
68 /*                                                                        */
69 /*  RELEASE HISTORY                                                       */
70 /*                                                                        */
71 /*    DATE              NAME                      DESCRIPTION             */
72 /*                                                                        */
73 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
74 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
75 /*                                            resulting in version 6.1    */
76 /*                                                                        */
77 /**************************************************************************/
_gx_pixelmap_prompt_background_draw(GX_PIXELMAP_PROMPT * prompt)78 VOID  _gx_pixelmap_prompt_background_draw(GX_PIXELMAP_PROMPT *prompt)
79 {
80 GX_WIDGET     *widget = (GX_WIDGET *)prompt;
81 GX_RECTANGLE   fill_rect = widget -> gx_widget_size;
82 GX_PIXELMAP   *map;
83 GX_RESOURCE_ID fill_id;
84 GX_RESOURCE_ID left_id;
85 GX_RESOURCE_ID right_id;
86 
87 
88     fill_id = prompt -> gx_normal_fill_pixelmap_id;
89     left_id = prompt -> gx_normal_left_pixelmap_id;
90     right_id = prompt -> gx_normal_right_pixelmap_id;
91 
92     if (prompt -> gx_widget_style & GX_STYLE_DRAW_SELECTED)
93     {
94         if (prompt -> gx_selected_fill_pixelmap_id)
95         {
96             fill_id = prompt -> gx_selected_fill_pixelmap_id;
97         }
98         if (prompt -> gx_selected_left_pixelmap_id)
99         {
100             left_id = prompt -> gx_selected_left_pixelmap_id;
101         }
102         if (prompt -> gx_selected_right_pixelmap_id)
103         {
104             right_id = prompt -> gx_selected_right_pixelmap_id;
105         }
106     }
107 
108 
109     /* draw the background */
110     if (fill_id == 0 &&
111         !(prompt -> gx_widget_style & GX_STYLE_TRANSPARENT))
112     {
113         _gx_widget_background_draw(widget);
114     }
115 
116     /* draw the left-end pixelmap if one was provided */
117     if (left_id)
118     {
119         _gx_context_pixelmap_get(left_id, &map);
120         if (map)
121         {
122             _gx_widget_context_fill_set(widget);
123             _gx_canvas_pixelmap_draw(fill_rect.gx_rectangle_left,
124                                      fill_rect.gx_rectangle_top, map);
125             fill_rect.gx_rectangle_left = (GX_VALUE)(fill_rect.gx_rectangle_left + map -> gx_pixelmap_width);
126         }
127     }
128 
129     /* draw the right end pixelmap, if one was provided */
130     if (right_id)
131     {
132         _gx_context_pixelmap_get(right_id, &map);
133         if (map)
134         {
135             _gx_widget_context_fill_set(widget);
136             _gx_canvas_pixelmap_draw((GX_VALUE)(fill_rect.gx_rectangle_right - map -> gx_pixelmap_width + 1),
137                                      fill_rect.gx_rectangle_top, map);
138             fill_rect.gx_rectangle_right = (GX_VALUE)(fill_rect.gx_rectangle_right - map -> gx_pixelmap_width);
139         }
140     }
141 
142     /* now fill the remaining area with the fill pixelmap */
143     if (fill_id)
144     {
145         _gx_context_pixelmap_get(fill_id, &map);
146         if (map)
147         {
148             _gx_canvas_pixelmap_tile(&fill_rect, map);
149         }
150     }
151 }
152 
153