]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu-div0test/draw.qc
tabbed dialog
[divverent/nexuiz.git] / data / qcsrc / menu-div0test / draw.qc
1 float drawfont;
2 string draw_mousepointer;
3
4 void draw_setMousePointer(string pic)
5 {
6         draw_mousepointer = pic;
7 }
8
9 void draw_drawMousePointer(vector where)
10 {
11         drawpic(boxToGlobal(where, draw_shift, draw_scale), draw_mousepointer, '32 32 0', '1 1 1', draw_alpha, 0);
12 }
13
14 void draw_reset()
15 {
16         drawfont = 8;
17         draw_shift = '0 0 0';
18         draw_scale = '1 0 0' * cvar("vid_conwidth") + '0 1 0' * cvar("vid_conheight");
19         draw_alpha = 1;
20 }
21
22 vector globalToBox(vector v, vector theOrigin, vector theScale)
23 {
24         v -= theOrigin;
25         v_x /= theScale_x;
26         v_y /= theScale_y;
27         return v;
28 }
29
30 vector globalToBoxSize(vector v, vector theScale)
31 {
32         v_x /= theScale_x;
33         v_y /= theScale_y;
34         return v;
35 }
36
37 vector boxToGlobal(vector v, vector theOrigin, vector theScale)
38 {
39         v_x *= theScale_x;
40         v_y *= theScale_y;
41         v += theOrigin;
42         return v;
43 }
44
45 vector boxToGlobalSize(vector v, vector theScale)
46 {
47         v_x *= theScale_x;
48         v_y *= theScale_y;
49         return v;
50 }
51
52 void draw_Picture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha)
53 {
54         drawpic(boxToGlobal(theOrigin, draw_shift, draw_scale), pic, boxToGlobalSize(theSize, draw_scale), theColor, theAlpha * draw_alpha, 0);
55 }
56
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)
64 {
65         vector square;
66         vector width, height;
67         vector bW;
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)
74         {
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);
81         }
82         else
83         {
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);
88         }
89 }
90
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)
98 {
99         vector square;
100         vector width, height;
101         vector bH;
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)
108         {
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);
115         }
116         else
117         {
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);
122         }
123 }
124
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
129 // divided into
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)
134 {
135         vector dX, dY;
136         vector width, height;
137         vector bW, bH;
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)
145         {
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)
149                 {
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);
156                 }
157                 else
158                 {
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);
166                 }
167         }
168         else
169         {
170                 if(theSize_y <= theBorderSize_y * 2)
171                 {
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);
181                 }
182                 else
183                 {
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);
195                 }
196         }
197 }
198 void draw_Text(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha)
199 {
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);
203 }
204
205 float draw_TextWidth(string theText)
206 {
207         //return strlen(theText);
208         //print("draw_TextWidth \"", theText, "\"\n");
209         return stringwidth(theText, 0);
210 }