GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_canvas_ellipse_draw.c Lines: 34 34 100.0 %
Date: 2024-12-05 08:52:37 Branches: 24 24 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_ellipse_draw                             PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Kenneth Maxwell, Microsoft Corporation                              */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This draws a ellipse into the currrent context.                     */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    xcenter                               x-coord of center of ellipse  */
50
/*    ycenter                               y-coord of center of ellipse  */
51
/*    r                                     Radius of circle              */
52
/*    a                                     Length of the Semi-major Axis */
53
/*    b                                     Length of the Semi-minor Axis */
54
/*                                                                        */
55
/*  OUTPUT                                                                */
56
/*                                                                        */
57
/*    None                                                                */
58
/*                                                                        */
59
/*  CALLS                                                                 */
60
/*                                                                        */
61
/*    _gx_utility_rectangle_define                                        */
62
/*    _gx_utility_rectangle_overlap_detect                                */
63
/*    [gx_display_driver_generic_ellipse_draw]                            */
64
/*                                                                        */
65
/*  CALLED BY                                                             */
66
/*                                                                        */
67
/*    Application 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
/**************************************************************************/
78
#if defined(GX_ARC_DRAWING_SUPPORT)
79
2814
UINT _gx_canvas_ellipse_draw(INT xcenter, INT ycenter, INT a, INT b)
80
{
81
GX_DRAW_CONTEXT *context;
82
GX_DISPLAY      *display;
83
GX_RECTANGLE     bound;
84
GX_RECTANGLE     clip_rect;
85
GX_VIEW         *view;
86
GX_BRUSH        *brush;
87
INT              brush_width;
88
VOID             (*outline_function)(GX_DRAW_CONTEXT *context, INT xcenter, INT ycenter, INT a, INT b);
89
90
    /* pick up the current drawing context */
91
2814
    context = _gx_system_current_draw_context;
92
93
2814
    brush = &context -> gx_draw_context_brush;
94
95
2814
    brush_width = (brush -> gx_brush_width + 1) >> 1;
96
97
    /* Define ellipse bounding rectangle. */
98
2814
    _gx_utility_rectangle_define(&bound, (GX_VALUE)(xcenter - a - brush_width), (GX_VALUE)(ycenter - b - brush_width),
99
2814
                                 (GX_VALUE)(xcenter + a + brush_width), (GX_VALUE)(ycenter + b + brush_width));
100
101
2814
    brush_width = brush -> gx_brush_width;
102
103
    /* clip the ellipse bounding box to the dirty rectangle */
104
2814
    if (!_gx_utility_rectangle_overlap_detect(&bound, &context -> gx_draw_context_dirty, &bound))
105
    {
106
        /* nothing to draw, return */
107
3
        return GX_SUCCESS;
108
    }
109
110
    /* pick up current display driver */
111
2811
    display = context -> gx_draw_context_display;
112
113
    /* configure outline function to utilize */
114
2811
    outline_function = GX_NULL;
115
116
    /* Determine which outline function to use.*/
117
2811
    if(brush_width == 1)
118
    {
119
        /* if anti-alias is requested and this is supported by display, use it */
120
827
        if ((brush -> gx_brush_style & GX_BRUSH_ALIAS) &&
121
425
            display -> gx_display_driver_anti_aliased_ellipse_draw != GX_NULL)
122
        {
123
395
            outline_function = display -> gx_display_driver_anti_aliased_ellipse_draw;
124
        }
125
        else
126
        {
127
432
            outline_function = display -> gx_display_driver_ellipse_draw;
128
        }
129
    }
130
    else
131
    {
132
1984
        if (brush_width > 1)
133
        {
134
            /* if anti-alias is requested and this is supported by display, use it */
135
1709
            if ((brush -> gx_brush_style & GX_BRUSH_ALIAS) &&
136
1207
                display -> gx_display_driver_anti_aliased_wide_ellipse_draw != GX_NULL)
137
            {
138
931
                outline_function = display -> gx_display_driver_anti_aliased_wide_ellipse_draw;
139
            }
140
            else
141
            {
142
778
                outline_function = display -> gx_display_driver_wide_ellipse_draw;
143
            }
144
        }
145
    }
146
147
    /* test to determine if the bounding rectangle overlaps the region we are allowed to draw
148
       into. For each view that overlaps the bounding rectangle, do some drawing.
149
     */
150
2811
    view = context -> gx_draw_context_view_head;
151
152
5631
    while (view)
153
    {
154
2820
        if (!_gx_utility_rectangle_overlap_detect(&view -> gx_view_rectangle, &bound, &clip_rect))
155
        {
156
12
            view = view -> gx_view_next;
157
12
            continue;
158
        }
159
160
        /* we have a view into which we can draw the line, do it */
161
2808
        context -> gx_draw_context_clip = &clip_rect;
162
163
2808
        if ((brush -> gx_brush_style & (GX_BRUSH_SOLID_FILL | GX_BRUSH_PIXELMAP_FILL)) &&
164
2406
            display -> gx_display_driver_ellipse_fill)
165
        {
166
            /* Call display driver ellipse filling routine.  */
167
2405
            display -> gx_display_driver_ellipse_fill(context, xcenter, ycenter, a, b);
168
        }
169
170
2808
        if (outline_function)
171
        {
172
2533
            outline_function(context, xcenter, ycenter, a, b);
173
        }
174
175
2808
        view = view -> gx_view_next;
176
    }
177
178
    /* Return successful completion.  */
179
2811
    return(GX_SUCCESS);
180
}
181
#endif
182