3 #include <client/hud/hud.qh>
5 void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag)
7 vector line_dim = '0 0 0';
9 // left and right lines
11 line_dim.x = thickness;
13 drawfill(pos, line_dim, color, theAlpha, drawflag);
14 drawfill(pos + (dim.x + thickness) * '1 0 0', line_dim, color, theAlpha, drawflag);
16 // upper and lower lines
18 line_dim.x = dim.x + thickness * 2; // make upper and lower lines longer
19 line_dim.y = thickness;
20 drawfill(pos, line_dim, color, theAlpha, drawflag);
21 drawfill(pos + (dim.y + thickness) * '0 1 0', line_dim, color, theAlpha, drawflag);
24 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag)
28 area = HUD_Scale(area);
30 vector current_pos = '0 0 0', end_pos, new_size = '0 0 0', ratio = '0 0 0';
33 current_pos.y = pos.y;
34 while (current_pos.y < end_pos.y)
36 current_pos.x = pos.x;
37 while (current_pos.x < end_pos.x)
39 new_size.x = min(sz.x, end_pos.x - current_pos.x);
40 new_size.y = min(sz.y, end_pos.y - current_pos.y);
41 ratio.x = new_size.x / sz.x;
42 ratio.y = new_size.y / sz.y;
43 drawsubpic(current_pos, new_size, pic, '0 0 0', ratio, color, theAlpha, drawflag);
44 current_pos.x += sz.x;
46 current_pos.y += sz.y;
50 float expandingbox_sizefactor_from_fadelerp(float fadelerp)
52 return 1.2 / (1.2 - fadelerp);
55 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor)
57 boxsize.x *= boxxsizefactor; // easier interface for text
58 return boxsize * (0.5 * (1 - sz));
61 void drawpic_aspect_skin_expanding(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
64 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
66 drawpic_aspect_skin(position + expandingbox_resize_centered_box_offset(sz, theScale, 1), pic, theScale * sz, rgb, theAlpha * (1 - fadelerp), flag);
69 void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
71 drawpic_aspect_skin_expanding(position, pic, theScale, rgb, theAlpha, flag, fadelerp);
72 drawpic_skin(position, pic, theScale, rgb, theAlpha * fadelerp, flag);
75 float stringwidth(string text, float handleColors, vector sz)
77 vector dfs = drawfontscale;
78 drawfontscale = '1 1 0';
79 float r = stringwidth_builtin(text, handleColors, sz);
84 #define SET_POS_AND_SZ_Y_ASPECT(allow_colors) MACRO_BEGIN \
85 float textaspect, oldsz; \
86 vector dfs = drawfontscale; \
87 drawfontscale = '1 1 0'; \
88 textaspect = stringwidth(text, allow_colors, '1 1 1' * sz.y) / sz.y; \
89 drawfontscale = dfs; \
90 if(sz.x/sz.y > textaspect) { \
92 sz.x = sz.y * textaspect; \
93 pos.x += (oldsz - sz.x) * 0.5; \
96 sz.y = sz.x / textaspect; \
97 pos.y += (oldsz - sz.y) * 0.5; \
101 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
102 void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag) {
103 SET_POS_AND_SZ_Y_ASPECT(false);
104 drawstring(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag);
107 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
108 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag) {
109 SET_POS_AND_SZ_Y_ASPECT(true);
110 drawcolorcodedstring(pos, text, '1 1 0' * sz.y, theAlpha, drawflag);
113 void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
116 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
118 drawfontscale = hud_scale * sz;
119 vector dfs = drawfontscale;
120 drawfontscale = sz * '1 1 0';
121 float textaspect = stringwidth_builtin(text, false, theScale * (sz / drawfontscale.x)) / (theScale.x * sz);
123 drawstring(position + expandingbox_resize_centered_box_offset(sz, theScale, textaspect), text, HUD_Scale(theScale * (sz / drawfontscale.x)), rgb, theAlpha * (1 - fadelerp), flag);
125 // (scale_x * sz / drawfontscale.x) * drawfontscale.x * SIZE1 / (scale_x * sz)
127 drawfontscale = hud_scale;
130 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
131 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp) {
132 SET_POS_AND_SZ_Y_ASPECT(false);
133 drawstring_expanding(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag, fadelerp);
136 void drawcolorcodedstring_expanding(vector position, string text, vector theScale, float theAlpha, float flag, float fadelerp)
139 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
141 drawfontscale = hud_scale * sz;
142 // eventually replace with drawcolorcodedstring
143 drawcolorcodedstring(position + expandingbox_resize_centered_box_offset(sz, theScale, stringwidth_builtin(text, true, theScale * (sz / drawfontscale.x)) / (theScale.x * sz)), text, theScale * (sz / drawfontscale.x), theAlpha * (1 - fadelerp), flag);
144 drawfontscale = hud_scale;
147 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp) {
148 SET_POS_AND_SZ_Y_ASPECT(true);
149 drawcolorcodedstring_expanding(pos, text, '1 1 0' * sz.y, theAlpha, drawflag, fadelerp);
152 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
153 float PolyDrawModelSurface(entity e, float i_s)
159 tex = getsurfacetexture(e, i_s);
161 return 0; // this is beyond the last one
162 n_t = getsurfacenumtriangles(e, i_s);
163 for(i_t = 0; i_t < n_t; ++i_t)
165 tri = getsurfacetriangle(e, i_s, i_t);
166 R_BeginPolygon(tex, 0, false);
167 R_PolygonVertex(getsurfacepoint(e, i_s, tri.x), getsurfacepointattribute(e, i_s, tri.x, SPA_TEXCOORDS0), '1 1 1', 1);
168 R_PolygonVertex(getsurfacepoint(e, i_s, tri.y), getsurfacepointattribute(e, i_s, tri.y, SPA_TEXCOORDS0), '1 1 1', 1);
169 R_PolygonVertex(getsurfacepoint(e, i_s, tri.z), getsurfacepointattribute(e, i_s, tri.z, SPA_TEXCOORDS0), '1 1 1', 1);
174 void PolyDrawModel(entity e)
177 for(i_s = 0; ; ++i_s)
178 if(!PolyDrawModelSurface(e, i_s))
182 void DrawCircleClippedPic(vector centre, float radi, string pic, float f, vector rgb, float a, float drawflag)
184 vector ringsize, v, t;
185 ringsize = radi * '1 1 0';
186 centre = HUD_Shift(centre);
187 ringsize = HUD_Scale(ringsize);
191 // draw full rectangle
192 R_BeginPolygon(pic, drawflag, true);
193 v = centre; t = '0.5 0.5 0';
194 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
195 R_PolygonVertex(v, t, rgb, a);
197 v = centre; t = '0.5 0.5 0';
198 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
199 R_PolygonVertex(v, t, rgb, a);
201 v = centre; t = '0.5 0.5 0';
202 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
203 R_PolygonVertex(v, t, rgb, a);
205 v = centre; t = '0.5 0.5 0';
206 v.y -= 0.5 * ringsize.y; t -= '0.5 -0.5 0';
207 R_PolygonVertex(v, t, rgb, a);
209 return; // Complete rectangle, nothing more needed.
212 float co = cos(f * 2 * M_PI);
213 float si = sin(f * 2 * M_PI);
214 float q = fabs(co) + fabs(si);
220 // draw upper half in full
221 R_BeginPolygon(pic, drawflag, true);
222 v = centre; t = '0.5 0.5 0';
223 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
224 R_PolygonVertex(v, t, rgb, a);
226 v = centre; t = '0.5 0.5 0';
227 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
228 R_PolygonVertex(v, t, rgb, a);
230 v = centre; t = '0.5 0.5 0';
231 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
232 R_PolygonVertex(v, t, rgb, a);
234 // draw clipped lower half as a quad
235 R_BeginPolygon(pic, drawflag, true);
236 v = centre; t = '0.5 0.5 0';
237 R_PolygonVertex(v, t, rgb, a);
239 v = centre; t = '0.5 0.5 0';
240 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
241 R_PolygonVertex(v, t, rgb, a);
243 v = centre; t = '0.5 0.5 0';
244 v.y -= 0.5 * ringsize.y; t -= '0.5 -0.5 0';
245 R_PolygonVertex(v, t, rgb, a);
249 // draw upper half in full
250 R_BeginPolygon(pic, drawflag, true);
251 v = centre; t = '0.5 0.5 0';
252 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
253 R_PolygonVertex(v, t, rgb, a);
255 v = centre; t = '0.5 0.5 0';
256 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
257 R_PolygonVertex(v, t, rgb, a);
259 v = centre; t = '0.5 0.5 0';
260 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
261 R_PolygonVertex(v, t, rgb, a);
263 // draw clipped lower half as a triangle
264 R_BeginPolygon(pic, drawflag, true);
265 v = centre; t = '0.5 0.5 0';
266 R_PolygonVertex(v, t, rgb, a);
268 v = centre; t = '0.5 0.5 0';
269 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
270 R_PolygonVertex(v, t, rgb, a);
274 // draw clipped lower half as a quad
275 R_BeginPolygon(pic, drawflag, true);
276 v = centre; t = '0.5 0.5 0';
277 R_PolygonVertex(v, t, rgb, a);
279 v = centre; t = '0.5 0.5 0';
280 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
281 R_PolygonVertex(v, t, rgb, a);
283 v = centre; t = '0.5 0.5 0';
284 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
285 R_PolygonVertex(v, t, rgb, a);
289 // draw clipped lower half as a triangle
290 R_BeginPolygon(pic, drawflag, true);
291 v = centre; t = '0.5 0.5 0';
292 R_PolygonVertex(v, t, rgb, a);
294 v = centre; t = '0.5 0.5 0';
295 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
296 R_PolygonVertex(v, t, rgb, a);
304 // The last, moving vertex.
305 v = centre; t = '0.5 0.5 0';
306 v.x += co * 0.5 * ringsize.x; t += co * '0.5 0.5 0';
307 v.y += si * 0.5 * ringsize.y; t += si * '0.5 -0.5 0';
308 R_PolygonVertex(v, t, rgb, a);