]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/textbox.qc
menu: video settings: add support for GL32 renderer (DP master)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / textbox.qc
1 #include "textbox.qh"
2 #include "../item/label.qh"
3
4 entity makeXonoticTextBox()
5 {
6         entity me;
7         me = NEW(XonoticTextBox);
8         me.configureXonoticListBox(me);
9         return me;
10 }
11
12 void XonoticTextBox_destroy(entity me)
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         string separator = (me.escapedNewLines) ? "\\n" : "\n";
36         for (int i = 0, n = tokenizebyseparator(text, separator); i < n; ++i)
37         {
38                 t = substring(argv(i), 0, -1);
39                 getWrappedLine_remaining = t;
40                 while (getWrappedLine_remaining)
41                 {
42                         t = getWrappedLine(1, me.realFontSize, (me.allowColors) ? draw_TextWidth_WithColors : draw_TextWidth_WithoutColors);
43                         bufstr_set(buf, line, t);
44                         line++;
45                 }
46         }
47
48         me.stringList = buf;
49         me.nItems = line+1;
50 }
51
52 string XonoticTextBox_getTextBoxLine(entity me, int i)
53 {
54         if (me.stringList >= 0)
55         {
56                 return bufstr_get(me.stringList, i);
57         }
58         return string_null;
59 }
60
61 // mostly copied from playerlist
62 // FIXME: is this really needed
63 void XonoticTextBox_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
64 {
65         me.itemAbsSize = '0 0 0';
66         SUPER(XonoticTextBox).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
67
68         me.itemAbsSize.y = absSize.y * me.itemHeight;
69         me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
70         me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
71         me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
72         string temp = string_null;
73         for (int i = 0; i < me.nItems; ++i)
74         {
75                 if (!temp)
76                 {
77                         temp = me.getTextBoxLine(me, i);
78                 }
79                 else
80                 {
81                         temp = strcat(temp, "\n", me.getTextBoxLine(me, i));
82                 }
83         }
84         me.setText(me, temp);
85 }
86
87 void XonoticTextBox_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
88 {
89         string s = me.getTextBoxLine(me, i);
90         vector color = (me.allowColors) ? '1 1 1' : me.colorL;
91         if (me.align == 0.5)
92                 draw_CenterText(0.5 * eX, s, me.realFontSize, color, 1, me.allowColors);
93         else
94                 draw_Text(vec2(0, 0), s, me.realFontSize, color, me.alpha, me.allowColors);
95 }