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 (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_widget.h" |
27 |
|
|
#include "gx_utility.h" |
28 |
|
|
#include "gx_progress_bar.h" |
29 |
|
|
|
30 |
|
|
#define GX_MAX_PROGRESS_BAR_TEXT_LENGTH 11 |
31 |
|
|
|
32 |
|
|
/**************************************************************************/ |
33 |
|
|
/* */ |
34 |
|
|
/* FUNCTION RELEASE */ |
35 |
|
|
/* */ |
36 |
|
|
/* _gx_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 progress bar with text. */ |
45 |
|
|
/* */ |
46 |
|
|
/* INPUT */ |
47 |
|
|
/* */ |
48 |
|
|
/* progress_bar Progress Bar control block */ |
49 |
|
|
/* */ |
50 |
|
|
/* OUTPUT */ |
51 |
|
|
/* */ |
52 |
|
|
/* None */ |
53 |
|
|
/* */ |
54 |
|
|
/* CALLS */ |
55 |
|
|
/* */ |
56 |
|
|
/* _gx_utility_ltoa Converts a long integer value */ |
57 |
|
|
/* into an ASCII string */ |
58 |
|
|
/* _gx_utility_string_length_check Test string length */ |
59 |
|
|
/* _gx_widget_text_draw Draw the text on the widget */ |
60 |
|
|
/* */ |
61 |
|
|
/* CALLED BY */ |
62 |
|
|
/* */ |
63 |
|
|
/* Application Code */ |
64 |
|
|
/* GUIX Internal Code */ |
65 |
|
|
/* */ |
66 |
|
|
/* RELEASE HISTORY */ |
67 |
|
|
/* */ |
68 |
|
|
/* DATE NAME DESCRIPTION */ |
69 |
|
|
/* */ |
70 |
|
|
/* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ |
71 |
|
|
/* 09-30-2020 Kenneth Maxwell Modified comment(s), */ |
72 |
|
|
/* resulting in version 6.1 */ |
73 |
|
|
/* */ |
74 |
|
|
/**************************************************************************/ |
75 |
|
2600 |
VOID _gx_progress_bar_text_draw(GX_PROGRESS_BAR *progress_bar) |
76 |
|
|
{ |
77 |
|
2600 |
GX_WIDGET *widget = (GX_WIDGET *)progress_bar; |
78 |
|
|
GX_RESOURCE_ID color; |
79 |
|
2600 |
GX_CHAR pText[GX_MAX_PROGRESS_BAR_TEXT_LENGTH + 1] = ""; |
80 |
|
|
INT cur_value; |
81 |
|
|
INT range; |
82 |
|
|
INT min_value; |
83 |
|
|
INT max_value; |
84 |
|
|
GX_STRING string; |
85 |
|
|
|
86 |
|
|
/* Pick up the text color. */ |
87 |
✓✓ |
2600 |
if (progress_bar -> gx_widget_style & GX_STYLE_ENABLED) |
88 |
|
|
{ |
89 |
✓✓ |
9 |
if (progress_bar -> gx_widget_style & GX_STYLE_DRAW_SELECTED) |
90 |
|
|
{ |
91 |
|
4 |
color = progress_bar -> gx_progress_bar_info.gx_progress_bar_selected_text_color; |
92 |
|
|
} |
93 |
|
|
else |
94 |
|
|
{ |
95 |
|
5 |
color = progress_bar -> gx_progress_bar_info.gx_progress_bar_normal_text_color; |
96 |
|
|
} |
97 |
|
|
} |
98 |
|
|
else |
99 |
|
|
{ |
100 |
|
2591 |
color = progress_bar -> gx_progress_bar_info.gx_progress_bar_disabled_text_color; |
101 |
|
|
} |
102 |
|
|
|
103 |
|
2600 |
string.gx_string_ptr = pText; |
104 |
|
|
|
105 |
|
2600 |
cur_value = progress_bar -> gx_progress_bar_info.gx_progress_bar_info_current_val; |
106 |
✓✓ |
2600 |
if (progress_bar -> gx_widget_style & GX_STYLE_PROGRESS_PERCENT) |
107 |
|
|
{ |
108 |
|
2579 |
min_value = progress_bar -> gx_progress_bar_info.gx_progress_bar_info_min_val; |
109 |
|
2579 |
max_value = progress_bar -> gx_progress_bar_info.gx_progress_bar_info_max_val; |
110 |
|
2579 |
range = max_value - min_value; |
111 |
✓✓ |
2579 |
if (range != 0) |
112 |
|
|
{ |
113 |
|
2577 |
_gx_utility_ltoa(((cur_value - min_value) * 100) / range, pText, sizeof(pText) - 1); |
114 |
|
|
|
115 |
|
|
/* Calculate string length. */ |
116 |
|
2577 |
_gx_utility_string_length_check(string.gx_string_ptr, &string.gx_string_length, GX_MAX_PROGRESS_BAR_TEXT_LENGTH - 1); |
117 |
|
|
|
118 |
|
|
/* Add "%" to the end of text. */ |
119 |
|
2577 |
pText[string.gx_string_length] = '%'; |
120 |
|
2577 |
pText[string.gx_string_length + 1] = '\0'; |
121 |
|
2577 |
string.gx_string_length ++; |
122 |
|
|
} |
123 |
|
|
} |
124 |
|
|
else |
125 |
|
|
{ |
126 |
|
21 |
_gx_utility_ltoa(cur_value, pText, sizeof(pText)); |
127 |
|
21 |
_gx_utility_string_length_check(string.gx_string_ptr, &string.gx_string_length, GX_MAX_PROGRESS_BAR_TEXT_LENGTH); |
128 |
|
|
} |
129 |
|
|
|
130 |
|
2600 |
_gx_widget_text_draw_ext(widget, color, progress_bar -> gx_progress_bar_info.gx_progress_bar_font_id, &string, 0, 0); |
131 |
|
2600 |
} |
132 |
|
|
|