GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_slider_needle_draw.c Lines: 50 50 100.0 %
Date: 2024-12-05 08:52:37 Branches: 6 6 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
/**   Slider Management (Slider)                                          */
18
/**                                                                       */
19
/**************************************************************************/
20
21
#define GX_SOURCE_CODE
22
23
/* Include necessary system files.  */
24
25
#include "gx_api.h"
26
#include "gx_system.h"
27
#include "gx_canvas.h"
28
#include "gx_context.h"
29
#include "gx_widget.h"
30
#include "gx_utility.h"
31
#include "gx_slider.h"
32
33
34
35
/**************************************************************************/
36
/*                                                                        */
37
/*  FUNCTION                                               RELEASE        */
38
/*                                                                        */
39
/*    _gx_slider_needle_draw                              PORTABLE C      */
40
/*                                                           6.1          */
41
/*  AUTHOR                                                                */
42
/*                                                                        */
43
/*    Kenneth Maxwell, Microsoft Corporation                              */
44
/*                                                                        */
45
/*  DESCRIPTION                                                           */
46
/*                                                                        */
47
/*    This service draws a slider needle.                                 */
48
/*                                                                        */
49
/*  INPUT                                                                 */
50
/*                                                                        */
51
/*    slider                                Slider widget control block   */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    None                                                                */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*    _gx_slider_needle_position_get        Get the position of the       */
60
/*                                            slider needle               */
61
/*    _gx_context_line_color_set            Set the line color for the    */
62
/*                                            context                     */
63
/*    _gx_context_brush_width_set           Set the brush width of the    */
64
/*                                            context                     */
65
/*    _gx_canvas_line_draw                  Draw a line on the canvas     */
66
/*    _gx_context_brush_define              Define the brush of the       */
67
/*                                            context                     */
68
/*    _gx_canvas_rectangle_draw             Draw a rectangle              */
69
/*                                                                        */
70
/*  CALLED BY                                                             */
71
/*                                                                        */
72
/*    Application Code                                                    */
73
/*    GUIX Internal Code                                                  */
74
/*                                                                        */
75
/*  RELEASE HISTORY                                                       */
76
/*                                                                        */
77
/*    DATE              NAME                      DESCRIPTION             */
78
/*                                                                        */
79
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
80
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
81
/*                                            resulting in version 6.1    */
82
/*                                                                        */
83
/**************************************************************************/
84
125772
VOID  _gx_slider_needle_draw(GX_SLIDER *slider)
85
{
86
GX_VALUE        NeedleSpace;
87
GX_VALUE        center;
88
GX_RECTANGLE    NeedleSize;
89
GX_SLIDER_INFO *info;
90
91
    /* pick up the needle width */
92
125772
    info = &slider -> gx_slider_info;
93
125772
    if (slider -> gx_widget_style & GX_STYLE_SLIDER_VERTICAL)
94
    {
95
14119
        NeedleSpace = info -> gx_slider_info_needle_height;
96
    }
97
    else
98
    {
99
111653
        NeedleSpace = info -> gx_slider_info_needle_width;
100
    }
101
102
    /* get needle dimensions based on current value */
103
125772
    _gx_slider_needle_position_get(slider, info, &NeedleSize);
104
105
    /* pick up brush pointer */
106
125772
    _gx_context_line_color_set(GX_COLOR_ID_SLIDER_GROOVE_TOP);
107
125772
    _gx_context_brush_width_set(1);
108
109
    /* draw the line on which the needle slides */
110
125772
    if (slider -> gx_widget_style & GX_STYLE_SLIDER_VERTICAL)
111
    {
112
14119
        center = (GX_VALUE)(slider -> gx_widget_size.gx_rectangle_left +
113
14119
                            slider -> gx_widget_size.gx_rectangle_right) / 2;
114
115
14119
        _gx_canvas_line_draw(center,
116
14119
                             (GX_VALUE)(slider -> gx_widget_size.gx_rectangle_top + NeedleSpace),
117
                             center,
118
14119
                             (GX_VALUE)(slider -> gx_widget_size.gx_rectangle_bottom - NeedleSpace));
119
14119
        _gx_context_line_color_set(GX_COLOR_ID_SLIDER_GROOVE_BOTTOM);
120
14119
        _gx_canvas_line_draw((GX_VALUE)(center + 1),
121
14119
                             (GX_VALUE)(slider -> gx_widget_size.gx_rectangle_top + NeedleSpace),
122
14119
                             (GX_VALUE)(center + 1),
123
14119
                             (GX_VALUE)(slider -> gx_widget_size.gx_rectangle_bottom - NeedleSpace));
124
    }
125
    else
126
    {
127
111653
        center = (GX_VALUE)(slider -> gx_widget_size.gx_rectangle_top +
128
111653
                            slider -> gx_widget_size.gx_rectangle_bottom) / 2;
129
130
111653
        _gx_canvas_line_draw((GX_VALUE)(slider -> gx_widget_size.gx_rectangle_left + NeedleSpace),
131
111653
                             center, (GX_VALUE)(slider -> gx_widget_size.gx_rectangle_right - NeedleSpace),
132
                             center);
133
111653
        _gx_context_line_color_set(GX_COLOR_ID_SLIDER_GROOVE_BOTTOM);
134
111653
        _gx_canvas_line_draw((GX_VALUE)(slider -> gx_widget_size.gx_rectangle_left + NeedleSpace),
135
111653
                             (GX_VALUE)(center + 1), (GX_VALUE)(slider -> gx_widget_size.gx_rectangle_right - NeedleSpace),
136
111653
                             (GX_VALUE)(center + 1));
137
    }
138
139
140
    /* draw the needle itself */
141
125772
    _gx_context_brush_define(GX_COLOR_ID_SLIDER_NEEDLE_OUTLINE,
142
                             GX_COLOR_ID_SLIDER_NEEDLE_FILL,
143
                             GX_BRUSH_SOLID_FILL);
144
125772
    _gx_canvas_rectangle_draw(&NeedleSize);
145
146
125772
    _gx_context_line_color_set(GX_COLOR_ID_SLIDER_NEEDLE_LINE1);
147
148
125772
    if (slider -> gx_widget_style & GX_STYLE_SLIDER_VERTICAL)
149
    {
150
14119
        _gx_canvas_line_draw((GX_VALUE)(NeedleSize.gx_rectangle_left + 1),
151
14119
                             (GX_VALUE)(NeedleSize.gx_rectangle_top + 2),
152
14119
                             (GX_VALUE)(NeedleSize.gx_rectangle_right - 1),
153
14119
                             (GX_VALUE)(NeedleSize.gx_rectangle_top + 2));
154
14119
        _gx_context_line_color_set(GX_COLOR_ID_SLIDER_NEEDLE_LINE2);
155
156
14119
        _gx_canvas_line_draw((GX_VALUE)(NeedleSize.gx_rectangle_left + 1),
157
14119
                             (GX_VALUE)(NeedleSize.gx_rectangle_top + 3),
158
14119
                             (GX_VALUE)(NeedleSize.gx_rectangle_right - 1),
159
14119
                             (GX_VALUE)(NeedleSize.gx_rectangle_top + 3));
160
    }
161
    else
162
    {
163
111653
        _gx_canvas_line_draw((GX_VALUE)(NeedleSize.gx_rectangle_left + 2),
164
111653
                             (GX_VALUE)(NeedleSize.gx_rectangle_top + 1),
165
111653
                             (GX_VALUE)(NeedleSize.gx_rectangle_left + 2),
166
111653
                             (GX_VALUE)(NeedleSize.gx_rectangle_bottom - 1));
167
111653
        _gx_context_line_color_set(GX_COLOR_ID_SLIDER_NEEDLE_LINE2);
168
169
111653
        _gx_canvas_line_draw((GX_VALUE)(NeedleSize.gx_rectangle_left + 3),
170
111653
                             (GX_VALUE)(NeedleSize.gx_rectangle_top + 1),
171
111653
                             (GX_VALUE)(NeedleSize.gx_rectangle_left + 3),
172
111653
                             (GX_VALUE)(NeedleSize.gx_rectangle_bottom - 1));
173
    }
174
125772
}
175