2 string draw_mousepointer;
4 void draw_setMousePointer(string pic)
6 draw_mousepointer = pic;
9 void draw_drawMousePointer(vector where)
11 drawpic(boxToGlobal(where, draw_shift, draw_scale), draw_mousepointer, '32 32 0', '1 1 1', draw_alpha, 0);
18 draw_scale = '1 0 0' * cvar("vid_conwidth") + '0 1 0' * cvar("vid_conheight");
22 vector globalToBox(vector v, vector theOrigin, vector theScale)
30 vector globalToBoxSize(vector v, vector theScale)
37 vector boxToGlobal(vector v, vector theOrigin, vector theScale)
45 vector boxToGlobalSize(vector v, vector theScale)
52 void draw_Picture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha)
54 drawpic(boxToGlobal(theOrigin, draw_shift, draw_scale), pic, boxToGlobalSize(theSize, draw_scale), theColor, theAlpha * draw_alpha, 0);
57 // a button picture is a texture containing three parts:
58 // 1/4 width: left part
59 // 1/2 width: middle part (stretched)
60 // 1/4 width: right part
61 // it is assumed to be 4x as wide as high for aspect ratio purposes, which
62 // means, the parts are a square, two squares and a square.
63 void draw_ButtonPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha)
68 theOrigin = boxToGlobal(theOrigin, draw_shift, draw_scale);
69 theSize = boxToGlobalSize(theSize, draw_scale);
70 theAlpha *= draw_alpha;
71 width = eX * theSize_x;
72 height = eY * theSize_y;
73 if(theSize_x <= theSize_y * 2)
75 // button not wide enough
76 // draw just left and right part then
77 square = eX * theSize_x * 0.5;
78 bW = eX * (0.25 * theSize_x / (theSize_y * 2));
79 drawsubpic(theOrigin, square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, 0);
80 drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, 0);
84 square = eX * theSize_y;
85 drawsubpic(theOrigin, height + square, pic, '0 0 0', '0.25 1 0', theColor, theAlpha, 0);
86 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0.25 0 0', '0.5 1 0', theColor, theAlpha, 0);
87 drawsubpic(theOrigin + width - square, height + square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, 0);
91 // a vertical button picture is a texture containing three parts:
92 // 1/4 height: left part
93 // 1/2 height: middle part (stretched)
94 // 1/4 height: right part
95 // it is assumed to be 4x as high as wide for aspect ratio purposes, which
96 // means, the parts are a square, two squares and a square.
97 void draw_VertButtonPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha)
100 vector width, height;
102 theOrigin = boxToGlobal(theOrigin, draw_shift, draw_scale);
103 theSize = boxToGlobalSize(theSize, draw_scale);
104 theAlpha *= draw_alpha;
105 width = eX * theSize_x;
106 height = eY * theSize_y;
107 if(theSize_y <= theSize_x * 2)
109 // button not high enough
110 // draw just upper and lower part then
111 square = eY * theSize_y * 0.5;
112 bH = eY * (0.25 * theSize_y / (theSize_x * 2));
113 drawsubpic(theOrigin, square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, 0);
114 drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, 0);
118 square = eY * theSize_x;
119 drawsubpic(theOrigin, width + square, pic, '0 0 0', '1 0.25 0', theColor, theAlpha, 0);
120 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5 0', theColor, theAlpha, 0);
121 drawsubpic(theOrigin + height - square, width + square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, 0);
125 // a border picture is a texture containing nine parts:
126 // 1/4 width: left part
127 // 1/2 width: middle part (stretched)
128 // 1/4 width: right part
130 // 1/4 height: top part
131 // 1/2 height: middle part (stretched)
132 // 1/4 height: bottom part
133 void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize)
136 vector width, height;
138 theOrigin = boxToGlobal(theOrigin, draw_shift, draw_scale);
139 theSize = boxToGlobalSize(theSize, draw_scale);
140 theBorderSize = boxToGlobalSize(theBorderSize, draw_scale);
141 theAlpha *= draw_alpha;
142 width = eX * theSize_x;
143 height = eY * theSize_y;
144 if(theSize_x <= theBorderSize_x * 2)
146 // not wide enough... draw just left and right then
147 bW = eX * (0.25 * theSize_x / (theBorderSize_x * 2));
148 if(theSize_y <= theBorderSize_y * 2)
150 // not high enough... draw just corners
151 bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
152 drawsubpic(theOrigin, width * 0.5 + height * 0.5, pic, '0 0 0', bW + bH, theColor, theAlpha, 0);
153 drawsubpic(theOrigin + width * 0.5, width * 0.5 + height * 0.5, pic, eX - bW, bW + bH, theColor, theAlpha, 0);
154 drawsubpic(theOrigin + height * 0.5, width * 0.5 + height * 0.5, pic, eY - bH, bW + bH, theColor, theAlpha, 0);
155 drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0);
159 dY = theBorderSize_x * eY;
160 drawsubpic(theOrigin, width * 0.5 + dY, pic, '0 0 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
161 drawsubpic(theOrigin + width * 0.5, width * 0.5 + dY, pic, '0 0 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
162 drawsubpic(theOrigin + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0', '0 0.5 0' + bW, theColor, theAlpha, 0);
163 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);
164 drawsubpic(theOrigin + height - dY, width * 0.5 + dY, pic, '0 0.75 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
165 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);
170 if(theSize_y <= theBorderSize_y * 2)
172 // not high enough... draw just top and bottom then
173 bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
174 dX = theBorderSize_x * eX;
175 drawsubpic(theOrigin, dX + height * 0.5, pic, '0 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
176 drawsubpic(theOrigin + dX, width - 2 * dX + height * 0.5, pic, '0.25 0 0', '0.5 0 0' + bH, theColor, theAlpha, 0);
177 drawsubpic(theOrigin + width - dX, dX + height * 0.5, pic, '0.75 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
178 drawsubpic(theOrigin + height * 0.5, dX + height * 0.5, pic, '0 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
179 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);
180 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);
184 dX = theBorderSize_x * eX;
185 dY = theBorderSize_x * eY;
186 drawsubpic(theOrigin, dX + dY, pic, '0 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
187 drawsubpic(theOrigin + dX, width - 2 * dX + dY, pic, '0.25 0 0', '0.5 0.25 0', theColor, theAlpha, 0);
188 drawsubpic(theOrigin + width - dX, dX + dY, pic, '0.75 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
189 drawsubpic(theOrigin + dY, dX + height - 2 * dY, pic, '0 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
190 drawsubpic(theOrigin + dY + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
191 drawsubpic(theOrigin + dY + width - dX, dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
192 drawsubpic(theOrigin + height - dY, dX + dY, pic, '0 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
193 drawsubpic(theOrigin + height - dY + dX, width - 2 * dX + dY, pic, '0.25 0.75 0', '0.5 0.25 0', theColor, theAlpha, 0);
194 drawsubpic(theOrigin + height - dY + width - dX, dX + dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
198 void draw_Text(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha)
200 if(theSize_x <= 0 || theSize_y <= 0)
201 error("Drawing zero size text?\n");
202 drawstring(boxToGlobal(theOrigin, draw_shift, draw_scale), theText, boxToGlobalSize(theSize, draw_scale), theColor, theAlpha * draw_alpha, 0);
205 float draw_TextWidth(string theText)
207 //return strlen(theText);
208 //print("draw_TextWidth \"", theText, "\"\n");
209 return stringwidth(theText, 0);