]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/draw.qh
Merge branch 'master' into TimePath/unified_weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / draw.qh
1 #ifdef CSQC
2 #ifndef DRAW_H
3 #define DRAW_H
4
5 #include "i18n.qh"
6 #include "vector.qh"
7
8 #include "../client/defs.qh"
9
10 void Draw_CylindricLine(vector from, vector to, float thickness, string texture, float aspect, float shift, vector rgb, float theAlpha, float drawflag, vector vieworg)
11 {
12         // I want to draw a quad...
13         // from and to are MIDPOINTS.
14
15         vector axis, thickdir, A, B, C, D;
16         float length_tex;
17
18         axis = normalize(to - from);
19         length_tex = aspect * vlen(to - from) / thickness;
20
21         // direction is perpendicular to the view normal, and perpendicular to the axis
22         thickdir = normalize(cross(axis, vieworg - from));
23
24         A = from - thickdir * (thickness / 2);
25         B = from + thickdir * (thickness / 2);
26         C = to + thickdir * (thickness / 2);
27         D = to - thickdir * (thickness / 2);
28
29         R_BeginPolygon(texture, drawflag);
30         R_PolygonVertex(A, '0 0 0' + shift * '1 0 0', rgb, theAlpha);
31         R_PolygonVertex(B, '0 1 0' + shift * '1 0 0', rgb, theAlpha);
32         R_PolygonVertex(C, '0 1 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
33         R_PolygonVertex(D, '0 0 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
34         R_EndPolygon();
35 }
36
37 // a border picture is a texture containing nine parts:
38 //   1/4 width: left part
39 //   1/2 width: middle part (stretched)
40 //   1/4 width: right part
41 // divided into
42 //   1/4 height: top part
43 //   1/2 height: middle part (stretched)
44 //   1/4 height: bottom part
45 void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize)
46 {
47     if (theBorderSize.x < 0 && theBorderSize.y < 0) // draw whole image as it is
48     {
49                 drawpic(theOrigin, pic, theSize, theColor, theAlpha, 0);
50                 return;
51     }
52         if (theBorderSize.x == 0 && theBorderSize.y == 0) // no border
53         {
54                 // draw only the central part
55                 drawsubpic(theOrigin, theSize, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
56                 return;
57         }
58
59         vector dX, dY;
60         vector width, height;
61         vector bW, bH;
62         //pic = draw_UseSkinFor(pic);
63         width = eX * theSize.x;
64         height = eY * theSize.y;
65         if(theSize.x <= theBorderSize.x * 2)
66         {
67                 // not wide enough... draw just left and right then
68                 bW = eX * (0.25 * theSize.x / (theBorderSize.x * 2));
69                 if(theSize.y <= theBorderSize.y * 2)
70                 {
71                         // not high enough... draw just corners
72                         bH = eY * (0.25 * theSize.y / (theBorderSize.y * 2));
73                         drawsubpic(theOrigin,                 width * 0.5 + height * 0.5, pic, '0 0 0',           bW + bH, theColor, theAlpha, 0);
74                         drawsubpic(theOrigin + width   * 0.5, width * 0.5 + height * 0.5, pic, eX - bW,           bW + bH, theColor, theAlpha, 0);
75                         drawsubpic(theOrigin + height  * 0.5, width * 0.5 + height * 0.5, pic, eY - bH,           bW + bH, theColor, theAlpha, 0);
76                         drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0);
77                 }
78                 else
79                 {
80                         dY = theBorderSize.x * eY;
81                         drawsubpic(theOrigin,                             width * 0.5          +     dY, pic, '0 0    0',           '0 0.25 0' + bW, theColor, theAlpha, 0);
82                         drawsubpic(theOrigin + width * 0.5,               width * 0.5          +     dY, pic, '0 0    0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
83                         drawsubpic(theOrigin                        + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0',           '0 0.5  0' + bW, theColor, theAlpha, 0);
84                         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);
85                         drawsubpic(theOrigin               + height - dY, width * 0.5          +     dY, pic, '0 0.75 0',           '0 0.25 0' + bW, theColor, theAlpha, 0);
86                         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);
87                 }
88         }
89         else
90         {
91                 if(theSize.y <= theBorderSize.y * 2)
92                 {
93                         // not high enough... draw just top and bottom then
94                         bH = eY * (0.25 * theSize.y / (theBorderSize.y * 2));
95                         dX = theBorderSize.x * eX;
96                         drawsubpic(theOrigin,                                         dX + height * 0.5, pic, '0    0 0',           '0.25 0 0' + bH, theColor, theAlpha, 0);
97                         drawsubpic(theOrigin + dX,                        width - 2 * dX + height * 0.5, pic, '0.25 0 0',           '0.5  0 0' + bH, theColor, theAlpha, 0);
98                         drawsubpic(theOrigin + width - dX,                            dX + height * 0.5, pic, '0.75 0 0',           '0.25 0 0' + bH, theColor, theAlpha, 0);
99                         drawsubpic(theOrigin              + height * 0.5,             dX + height * 0.5, pic, '0    0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
100                         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);
101                         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);
102                 }
103                 else
104                 {
105                         dX = theBorderSize.x * eX;
106                         dY = theBorderSize.x * eY;
107                         drawsubpic(theOrigin,                                        dX          +     dY, pic, '0    0    0', '0.25 0.25 0', theColor, theAlpha, 0);
108                         drawsubpic(theOrigin                  + dX,      width - 2 * dX          +     dY, pic, '0.25 0    0', '0.5  0.25 0', theColor, theAlpha, 0);
109                         drawsubpic(theOrigin          + width - dX,                  dX          +     dY, pic, '0.75 0    0', '0.25 0.25 0', theColor, theAlpha, 0);
110                         drawsubpic(theOrigin          + dY,                          dX + height - 2 * dY, pic, '0    0.25 0', '0.25 0.5  0', theColor, theAlpha, 0);
111                         drawsubpic(theOrigin          + dY         + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5  0.5  0', theColor, theAlpha, 0);
112                         drawsubpic(theOrigin          + dY + width - dX,             dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5  0', theColor, theAlpha, 0);
113                         drawsubpic(theOrigin + height - dY,                          dX          +     dY, pic, '0    0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
114                         drawsubpic(theOrigin + height - dY         + dX, width - 2 * dX          +     dY, pic, '0.25 0.75 0', '0.5  0.25 0', theColor, theAlpha, 0);
115                         drawsubpic(theOrigin + height - dY + width - dX,             dX          +     dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
116                 }
117         }
118 }
119
120 void drawstringright(vector position, string text, vector theScale, vector rgb, float theAlpha, int flag)
121 {
122         position.x -= 2 / 3 * strlen(text) * theScale.x;
123         drawstring(position, text, theScale, rgb, theAlpha, flag);
124 }
125
126 void drawstringcenter(vector position, string text, vector theScale, vector rgb, float theAlpha, int flag)
127 {
128         position.x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * theScale.x);
129         drawstring(position, text, theScale, rgb, theAlpha, flag);
130 }
131
132 #endif
133 #endif