UFO: Alien Invasion
Loading...
Searching...
No Matches
ui_node_rows.cpp
Go to the documentation of this file.
1
5
6/*
7Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24*/
25
26#include "../ui_behaviour.h"
27#include "../ui_render.h"
28#include "ui_node_rows.h"
30
32
33#define EXTRADATA_TYPE rowsExtraData_t
34#define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
35#define EXTRADATACONST(node) UI_EXTRADATACONST(node, EXTRADATA_TYPE)
36
41{
42 int current = 0;
43 int i = EXTRADATA(node).current;
44 vec2_t pos;
45 UI_GetNodeAbsPos(node, pos);
46
47 while (current < node->box.size[1]) {
48 const float* color;
49 const int height = std::min(EXTRADATA(node).lineHeight, (int)node->box.size[1] - current);
50
51 if (i % 2)
52 color = node->color;
53 else
54 color = node->selectedColor;
55 UI_DrawFill(pos[0], pos[1] + current, node->box.size[0], height, color);
56 current += height;
57 i++;
58 }
59}
60
62{
63 /* prevent infinite loop into the draw */
64 if (EXTRADATA(node).lineHeight == 0) {
65 EXTRADATA(node).lineHeight = 10;
66 }
67}
68
70{
71 behaviour->name = "rows";
72 behaviour->manager = UINodePtr(new uiRowsNode());
73 behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
74 behaviour->lua_SWIG_typeinfo = UI_SWIG_TypeQuery("uiRowsNode_t *");
75
76 /* Background color for odd elements */
77 UI_RegisterNodeProperty(behaviour, "color1", V_COLOR, uiNode_t, color);
78 /* Background color for even elements */
79 UI_RegisterNodeProperty(behaviour, "color2", V_COLOR, uiNode_t, selectedColor);
80 /* Element height */
81 UI_RegisterExtradataNodeProperty(behaviour, "lineheight", V_INT, rowsExtraData_t, lineHeight);
82 /* Element number on the top of the list. It is used to scroll the node content. */
83 UI_RegisterExtradataNodeProperty(behaviour, "current", V_INT, rowsExtraData_t, current);
84}
void draw(uiNode_t *node) override
Handles Button draw.
void onLoaded(uiNode_t *node) override
QGL_EXTERN GLint i
Definition r_gl.h:113
@ V_INT
Definition scripts.h:52
@ V_COLOR
Definition scripts.h:57
Header for lua script functions.
node behaviour, how a node work
const char * name
void * lua_SWIG_typeinfo
UINodePtr manager
intptr_t extraDataSize
vec2_t size
Definition ui_nodes.h:52
Atomic structure used to define most of the UI.
Definition ui_nodes.h:80
vec4_t color
Definition ui_nodes.h:127
vec4_t selectedColor
Definition ui_nodes.h:128
uiBox_t box
Definition ui_nodes.h:96
vec_t vec2_t[2]
Definition ufotypes.h:38
#define UI_RegisterNodeProperty(BEHAVIOUR, NAME, TYPE, OBJECTTYPE, ATTRIBUTE)
Initialize a property.
#define UI_RegisterExtradataNodeProperty(BEHAVIOUR, NAME, TYPE, EXTRADATATYPE, ATTRIBUTE)
Initialize a property from extradata of node.
void * UI_SWIG_TypeQuery(const char *name)
This function queries the SWIG type table for a type information structure. It is used in combination...
void UI_GetNodeAbsPos(const uiNode_t *node, vec2_t pos)
Returns the absolute position of a node.
Definition ui_node.cpp:526
SharedPtr< uiNode > UINodePtr
#define EXTRADATA_TYPE
#define EXTRADATA(node)
void UI_RegisterRowsNode(uiBehaviour_t *behaviour)
void UI_DrawFill(int x, int y, int w, int h, const vec4_t color)
Fills a box of pixels with a single color.
Definition ui_render.cpp:37