Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
draw.qh
Go to the documentation of this file.
1#pragma once
2
3#ifdef CSQC
4 #include "i18n.qh"
5 #include "vector.qh"
6
7 noref float vid_conwidth;
8 noref float vid_conheight;
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 float len = vlen(to - from);
16 if (!len)
17 return;
18
19 float length_tex = aspect * len / thickness;
20 vector axis = (to - from) / len; // same as axis = normalize(to - from) but cheaper
21
22 // direction is perpendicular to the view normal, and perpendicular to the axis
23 vector thickdir = normalize(cross(axis, vieworg - from));
24
25 vector ofs = thickdir * (thickness * 0.5);
26
27 R_BeginPolygon(texture, drawflag, false);
28 R_PolygonVertex(from - ofs, '0 0 0' + shift * '1 0 0', rgb, theAlpha);
29 R_PolygonVertex(from + ofs, '0 1 0' + shift * '1 0 0', rgb, theAlpha);
30 R_PolygonVertex(to + ofs, '0 1 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
31 R_PolygonVertex(to - ofs, '0 0 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
32 R_EndPolygon();
33 }
34
35// a border picture is a texture containing nine parts:
36// 1/4 width: left part
37// 1/2 width: middle part (stretched)
38// 1/4 width: right part
39// divided into
40// 1/4 height: top part
41// 1/2 height: middle part (stretched)
42// 1/4 height: bottom part
43 void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize)
44 {
45 if (theBorderSize.x < 0 && theBorderSize.y < 0) // draw whole image as it is
46 {
47 drawpic_builtin(theOrigin, pic, theSize, theColor, theAlpha, 0);
48 return;
49 }
50 if (theBorderSize.x == 0 && theBorderSize.y == 0) // no border
51 {
52 // draw only the central part
53 drawsubpic(theOrigin, theSize, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
54 return;
55 }
56
57 vector dX, dY;
58 vector width, height;
59 vector bW, bH;
60 // pic = draw_UseSkinFor(pic);
61 width = eX * theSize.x;
62 height = eY * theSize.y;
63 if (theSize.x <= theBorderSize.x * 2)
64 {
65 // not wide enough... draw just left and right then
66 bW = eX * (0.25 * theSize.x / (theBorderSize.x * 2));
67 if (theSize.y <= theBorderSize.y * 2)
68 {
69 // not high enough... draw just corners
70 bH = eY * (0.25 * theSize.y / (theBorderSize.y * 2));
71 drawsubpic(theOrigin, width * 0.5 + height * 0.5, pic, '0 0 0', bW + bH, theColor, theAlpha, 0);
72 drawsubpic(theOrigin + width * 0.5, width * 0.5 + height * 0.5, pic, eX - bW, bW + bH, theColor, theAlpha, 0);
73 drawsubpic(theOrigin + height * 0.5, width * 0.5 + height * 0.5, pic, eY - bH, bW + bH, theColor, theAlpha, 0);
74 drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0);
75 }
76 else
77 {
78 dY = theBorderSize.x * eY;
79 drawsubpic(theOrigin, width * 0.5 + dY, pic, '0 0 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
80 drawsubpic(theOrigin + width * 0.5, width * 0.5 + dY, pic, '0 0 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
81 drawsubpic(theOrigin + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0', '0 0.5 0' + bW, theColor, theAlpha, 0);
82 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);
83 drawsubpic(theOrigin + height - dY, width * 0.5 + dY, pic, '0 0.75 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
84 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);
85 }
86 }
87 else
88 {
89 if (theSize.y <= theBorderSize.y * 2)
90 {
91 // not high enough... draw just top and bottom then
92 bH = eY * (0.25 * theSize.y / (theBorderSize.y * 2));
93 dX = theBorderSize.x * eX;
94 drawsubpic(theOrigin, dX + height * 0.5, pic, '0 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
95 drawsubpic(theOrigin + dX, width - 2 * dX + height * 0.5, pic, '0.25 0 0', '0.5 0 0' + bH, theColor, theAlpha, 0);
96 drawsubpic(theOrigin + width - dX, dX + height * 0.5, pic, '0.75 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
97 drawsubpic(theOrigin + height * 0.5, dX + height * 0.5, pic, '0 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
98 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);
99 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);
100 }
101 else
102 {
103 dX = theBorderSize.x * eX;
104 dY = theBorderSize.x * eY;
105 drawsubpic(theOrigin, dX + dY, pic, '0 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
106 drawsubpic(theOrigin + dX, width - 2 * dX + dY, pic, '0.25 0 0', '0.5 0.25 0', theColor, theAlpha, 0);
107 drawsubpic(theOrigin + width - dX, dX + dY, pic, '0.75 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
108 drawsubpic(theOrigin + dY, dX + height - 2 * dY, pic, '0 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
109 drawsubpic(theOrigin + dY + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
110 drawsubpic(theOrigin + dY + width - dX, dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
111 drawsubpic(theOrigin + height - dY, dX + dY, pic, '0 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
112 drawsubpic(theOrigin + height - dY + dX, width - 2 * dX + dY, pic, '0.25 0.75 0', '0.5 0.25 0', theColor, theAlpha, 0);
113 drawsubpic(theOrigin + height - dY + width - dX, dX + dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
114 }
115 }
116 }
117
119 void drawstringright(vector position, string text, vector theScale, vector rgb, float theAlpha, int flag)
120 {
121 position.x -= 2 / 3 * strlen(text) * theScale.x;
122 drawstring_builtin(position, text, theScale, rgb, theAlpha, flag);
123 }
124
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_builtin(position, text, theScale, rgb, theAlpha, flag);
130 }
131#endif // CSQC
float height
Definition bobbing.qc:3
float drawsubpic(vector position, vector size, string pic, vector srcPosition, vector srcSize, vector rgb, float alpha, float flag)
#define strlen
#define ERASEABLE
Definition _all.inc:37
noref float vid_conwidth
Definition draw.qh:7
noref float vid_conheight
Definition draw.qh:8
void Draw_CylindricLine(vector from, vector to, float thickness, string texture, float aspect, float shift, vector rgb, float theAlpha, float drawflag, vector vieworg)
Definition draw.qh:10
ERASEABLE void drawstringcenter(vector position, string text, vector theScale, vector rgb, float theAlpha, int flag)
Definition draw.qh:126
ERASEABLE void drawstringright(vector position, string text, vector theScale, vector rgb, float theAlpha, int flag)
Definition draw.qh:119
void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize)
Definition draw.qh:43
float vlen(vector v)
vector normalize(vector v)
vector
Definition self.qh:96
const vector eY
Definition vector.qh:44
#define cross(a, b)
Definition vector.qh:25
const vector eX
Definition vector.qh:43