From: terencehill Date: Sun, 5 Apr 2015 13:21:42 +0000 (+0200) Subject: textlistbox.qc --> textbox.qc X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f1aee72c90f58fdc25c3eae1ee13bd707c6a7408;p=xonotic%2Fxonotic-data.pk3dir.git textlistbox.qc --> textbox.qc --- diff --git a/qcsrc/menu/classes.qc b/qcsrc/menu/classes.qc index 7439a3ed7..b2b1a46d7 100644 --- a/qcsrc/menu/classes.qc +++ b/qcsrc/menu/classes.qc @@ -57,7 +57,7 @@ #include "xonotic/dialog_multiplayer_join_serverinfo.qc" #include "xonotic/playerlist.qc" #include "xonotic/listbox.qc" -#include "xonotic/textlistbox.qc" +#include "xonotic/textbox.qc" #include "xonotic/serverlist.qc" #include "xonotic/inputbox.qc" #include "xonotic/dialog_quit.qc" diff --git a/qcsrc/menu/xonotic/textbox.qc b/qcsrc/menu/xonotic/textbox.qc new file mode 100644 index 000000000..7c6ec9a44 --- /dev/null +++ b/qcsrc/menu/xonotic/textbox.qc @@ -0,0 +1,94 @@ +#ifdef INTERFACE +CLASS(XonoticTextListBox) EXTENDS(ListBox) + METHOD(XonoticTextListBox, configureXonoticTextListBox, void(entity)) + ATTRIB(XonoticTextListBox, fontSize, float, SKINFONTSIZE_NORMAL) + ATTRIB(XonoticTextListBox, scrollbarWidth, float, SKINWIDTH_SCROLLBAR) + ATTRIB(XonoticTextListBox, src, string, SKINGFX_SCROLLBAR) + ATTRIB(XonoticTextListBox, tolerance, vector, SKINTOLERANCE_SLIDER) + ATTRIB(XonoticTextListBox, rowsPerItem, float, 1) + METHOD(XonoticTextListBox, resizeNotify, void(entity, vector, vector, vector, vector)) + ATTRIB(XonoticTextListBox, color, vector, SKINCOLOR_SCROLLBAR_N) + ATTRIB(XonoticTextListBox, colorF, vector, SKINCOLOR_SCROLLBAR_F) + ATTRIB(XonoticTextListBox, color2, vector, SKINCOLOR_SCROLLBAR_S) + ATTRIB(XonoticTextListBox, colorC, vector, SKINCOLOR_SCROLLBAR_C) + ATTRIB(XonoticTextListBox, colorBG, vector, SKINCOLOR_LISTBOX_BACKGROUND) + ATTRIB(XonoticTextListBox, alphaBG, float, SKINALPHA_LISTBOX_BACKGROUND) + + METHOD(XonoticTextListBox, setSelected, void(entity, float)) + METHOD(XonoticTextListBox, destroy, void(entity)) + ATTRIB(XonoticTextListBox, textbuf, float, -1) + ATTRIB(XonoticTextListBox, textbufSize, float, 0) + ATTRIB(XonoticTextListBox, allowColors, float, 0) + METHOD(XonoticTextListBox, setText, void(entity, string)) + METHOD(XonoticTextListBox, drawListBoxItem, void(entity, float, vector, float)) // item number, width/height, selected +ENDCLASS(XonoticTextListBox) +entity makeXonoticTextListBox(); +#endif + +#ifdef IMPLEMENTATION +entity makeXonoticTextListBox() +{ + entity me; + me = spawnXonoticTextListBox(); + me.configureXonoticTextListBox(me); + return me; +} +void XonoticTextListBox_configureXonoticTextListBox(entity me) +{ + me.configureListBox(me, me.scrollbarWidth, 1); // item height gets set up later +} +void XonoticTextListBox_setSelected(entity me, float i) +{ + // nothing +} +void XonoticTextListBox_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) +{ + me.itemHeight = me.rowsPerItem * me.fontSize / absSize_y; + SUPER(XonoticTextListBox).resizeNotify(me, relOrigin, relSize, absOrigin, absSize); + + me.realFontSize_y = me.fontSize / (absSize_y * me.itemHeight); + me.realFontSize_x = me.fontSize / (absSize_x * (1 - me.controlWidth)); + me.realUpperMargin = 0.5 * (1 - me.realFontSize_y); +} +void XonoticTextListBox_setText(entity me, string theText) +{ + int i, k; + string ts; + if(me.textbuf >= 0) + buf_del(me.textbuf); + me.textbuf = buf_create(); + string s = strzone(theText); + me.nItems = 0; + k = tokenizebyseparator(s, "\\n"); + for(i = 0; i < k; ++i) + { + getWrappedLine_remaining = argv(i); + if(!getWrappedLine_remaining) + { + bufstr_add(me.textbuf, "", 1); + ++me.nItems; + } + else while(getWrappedLine_remaining) + { + ts = getWrappedLine(1 - me.controlWidth, me.realFontSize, draw_TextWidth_WithColors); + if (ts != "") + { + bufstr_add(me.textbuf, ts, 1); + ++me.nItems; + } + } + } + strunzone(s); + me.textbufSize = buf_getsize(me.textbuf); +} +void XonoticTextListBox_destroy(entity me) +{ + if(me.textbuf >= 0) + buf_del(me.textbuf); +} +void XonoticTextListBox_drawListBoxItem(entity me, float i, vector absSize, float isSelected) +{ + if(me.textbufSize > 0) + draw_CenterText(me.realUpperMargin * eY + 0.5 * eX, bufstr_get(me.textbuf, i), me.realFontSize, '1 1 1', 1, me.allowColors); +} +#endif diff --git a/qcsrc/menu/xonotic/textlistbox.qc b/qcsrc/menu/xonotic/textlistbox.qc deleted file mode 100644 index 7c6ec9a44..000000000 --- a/qcsrc/menu/xonotic/textlistbox.qc +++ /dev/null @@ -1,94 +0,0 @@ -#ifdef INTERFACE -CLASS(XonoticTextListBox) EXTENDS(ListBox) - METHOD(XonoticTextListBox, configureXonoticTextListBox, void(entity)) - ATTRIB(XonoticTextListBox, fontSize, float, SKINFONTSIZE_NORMAL) - ATTRIB(XonoticTextListBox, scrollbarWidth, float, SKINWIDTH_SCROLLBAR) - ATTRIB(XonoticTextListBox, src, string, SKINGFX_SCROLLBAR) - ATTRIB(XonoticTextListBox, tolerance, vector, SKINTOLERANCE_SLIDER) - ATTRIB(XonoticTextListBox, rowsPerItem, float, 1) - METHOD(XonoticTextListBox, resizeNotify, void(entity, vector, vector, vector, vector)) - ATTRIB(XonoticTextListBox, color, vector, SKINCOLOR_SCROLLBAR_N) - ATTRIB(XonoticTextListBox, colorF, vector, SKINCOLOR_SCROLLBAR_F) - ATTRIB(XonoticTextListBox, color2, vector, SKINCOLOR_SCROLLBAR_S) - ATTRIB(XonoticTextListBox, colorC, vector, SKINCOLOR_SCROLLBAR_C) - ATTRIB(XonoticTextListBox, colorBG, vector, SKINCOLOR_LISTBOX_BACKGROUND) - ATTRIB(XonoticTextListBox, alphaBG, float, SKINALPHA_LISTBOX_BACKGROUND) - - METHOD(XonoticTextListBox, setSelected, void(entity, float)) - METHOD(XonoticTextListBox, destroy, void(entity)) - ATTRIB(XonoticTextListBox, textbuf, float, -1) - ATTRIB(XonoticTextListBox, textbufSize, float, 0) - ATTRIB(XonoticTextListBox, allowColors, float, 0) - METHOD(XonoticTextListBox, setText, void(entity, string)) - METHOD(XonoticTextListBox, drawListBoxItem, void(entity, float, vector, float)) // item number, width/height, selected -ENDCLASS(XonoticTextListBox) -entity makeXonoticTextListBox(); -#endif - -#ifdef IMPLEMENTATION -entity makeXonoticTextListBox() -{ - entity me; - me = spawnXonoticTextListBox(); - me.configureXonoticTextListBox(me); - return me; -} -void XonoticTextListBox_configureXonoticTextListBox(entity me) -{ - me.configureListBox(me, me.scrollbarWidth, 1); // item height gets set up later -} -void XonoticTextListBox_setSelected(entity me, float i) -{ - // nothing -} -void XonoticTextListBox_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) -{ - me.itemHeight = me.rowsPerItem * me.fontSize / absSize_y; - SUPER(XonoticTextListBox).resizeNotify(me, relOrigin, relSize, absOrigin, absSize); - - me.realFontSize_y = me.fontSize / (absSize_y * me.itemHeight); - me.realFontSize_x = me.fontSize / (absSize_x * (1 - me.controlWidth)); - me.realUpperMargin = 0.5 * (1 - me.realFontSize_y); -} -void XonoticTextListBox_setText(entity me, string theText) -{ - int i, k; - string ts; - if(me.textbuf >= 0) - buf_del(me.textbuf); - me.textbuf = buf_create(); - string s = strzone(theText); - me.nItems = 0; - k = tokenizebyseparator(s, "\\n"); - for(i = 0; i < k; ++i) - { - getWrappedLine_remaining = argv(i); - if(!getWrappedLine_remaining) - { - bufstr_add(me.textbuf, "", 1); - ++me.nItems; - } - else while(getWrappedLine_remaining) - { - ts = getWrappedLine(1 - me.controlWidth, me.realFontSize, draw_TextWidth_WithColors); - if (ts != "") - { - bufstr_add(me.textbuf, ts, 1); - ++me.nItems; - } - } - } - strunzone(s); - me.textbufSize = buf_getsize(me.textbuf); -} -void XonoticTextListBox_destroy(entity me) -{ - if(me.textbuf >= 0) - buf_del(me.textbuf); -} -void XonoticTextListBox_drawListBoxItem(entity me, float i, vector absSize, float isSelected) -{ - if(me.textbufSize > 0) - draw_CenterText(me.realUpperMargin * eY + 0.5 * eX, bufstr_get(me.textbuf, i), me.realFontSize, '1 1 1', 1, me.allowColors); -} -#endif