3 #include <menu/xonotic/listbox.qh>
4 CLASS(XonoticGuideDescription, XonoticListBox)
5 ATTRIB(XonoticGuideDescription, rowsPerItem, float, 1);
6 ATTRIB(XonoticGuideDescription, selectionDoesntMatter, bool, true);
8 METHOD(XonoticGuideDescription, setDescription, void(entity, string));
9 ATTRIB(XonoticGuideDescription, description, string, string_null);
11 METHOD(XonoticGuideDescription, resizeNotify, void(entity this, vector relOrigin, vector relSize, vector absOrigin, vector absSize)) {
12 SUPER(XonoticGuideDescription).resizeNotify(this, relOrigin, relSize, absOrigin, absSize);
14 this.realFontSize_y = this.fontSize / (absSize.y * this.itemHeight);
15 this.realFontSize_x = this.fontSize / (absSize.x * (1 - this.controlWidth));
16 this.realUpperMargin = 0.5 * (1 - this.realFontSize.y);
17 this.setDescription(this, this.description);
20 INIT(XonoticGuideDescription) {
21 this.configureXonoticListBox(this);
24 ATTRIB(XonoticGuideDescription, descriptionWrapped, string, string_null);
25 void XonoticGuideDescription_setDescription(entity this, string desc)
27 string current = this.description;
28 if (current && current != desc) strunzone(current);
29 this.description = strzone(desc);
31 string currentWrapped = this.descriptionWrapped;
32 if (currentWrapped) strunzone(currentWrapped);
34 for (int i = 0, n = tokenizebyseparator(desc, "\n"); i < n; ++i) {
36 for (getWrappedLine_remaining = argv(i); getWrappedLine_remaining; ) {
37 string s = getWrappedLine(1, this.realFontSize, draw_TextWidth_WithColors);
38 line = sprintf("%s\n%s", line, s);
40 wrapped = strcat(wrapped, line);
42 this.descriptionWrapped = strzone(wrapped);
44 this.nItems = tokenizebyseparator(wrapped, "\n");
47 METHOD(XonoticGuideDescription, drawListBoxItem, void(entity this, int i, vector absSize, bool isSelected, bool isFocused)) {
48 tokenizebyseparator(this.descriptionWrapped, "\n");
49 draw_Text(this.realUpperMargin * eY, argv(i), this.realFontSize, '1 1 1', 1, 0);
51 ENDCLASS(XonoticGuideDescription)