UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ui_node_base.cpp
Go to the documentation of this file.
1 
5 /*
6 Copyright (C) 2002-2020 UFO: Alien Invasion.
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 See the GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23 
24 #include "../ui_main.h"
25 #include "../ui_parse.h"
26 #include "../ui_behaviour.h"
27 #include "../ui_tooltip.h"
28 #include "../ui_nodes.h"
29 #include "../ui_render.h"
30 #include "ui_node_base.h"
31 
32 #include "../../cl_shared.h"
33 #include "../../cgame/cl_game.h"
34 #include "../../input/cl_input.h"
35 #include "../../input/cl_keys.h"
36 #include "../../sound/s_main.h"
37 
38 #include "../../../common/scripts_lua.h"
39 
40 #define EXTRADATA_TYPE baseExtraData_t
41 #define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
42 #define EXTRADATACONST(node) UI_EXTRADATACONST(node, EXTRADATA_TYPE)
43 
44 // TODO: remove me - duplicated in cp_base.h
45 #define BASE_SIZE 5
46 
52 void uiBaseLayoutNode::drawTooltip (const uiNode_t* node, int x, int y) const
53 {
54  GAME_DrawBaseLayoutTooltip(EXTRADATACONST(node).baseid, x, y);
55 }
56 
61 {
62  const int totalMarge = node->padding * (BASE_SIZE + 1);
63  const int width = (node->box.size[0] - totalMarge) / BASE_SIZE;
64  const int height = (node->box.size[1] - totalMarge) / BASE_SIZE;
65 
66  vec2_t nodepos;
67  UI_GetNodeAbsPos(node, nodepos);
68 
69  GAME_DrawBaseLayout(EXTRADATA(node).baseid, nodepos[0], nodepos[1], totalMarge, width, height, node->padding, node->bgcolor, node->color);
70 }
71 
76 {
77  EXTRADATA(node).baseid = -1;
78  node->padding = 3;
79  Vector4Set(node->color, 1, 1, 1, 1);
80  Vector4Set(node->bgcolor, 0.5, 0.5, 0.5, 1);
81 }
82 
84 {
85  behaviour->name = "baselayout";
86  behaviour->manager = UINodePtr(new uiBaseLayoutNode());
87  behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
88  behaviour->lua_SWIG_typeinfo = UI_SWIG_TypeQuery("uiBaseLayoutNode_t *");
89 
90  /* Identify the base, from a base ID, the node use. */
91  UI_RegisterExtradataNodeProperty(behaviour, "baseid", V_INT, baseExtraData_t, baseid);
92 }
vec2_t size
Definition: ui_nodes.h:52
void onLoading(uiNode_t *node) override
Called before loading. Used to set default attribute values.
const char * name
Definition: ui_behaviour.h:41
UINodePtr manager
Definition: ui_behaviour.h:43
#define UI_RegisterExtradataNodeProperty(BEHAVIOUR, NAME, TYPE, EXTRADATATYPE, ATTRIBUTE)
Initialize a property from extradata of node.
Definition: ui_behaviour.h:109
void UI_RegisterBaseLayoutNode(uiBehaviour_t *behaviour)
#define Vector4Set(v, r, g, b, a)
Definition: vector.h:62
SharedPtr< uiNode > UINodePtr
int padding
Definition: ui_nodes.h:109
void * lua_SWIG_typeinfo
Definition: ui_behaviour.h:57
void GAME_DrawBaseLayout(int baseIdx, int x, int y, int totalMarge, int w, int h, int padding, const vec4_t bgcolor, const vec4_t color)
Definition: cl_game.cpp:1699
Atomic structure used to define most of the UI.
Definition: ui_nodes.h:80
void draw(uiNode_t *node) override
Draw a small square with the layout of the given base.
void * UI_SWIG_TypeQuery(const char *name)
This function queries the SWIG type table for a type information structure. It is used in combination...
#define EXTRADATA(node)
void UI_GetNodeAbsPos(const uiNode_t *node, vec2_t pos)
Returns the absolute position of a node.
Definition: ui_node.cpp:514
#define EXTRADATA_TYPE
vec4_t bgcolor
Definition: ui_nodes.h:125
intptr_t extraDataSize
Definition: ui_behaviour.h:54
node behaviour, how a node work
Definition: ui_behaviour.h:39
#define BASE_SIZE
vec4_t color
Definition: ui_nodes.h:127
#define EXTRADATACONST(node)
vec_t vec2_t[2]
Definition: ufotypes.h:38
Definition: scripts.h:52
void drawTooltip(const uiNode_t *node, int x, int y) const override
Custom tooltip for baseayout.
uiBox_t box
Definition: ui_nodes.h:96
void GAME_DrawBaseLayoutTooltip(int baseIdx, int x, int y)
Cgame callback to draw tooltip for baselayout UI node.
Definition: cl_game.cpp:1712