GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_window_border_draw.c Lines: 29 29 100.0 %
Date: 2024-12-05 08:52:37 Branches: 18 18 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
/**   Window Management (Window)                                          */
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_utility.h"
32
#include "gx_window.h"
33
34
/**************************************************************************/
35
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _gx_window_border_draw                              PORTABLE C      */
39
/*                                                           6.1          */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Kenneth Maxwell, Microsoft Corporation                              */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This function draws the background of a window widget width         */
47
/*    specified fill color.                                               */
48
/*                                                                        */
49
/*  INPUT                                                                 */
50
/*                                                                        */
51
/*    win                                   Window control block          */
52
/*    fill_color                            Specified fill color ID       */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    status                                Completion status             */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    _gx_context_pixelmap_get              Get pixelmap with specified   */
61
/*                                            resource ID                 */
62
/*    _gx_widget_border_width_get           Get the border width          */
63
/*    _gx_widget_client_get                 Get the widget client         */
64
/*    _gx_widget_border_draw                Draw widget background        */
65
/*    _gx_canvas_pixelmap_tile              Draw pixelmap in tile style   */
66
/*    _gx_canvas_pixelmap_draw              Draw the pixelmap             */
67
/*    _gx_utility_rectangle_overlap_detect  Detect rectangle overlap      */
68
/*                                                                        */
69
/*  CALLED BY                                                             */
70
/*                                                                        */
71
/*    Application Code                                                    */
72
/*    GUIX Internal Code                                                  */
73
/*                                                                        */
74
/*  RELEASE HISTORY                                                       */
75
/*                                                                        */
76
/*    DATE              NAME                      DESCRIPTION             */
77
/*                                                                        */
78
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
79
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
80
/*                                            resulting in version 6.1    */
81
/*                                                                        */
82
/**************************************************************************/
83
492262
VOID  _gx_window_border_draw(GX_WINDOW *win, GX_RESOURCE_ID fill_color)
84
{
85
492262
GX_WIDGET       *widget = (GX_WIDGET *)win;
86
492262
GX_PIXELMAP     *pixelmap = GX_NULL;
87
492262
GX_BOOL          fill = GX_TRUE;
88
GX_DRAW_CONTEXT *context;
89
GX_VALUE         width;
90
GX_VALUE         height;
91
GX_RECTANGLE     client;
92
GX_RECTANGLE     old_clip;
93
GX_VALUE         border_width;
94
95
    /* test to see if we need to solid fill */
96
97
492262
    if (win -> gx_window_wallpaper != 0)
98
    {
99
96407
        _gx_context_pixelmap_get(win -> gx_window_wallpaper, &pixelmap);
100
101
        /* do we have a wallpaper ? */
102
96407
        if (pixelmap)
103
        {
104
96400
            _gx_widget_border_width_get(widget, &border_width);
105
106
            /* get size of client rectangle */
107
96400
            _gx_widget_client_get(widget, border_width, &client);
108
109
            /* is the wallpaper transparent at all ? */
110
96400
            if ((pixelmap -> gx_pixelmap_flags & (GX_PIXELMAP_TRANSPARENT | GX_PIXELMAP_ALPHA)) == 0)
111
            {
112
                /* will the wallpaper fill my client area ? */
113
51594
                if (widget -> gx_widget_style & GX_STYLE_TILE_WALLPAPER)
114
                {
115
                    /* yes, don't need to fill */
116
1737
                    fill = GX_FALSE;
117
                }
118
                else
119
                {
120
49857
                    width = (GX_VALUE)(client.gx_rectangle_right - client.gx_rectangle_left + 1);
121
49857
                    height = (GX_VALUE)(client.gx_rectangle_bottom - client.gx_rectangle_top + 1);
122
123
49857
                    if (pixelmap -> gx_pixelmap_width >= width &&
124
47995
                        pixelmap -> gx_pixelmap_height >= height)
125
                    {
126
                        /* yes, don't need to solid fill */
127
47991
                        fill = GX_FALSE;
128
                    }
129
                }
130
            }
131
        }
132
    }
133
134
492262
    _gx_widget_border_draw(widget, GX_COLOR_ID_WINDOW_BORDER, fill_color, fill_color, fill);
135
136
492262
    if (pixelmap)
137
    {
138
96400
        _gx_widget_context_fill_set(widget);
139
96400
        if (widget -> gx_widget_style & GX_STYLE_TILE_WALLPAPER)
140
        {
141
            /* tile the pixelmap into the window client area */
142
1967
            _gx_canvas_pixelmap_tile(&client, pixelmap);
143
        }
144
        else
145
        {
146
            /* temporarily set context clipping to my client area */
147
94433
            context = _gx_system_current_draw_context;
148
94433
            old_clip = context -> gx_draw_context_dirty;
149
94433
            fill = _gx_utility_rectangle_overlap_detect(&client, &old_clip, &context -> gx_draw_context_dirty);
150
151
94433
            if (fill)
152
            {
153
                /* draw the pixelmap */
154
94374
                _gx_canvas_pixelmap_draw(client.gx_rectangle_left, client.gx_rectangle_top, pixelmap);
155
94374
                context -> gx_draw_context_dirty = old_clip;
156
            }
157
        }
158
    }
159
492262
}
160