GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_canvas_ellipse_draw.c Lines: 36 36 100.0 %
Date: 2026-03-06 19:21:09 Branches: 24 24 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
10
 **************************************************************************/
11
12
13
/**************************************************************************/
14
/**************************************************************************/
15
/**                                                                       */
16
/** GUIX Component                                                        */
17
/**                                                                       */
18
/**   Display Management (Display)                                        */
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_utility.h"
30
#include "gx_display.h"
31
#include "gx_canvas.h"
32
33
34
/**************************************************************************/
35
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _gx_canvas_ellipse_draw                             PORTABLE C      */
39
/*                                                           6.1          */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Kenneth Maxwell, Microsoft Corporation                              */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This draws a ellipse into the currrent context.                     */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    xcenter                               x-coord of center of ellipse  */
51
/*    ycenter                               y-coord of center of ellipse  */
52
/*    r                                     Radius of circle              */
53
/*    a                                     Length of the Semi-major Axis */
54
/*    b                                     Length of the Semi-minor Axis */
55
/*                                                                        */
56
/*  OUTPUT                                                                */
57
/*                                                                        */
58
/*    None                                                                */
59
/*                                                                        */
60
/*  CALLS                                                                 */
61
/*                                                                        */
62
/*    _gx_utility_rectangle_define                                        */
63
/*    _gx_utility_rectangle_overlap_detect                                */
64
/*    [gx_display_driver_generic_ellipse_draw]                            */
65
/*                                                                        */
66
/*  CALLED BY                                                             */
67
/*                                                                        */
68
/*    Application code                                                    */
69
/*                                                                        */
70
/**************************************************************************/
71
#if defined(GX_ARC_DRAWING_SUPPORT)
72
2814
UINT _gx_canvas_ellipse_draw(INT xcenter, INT ycenter, INT a, INT b)
73
{
74
GX_DRAW_CONTEXT *context;
75
GX_DISPLAY      *display;
76
GX_RECTANGLE     bound;
77
GX_RECTANGLE     clip_rect;
78
GX_VIEW         *view;
79
GX_BRUSH        *brush;
80
INT              brush_width;
81
VOID             (*outline_function)(GX_DRAW_CONTEXT *context, INT xcenter, INT ycenter, INT a, INT b);
82
83
    /* pick up the current drawing context */
84
2814
    context = _gx_system_current_draw_context;
85
86
2814
    brush = &context -> gx_draw_context_brush;
87
88
2814
    brush_width = (brush -> gx_brush_width + 1) >> 1;
89
90
    /* Define ellipse bounding rectangle. */
91
2814
    _gx_utility_rectangle_define(&bound, (GX_VALUE)(xcenter - a - brush_width), (GX_VALUE)(ycenter - b - brush_width),
92
2814
                                 (GX_VALUE)(xcenter + a + brush_width), (GX_VALUE)(ycenter + b + brush_width));
93
94
2814
    brush_width = brush -> gx_brush_width;
95
96
    /* clip the ellipse bounding box to the dirty rectangle */
97
2814
    if (!_gx_utility_rectangle_overlap_detect(&bound, &context -> gx_draw_context_dirty, &bound))
98
    {
99
        /* nothing to draw, return */
100
3
        return GX_SUCCESS;
101
    }
102
103
    /* pick up current display driver */
104
2811
    display = context -> gx_draw_context_display;
105
106
    /* configure outline function to utilize */
107
2811
    outline_function = GX_NULL;
108
109
    /* Determine which outline function to use.*/
110
2811
    if(brush_width == 1)
111
    {
112
        /* if anti-alias is requested and this is supported by display, use it */
113
827
        if ((brush -> gx_brush_style & GX_BRUSH_ALIAS) &&
114
425
            display -> gx_display_driver_anti_aliased_ellipse_draw != GX_NULL)
115
        {
116
395
            outline_function = display -> gx_display_driver_anti_aliased_ellipse_draw;
117
        }
118
        else
119
        {
120
432
            outline_function = display -> gx_display_driver_ellipse_draw;
121
        }
122
    }
123
    else
124
    {
125
1984
        if (brush_width > 1)
126
        {
127
            /* if anti-alias is requested and this is supported by display, use it */
128
1709
            if ((brush -> gx_brush_style & GX_BRUSH_ALIAS) &&
129
1207
                display -> gx_display_driver_anti_aliased_wide_ellipse_draw != GX_NULL)
130
            {
131
931
                outline_function = display -> gx_display_driver_anti_aliased_wide_ellipse_draw;
132
            }
133
            else
134
            {
135
778
                outline_function = display -> gx_display_driver_wide_ellipse_draw;
136
            }
137
        }
138
    }
139
140
    /* test to determine if the bounding rectangle overlaps the region we are allowed to draw
141
       into. For each view that overlaps the bounding rectangle, do some drawing.
142
     */
143
2811
    view = context -> gx_draw_context_view_head;
144
145
5631
    while (view)
146
    {
147
2820
        if (!_gx_utility_rectangle_overlap_detect(&view -> gx_view_rectangle, &bound, &clip_rect))
148
        {
149
12
            view = view -> gx_view_next;
150
12
            continue;
151
        }
152
153
        /* we have a view into which we can draw the line, do it */
154
2808
        GX_RECTANGLE *original_clip = context->gx_draw_context_clip;
155
2808
        context -> gx_draw_context_clip = &clip_rect;
156
157
2808
        if ((brush -> gx_brush_style & (GX_BRUSH_SOLID_FILL | GX_BRUSH_PIXELMAP_FILL)) &&
158
2406
            display -> gx_display_driver_ellipse_fill)
159
        {
160
            /* Call display driver ellipse filling routine.  */
161
2405
            display -> gx_display_driver_ellipse_fill(context, xcenter, ycenter, a, b);
162
        }
163
164
2808
        if (outline_function)
165
        {
166
2533
            outline_function(context, xcenter, ycenter, a, b);
167
        }
168
169
2808
        view = view -> gx_view_next;
170
2808
        context -> gx_draw_context_clip = original_clip;
171
    }
172
173
    /* Return successful completion.  */
174
2811
    return(GX_SUCCESS);
175
}
176
#endif
177