From: Freddy Date: Mon, 30 Dec 2019 23:37:41 +0000 (+0100) Subject: Add multiline textbox widget X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=9ee6931f4fb28df8d730b1568b1564bf3acce035;p=xonotic%2Fxonotic-data.pk3dir.git Add multiline textbox widget --- diff --git a/qcsrc/menu/xonotic/_mod.inc b/qcsrc/menu/xonotic/_mod.inc index 75d37e4fc..938e64d20 100644 --- a/qcsrc/menu/xonotic/_mod.inc +++ b/qcsrc/menu/xonotic/_mod.inc @@ -115,6 +115,7 @@ #include #include #include +#include #include #include #include diff --git a/qcsrc/menu/xonotic/_mod.qh b/qcsrc/menu/xonotic/_mod.qh index 452c56658..2c060e7f0 100644 --- a/qcsrc/menu/xonotic/_mod.qh +++ b/qcsrc/menu/xonotic/_mod.qh @@ -115,6 +115,7 @@ #include #include #include +#include #include #include #include diff --git a/qcsrc/menu/xonotic/textbox.qc b/qcsrc/menu/xonotic/textbox.qc new file mode 100644 index 000000000..7623bbcef --- /dev/null +++ b/qcsrc/menu/xonotic/textbox.qc @@ -0,0 +1,59 @@ +#include "textbox.qh" + +entity makeXonoticTextBox() +{ + entity me; + me = NEW(XonoticTextBox); + me.configureXonoticListBox(me); + return me; +} + +void XonoticTextBox_setText(entity me, string text) +{ + int buf; + int line = 0; + + string t; + + buf = buf_create(); + for (int i = 0, n = tokenizebyseparator(text, "\n"); i < n; ++i) + { + t = substring(argv(i), 0, -1); + getWrappedLine_remaining = t; + while (getWrappedLine_remaining) + { + t = getWrappedLine(1, me.realFontSize, draw_TextWidth_WithColors); + bufstr_set(buf, line, t); + line++; + } + } + + me.stringList = buf; + me.nItems = line+1; +} + +string XonoticTextBox_getTextBoxContent(entity me, int i) +{ + return bufstr_get(me.stringList, i); +} + +// mostly copied from playerlist +// FIXME: is this really needed +void XonoticTextBox_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) +{ + me.itemAbsSize = '0 0 0'; + SUPER(XonoticTextBox).resizeNotify(me, relOrigin, relSize, absOrigin, absSize); + + me.itemAbsSize.y = absSize.y * me.itemHeight; + me.itemAbsSize.x = absSize.x * (1 - me.controlWidth); + me.realFontSize.y = me.fontSize / me.itemAbsSize.y; + me.realFontSize.x = me.fontSize / me.itemAbsSize.x; +} + +void XonoticTextBox_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused) +{ + string s; + + s = me.getTextBoxContent(me, i); + draw_Text(vec2(0, 0), s, me.realFontSize, me.colorL, me.alpha, true); +} diff --git a/qcsrc/menu/xonotic/textbox.qh b/qcsrc/menu/xonotic/textbox.qh new file mode 100644 index 000000000..e8afda016 --- /dev/null +++ b/qcsrc/menu/xonotic/textbox.qh @@ -0,0 +1,21 @@ +#pragma once + +#include "listbox.qh" + +// slightly hacky multiline textbox with scrollbar +CLASS(XonoticTextBox, XonoticListBox) + ATTRIB(XonoticTextBox, rowsPerItem, float, 1); + METHOD(XonoticTextBox, resizeNotify, void(entity, vector, vector, vector, vector)); + METHOD(XonoticTextBox, drawListBoxItem, void(entity, int, vector, bool, bool)); + ATTRIB(XonoticTextBox, allowFocusSound, float, 0); + ATTRIB(XonoticTextBox, alpha, float, SKINALPHA_TEXT); + ATTRIB(XonoticTextBox, fontSize, float, SKINFONTSIZE_NORMAL); + ATTRIB(XonoticTextBox, realFontSize, vector, '0 0 0'); + ATTRIB(XonoticTextBox, itemAbsSize, vector, '0 0 0'); + METHOD(XonoticTextBox, setText, void(entity, string)); + METHOD(XonoticTextBox, getTextBoxContent, string(entity, int)); + ATTRIB(XonoticTextBox, stringList, int, -1); + ATTRIB(XonoticTextBox, selectionDoesntMatter, bool, true); +ENDCLASS(XonoticTextBox) +entity makeXonoticTextBox(); +