GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_pixelmap_slider_draw.c Lines: 43 43 100.0 %
Date: 2024-12-05 08:52:37 Branches: 16 16 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_slider.h"
31
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _gx_pixelmap_slider_draw                            PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Kenneth Maxwell, Microsoft Corporation                              */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function draws the specified slider, which is a type of        */
46
/*    of widget designed to allow adjusting or display a value            */
47
/*    graphically                                                         */
48
/*                                                                        */
49
/*  INPUT                                                                 */
50
/*                                                                        */
51
/*    slider                                Slider 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_canvas_pixelmap_tile              Tile a pixelmap               */
62
/*    _gx_context_pixelmap_get              Retrieve pixelmap image       */
63
/*    _gx_sidget_width_get                  Obtain the width of a widget  */
64
/*    _gx_wdiget_background_draw            Draw widget background        */
65
/*    _gx_canvas_pixelmap_draw              Draw pixelmap on canvas       */
66
/*                                                                        */
67
/*  CALLED BY                                                             */
68
/*                                                                        */
69
/*    Application Code                                                    */
70
/*    GUIX Internal 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
11736
VOID  _gx_pixelmap_slider_draw(GX_PIXELMAP_SLIDER *slider)
82
{
83
GX_PIXELMAP             *map;
84
GX_PIXELMAP             *uppermap;
85
GX_RECTANGLE             fillrect;
86
GX_SLIDER_INFO          *info;
87
GX_PIXELMAP_SLIDER_INFO *pixinfo;
88
GX_VALUE                 space;
89
GX_RECTANGLE             needle_size;
90
91
11736
    info = &slider -> gx_slider_info;
92
11736
    pixinfo = &slider -> gx_pixelmap_slider_pixelmap_info;
93
94
11736
    _gx_context_pixelmap_get(pixinfo -> gx_pixelmap_slider_info_lower_background_pixelmap, &map);
95
11736
    _gx_context_pixelmap_get(pixinfo -> gx_pixelmap_slider_info_upper_background_pixelmap, &uppermap);
96
11736
    _gx_slider_needle_position_get((GX_SLIDER *)slider, info, &needle_size);
97
11736
    _gx_widget_context_fill_set((GX_WIDGET *)slider);
98
99

11736
    if ((slider -> gx_widget_style & GX_STYLE_TILE_BACKGROUND) && map && uppermap)
100
    {
101
5890
        if (slider -> gx_widget_style & GX_STYLE_SLIDER_VERTICAL)
102
        {
103
2418
            _gx_widget_width_get((GX_WIDGET *)slider, &space);
104
2418
            space = (GX_VALUE)(space - map -> gx_pixelmap_width);
105
2418
            space /= 2;
106
2418
            fillrect.gx_rectangle_top = slider -> gx_widget_size.gx_rectangle_top;
107
2418
            fillrect.gx_rectangle_left = (GX_VALUE)(slider -> gx_widget_size.gx_rectangle_left + space);
108
2418
            fillrect.gx_rectangle_right = (GX_VALUE)(fillrect.gx_rectangle_left + map -> gx_pixelmap_width - 1);
109
2418
            fillrect.gx_rectangle_bottom = (GX_VALUE)(needle_size.gx_rectangle_top + info -> gx_slider_info_needle_hotspot_offset);
110
2418
            _gx_canvas_pixelmap_tile(&fillrect, uppermap);
111
112
2418
            fillrect.gx_rectangle_top = (GX_VALUE)(fillrect.gx_rectangle_bottom + 1);
113
2418
            fillrect.gx_rectangle_bottom = slider -> gx_widget_size.gx_rectangle_bottom;
114
2418
            _gx_canvas_pixelmap_tile(&fillrect, map);
115
        }
116
        else
117
        {
118
3472
            _gx_widget_height_get((GX_WIDGET *)slider, &space);
119
3472
            space = (GX_VALUE)(space - map -> gx_pixelmap_height);
120
3472
            space /= 2;
121
3472
            fillrect.gx_rectangle_top = (GX_VALUE)(slider -> gx_widget_size.gx_rectangle_top + space);
122
3472
            fillrect.gx_rectangle_left = slider -> gx_widget_size.gx_rectangle_left;
123
3472
            fillrect.gx_rectangle_right = (GX_VALUE)(needle_size.gx_rectangle_left + info -> gx_slider_info_needle_hotspot_offset);
124
3472
            fillrect.gx_rectangle_bottom = (GX_VALUE)(fillrect.gx_rectangle_top + map -> gx_pixelmap_height - 1);
125
3472
            _gx_canvas_pixelmap_tile(&fillrect, map);
126
127
3472
            fillrect.gx_rectangle_left = (GX_VALUE)(fillrect.gx_rectangle_right + 1);
128
3472
            fillrect.gx_rectangle_right = slider -> gx_widget_size.gx_rectangle_right;
129
3472
            _gx_canvas_pixelmap_tile(&fillrect, uppermap);
130
        }
131
    }
132
    else
133
    {
134
5846
        if (map)
135
        {
136
4570
            if (slider -> gx_widget_style & GX_STYLE_TILE_BACKGROUND)
137
            {
138
629
                _gx_canvas_pixelmap_tile(&slider -> gx_widget_size, map);
139
            }
140
            else
141
            {
142
3941
                _gx_canvas_pixelmap_draw(slider -> gx_widget_size.gx_rectangle_left,
143
3941
                                         slider -> gx_widget_size.gx_rectangle_top, map);
144
            }
145
        }
146
        else
147
        {
148
1276
            if (!(slider -> gx_widget_style & GX_STYLE_TRANSPARENT))
149
            {
150
647
                _gx_widget_background_draw((GX_WIDGET *)slider);
151
            }
152
        }
153
    }
154
155
    /* Pick up needle pixelmap. */
156
11736
    _gx_context_pixelmap_get(pixinfo -> gx_pixelmap_slider_info_needle_pixelmap, &map);
157
158
11736
    if (map)
159
    {
160
        /* Draw needle pixelmap. */
161
11605
        _gx_canvas_pixelmap_draw(needle_size.gx_rectangle_left, needle_size.gx_rectangle_top, map);
162
    }
163
164
11736
    _gx_widget_children_draw((GX_WIDGET *)slider);
165
11736
}
166