1 string draw_mousepointer;
2 vector draw_mousepointer_offset;
3 vector draw_mousepointer_size;
5 void draw_setMousePointer(string pic, vector theSize, vector theOffset)
7 draw_mousepointer = strzone(draw_UseSkinFor(pic));
8 draw_mousepointer_size = theSize;
9 draw_mousepointer_offset = eX * (theOffset.x * theSize.x) + eY * (theOffset.y * theSize.y);
12 void draw_drawMousePointer(vector where)
14 drawpic(boxToGlobal(where, draw_shift, draw_scale) - draw_mousepointer_offset, draw_mousepointer, draw_mousepointer_size, '1 1 1', draw_alpha, 0);
17 void draw_reset(float cw, float ch, float ox, float oy)
19 draw_shift = '1 0 0' * ox + '0 1 0' * oy;
20 draw_scale = '1 0 0' * cw + '0 1 0' * ch;
22 draw_fontscale = '1 1 0';
26 void draw_beginBoldFont()
28 drawfont = FONT_USER+3;
31 void draw_endBoldFont()
33 drawfont = FONT_USER+0;
36 vector globalToBox(vector v, vector theOrigin, vector theScale)
44 vector globalToBoxSize(vector v, vector theScale)
51 vector boxToGlobal(vector v, vector theOrigin, vector theScale)
59 vector boxToGlobalSize(vector v, vector theScale)
66 string draw_PreloadPicture(string pic)
68 pic = draw_UseSkinFor(pic);
69 return precache_pic(pic);
72 string draw_PreloadPictureWithFlags(string pic, float f)
74 pic = draw_UseSkinFor(pic);
75 return precache_pic(pic, f);
78 void draw_Picture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha)
80 if(theSize_x == 0 || theSize.y <= 0) // no default sizing please
82 pic = draw_UseSkinFor(pic);
83 drawpic(boxToGlobal(theOrigin, draw_shift, draw_scale), pic, boxToGlobalSize(theSize, draw_scale), theColor, theAlpha * draw_alpha, 0);
86 vector draw_PictureSize(string pic)
88 pic = draw_UseSkinFor(pic);
89 return drawgetimagesize(pic);
92 void draw_Fill(vector theOrigin, vector theSize, vector theColor, float theAlpha)
94 drawfill(boxToGlobal(theOrigin, draw_shift, draw_scale), boxToGlobalSize(theSize, draw_scale), theColor, theAlpha * draw_alpha, 0);
97 // a button picture is a texture containing three parts:
98 // 1/4 width: left part
99 // 1/2 width: middle part (stretched)
100 // 1/4 width: right part
101 // it is assumed to be 4x as wide as high for aspect ratio purposes, which
102 // means, the parts are a square, two squares and a square.
103 void draw_ButtonPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha)
106 vector width, height;
108 pic = draw_UseSkinFor(pic);
109 theOrigin = boxToGlobal(theOrigin, draw_shift, draw_scale);
110 theSize = boxToGlobalSize(theSize, draw_scale);
111 theAlpha *= draw_alpha;
112 width = eX * theSize.x;
113 height = eY * theSize.y;
114 if(theSize.x <= theSize.y * 2)
116 // button not wide enough
117 // draw just left and right part then
118 square = eX * theSize.x * 0.5;
119 bW = eX * (0.25 * theSize.x / (theSize.y * 2));
120 drawsubpic(theOrigin, square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, 0);
121 drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, 0);
125 square = eX * theSize.y;
126 drawsubpic(theOrigin, height + square, pic, '0 0 0', '0.25 1 0', theColor, theAlpha, 0);
127 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0.25 0 0', '0.5 1 0', theColor, theAlpha, 0);
128 drawsubpic(theOrigin + width - square, height + square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, 0);
132 // a vertical button picture is a texture containing three parts:
133 // 1/4 height: left part
134 // 1/2 height: middle part (stretched)
135 // 1/4 height: right part
136 // it is assumed to be 4x as high as wide for aspect ratio purposes, which
137 // means, the parts are a square, two squares and a square.
138 void draw_VertButtonPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha)
141 vector width, height;
143 pic = draw_UseSkinFor(pic);
144 theOrigin = boxToGlobal(theOrigin, draw_shift, draw_scale);
145 theSize = boxToGlobalSize(theSize, draw_scale);
146 theAlpha *= draw_alpha;
147 width = eX * theSize.x;
148 height = eY * theSize.y;
149 if(theSize.y <= theSize.x * 2)
151 // button not high enough
152 // draw just upper and lower part then
153 square = eY * theSize.y * 0.5;
154 bH = eY * (0.25 * theSize.y / (theSize.x * 2));
155 drawsubpic(theOrigin, square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, 0);
156 drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, 0);
160 square = eY * theSize.x;
161 drawsubpic(theOrigin, width + square, pic, '0 0 0', '1 0.25 0', theColor, theAlpha, 0);
162 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5 0', theColor, theAlpha, 0);
163 drawsubpic(theOrigin + height - square, width + square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, 0);
167 // a border picture is a texture containing nine parts:
168 // 1/4 width: left part
169 // 1/2 width: middle part (stretched)
170 // 1/4 width: right part
172 // 1/4 height: top part
173 // 1/2 height: middle part (stretched)
174 // 1/4 height: bottom part
175 void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize)
178 vector width, height;
180 pic = draw_UseSkinFor(pic);
181 theOrigin = boxToGlobal(theOrigin, draw_shift, draw_scale);
182 theSize = boxToGlobalSize(theSize, draw_scale);
183 theBorderSize = boxToGlobalSize(theBorderSize, draw_scale);
184 theAlpha *= draw_alpha;
185 width = eX * theSize.x;
186 height = eY * theSize.y;
187 // zero size? bail out, we cannot handle this
188 if(theSize.x <= 0 || theSize.y <= 0)
190 if(theBorderSize.x <= 0) // no x border
192 if(theBorderSize.y <= 0)
194 drawsubpic(theOrigin, width + height, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
196 else if(theSize.y <= theBorderSize.y * 2)
198 // not high enough... draw just top and bottom then
199 bH = eY * (0.25 * theSize.y / (theBorderSize.y * 2));
200 drawsubpic(theOrigin, width + height * 0.5, pic, '0.25 0 0', '0.5 0 0' + bH, theColor, theAlpha, 0);
201 drawsubpic(theOrigin + height * 0.5, width + height * 0.5, pic, '0.25 0 0' + eY - bH, '0.5 0 0' + bH, theColor, theAlpha, 0);
205 dY = theBorderSize.y * eY;
206 drawsubpic(theOrigin, width + dY, pic, '0.25 0 0', '0.5 0.25 0', theColor, theAlpha, 0);
207 drawsubpic(theOrigin + dY, width + height - 2 * dY, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
208 drawsubpic(theOrigin + height - dY, width + dY, pic, '0.25 0.75 0', '0.5 0.25 0', theColor, theAlpha, 0);
211 else if(theSize.x <= theBorderSize.x * 2)
213 // not wide enough... draw just left and right then
214 bW = eX * (0.25 * theSize.x / (theBorderSize.x * 2));
215 if(theBorderSize.y <= 0)
217 drawsubpic(theOrigin, width * 0.5 + height, pic, '0 0.25 0', '0 0.5 0' + bW, theColor, theAlpha, 0);
218 drawsubpic(theOrigin + width * 0.5, width * 0.5 + height, pic, '0 0.25 0' + eX - bW, '0 0.5 0' + bW, theColor, theAlpha, 0);
220 else if(theSize.y <= theBorderSize.y * 2)
222 // not high enough... draw just corners
223 bH = eY * (0.25 * theSize.y / (theBorderSize.y * 2));
224 drawsubpic(theOrigin, width * 0.5 + height * 0.5, pic, '0 0 0', bW + bH, theColor, theAlpha, 0);
225 drawsubpic(theOrigin + width * 0.5, width * 0.5 + height * 0.5, pic, eX - bW, bW + bH, theColor, theAlpha, 0);
226 drawsubpic(theOrigin + height * 0.5, width * 0.5 + height * 0.5, pic, eY - bH, bW + bH, theColor, theAlpha, 0);
227 drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0);
231 dY = theBorderSize.y * eY;
232 drawsubpic(theOrigin, width * 0.5 + dY, pic, '0 0 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
233 drawsubpic(theOrigin + width * 0.5, width * 0.5 + dY, pic, '0 0 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
234 drawsubpic(theOrigin + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0', '0 0.5 0' + bW, theColor, theAlpha, 0);
235 drawsubpic(theOrigin + width * 0.5 + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0' + eX - bW, '0 0.5 0' + bW, theColor, theAlpha, 0);
236 drawsubpic(theOrigin + height - dY, width * 0.5 + dY, pic, '0 0.75 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
237 drawsubpic(theOrigin + width * 0.5 + height - dY, width * 0.5 + dY, pic, '0 0.75 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
242 if(theBorderSize.y <= 0)
244 dX = theBorderSize.x * eX;
245 drawsubpic(theOrigin, dX + height, pic, '0 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
246 drawsubpic(theOrigin + dX, width - 2 * dX + height, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
247 drawsubpic(theOrigin + width - dX, dX + height, pic, '0.75 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
249 else if(theSize.y <= theBorderSize.y * 2)
251 // not high enough... draw just top and bottom then
252 bH = eY * (0.25 * theSize.y / (theBorderSize.y * 2));
253 dX = theBorderSize.x * eX;
254 drawsubpic(theOrigin, dX + height * 0.5, pic, '0 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
255 drawsubpic(theOrigin + dX, width - 2 * dX + height * 0.5, pic, '0.25 0 0', '0.5 0 0' + bH, theColor, theAlpha, 0);
256 drawsubpic(theOrigin + width - dX, dX + height * 0.5, pic, '0.75 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
257 drawsubpic(theOrigin + height * 0.5, dX + height * 0.5, pic, '0 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
258 drawsubpic(theOrigin + dX + height * 0.5, width - 2 * dX + height * 0.5, pic, '0.25 0 0' + eY - bH, '0.5 0 0' + bH, theColor, theAlpha, 0);
259 drawsubpic(theOrigin + width - dX + height * 0.5, dX + height * 0.5, pic, '0.75 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
263 dX = theBorderSize.x * eX;
264 dY = theBorderSize.y * eY;
265 drawsubpic(theOrigin, dX + dY, pic, '0 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
266 drawsubpic(theOrigin + dX, width - 2 * dX + dY, pic, '0.25 0 0', '0.5 0.25 0', theColor, theAlpha, 0);
267 drawsubpic(theOrigin + width - dX, dX + dY, pic, '0.75 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
268 drawsubpic(theOrigin + dY, dX + height - 2 * dY, pic, '0 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
269 drawsubpic(theOrigin + dY + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
270 drawsubpic(theOrigin + dY + width - dX, dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
271 drawsubpic(theOrigin + height - dY, dX + dY, pic, '0 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
272 drawsubpic(theOrigin + height - dY + dX, width - 2 * dX + dY, pic, '0.25 0.75 0', '0.5 0.25 0', theColor, theAlpha, 0);
273 drawsubpic(theOrigin + height - dY + width - dX, dX + dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
277 void draw_Text(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha, float ICanHasKallerz)
279 if(theSize.x <= 0 || theSize.y <= 0) {
280 dprint("Drawing zero size text?\n");
285 //wi = draw_TextWidth(theText, ICanHasKallerz, theSize);
286 //draw_Fill(theOrigin, '1 0 0' * wi + '0 1 0' * theSize_y, '1 0 0', 0.3);
289 drawcolorcodedstring(boxToGlobal(theOrigin, draw_shift, draw_scale), theText, globalToBoxSize(boxToGlobalSize(theSize, draw_scale), draw_fontscale), theAlpha * draw_alpha, 0);
291 drawstring(boxToGlobal(theOrigin, draw_shift, draw_scale), theText, globalToBoxSize(boxToGlobalSize(theSize, draw_scale), draw_fontscale), theColor, theAlpha * draw_alpha, 0);
293 void draw_CenterText(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha, float ICanHasKallerz)
295 //dprint(strcat("orig = ", vtos(theOrigin) ," tx = ", ftos(draw_TextWidth(theText, ICanHasKallerz, theSize)), "\n"));
296 draw_Text(theOrigin - eX * 0.5 * draw_TextWidth(theText, ICanHasKallerz, theSize), theText, theSize, theColor, theAlpha, ICanHasKallerz);
299 float draw_TextWidth(string theText, float ICanHasKallerz, vector SizeThxBye)
301 //return strlen(theText);
302 //dprint("draw_TextWidth \"", theText, "\"\n");
306 v_x = stringwidth(theText, ICanHasKallerz, globalToBoxSize(boxToGlobalSize(SizeThxBye, draw_scale), draw_fontscale));
307 v = globalToBoxSize(v, draw_scale);
311 float draw_CondensedFontFactor(string theText, float ICanHasKallerz, vector SizeThxBye, float maxWidth)
313 float w = draw_TextWidth(theText, ICanHasKallerz, SizeThxBye);
315 //dprintf("NOTE: label text %s too wide for label, condensed by factor %f\n", theText, maxWidth / w);
325 error("Already clipping, no stack implemented here, sorry");
326 drawsetcliparea(draw_shift.x, draw_shift.y, draw_scale.x, draw_scale.y);
330 void draw_SetClipRect(vector theOrigin, vector theScale)
334 error("Already clipping, no stack implemented here, sorry");
335 o = boxToGlobal(theOrigin, draw_shift, draw_scale);
336 s = boxToGlobalSize(theScale, draw_scale);
337 drawsetcliparea(o.x, o.y, s.x, s.y);
341 void draw_ClearClip()
344 error("Not clipping, can't clear it then");
349 string draw_TextShortenToWidth(string theText, float maxWidth, float ICanHasKallerz, vector SizeThxBye)
352 if(draw_TextWidth(theText, ICanHasKallerz, SizeThxBye) <= maxWidth)
355 return strcat(substring(theText, 0, draw_TextLengthUpToWidth(theText, maxWidth - draw_TextWidth("...", ICanHasKallerz, SizeThxBye), ICanHasKallerz, SizeThxBye)), "...");
358 return textShortenToWidth(theText, maxWidth, SizeThxBye, draw_TextWidth_WithColors);
360 return textShortenToWidth(theText, maxWidth, SizeThxBye, draw_TextWidth_WithoutColors);
363 float draw_TextWidth_WithColors(string s, vector theFontSize)
365 return draw_TextWidth(s, TRUE, theFontSize);
368 float draw_TextWidth_WithoutColors(string s, vector theFontSize)
370 return draw_TextWidth(s, FALSE, theFontSize);
373 float draw_TextLengthUpToWidth(string theText, float maxWidth, float allowColorCodes, vector theFontSize)
376 return textLengthUpToWidth(theText, maxWidth, theFontSize, draw_TextWidth_WithColors);
378 return textLengthUpToWidth(theText, maxWidth, theFontSize, draw_TextWidth_WithoutColors);