Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
description.qc
Go to the documentation of this file.
1#include "description.qh"
2
3void XonoticGuideDescription_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
4{
5 tokenizebyseparator(me.m_descriptionWrapped, "\n");
6 draw_Text(me.keepspaceLeft * eX, argv(i), me.realFontSize, '1 1 1', 1, true);
7}
8
10string wrapGuideText(string desc, float maxWidth, vector theFontSize)
11{
12 string wrapped = "";
13 bool keep_indenting = false;
14 const int n = tokenizebyseparator(desc, "\n");
15 for (int i = 0; i < n; ++i)
16 {
17 string s, line = "";
19 bool dotpoint = false, indent = false;
20 if (substring(getWrappedLine_remaining, 0, 2) == "* ")
21 {
22 dotpoint = true;
23 // We use Middle Dot (U+00B7) because it has the same width as space
24 // and makes the alignment with wrapped lines perfect.
26 }
27 else if (keep_indenting)
28 {
29 dotpoint = true;
30 indent = true;
31 }
33 {
34 if (indent) // indent lines inside dot point lists
36 s = getWrappedLine(maxWidth, theFontSize, draw_TextWidth_WithColors);
37 indent = dotpoint;
38 line = strcat(line, "\n", s);
39 }
40 wrapped = strcat(wrapped, line);
41
42 // if the current line is indented, the following non-empty lines must be indented too
43 keep_indenting = (indent && i + 1 < n && argv(i+1) != "");
44 }
45 return strcat(wrapped, "\n\n");
46}
47
49{
50 if (me.m_description && me.m_description != desc)
51 strunzone(me.m_description);
52 me.m_description = strzone(desc);
53
54 strfree(me.m_descriptionWrapped);
55
56 const float maxWidth = 1 - me.keepspaceLeft - me.keepspaceRight;
57 me.m_descriptionWrapped = strzone(wrapGuideText(me.m_description, maxWidth, me.realFontSize));
58
59 me.nItems = tokenizebyseparator(me.m_descriptionWrapped, "\n");
60 me.setSelected(me, 0); // reset scrollbar position
61}
62
63void XonoticGuideDescription_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
64{
65 SUPER(XonoticGuideDescription).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 me.keepspaceLeft = me.keepspaceRight = me.realFontSize.x;
72 me.setDescription(me, me.m_description);
73}
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
string wrapGuideText(string desc, float maxWidth, vector theFontSize)
wraps text and creates dot point lists from lines starting with "* "
void XonoticGuideDescription_setDescription(entity me, string desc)
void XonoticGuideDescription_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
void XonoticGuideDescription_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
Definition description.qc:3
#define tokenizebyseparator
void draw_Text(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha, float ICanHasKallerz)
Definition draw.qc:282
float draw_TextWidth_WithColors(string s, vector theFontSize)
Definition draw.qc:391
string substring(string s, float start, float length)
void strunzone(string s)
string strzone(string s)
string argv(float n)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define SUPER(cname)
Definition oo.qh:231
vector
Definition self.qh:92
#define strfree(this)
Definition string.qh:59
const vector eX
Definition vector.qh:44