GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_slider_tickmarks_draw.c Lines: 30 30 100.0 %
Date: 2024-12-05 08:52:37 Branches: 8 8 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_tickmarks_draw                           PORTABLE C      */
40
/*                                                           6.1          */
41
/*  AUTHOR                                                                */
42
/*                                                                        */
43
/*    Kenneth Maxwell, Microsoft Corporation                              */
44
/*                                                                        */
45
/*  DESCRIPTION                                                           */
46
/*                                                                        */
47
/*    This service draws the slider tickmarks.                            */
48
/*                                                                        */
49
/*  INPUT                                                                 */
50
/*                                                                        */
51
/*    slider                                Slider widget control block   */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    None                                                                */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*    _gx_slider_travel_get                 Get the slider travel         */
60
/*    _gx_context_line_color_set            Set the line color for the    */
61
/*                                            drawing context             */
62
/*    _gx_context_brush_width_set           Set the brush width for the   */
63
/*                                            drawing context             */
64
/*    _gx_canvas_line_draw                  Draw a line                   */
65
/*                                                                        */
66
/*  CALLED BY                                                             */
67
/*                                                                        */
68
/*    Application Code                                                    */
69
/*    GUIX Internal Code                                                  */
70
/*                                                                        */
71
/*  RELEASE HISTORY                                                       */
72
/*                                                                        */
73
/*    DATE              NAME                      DESCRIPTION             */
74
/*                                                                        */
75
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
76
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
77
/*                                            resulting in version 6.1    */
78
/*                                                                        */
79
/**************************************************************************/
80
123845
VOID  _gx_slider_tickmarks_draw(GX_SLIDER *slider)
81
{
82
INT             mintravel;
83
INT             maxtravel;
84
INT             tickstart;
85
INT             tickend;
86
INT             space;
87
GX_FIXED_VAL    tickpos;
88
INT             tickcount;
89
GX_SLIDER_INFO *info;
90
91
123845
    if (slider -> gx_slider_tick_count <= 1)
92
    {
93
1
        return;
94
    }
95
96
    /* make a border 1/8 of widget size around ticksmarks */
97
123844
    if (slider -> gx_widget_style & GX_STYLE_SLIDER_VERTICAL)
98
    {
99
13640
        mintravel = slider -> gx_widget_size.gx_rectangle_left;
100
13640
        maxtravel = slider -> gx_widget_size.gx_rectangle_right;
101
13640
        space = (maxtravel - mintravel) / 8;
102
103
        /* draw left in */
104
13640
        tickend = (maxtravel + mintravel) / 2;
105
13640
        tickend -= space;
106
13640
        tickstart = mintravel + space;
107
    }
108
    else
109
    {
110
110204
        mintravel = slider -> gx_widget_size.gx_rectangle_top;
111
110204
        maxtravel = slider -> gx_widget_size.gx_rectangle_bottom;
112
110204
        space = (maxtravel - mintravel) / 8;
113
114
        /* draw ticks from center down */
115
110204
        tickend = maxtravel - space;
116
110204
        tickstart = (maxtravel + mintravel) / 2;
117
110204
        tickstart += space;
118
    }
119
120
    /* pick up pointer to slider info struct */
121
123844
    info = &slider -> gx_slider_info;
122
123
    /* get the limits of the slider travel */
124
123844
    _gx_slider_travel_get(slider, info, &mintravel, &maxtravel);
125
126
123844
    tickcount = slider -> gx_slider_tick_count;
127
123844
    space = GX_FIXED_VAL_MAKE(maxtravel - mintravel) / (tickcount - 1);
128
129
    /* set line color */
130
123844
    _gx_context_line_color_set(slider -> gx_slider_tick_color);
131
123844
    _gx_context_brush_width_set(1);
132
123844
    tickpos = GX_FIXED_VAL_MAKE(mintravel);
133
134
1355546
    while (tickcount > 0)
135
    {
136
1231702
        mintravel = GX_FIXED_VAL_RND(tickpos);
137
1231702
        if (slider -> gx_widget_style & GX_STYLE_SLIDER_VERTICAL)
138
        {
139
131227
            _gx_canvas_line_draw((GX_VALUE)tickstart, (GX_VALUE)mintravel, (GX_VALUE)tickend, (GX_VALUE)mintravel);
140
        }
141
        else
142
        {
143
1100475
            _gx_canvas_line_draw((GX_VALUE)mintravel, (GX_VALUE)tickstart, (GX_VALUE)mintravel, (GX_VALUE)tickend);
144
        }
145
1231702
        tickpos += space;
146
1231702
        tickcount--;
147
    }
148
}
149