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);
55 drawsubpic(boxToGlobal(theOrigin, draw_shift, draw_scale), boxToGlobalSize(theSize, draw_scale), pic, '0 0 0', '1 1 1', theColor, theAlpha * draw_alpha, 0);
58 // a button picture is a texture containing three parts:
59 // 1/4 width: left part
60 // 1/2 width: middle part (stretched)
61 // 1/4 width: right part
62 // it is assumed to be 4x as wide as high for aspect ratio purposes, which
63 // means, the parts are a square, two squares and a square.
64 void draw_ButtonPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha)
69 theOrigin = boxToGlobal(theOrigin, draw_shift, draw_scale);
70 theSize = boxToGlobalSize(theSize, draw_scale);
71 theAlpha *= draw_alpha;
72 width = eX * theSize_x;
73 height = eY * theSize_y;
74 if(theSize_x <= theSize_y * 2)
76 // button not wide enough
77 // draw just left and right part then
78 square = eX * theSize_x * 0.5;
79 bW = eX * (0.25 * theSize_x / (theSize_y * 2));
80 drawsubpic(theOrigin, square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, 0);
81 drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, 0);
85 square = eX * theSize_y;
86 drawsubpic(theOrigin, height + square, pic, '0 0 0', '0.25 1 0', theColor, theAlpha, 0);
87 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0.25 0 0', '0.5 1 0', theColor, theAlpha, 0);
88 drawsubpic(theOrigin + width - square, height + square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, 0);
92 // a vertical button picture is a texture containing three parts:
93 // 1/4 height: left part
94 // 1/2 height: middle part (stretched)
95 // 1/4 height: right part
96 // it is assumed to be 4x as high as wide for aspect ratio purposes, which
97 // means, the parts are a square, two squares and a square.
98 void draw_VertButtonPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha)
101 vector width, height;
103 theOrigin = boxToGlobal(theOrigin, draw_shift, draw_scale);
104 theSize = boxToGlobalSize(theSize, draw_scale);
105 theAlpha *= draw_alpha;
106 width = eX * theSize_x;
107 height = eY * theSize_y;
108 if(theSize_y <= theSize_x * 2)
110 // button not high enough
111 // draw just upper and lower part then
112 square = eY * theSize_y * 0.5;
113 bH = eY * (0.25 * theSize_y / (theSize_x * 2));
114 drawsubpic(theOrigin, square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, 0);
115 drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, 0);
119 square = eY * theSize_x;
120 drawsubpic(theOrigin, width + square, pic, '0 0 0', '1 0.25 0', theColor, theAlpha, 0);
121 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5 0', theColor, theAlpha, 0);
122 drawsubpic(theOrigin + height - square, width + square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, 0);
126 // a border picture is a texture containing nine parts:
127 // 1/4 width: left part
128 // 1/2 width: middle part (stretched)
129 // 1/4 width: right part
131 // 1/4 height: top part
132 // 1/2 height: middle part (stretched)
133 // 1/4 height: bottom part
134 void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize)
137 vector width, height;
139 theOrigin = boxToGlobal(theOrigin, draw_shift, draw_scale);
140 theSize = boxToGlobalSize(theSize, draw_scale);
141 theBorderSize = boxToGlobalSize(theBorderSize, draw_scale);
142 theAlpha *= draw_alpha;
143 width = eX * theSize_x;
144 height = eY * theSize_y;
145 if(theSize_x <= theBorderSize_x * 2)
147 // not wide enough... draw just left and right then
148 bW = eX * (0.25 * theSize_x / (theBorderSize_x * 2));
149 if(theSize_y <= theBorderSize_y * 2)
151 // not high enough... draw just corners
152 bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
153 drawsubpic(theOrigin, width * 0.5 + height * 0.5, pic, '0 0 0', bW + bH, theColor, theAlpha, 0);
154 drawsubpic(theOrigin + width * 0.5, width * 0.5 + height * 0.5, pic, eX - bW, bW + bH, theColor, theAlpha, 0);
155 drawsubpic(theOrigin + height * 0.5, width * 0.5 + height * 0.5, pic, eY - bH, bW + bH, theColor, theAlpha, 0);
156 drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0);
160 dY = theBorderSize_x * eY;
161 drawsubpic(theOrigin, width * 0.5 + dY, pic, '0 0 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
162 drawsubpic(theOrigin + width * 0.5, width * 0.5 + dY, pic, '0 0 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
163 drawsubpic(theOrigin + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0', '0 0.5 0' + bW, theColor, theAlpha, 0);
164 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);
165 drawsubpic(theOrigin + height - dY, width * 0.5 + dY, pic, '0 0.75 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
166 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);
171 if(theSize_y <= theBorderSize_y * 2)
173 // not high enough... draw just top and bottom then
174 bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
175 dX = theBorderSize_x * eX;
176 drawsubpic(theOrigin, dX + height * 0.5, pic, '0 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
177 drawsubpic(theOrigin + dX, width - 2 * dX + height * 0.5, pic, '0.25 0 0', '0.5 0 0' + bH, theColor, theAlpha, 0);
178 drawsubpic(theOrigin + width - dX, dX + height * 0.5, pic, '0.75 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
179 drawsubpic(theOrigin + height * 0.5, dX + height * 0.5, pic, '0 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
180 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);
181 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);
185 dX = theBorderSize_x * eX;
186 dY = theBorderSize_x * eY;
187 drawsubpic(theOrigin, dX + dY, pic, '0 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
188 drawsubpic(theOrigin + dX, width - 2 * dX + dY, pic, '0.25 0 0', '0.5 0.25 0', theColor, theAlpha, 0);
189 drawsubpic(theOrigin + width - dX, dX + dY, pic, '0.75 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
190 drawsubpic(theOrigin + dY, dX + height - 2 * dY, pic, '0 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
191 drawsubpic(theOrigin + dY + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
192 drawsubpic(theOrigin + dY + width - dX, dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
193 drawsubpic(theOrigin + height - dY, dX + dY, pic, '0 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
194 drawsubpic(theOrigin + height - dY + dX, width - 2 * dX + dY, pic, '0.25 0.75 0', '0.5 0.25 0', theColor, theAlpha, 0);
195 drawsubpic(theOrigin + height - dY + width - dX, dX + dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
199 void draw_Text(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha)
201 if(theSize_x <= 0 || theSize_y <= 0)
202 error("Drawing zero size text?\n");
203 drawstring(boxToGlobal(theOrigin, draw_shift, draw_scale), theText, boxToGlobalSize(theSize, draw_scale), theColor, theAlpha * draw_alpha, 0);
206 float draw_TextWidth(string theText)
208 //return strlen(theText);
209 //print("draw_TextWidth \"", theText, "\"\n");
210 return stringwidth(theText, 0);