GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_canvas_arc_draw.c Lines: 43 43 100.0 %
Date: 2024-12-05 08:52:37 Branches: 32 32 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
/**   Display Management (Display)                                        */
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_utility.h"
29
#include "gx_display.h"
30
#include "gx_canvas.h"
31
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _gx_canvas_arc_draw                                 PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Kenneth Maxwell, Microsoft Corporation                              */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This draws a circle arc into the currrent context.                  */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    xcenter                               x-coord of center of circle   */
50
/*                                            arc                         */
51
/*    ycenter                               y-coord of center of circle   */
52
/*                                            arc                         */
53
/*    r                                     Radius of circle arc          */
54
/*    start_angle                           The start angle of circle arc */
55
/*    end_angle                             The end angle of circle arc   */
56
/*                                                                        */
57
/*  OUTPUT                                                                */
58
/*                                                                        */
59
/*    None                                                                */
60
/*                                                                        */
61
/*  CALLS                                                                 */
62
/*                                                                        */
63
/*    _gx_utility_rectangle_define                                        */
64
/*    _gx_utility_rectangle_overlap_detect                                */
65
/*    _gx_display_driver_arc_draw                                         */
66
/*    _gx_display_driver_anti_aliased_arc_draw                            */
67
/*                                                                        */
68
/*  CALLED BY                                                             */
69
/*                                                                        */
70
/*    Application code                                                    */
71
/*                                                                        */
72
/*  RELEASE HISTORY                                                       */
73
/*                                                                        */
74
/*    DATE              NAME                      DESCRIPTION             */
75
/*                                                                        */
76
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
77
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
78
/*                                            resulting in version 6.1    */
79
/*                                                                        */
80
/**************************************************************************/
81
#if defined(GX_ARC_DRAWING_SUPPORT)
82
7236
UINT _gx_canvas_arc_draw(INT xcenter, INT ycenter, UINT r, INT start_angle, INT end_angle)
83
{
84
GX_DRAW_CONTEXT *context;
85
GX_DISPLAY      *display;
86
GX_RECTANGLE     bound;
87
GX_RECTANGLE     clip_rect;
88
GX_VIEW         *view;
89
GX_BRUSH        *brush;
90
UINT             brush_width;
91
VOID             (*outline_function)(GX_DRAW_CONTEXT *context, INT xcenter, INT ycenter, UINT r, INT start_angle, INT end_angle);
92
93
10241
    while (start_angle < 0)
94
    {
95
3005
        start_angle += 360;
96
    }
97
98
7309
    while (end_angle < 0)
99
    {
100
73
        end_angle += 360;
101
    }
102
103
7236
    if (start_angle >= 360)
104
    {
105
138
        start_angle %= 360;
106
    }
107
108
7236
    if (end_angle >= 360)
109
    {
110
807
        end_angle %= 360;
111
    }
112
113
7236
    if (end_angle <= start_angle)
114
    {
115
3684
        end_angle += 360;
116
    }
117
118
119
    /* pick up the current drawing context */
120
7236
    context = _gx_system_current_draw_context;
121
122
7236
    brush = &context -> gx_draw_context_brush;
123
124
7236
    brush_width = (UINT)((brush -> gx_brush_width + 1) >> 1);
125
126
7236
    _gx_utility_rectangle_define(&bound, (GX_VALUE)((UINT)xcenter - r - brush_width), (GX_VALUE)((UINT)ycenter - r - brush_width),
127
7236
                                 (GX_VALUE)((UINT)xcenter + r + brush_width), (GX_VALUE)((UINT)ycenter + r + brush_width));
128
129
7236
    brush_width = (UINT)brush -> gx_brush_width;
130
131
    /* clip the arc bounding box to the dirty rectangle */
132
7236
    if (!_gx_utility_rectangle_overlap_detect(&bound, &context -> gx_draw_context_dirty, &bound))
133
    {
134
        /* nothing to draw, return */
135
5
        return GX_SUCCESS;
136
    }
137
138
    /* pick up current display driver */
139
7231
    display = context -> gx_draw_context_display;
140
141
    /* Default to no outline */
142
7231
    outline_function = GX_NULL;
143
144
    /* Determine which outline function to use.*/
145
7231
    if (brush_width == 1)
146
    {
147
        /* if anti-alias is requested and this is supported by display, use it */
148
295
        if ((brush -> gx_brush_style & GX_BRUSH_ALIAS) &&
149
190
            display -> gx_display_driver_anti_aliased_arc_draw != GX_NULL)
150
        {
151
126
            outline_function = display -> gx_display_driver_anti_aliased_arc_draw;
152
        }
153
        else
154
        {
155
            /* otherwise use non-aliased outline */
156
169
            outline_function = display -> gx_display_driver_arc_draw;
157
        }
158
    }
159
    else
160
    {
161
6936
        if (brush_width > 1)
162
        {
163
            /* if anti-alias is requested and this is supported by display, use it */
164
6807
            if ((brush -> gx_brush_style & GX_BRUSH_ALIAS) &&
165
6142
                display -> gx_display_driver_anti_aliased_wide_arc_draw)
166
            {
167
5770
                outline_function = display -> gx_display_driver_anti_aliased_wide_arc_draw;
168
            }
169
            else
170
            {
171
                /* otherwise use non-aliased outline */
172
1037
                outline_function = display -> gx_display_driver_wide_arc_draw;
173
            }
174
        }
175
    }
176
177
    /* test to determine if the bounding rectangle overlaps the region we are allowed to draw
178
       into. For each view that overlaps the bounding rectangle, do some drawing.
179
     */
180
7231
    view = context -> gx_draw_context_view_head;
181
182
14465
    while (view)
183
    {
184
7234
        if (!_gx_utility_rectangle_overlap_detect(&view -> gx_view_rectangle, &bound, &clip_rect))
185
        {
186
4
            view = view -> gx_view_next;
187
4
            continue;
188
        }
189
190
        /* we have a view into which we can draw the arc, do it */
191
7230
        context -> gx_draw_context_clip = &clip_rect;
192
193
7230
        if (brush -> gx_brush_style & (GX_BRUSH_SOLID_FILL | GX_BRUSH_PIXELMAP_FILL))
194
        {
195
919
            display -> gx_display_driver_arc_fill(context, xcenter, ycenter, r, start_angle, end_angle);
196
        }
197
198
7230
        if (outline_function)
199
        {
200
7101
            outline_function(context, xcenter, ycenter, r, start_angle, end_angle);
201
        }
202
7230
        view = view -> gx_view_next;
203
    }
204
205
    /* Return successful completion.  */
206
7231
    return(GX_SUCCESS);
207
}
208
209
#endif
210