1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
10 |
|
|
**************************************************************************/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/**************************************************************************/ |
15 |
|
|
/** */ |
16 |
|
|
/** GUIX Component */ |
17 |
|
|
/** */ |
18 |
|
|
/** Progress Bar Management (Progress Bar) */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
#define GX_SOURCE_CODE |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
/* Include necessary system files. */ |
26 |
|
|
#include "gx_api.h" |
27 |
|
|
#include "gx_widget.h" |
28 |
|
|
#include "gx_utility.h" |
29 |
|
|
#include "gx_progress_bar.h" |
30 |
|
|
|
31 |
|
|
#define GX_MAX_PROGRESS_BAR_TEXT_LENGTH 11 |
32 |
|
|
|
33 |
|
|
/**************************************************************************/ |
34 |
|
|
/* */ |
35 |
|
|
/* FUNCTION RELEASE */ |
36 |
|
|
/* */ |
37 |
|
|
/* _gx_progress_bar_text_draw PORTABLE C */ |
38 |
|
|
/* 6.1 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function draws the specified progress bar with text. */ |
46 |
|
|
/* */ |
47 |
|
|
/* INPUT */ |
48 |
|
|
/* */ |
49 |
|
|
/* progress_bar Progress Bar control 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 |
|
|
/**************************************************************************/ |
68 |
|
2600 |
VOID _gx_progress_bar_text_draw(GX_PROGRESS_BAR *progress_bar) |
69 |
|
|
{ |
70 |
|
2600 |
GX_WIDGET *widget = (GX_WIDGET *)progress_bar; |
71 |
|
|
GX_RESOURCE_ID color; |
72 |
|
2600 |
GX_CHAR pText[GX_MAX_PROGRESS_BAR_TEXT_LENGTH + 1] = ""; |
73 |
|
|
INT cur_value; |
74 |
|
|
INT range; |
75 |
|
|
INT min_value; |
76 |
|
|
INT max_value; |
77 |
|
|
GX_STRING string; |
78 |
|
|
|
79 |
|
|
/* Pick up the text color. */ |
80 |
✓✓ |
2600 |
if (progress_bar -> gx_widget_style & GX_STYLE_ENABLED) |
81 |
|
|
{ |
82 |
✓✓ |
9 |
if (progress_bar -> gx_widget_style & GX_STYLE_DRAW_SELECTED) |
83 |
|
|
{ |
84 |
|
4 |
color = progress_bar -> gx_progress_bar_info.gx_progress_bar_selected_text_color; |
85 |
|
|
} |
86 |
|
|
else |
87 |
|
|
{ |
88 |
|
5 |
color = progress_bar -> gx_progress_bar_info.gx_progress_bar_normal_text_color; |
89 |
|
|
} |
90 |
|
|
} |
91 |
|
|
else |
92 |
|
|
{ |
93 |
|
2591 |
color = progress_bar -> gx_progress_bar_info.gx_progress_bar_disabled_text_color; |
94 |
|
|
} |
95 |
|
|
|
96 |
|
2600 |
string.gx_string_ptr = pText; |
97 |
|
|
|
98 |
|
2600 |
cur_value = progress_bar -> gx_progress_bar_info.gx_progress_bar_info_current_val; |
99 |
✓✓ |
2600 |
if (progress_bar -> gx_widget_style & GX_STYLE_PROGRESS_PERCENT) |
100 |
|
|
{ |
101 |
|
2579 |
min_value = progress_bar -> gx_progress_bar_info.gx_progress_bar_info_min_val; |
102 |
|
2579 |
max_value = progress_bar -> gx_progress_bar_info.gx_progress_bar_info_max_val; |
103 |
|
2579 |
range = max_value - min_value; |
104 |
✓✓ |
2579 |
if (range != 0) |
105 |
|
|
{ |
106 |
|
2577 |
_gx_utility_ltoa(((cur_value - min_value) * 100) / range, pText, sizeof(pText) - 1); |
107 |
|
|
|
108 |
|
|
/* Calculate string length. */ |
109 |
|
2577 |
_gx_utility_string_length_check(string.gx_string_ptr, &string.gx_string_length, GX_MAX_PROGRESS_BAR_TEXT_LENGTH - 1); |
110 |
|
|
|
111 |
|
|
/* Add "%" to the end of text. */ |
112 |
|
2577 |
pText[string.gx_string_length] = '%'; |
113 |
|
2577 |
pText[string.gx_string_length + 1] = '\0'; |
114 |
|
2577 |
string.gx_string_length ++; |
115 |
|
|
} |
116 |
|
|
} |
117 |
|
|
else |
118 |
|
|
{ |
119 |
|
21 |
_gx_utility_ltoa(cur_value, pText, sizeof(pText)); |
120 |
|
21 |
_gx_utility_string_length_check(string.gx_string_ptr, &string.gx_string_length, GX_MAX_PROGRESS_BAR_TEXT_LENGTH); |
121 |
|
|
} |
122 |
|
|
|
123 |
|
2600 |
_gx_widget_text_draw_ext(widget, color, progress_bar -> gx_progress_bar_info.gx_progress_bar_font_id, &string, 0, 0); |
124 |
|
2600 |
} |
125 |
|
|
|