Debian Codegraph @

ui/UIDraw.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/UIDraw.cpp $
21 * $Revision: 16 $
22 * $Date: 4/14/99 1:52a $
23 * $Author: Jeff $
24 *
25 * UI Library internal code.
26 *
27 * $Log: /DescentIII/Main/ui/UIDraw.cpp $
28 *
29 * 16 4/14/99 1:52a Jeff
30 * fixed case mismatched #includes
31 *
32 * 15 10/22/98 2:43p Samir
33 * ui_DrawStiring uses grtext_Puts.
34 *
35 * 14 10/12/98 9:28a Jason
36 * fixed some rendering bugs
37 *
38 * 13 9/30/98 4:32p Samir
39 * alpha is set to UICharAlpha when drawing a string.
40 *
41 * 12 9/08/98 10:27a Samir
42 * added function to get text height.
43 *
44 * 11 5/07/98 2:59p Samir
45 * modified ui_StartDraw.
46 *
47 * 10 3/18/98 6:25p Samir
48 * Don't turn Z-buffering back on.
49 *
50 * 9 3/10/98 1:08p Samir
51 * Fixed ui_DrawBitmap to always draw properly by setting states.
52 *
53 * 8 3/10/98 12:49p Samir
54 * Added text saturation support.
55 *
56 * 7 2/26/98 4:56p Samir
57 * Fixed some line drawing probs.
58 *
59 * 6 2/10/98 4:56p Samir
60 * Fixed bug in ui_DrawRect.
61 *
62 * 5 1/30/98 7:06p Samir
63 * Added text clipping.
64 *
65 * 4 1/18/98 4:22p Samir
66 * Implemented new UIItem system.
67 *
68 * 3 1/05/98 4:36p Samir
69 * Moved centering and fittext control flags to UIGadget class.
70 *
71 * 2 1/02/98 12:42p Samir
72 * Added ui_GetTextWidth.
73 *
74 * 1 12/30/97 4:36p Samir
75 * Initial revision
76 *
77 * $NoKeywords: $
78 */
79
80 #include "UIlib.h"cxx . . $ `<file>/ui/UIlib.h`/
81 #include "3d.h"cxx . . $ `<file>/lib/3d.h`/
82 #include "bitmap.h"cxx . . $ `<file>/lib/bitmap.h`/
83 #include "grtext.h"cxx . . $ `<file>/grtext/grtext.h`/
84 #include "ddvid.h"cxx . . $ `<file>/lib/ddvid.h`/
85 #include "renderer.h"cxx . . $ `<file>/lib/renderer.h`/
86
87 //////////////////////////////////////////////////////////////////////////////
88 // VARIABLES
89 static int m_UIDrawLeftcxx . . $ m_UIDrawLeft.;
90 static int m_UIDrawTopcxx . . $ m_UIDrawTop.;
91 static int m_UIDrawRightcxx . . $ m_UIDrawRight.;
92 static int m_UIDrawBottomcxx . . $ m_UIDrawBottom.;
93 static uint8_tcxx . . $ uint8_t# m_UIDrawAlphacxx . . $ m_UIDrawAlpha., m_UICharAlphacxx . . $ m_UICharAlpha.;
94 static int m_UITextFlagscxx . . $ m_UITextFlags. = 0;
95
96 //////////////////////////////////////////////////////////////////////////////
97 // FUNCTIONS
98
99 //////////////////////////////////////////////////////////////////////////////
100 // DRAWING PRIMATIVE FUNCTIONS
101
102 void ui_StartDrawcxx . . $ ui_StartDraw(748afa4755bc9595).(int left, int top, int right, int bottom) {
103 m_UIDrawLeftcxx . . $ m_UIDrawLeft. = left;
104 m_UIDrawTopcxx . . $ m_UIDrawTop. = top;
105 m_UIDrawRightcxx . . $ m_UIDrawRight. = right;
106 m_UIDrawBottomcxx . . $ m_UIDrawBottom. = bottom;
107 m_UIDrawAlphacxx . . $ m_UIDrawAlpha. = m_UICharAlphacxx . . $ m_UICharAlpha. = 255;
108
109 rend_StartFramecxx . . $ rend_StartFrame(1559a299834bcdd5).(m_UIDrawLeftcxx . . $ m_UIDrawLeft., m_UIDrawTopcxx . . $ m_UIDrawTop., m_UIDrawRightcxx . . $ m_UIDrawRight., m_UIDrawBottomcxx . . $ m_UIDrawBottom.);
110 grtext_SetParameterscxx . . $ grtext_SetParameters(1559a299834bcdd5).(0, 0, right - left + 1, bottom - top + 1);
111 }
112
113 void ui_EndDrawcxx . . $ ui_EndDraw(49f6e7a06ebc5aa8).() {
114 grtext_Flushcxx . . $ grtext_Flush(49f6e7a06ebc5aa8).();
115 rend_EndFramecxx . . $ rend_EndFrame(49f6e7a06ebc5aa8).();
116 }
117
118 // sets text clipping within the startdraw region
119 void ui_SetTextClipcxx . . $ ui_SetTextClip(748afa4755bc9595).(int left, int top, int right, int bottom) { grtext_SetParameterscxx . . $ grtext_SetParameters(1559a299834bcdd5).(left, top, right, bottom); }
120
121 void ui_ResetTextClipcxx . . $ ui_ResetTextClip(49f6e7a06ebc5aa8).() { grtext_SetParameterscxx . . $ grtext_SetParameters(1559a299834bcdd5).(m_UIDrawLeftcxx . . $ m_UIDrawLeft., m_UIDrawTopcxx . . $ m_UIDrawTop., m_UIDrawRightcxx . . $ m_UIDrawRight., m_UIDrawBottomcxx . . $ m_UIDrawBottom.); }
122
123 // draw primatives
124 void ui_DrawSetAlphacxx . . $ ui_DrawSetAlpha(ac50b47256ae7414).(uint8_tcxx . . $ uint8_t# alpha) { m_UIDrawAlphacxx . . $ m_UIDrawAlpha. = alpha; }
125
126 void ui_DrawLinecxx . . $ ui_DrawLine(fe09a4b73d8d396f).(ddgr_colorcxx . . $ ddgr_color# color, int x1, int y1, int x2, int y2) {
127 if (color == TRANSPARENT_COLOR32cxx . . $ `lib/grdefs.h:70:9`!)
128 return;
129
130 rend_SetFlatColorcxx . . $ rend_SetFlatColor(cb2f890c2fdad230).(color);
131 rend_DrawLinecxx . . $ rend_DrawLine(748afa4755bc9595).(x1, y1, x2, y2);
132 }
133
134 void ui_DrawBoxcxx . . $ ui_DrawBox(fe09a4b73d8d396f).(ddgr_colorcxx . . $ ddgr_color# color, int l, int t, int r, int b) {
135 if (color == TRANSPARENT_COLOR32cxx . . $ `lib/grdefs.h:70:9`!)
136 return;
137 rend_SetFlatColorcxx . . $ rend_SetFlatColor(cb2f890c2fdad230).(color);
138 rend_DrawLinecxx . . $ rend_DrawLine(748afa4755bc9595).(l, t, r - 1, t);
139 rend_DrawLinecxx . . $ rend_DrawLine(748afa4755bc9595).(r - 1, t, r - 1, b - 1);
140 rend_DrawLinecxx . . $ rend_DrawLine(748afa4755bc9595).(l, b - 1, r - 1, b - 1);
141 rend_DrawLinecxx . . $ rend_DrawLine(748afa4755bc9595).(l, t, l, b - 1);
142 }
143
144 void ui_DrawLTBoxcxx . . $ ui_DrawLTBox(c7c2c8c9daee4a15).(ddgr_colorcxx . . $ ddgr_color# lt_col, ddgr_colorcxx . . $ ddgr_color# rb_col, int l, int t, int r, int b) {
145 if (lt_col != TRANSPARENT_COLOR32cxx . . $ `lib/grdefs.h:70:9`!) {
146 rend_SetFlatColorcxx . . $ rend_SetFlatColor(cb2f890c2fdad230).(lt_col);
147 rend_DrawLinecxx . . $ rend_DrawLine(748afa4755bc9595).(l, t, r - 1, t);
148 rend_DrawLinecxx . . $ rend_DrawLine(748afa4755bc9595).(l, t, l, b - 1);
149 }
150 if (rb_col != TRANSPARENT_COLOR32cxx . . $ `lib/grdefs.h:70:9`!) {
151 rend_SetFlatColorcxx . . $ rend_SetFlatColor(cb2f890c2fdad230).(rb_col);
152 rend_DrawLinecxx . . $ rend_DrawLine(748afa4755bc9595).(l, b - 1, r - 1, b - 1);
153 rend_DrawLinecxx . . $ rend_DrawLine(748afa4755bc9595).(r - 1, t + 1, r - 1, b - 1);
154 }
155 }
156
157 void ui_DrawRectcxx . . $ ui_DrawRect(fe09a4b73d8d396f).(ddgr_colorcxx . . $ ddgr_color# color, int l, int t, int r, int b) {
158 if (color == TRANSPARENT_COLOR32cxx . . $ `lib/grdefs.h:70:9`!)
159 return;
160
161 g3Pointcxx . . $ g3Point# *pntlist[4], points[4];
162 int i;
163
164 // Set our four corners to cover the screen
165 points[0].p3_sxcxx . . $ g3Point#p3_sx. = l;
166 points[0].p3_sycxx . . $ g3Point#p3_sy. = t;
167 points[1].p3_sxcxx . . $ g3Point#p3_sx. = r;
168 points[1].p3_sycxx . . $ g3Point#p3_sy. = t;
169 points[2].p3_sxcxx . . $ g3Point#p3_sx. = r;
170 points[2].p3_sycxx . . $ g3Point#p3_sy. = b;
171 points[3].p3_sxcxx . . $ g3Point#p3_sx. = l;
172 points[3].p3_sycxx . . $ g3Point#p3_sy. = b;
173
174 for (i = 0; i < 4; i++) {
175 points[i].p3_zcxx . . $ `lib/3d.h:247:9`! = 0;
176 points[i].p3_flagscxx . . $ g3Point#p3_flags. = PF_PROJECTEDcxx . . $ `lib/3d.h:214:9`!;
177 pntlist[i] = &points[i];
178 }
179
180 rend_SetZBufferStatecxx . . $ rend_SetZBufferState(4af4fd0e2b26c4ac).(0);
181 rend_SetTextureTypecxx . . $ rend_SetTextureType(cccd9781d96f97ff).(TT_FLATcxx . . $ TT_FLAT.);
182 rend_SetAlphaTypecxx . . $ rend_SetAlphaType(4af4fd0e2b26c4ac).(AT_CONSTANTcxx . . $ `lib/renderer.h:400:9`!);
183 rend_SetLightingcxx . . $ rend_SetLighting(e55526c9d3dd1656).(LS_NONEcxx . . $ LS_NONE.);
184 rend_SetFlatColorcxx . . $ rend_SetFlatColor(cb2f890c2fdad230).(color);
185 rend_SetAlphaValuecxx . . $ rend_SetAlphaValue(ac50b47256ae7414).(m_UIDrawAlphacxx . . $ m_UIDrawAlpha.);
186 rend_DrawPolygon2Dcxx . . $ rend_DrawPolygon2D(1464bdba6025a51).(0, pntlist, 4);
187 }
188
189 // draws all textures derived from ui_bm_handle.
190 void ui_DrawBitmapcxx . . $ ui_DrawBitmap(d33d35b40e6b2157).(UIBitmapItemcxx . . $ UIBitmapItem# *bi, int x, int y, uint8_tcxx . . $ uint8_t# alpha) {
191 if (bi->is_chunkedcxx . . $ UIBitmapItem#is_chunked(50ce9a9e25b4a850).()) {
192 chunked_bitmapcxx . . $ chunked_bitmap# *chunk = bi->get_chunked_bitmapcxx . . $ UIBitmapItem#get_chunked_bitmap(c897c69353849a).();
193 rend_DrawChunkedBitmapcxx . . $ rend_DrawChunkedBitmap(529c7906ea1e7bf7).(chunk, x, y, alpha);
194 } else {
195 int bmp_w = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(bi->get_bitmapcxx . . $ UIBitmapItem#get_bitmap(455f465bc33b4cdf).(), 0);
196 int bmp_h = bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(bi->get_bitmapcxx . . $ UIBitmapItem#get_bitmap(455f465bc33b4cdf).(), 0);
197 float u1, v1;
198
199 if ((x + bmp_w) > m_UIDrawRightcxx . . $ m_UIDrawRight.) {
200 u1 = ((float)(m_UIDrawRightcxx . . $ m_UIDrawRight. - x)) / ((float)bmp_w);
201 bmp_w = m_UIDrawRightcxx . . $ m_UIDrawRight. - x;
202 } else
203 u1 = 1.0f;
204
205 if ((y + bmp_h) > m_UIDrawBottomcxx . . $ m_UIDrawBottom.) {
206 v1 = ((float)(m_UIDrawBottomcxx . . $ m_UIDrawBottom. - y)) / ((float)bmp_h);
207 bmp_h = m_UIDrawBottomcxx . . $ m_UIDrawBottom. - y;
208 } else
209 v1 = 1.0f;
210
211 rend_SetOverlayTypecxx . . $ rend_SetOverlayType(ac50b47256ae7414).(OT_NONEcxx . . $ `lib/renderer.h:333:9`!);
212 rend_SetLightingcxx . . $ rend_SetLighting(e55526c9d3dd1656).(LS_NONEcxx . . $ LS_NONE.);
213 rend_SetColorModelcxx . . $ rend_SetColorModel(e3c5062d5af601c7).(CM_MONOcxx . . $ CM_MONO.);
214 rend_SetZBufferStatecxx . . $ rend_SetZBufferState(4af4fd0e2b26c4ac).(0);
215 rend_SetAlphaTypecxx . . $ rend_SetAlphaType(4af4fd0e2b26c4ac).(ATF_CONSTANTcxx . . $ `lib/renderer.h:394:9`! + ATF_TEXTUREcxx . . $ `lib/renderer.h:395:9`!);
216 rend_SetAlphaValuecxx . . $ rend_SetAlphaValue(ac50b47256ae7414).(alpha);
217 rend_SetWrapTypecxx . . $ rend_SetWrapType(da524b148887c0e7).(WT_CLAMPcxx . . $ WT_CLAMP.);
218
219 rend_DrawScaledBitmapcxx . . $ rend_DrawScaledBitmap(bffd21ce5f93b71b).(x, y, x + bmp_w, y + bmp_h, bi->get_bitmapcxx . . $ UIBitmapItem#get_bitmap(455f465bc33b4cdf).(), 0, 0, u1, v1);
220 }
221 }
222
223 int ui_GetBitmapWidthcxx . . $ ui_GetBitmapWidth(fac790737e02cbfd).(UIBitmapItemcxx . . $ UIBitmapItem# *bi) {
224 if (bi->is_chunkedcxx . . $ UIBitmapItem#is_chunked(50ce9a9e25b4a850).()) {
225 chunked_bitmapcxx . . $ chunked_bitmap# *chunk = bi->get_chunked_bitmapcxx . . $ UIBitmapItem#get_chunked_bitmap(c897c69353849a).();
226 return chunk->pwcxx . . $ chunked_bitmap#pw.;
227 } else {
228 return bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(bi->get_bitmapcxx . . $ UIBitmapItem#get_bitmap(455f465bc33b4cdf).(), 0);
229 }
230 }
231
232 int ui_GetBitmapHeightcxx . . $ ui_GetBitmapHeight(fac790737e02cbfd).(UIBitmapItemcxx . . $ UIBitmapItem# *bi) {
233 if (bi->is_chunkedcxx . . $ UIBitmapItem#is_chunked(50ce9a9e25b4a850).()) {
234 chunked_bitmapcxx . . $ chunked_bitmap# *chunk = bi->get_chunked_bitmapcxx . . $ UIBitmapItem#get_chunked_bitmap(c897c69353849a).();
235 return chunk->phcxx . . $ chunked_bitmap#ph.;
236 } else {
237 return bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(bi->get_bitmapcxx . . $ UIBitmapItem#get_bitmap(455f465bc33b4cdf).(), 0);
238 }
239 }
240
241 // sets font for text drawing.
242 void ui_DrawSetFontcxx . . $ ui_DrawSetFont(d4f767463ce0a6b3).(int handle) { grtext_SetFontcxx . . $ grtext_SetFont(d4f767463ce0a6b3).(handle); }
243
244 int ui_DrawGetFontcxx . . $ ui_DrawGetFont(b126dc7c1de90089).() { return grtext_GetFontcxx . . $ grtext_GetFont(b126dc7c1de90089).(); }
245
246 int ui_GetFontHeightcxx . . $ ui_GetFontHeight(b126dc7c1de90089).() { return grfont_GetHeightcxx . . $ grfont_GetHeight(7864480464b09eea).(grtext_GetFontcxx . . $ grtext_GetFont(b126dc7c1de90089).()); }
247
248 void ui_SetCharAlphacxx . . $ ui_SetCharAlpha(ac50b47256ae7414).(uint8_tcxx . . $ uint8_t# alpha) { m_UICharAlphacxx . . $ m_UICharAlpha. = alpha; }
249
250 int ui_GetTextWidthcxx . . $ ui_GetTextWidth(5c4306d8553b3696).(const char *text) { return grtext_GetLineWidthcxx . . $ `grtext/grtext.h:172:9`!((char *)text); }
251
252 int ui_GetTextHeightcxx . . $ ui_GetTextHeight(5c4306d8553b3696).(const char *text) { return grtext_GetHeightcxx . . $ `grtext/grtext.h:164:9`!(text); }
253
254 void ui_DrawSetTextTypecxx . . $ ui_DrawSetTextType(d4f767463ce0a6b3).(int type) {
255 switch (type) {
256 case UI_TEXTTYPE_SHADOWcxx . . $ `ui/uidraw.h:53:9`!:
257 m_UITextFlagscxx . . $ m_UITextFlags. = GRTEXTFLAG_SHADOWcxx . . $ `grtext/grtext.h:120:9`!;
258 break;
259 case UI_TEXTTYPE_SATURATEcxx . . $ `ui/uidraw.h:52:9`!:
260 m_UITextFlagscxx . . $ m_UITextFlags. = GRTEXTFLAG_SATURATEcxx . . $ `grtext/grtext.h:119:9`!;
261 break;
262 default:
263 m_UITextFlagscxx . . $ m_UITextFlags. = 0;
264 }
265 }
266
267 // draws a line of text.
268 void ui_DrawStringcxx . . $ ui_DrawString(c261e420eb73c8b5).(ddgr_colorcxx . . $ ddgr_color# col, int x, int y, const char *str) {
269 grtext_SetFlagscxx . . $ grtext_SetFlags(d4f767463ce0a6b3).(m_UITextFlagscxx . . $ m_UITextFlags.);
270 grtext_SetAlphacxx . . $ grtext_SetAlpha(ac50b47256ae7414).(m_UICharAlphacxx . . $ m_UICharAlpha.);
271 grtext_SetColorcxx . . $ grtext_SetColor(cb2f890c2fdad230).(col);
272 grtext_Putscxx . . $ grtext_Puts(3139f19a0dbb8edf).(x, y, str);
273 grtext_Flushcxx . . $ grtext_Flush(49f6e7a06ebc5aa8).();
274 }
275
276 void ui_DrawCenteredStringcxx . . $ ui_DrawCenteredString(c261e420eb73c8b5).(ddgr_colorcxx . . $ ddgr_color# col, int xoff, int y, const char *str) {
277 grtext_SetFlagscxx . . $ grtext_SetFlags(d4f767463ce0a6b3).(m_UITextFlagscxx . . $ m_UITextFlags.);
278 grtext_SetAlphacxx . . $ grtext_SetAlpha(ac50b47256ae7414).(m_UICharAlphacxx . . $ m_UICharAlpha.);
279 grtext_SetColorcxx . . $ grtext_SetColor(cb2f890c2fdad230).(col);
280 grtext_CenteredPrintfcxx . . $ grtext_CenteredPrintf(9514e36549094170).(xoff, y, str);
281 grtext_Flushcxx . . $ grtext_Flush(49f6e7a06ebc5aa8).();
282 }