Debian Codegraph @

ui/UIStatic.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/ui/UIStatic.cpp $
21 * $Revision: 12 $
22 * $Date: 4/14/99 1:53a $
23 * $Author: Jeff $
24 *
25 * Static text
26 *
27 * $Log: /DescentIII/Main/ui/UIStatic.cpp $
28 *
29 * 12 4/14/99 1:53a Jeff
30 * fixed case mismatched #includes
31 *
32 * 11 1/02/99 6:46p Matt
33 * Fixed compile warning
34 *
35 * 10 12/30/98 12:16p Kevin
36 * Auto Mission Download system
37 *
38 * 9 10/01/98 12:57p Samir
39 * fixed hotspots so their width and height touch text, no outer border.
40 *
41 * 8 8/31/98 12:37p Samir
42 * disable all static controls.
43 *
44 * 7 6/05/98 5:36p Samir
45 * disable static items by default, so they don't mess up keyboard focus.
46 *
47 * 6 2/13/98 6:34p Samir
48 * Added UIStatic class.
49 *
50 * 5 1/30/98 7:07p Samir
51 * Changes to gadget system.
52 *
53 * 4 1/18/98 4:22p Samir
54 * Implemented new UIItem system.
55 *
56 * 3 1/08/98 12:18p Samir
57 * Static control size is always calculated.
58 *
59 * 2 1/05/98 4:36p Samir
60 * Moved centering and fittext control flags to UIGadget class.
61 *
62 * 1 1/02/98 12:49p Samir
63 * Initial revision.
64 *
65 *
66 * $NoKeywords: $
67 */
68
69 #include <cstring>
70
71 #include "UIlib.h"
72
73 // ----------------------------------------------------------------------------
74 // UIText
75 // This is a simple text.
76
77 void UIText::Create(UIWindow *parent, UITextItem *text, int x, int y, int flags) {
78 UIStatic::Create(parent, text, x, y, 1, 1, flags);
79 }
80
81 // inheritable operations
82 // override: called when resized or before drawing.
83 void UIText::OnFormat() {
84 m_W = m_Title->width();
85 m_H = m_Title->height();
86
87 UIGadget::OnFormat();
88 }
89
90 UIStatic::UIStatic() {
91 m_Title = NULL;
92 m_Background = NULL;
93 }
94
95 UIStatic::~UIStatic() {}
96
97 void UIStatic::Create(UIWindow *parent, UIItem *item, int x, int y, int w, int h, int flags) {
98 m_Background = NULL;
99 if (item)
100 m_Title = item->CopyUIItem();
101 else
102 m_Title = NULL;
103 UIGadget::Create(parent, -1, x, y, w, h, flags);
104 UIGadget::Disable();
105 }
106
107 void UIStatic::SetBackground(UIPrimativeItem *item) {
108 if (m_Background)
109 delete m_Background;
110 m_Background = NULL;
111 if (item)
112 m_Background = (UIPrimativeItem *)item->CopyUIItem();
113 }
114
115 void UIStatic::SetTitle(UIItem *item) {
116 if (m_Title)
117 delete m_Title;
118 m_Title = NULL;
119 if (item)
120 m_Title = (UIPrimativeItem *)item->CopyUIItem();
121 }
122
123 void UIStatic::OnDraw() {
124 if (m_Flags & UIF_BORDER)
125 ui_DrawBox(GR_WHITE, 0, 0, m_W, m_H);
126
127 if (m_Background)
128 m_Background->draw(0, 0, m_W, m_H);
129 if (m_Title) {
130 // int y = (m_H/2 - m_Title->height()/2);
131 // int x = (m_W/2 - m_Title->width()/2);
132 m_Title->draw(0, 0);
133 }
134 }
135
136 void UIStatic::OnFormat() {
137 if (m_Flags & UIF_FIT) {
138 if (m_Title) {
139 m_W = m_Title->width();
140 m_H = m_Title->height();
141 } else {
142 m_W = 10;
143 m_H = 10;
144 }
145 }
146
147 UIGadget::OnFormat();
148 }
149
150 // called when gadget is being nuked.
151 void UIStatic::OnDestroy() {
152 if (m_Title)
153 delete m_Title;
154 if (m_Background)
155 delete m_Background;
156
157 m_Title = NULL;
158 m_Background = NULL;
159 }
160
161 // ----------------------------------------------------------------------------
162 // UIProgress
163 // This is a simple text.
164
165 void UIProgress::Create(UIWindow *parent, int x, int y, int w, int h, int flags) {
166 m_W = w;
167 m_H = h;
168 m_ProgressWidth = 0;
169 UIStatic::Create(parent, NULL, x, y, w, h, flags);
170 }
171
172 // inheritable operations
173 // override: called when resized or before drawing.
174 void UIProgress::OnFormat() { UIGadget::OnFormat(); }
175
176 void UIProgress::Update(float progress) {
177 m_Progress = progress;
178 m_ProgressWidth = ((int)((m_W - 2) * m_Progress));
179 }
180
181 void UIProgress::OnDraw() {
182 // Take the x & y & w/h & progress to draw the progress bar
183 ui_DrawBox(GR_WHITE, 0, 0, m_W, m_H);
184 ui_DrawBox(GR_WHITE, 1, 1, m_W - 1, m_H - 1);
185 ui_DrawRect(GR_LIGHTGRAY, 2, 2, m_ProgressWidth, m_H - 2);
186 }