UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ui_node_rows.cpp
Go to the documentation of this file.
1 
6 /*
7 Copyright (C) 2002-2020 UFO: Alien Invasion.
8 
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 
18 See the GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, 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"
29 #include "ui_node_abstractnode.h"
30 
31 #include "../../../common/scripts_lua.h"
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 }
vec2_t size
Definition: ui_nodes.h:52
const char * name
Definition: ui_behaviour.h:41
void draw(uiNode_t *node) override
Handles Button draw.
UINodePtr manager
Definition: ui_behaviour.h:43
#define UI_RegisterNodeProperty(BEHAVIOUR, NAME, TYPE, OBJECTTYPE, ATTRIBUTE)
Initialize a property.
Definition: ui_behaviour.h:91
#define EXTRADATA(node)
#define UI_RegisterExtradataNodeProperty(BEHAVIOUR, NAME, TYPE, EXTRADATATYPE, ATTRIBUTE)
Initialize a property from extradata of node.
Definition: ui_behaviour.h:109
void UI_RegisterRowsNode(uiBehaviour_t *behaviour)
#define EXTRADATA_TYPE
SharedPtr< uiNode > UINodePtr
void * lua_SWIG_typeinfo
Definition: ui_behaviour.h:57
Atomic structure used to define most of the UI.
Definition: ui_nodes.h:80
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:514
vec4_t selectedColor
Definition: ui_nodes.h:128
intptr_t extraDataSize
Definition: ui_behaviour.h:54
QGL_EXTERN GLint i
Definition: r_gl.h:113
node behaviour, how a node work
Definition: ui_behaviour.h:39
vec4_t color
Definition: ui_nodes.h:127
vec_t vec2_t[2]
Definition: ufotypes.h:38
Definition: scripts.h:52
void onLoaded(uiNode_t *node) override
uiBox_t box
Definition: ui_nodes.h:96
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