]> icculus.org git repositories - divverent/nexuiz.git/blob - qcsrc/menu-div0test/draw.qc
first attempt at teamselect dialog... not good yet (need a better way to implement...
[divverent/nexuiz.git] / 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         drawsubpic(boxToGlobal(theOrigin, draw_shift, draw_scale), boxToGlobalSize(theSize, draw_scale), pic, '0 0 0', '1 1 1', theColor, theAlpha * draw_alpha, 0);
56 }
57
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)
65 {
66         vector square;
67         vector width, height;
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                 drawsubpic(theOrigin,          square + height, pic, '0   0 0', '0.25 1 0', theColor, theAlpha, 0);
79                 drawsubpic(theOrigin + square, square + height, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, 0);
80         }
81         else
82         {
83                 square = theSize_y * '1 0 0';
84                 drawsubpic(theOrigin,                  height  +     square, pic, '0    0 0', '0.25 1 0', theColor, theAlpha, 0);
85                 drawsubpic(theOrigin +         square, theSize - 2 * square, pic, '0.25 0 0', '0.5  1 0', theColor, theAlpha, 0);
86                 drawsubpic(theOrigin + width - square, height  +     square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, 0);
87         }
88 }
89
90 // a border picture is a texture containing nine parts:
91 //   1/4 width: left part
92 //   1/2 width: middle part (stretched)
93 //   1/4 width: right part
94 // divided into
95 //   1/4 height: top part
96 //   1/2 height: middle part (stretched)
97 //   1/4 height: bottom part
98 void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize)
99 {
100         vector dX, dY;
101         vector width, height;
102         theOrigin = boxToGlobal(theOrigin, draw_shift, draw_scale);
103         theSize = boxToGlobalSize(theSize, draw_scale);
104         theBorderSize = boxToGlobalSize(theBorderSize, draw_scale);
105         theAlpha *= draw_alpha;
106         width = eX * theSize_x;
107         height = eY * theSize_y;
108         if(theSize_x <= theBorderSize_x * 2)
109         {
110                 // not wide enough... draw just left and right then
111                 if(theSize_y <= theBorderSize_y * 2)
112                 {
113                         // not high enough... draw just corners
114                         drawsubpic(theOrigin,                 width * 0.5 + height * 0.5, pic, '0    0    0', '0.25 0.25 0', theColor, theAlpha, 0);
115                         drawsubpic(theOrigin + width   * 0.5, width * 0.5 + height * 0.5, pic, '0.75 0    0', '0.25 0.25 0', theColor, theAlpha, 0);
116                         drawsubpic(theOrigin + height  * 0.5, width * 0.5 + height * 0.5, pic, '0    0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
117                         drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
118                 }
119                 else
120                 {
121                         dY = theBorderSize_x * eY;
122                         drawsubpic(theOrigin,                      width * 0.5          +     dY, pic, '0    0    0', '0.25 0.25 0', theColor, theAlpha, 0);
123                         drawsubpic(theOrigin + width   * 0.5,      width * 0.5          +     dY, pic, '0.75 0    0', '0.25 0.25 0', theColor, theAlpha, 0);
124                         drawsubpic(theOrigin                 + dY, width * 0.5 + height - 2 * dY, pic, '0    0.25 0', '0.25 0.5  0', theColor, theAlpha, 0);
125                         drawsubpic(theOrigin + width   * 0.5 + dY, width * 0.5 + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5  0', theColor, theAlpha, 0);
126                         drawsubpic(theOrigin + height        - dY, width * 0.5          +     dY, pic, '0    0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
127                         drawsubpic(theOrigin + width   * 0.5 + dY, width * 0.5          +     dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
128                 }
129         }
130         else
131         {
132                 if(theSize_y <= theBorderSize_y * 2)
133                 {
134                         // not high enough... draw just top and bottom then
135                         dX = theBorderSize_x * eX;
136                         drawsubpic(theOrigin,                                         dX + height * 0.5, pic, '0    0    0', '0.25 0.25 0', theColor, theAlpha, 0);
137                         drawsubpic(theOrigin + dX,                        width - 2 * dX + height * 0.5, pic, '0.25 0    0', '0.5  0.25 0', theColor, theAlpha, 0);
138                         drawsubpic(theOrigin + width - dX,                            dX + height * 0.5, pic, '0.75 0    0', '0.25 0.25 0', theColor, theAlpha, 0);
139                         drawsubpic(theOrigin              + height * 0.5,             dX + height * 0.5, pic, '0    0    0', '0.25 0.25 0', theColor, theAlpha, 0);
140                         drawsubpic(theOrigin + dX         + height * 0.5, width - 2 * dX + height * 0.5, pic, '0.25 0    0', '0.5  0.25 0', theColor, theAlpha, 0);
141                         drawsubpic(theOrigin + width - dX + height * 0.5,             dX + height * 0.5, pic, '0.75 0    0', '0.25 0.25 0', theColor, theAlpha, 0);
142                 }
143                 else
144                 {
145                         dX = theBorderSize_x * eX;
146                         dY = theBorderSize_x * eY;
147                         drawsubpic(theOrigin,                                        dX          +     dY, pic, '0    0    0', '0.25 0.25 0', theColor, theAlpha, 0);
148                         drawsubpic(theOrigin                  + dX,      width - 2 * dX          +     dY, pic, '0.25 0    0', '0.5  0.25 0', theColor, theAlpha, 0);
149                         drawsubpic(theOrigin          + width - dX,                  dX          +     dY, pic, '0.75 0    0', '0.25 0.25 0', theColor, theAlpha, 0);
150                         drawsubpic(theOrigin          + dY,                          dX + height - 2 * dY, pic, '0    0.25 0', '0.25 0.5  0', theColor, theAlpha, 0);
151                         drawsubpic(theOrigin          + dY         + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5  0.5  0', theColor, theAlpha, 0);
152                         drawsubpic(theOrigin          + dY + width - dX,             dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5  0', theColor, theAlpha, 0);
153                         drawsubpic(theOrigin + height - dY,                          dX          +     dY, pic, '0    0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
154                         drawsubpic(theOrigin + height - dY         + dX, width - 2 * dX          +     dY, pic, '0.25 0.75 0', '0.5  0.25 0', theColor, theAlpha, 0);
155                         drawsubpic(theOrigin + height - dY + width - dX,             dX          +     dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
156                 }
157         }
158 }
159 void draw_Text(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha)
160 {
161         if(theSize_x <= 0 || theSize_y <= 0)
162                 error("Drawing zero size text?\n");
163         drawstring(boxToGlobal(theOrigin, draw_shift, draw_scale), theText, boxToGlobalSize(theSize, draw_scale), theColor, theAlpha * draw_alpha, 0);
164 }
165
166 float draw_TextWidth(string theText)
167 {
168         //return strlen(theText);
169         //print("draw_TextWidth \"", theText, "\"\n");
170         return stringwidth(theText, 0);
171 }