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{
6 entity me;
8 me.configureXonoticListBox(me);
9 return me;
10}
11
13{
14 if (me.stringList >= 0)
15 {
16 buf_del(me.stringList);
17 me.stringList = -1;
18 }
19 strfree(me.text);
20}
21
22void XonoticTextBox_setText(entity me, string txt)
23{
24 if (me.stringList >= 0)
25 {
26 buf_del(me.stringList);
27 me.stringList = -1;
28 }
29
30 strcpy(me.text, txt);
31
32 int buf;
33 int line = 0;
34
35 string t;
36
37 buf = buf_create();
38 string separator = (me.escapedNewLines) ? "\\n" : "\n";
39 for (int i = 0, n = tokenizebyseparator(txt, separator); i < n; ++i)
40 {
41 t = substring(argv(i), 0, -1);
44 {
45 t = getWrappedLine(1 - me.controlWidth, me.realFontSize,
47 bufstr_set(buf, line, t);
48 line++;
49 }
50 }
51
52 me.stringList = buf;
53 me.nItems = line+1;
54}
55
57{
58 if (me.stringList >= 0)
59 {
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(vec2(0, 0), 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:995
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:396
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:391
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:65
void XonoticTextBox_destroy(entity me)
Definition textbox.qc:12
entity makeXonoticTextBox()
Definition textbox.qc:4
void XonoticTextBox_setText(entity me, string txt)
Definition textbox.qc:22
string XonoticTextBox_getTextBoxLine(entity me, int i)
Definition textbox.qc:56
void XonoticTextBox_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
Definition textbox.qc:77
const vector eX
Definition vector.qh:44
#define vec2(...)
Definition vector.qh:90