Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
textbox.qc
Go to the documentation of this file.
1#include "textbox.qh"
2#include "../item/label.qh"
3
5{
7 me.configureXonoticListBox(me);
8 return me;
9}
10
12{
13 if (me.stringList >= 0)
14 {
15 buf_del(me.stringList);
16 me.stringList = -1;
17 }
18 strfree(me.text);
19}
20
21void XonoticTextBox_setText(entity me, string txt)
22{
23 if (me.stringList >= 0)
24 {
25 buf_del(me.stringList);
26 me.stringList = -1;
27 }
28
29 strcpy(me.text, txt);
30
31 int buf;
32 int line = 0;
33
34 string t;
35
36 buf = buf_create();
37 string separator = (me.escapedNewLines) ? "\\n" : "\n";
38 for (int i = 0, n = tokenizebyseparator(txt, separator); i < n; ++i)
39 {
40 t = substring(argv(i), 0, -1);
43 {
44 t = getWrappedLine(1 - me.controlWidth, me.realFontSize,
46 bufstr_set(buf, line, t);
47 ++line;
48 }
49 }
50
51 me.stringList = buf;
52 me.nItems = line+1;
53}
54
56{
57 if (me.stringList >= 0)
58 {
59 return bufstr_get(me.stringList, i);
60 }
61 return string_null;
62}
63
64void XonoticTextBox_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
65{
66 me.itemAbsSize = '0 0 0';
67 SUPER(XonoticTextBox).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
68
69 me.itemAbsSize.y = absSize.y * me.itemHeight;
70 me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
71 me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
72 me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
73 me.setText(me, strcat(me.text)); // rewrap
74}
75
76void XonoticTextBox_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
77{
78 string s = me.getTextBoxLine(me, i);
79 vector color = (me.allowColors) ? '1 1 1' : me.colorL;
80 if (me.align == 0.5)
81 draw_CenterText(0.5 * eX, s, me.realFontSize, color, 1, me.allowColors);
82 else
83 draw_Text(vec2(0, 0), s, me.realFontSize, color, me.alpha, me.allowColors);
84}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
string getWrappedLine(float maxWidth, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:1131
string getWrappedLine_remaining
Definition util.qh:147
#define tokenizebyseparator
#define buf_create
vector color
Definition dynlight.qc:15
float draw_TextWidth_WithoutColors(string s, vector theFontSize)
Definition draw.qc:397
void draw_Text(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha, float ICanHasKallerz)
Definition draw.qc:282
void draw_CenterText(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha, float ICanHasKallerz)
Definition draw.qc:298
float draw_TextWidth_WithColors(string s, vector theFontSize)
Definition draw.qc:392
string substring(string s, float start, float length)
string argv(float n)
string string_null
Definition nil.qh:9
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define NEW(cname,...)
Definition oo.qh:117
#define SUPER(cname)
Definition oo.qh:231
vector
Definition self.qh:92
#define strfree(this)
Definition string.qh:59
#define strcpy(this, s)
Definition string.qh:52
void XonoticTextBox_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
Definition textbox.qc:64
void XonoticTextBox_destroy(entity me)
Definition textbox.qc:11
entity makeXonoticTextBox()
Definition textbox.qc:4
void XonoticTextBox_setText(entity me, string txt)
Definition textbox.qc:21
string XonoticTextBox_getTextBoxLine(entity me, int i)
Definition textbox.qc:55
void XonoticTextBox_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
Definition textbox.qc:76
const vector eX
Definition vector.qh:44
#define vec2(...)
Definition vector.qh:90