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 // WORKAROUND: correct line width is 1 - me.realFontSize.x, we make it slightly shorter
45 // to prevent text overlapping the scrollbar due to r_font_size_snapping > 0
46 t = getWrappedLine(1 - me.realFontSize.x * 1.75, me.realFontSize,
48 bufstr_set(buf, line, t);
49 ++line;
50 }
51 }
52
53 me.stringList = buf;
54 me.nItems = line+1;
55}
56
58{
59 if (me.stringList >= 0)
60 return bufstr_get(me.stringList, i);
61
62 return string_null;
63}
64
65void XonoticTextBox_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
66{
67 me.itemAbsSize = '0 0 0';
68 SUPER(XonoticTextBox).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
69
70 me.itemAbsSize.y = absSize.y * me.itemHeight;
71 me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
72 me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
73 me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
74 me.setText(me, strcat(me.text)); // rewrap
75}
76
77void XonoticTextBox_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
78{
79 string s = me.getTextBoxLine(me, i);
80 vector color = (me.allowColors) ? '1 1 1' : me.colorL;
81 if (me.align == 0.5)
82 draw_CenterText(0.5 * eX, s, me.realFontSize, color, 1, me.allowColors);
83 else
84 draw_Text(eX * 0.5 * me.realFontSize.x, s, me.realFontSize, color, me.alpha, me.allowColors);
85}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
string getWrappedLine(float maxWidth, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:1133
string getWrappedLine_remaining
Definition util.qh:154
#define tokenizebyseparator
#define buf_create
vector color
Definition dynlight.qc:15
float draw_TextWidth_WithoutColors(string s, vector theFontSize)
Definition draw.qc:382
void draw_Text(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha, bool allowColorCodes)
Definition draw.qc:281
float draw_TextWidth_WithColors(string s, vector theFontSize)
Definition draw.qc:377
void draw_CenterText(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha, bool allowColorCodes)
Definition draw.qc:296
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:120
#define SUPER(cname)
Definition oo.qh:236
vector
Definition self.qh:96
#define strfree(this)
Definition string.qh:57
#define strcpy(this, s)
Definition string.qh:51
void XonoticTextBox_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
Definition textbox.qc:65
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:57
void XonoticTextBox_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
Definition textbox.qc:77
const vector eX
Definition vector.qh:43