GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_radial_progress_bar_text_draw.c Lines: 19 19 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
/**   Progress Bar Management (Radial Progress Bar)                       */
18
/**                                                                       */
19
/**************************************************************************/
20
21
#define GX_SOURCE_CODE
22
23
24
/* Include necessary system files.  */
25
#include "gx_api.h"
26
#include "gx_utility.h"
27
#include "gx_widget.h"
28
#include "gx_radial_progress_bar.h"
29
30
#define GX_MAX_RAIDAL_PROGRESS_BAR_TEXT_LENGTH 4
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _gx_radial_progress_bar_text_draw                   PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Kenneth Maxwell, Microsoft Corporation                              */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function draws the specified radial progress bar with text.    */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    progress_bar                          Radial Progress Bar control   */
49
/*                                            block                       */
50
/*                                                                        */
51
/*  OUTPUT                                                                */
52
/*                                                                        */
53
/*    None                                                                */
54
/*                                                                        */
55
/*  CALLS                                                                 */
56
/*                                                                        */
57
/*    _gx_utility_ltoa                      Converts a long integer value */
58
/*                                            into an ASCII string        */
59
/*    _gx_utility_string_length_check       Test string length            */
60
/*    _gx_widget_text_draw                  Draw the text on the widget   */
61
/*                                                                        */
62
/*  CALLED BY                                                             */
63
/*                                                                        */
64
/*    Application Code                                                    */
65
/*    GUIX Internal Code                                                  */
66
/*                                                                        */
67
/*  RELEASE HISTORY                                                       */
68
/*                                                                        */
69
/*    DATE              NAME                      DESCRIPTION             */
70
/*                                                                        */
71
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
72
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
73
/*                                            resulting in version 6.1    */
74
/*                                                                        */
75
/**************************************************************************/
76
4067
VOID  _gx_radial_progress_bar_text_draw(GX_RADIAL_PROGRESS_BAR *progress_bar)
77
{
78
GX_RADIAL_PROGRESS_BAR_INFO *info;
79
GX_CHAR                      text[GX_MAX_RAIDAL_PROGRESS_BAR_TEXT_LENGTH + 1];
80
INT                          percent;
81
GX_RESOURCE_ID               color_id;
82
GX_STRING                    string;
83
84
4067
    info = &progress_bar -> gx_radial_progress_bar_info;
85
86
4067
    string.gx_string_ptr = text;
87
88
4067
    if (progress_bar -> gx_widget_style & GX_STYLE_PROGRESS_PERCENT)
89
    {
90
91
4063
        percent = GX_ABS(info -> gx_radial_progress_bar_info_current_val) * 100 / 360;
92
4063
        _gx_utility_ltoa(percent, text, sizeof(text) - 1);
93
94
        /* Calculate text length. */
95
4063
        _gx_utility_string_length_check(text, &string.gx_string_length, GX_MAX_RAIDAL_PROGRESS_BAR_TEXT_LENGTH - 1);
96
97
        /* Add "%" to the end of text. */
98
4063
        memcpy(text + string.gx_string_length, "%", 2); /* Use case of memcpy is verified. */
99
4063
        string.gx_string_length++;
100
    }
101
    else
102
    {
103
4
        _gx_utility_ltoa(info -> gx_radial_progress_bar_info_current_val, text, sizeof(text));
104
4
        _gx_utility_string_length_check(string.gx_string_ptr, &string.gx_string_length, sizeof(text) - 1);
105
    }
106
107
4067
    if (progress_bar -> gx_widget_style & GX_STYLE_ENABLED)
108
    {
109
1650
        if (progress_bar -> gx_widget_style & GX_STYLE_DRAW_SELECTED)
110
        {
111
1090
            color_id = info -> gx_radial_progress_bar_info_selected_text_color;
112
        }
113
        else
114
        {
115
560
            color_id = info -> gx_radial_progress_bar_info_normal_text_color;
116
        }
117
    }
118
    else
119
    {
120
2417
        color_id = info -> gx_radial_progress_bar_info_disabled_text_color;
121
    }
122
123
4067
    _gx_widget_text_draw_ext((GX_WIDGET *)progress_bar,
124
                             color_id,
125
4067
                             info -> gx_radial_progress_bar_info_font_id, &string, 0, 0);
126
4067
}
127