Xonotic
textbox.qc
Go to the documentation of this file.
1 #include "textbox.qh"
2 #include "../item/label.qh"
3 
5 {
6  entity me;
7  me = NEW(XonoticTextBox);
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 }
20 
21 void XonoticTextBox_setText(entity me, string text)
22 {
23  if (me.stringList >= 0)
24  {
25  buf_del(me.stringList);
26  me.stringList = -1;
27  }
28 
29  int buf;
30  int line = 0;
31 
32  string t;
33 
34  buf = buf_create();
35  for (int i = 0, n = tokenizebyseparator(text, "\n"); i < n; ++i)
36  {
37  t = substring(argv(i), 0, -1);
40  {
41  t = getWrappedLine(1, me.realFontSize, draw_TextWidth_WithColors);
42  bufstr_set(buf, line, t);
43  line++;
44  }
45  }
46 
47  me.stringList = buf;
48  me.nItems = line+1;
49 }
50 
52 {
53  if (me.stringList >= 0)
54  {
55  return bufstr_get(me.stringList, i);
56  }
57  return string_null;
58 }
59 
60 // mostly copied from playerlist
61 // FIXME: is this really needed
62 void XonoticTextBox_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
63 {
64  me.itemAbsSize = '0 0 0';
65  SUPER(XonoticTextBox).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
66 
67  me.itemAbsSize.y = absSize.y * me.itemHeight;
68  me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
69  me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
70  me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
71  string temp = string_null;
72  for (int i = 0; i < me.nItems; ++i)
73  {
74  if (!temp)
75  {
76  temp = me.getTextBoxLine(me, i);
77  }
78  else
79  {
80  temp = strcat(temp, "\n", me.getTextBoxLine(me, i));
81  }
82  }
83  me.setText(me, temp);
84 }
85 
86 void XonoticTextBox_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
87 {
88  string s = me.getTextBoxLine(me, i);
89  draw_Text(vec2(0, 0), s, me.realFontSize, me.colorL, me.alpha, true);
90 }
string string_null
Definition: nil.qh:9
string getWrappedLine_remaining
Definition: util.qh:108
#define NEW(cname,...)
Definition: oo.qh:105
string XonoticTextBox_getTextBoxLine(entity me, int i)
Definition: textbox.qc:51
void XonoticTextBox_setText(entity me, string text)
Definition: textbox.qc:21
entity() spawn
void XonoticTextBox_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
Definition: textbox.qc:62
#define SUPER(cname)
Definition: oo.qh:219
#define buf_create
Definition: dpextensions.qh:63
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
entity makeXonoticTextBox()
Definition: textbox.qc:4
vector(float skel, float bonenum) _skel_get_boneabs_hidden
void XonoticTextBox_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
Definition: textbox.qc:86
#define tokenizebyseparator
Definition: dpextensions.qh:21
#define vec2(...)
Definition: vector.qh:90
string getWrappedLine(float w, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
Definition: util.qc:880
void XonoticTextBox_destroy(entity me)
Definition: textbox.qc:12