UFO: Alien Invasion
Toggle main menu visibility
Loading...
Searching...
No Matches
ui_node_tbar.cpp
Go to the documentation of this file.
1
4
5
/*
6
Copyright (C) 2002-2025 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
25
#include "
../ui_nodes.h
"
26
#include "
../ui_parse.h
"
27
#include "
../ui_behaviour.h
"
28
#include "
../ui_render.h
"
29
#include "
../ui_actions.h
"
30
#include "
ui_node_tbar.h
"
31
#include "
ui_node_abstractvalue.h
"
32
#include "
ui_node_abstractnode.h
"
33
34
#include "
../../../common/scripts_lua.h
"
35
36
#define EXTRADATA_TYPE tbarExtraData_t
37
#define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
38
#define EXTRADATACONST(node) UI_EXTRADATACONST(node, EXTRADATA_TYPE)
39
40
#define TEXTURE_WIDTH 250.0
41
42
extern
memPool_t
*
ui_dynStringPool
;
43
44
void
uiTBarNode::draw
(
uiNode_t
* node)
45
{
46
/* dataImageOrModel is the texture name */
47
float
shx;
48
vec2_t
nodepos;
49
const
char
* ref =
UI_GetReferenceString
(node,
EXTRADATA
(node).image);
50
float
pointWidth;
51
float
width;
52
if
(
Q_strnull
(ref))
53
return
;
54
55
UI_GetNodeAbsPos
(node, nodepos);
56
57
pointWidth =
TEXTURE_WIDTH
/ 100.0;
/* relative to the texture */
58
59
{
60
float
ps;
61
const
float
min =
getMin
(node);
62
const
float
max =
getMax
(node);
63
float
value =
getValue
(node);
64
/* clamp the value */
65
if
(value > max)
66
value = max;
67
if
(value < min)
68
value = min;
69
ps = (value - min) / (max - min) * 100;
70
shx =
EXTRADATA
(node).texl[0];
/* left gap to the texture */
71
shx += round(ps * pointWidth);
/* add size from 0..TEXTURE_WIDTH */
72
}
73
74
width = (shx * node->
box
.
size
[0]) /
TEXTURE_WIDTH
;
75
76
UI_DrawNormImageByName
(
false
, nodepos[0], nodepos[1], width, node->
box
.
size
[1],
77
shx,
EXTRADATA
(node).texh[1],
EXTRADATA
(node).texl[0],
EXTRADATA
(node).texl[1], ref);
78
}
79
80
void
UI_TBar_SetImage
(
uiNode_t
* node,
const
char
*
name
) {
81
UI_FreeStringProperty
(node->
image
);
82
node->
image
=
Mem_PoolStrDup
(
name
,
ui_dynStringPool
, 0);
83
}
84
85
void
UI_RegisterTBarNode
(
uiBehaviour_t
* behaviour)
86
{
87
behaviour->
name
=
"tbar"
;
88
behaviour->
extends
=
"abstractvalue"
;
89
behaviour->
manager
=
UINodePtr
(
new
uiTBarNode
());
90
behaviour->
extraDataSize
=
sizeof
(
EXTRADATA_TYPE
);
91
behaviour->
lua_SWIG_typeinfo
=
UI_SWIG_TypeQuery
(
"uiTBarNode_t *"
);
92
93
/* Image to use. Each behaviour use it like they want.
94
* @todo use V_REF_OF_STRING when its possible ('image' is never a cvar)
95
*/
96
UI_RegisterExtradataNodeProperty
(behaviour,
"image"
,
V_CVAR_OR_STRING
,
EXTRADATA_TYPE
, image);
97
98
/* @todo Need documentation */
99
UI_RegisterExtradataNodeProperty
(behaviour,
"texh"
,
V_POS
,
EXTRADATA_TYPE
, texh);
100
/* @todo Need documentation */
101
UI_RegisterExtradataNodeProperty
(behaviour,
"texl"
,
V_POS
,
EXTRADATA_TYPE
, texl);
102
}
uiAbstractValueNode::getValue
float getValue(uiNode_t const *node)
Definition
ui_node_abstractvalue.cpp:287
uiAbstractValueNode::getMax
float getMax(uiNode_t const *node)
Definition
ui_node_abstractvalue.cpp:277
uiAbstractValueNode::getMin
float getMin(uiNode_t const *node)
Definition
ui_node_abstractvalue.cpp:272
uiTBarNode
Definition
ui_node_tbar.h:29
uiTBarNode::draw
void draw(uiNode_t *node) override
Definition
ui_node_tbar.cpp:44
Mem_PoolStrDup
#define Mem_PoolStrDup(in, pool, tagNum)
Definition
mem.h:50
name
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition
r_gl.h:110
V_POS
@ V_POS
Definition
scripts.h:55
scripts_lua.h
Header for lua script functions.
Q_strnull
bool Q_strnull(const char *string)
Definition
shared.h:138
memPool_t
Definition
mem.cpp:55
uiBehaviour_t
node behaviour, how a node work
Definition
ui_behaviour.h:39
uiBehaviour_t::name
const char * name
Definition
ui_behaviour.h:41
uiBehaviour_t::lua_SWIG_typeinfo
void * lua_SWIG_typeinfo
Definition
ui_behaviour.h:57
uiBehaviour_t::manager
UINodePtr manager
Definition
ui_behaviour.h:43
uiBehaviour_t::extends
const char * extends
Definition
ui_behaviour.h:42
uiBehaviour_t::extraDataSize
intptr_t extraDataSize
Definition
ui_behaviour.h:54
uiBox_t::size
vec2_t size
Definition
ui_nodes.h:52
uiNode_t
Atomic structure used to define most of the UI.
Definition
ui_nodes.h:80
uiNode_t::box
uiBox_t box
Definition
ui_nodes.h:96
uiNode_t::image
char * image
Definition
ui_nodes.h:123
vec2_t
vec_t vec2_t[2]
Definition
ufotypes.h:38
UI_FreeStringProperty
void UI_FreeStringProperty(void *pointer)
Free a string property if it is allocated into ui_dynStringPool.
Definition
ui_actions.cpp:778
ui_actions.h
ui_behaviour.h
UI_RegisterExtradataNodeProperty
#define UI_RegisterExtradataNodeProperty(BEHAVIOUR, NAME, TYPE, EXTRADATATYPE, ATTRIBUTE)
Initialize a property from extradata of node.
Definition
ui_behaviour.h:109
UI_SWIG_TypeQuery
void * UI_SWIG_TypeQuery(const char *name)
This function queries the SWIG type table for a type information structure. It is used in combination...
Definition
ui_lua_shared.cpp:2903
UI_GetNodeAbsPos
void UI_GetNodeAbsPos(const uiNode_t *node, vec2_t pos)
Returns the absolute position of a node.
Definition
ui_node.cpp:526
ui_node_abstractnode.h
UINodePtr
SharedPtr< uiNode > UINodePtr
Definition
ui_node_abstractnode.h:66
EXTRADATA_TYPE
#define EXTRADATA_TYPE
Definition
ui_node_abstractoption.cpp:38
EXTRADATA
#define EXTRADATA(node)
Definition
ui_node_abstractoption.cpp:39
ui_node_abstractvalue.h
Define common thing for GUI controls which allow to edit a value (scroolbar, spinner,...
ui_dynStringPool
memPool_t * ui_dynStringPool
Definition
ui_main.cpp:40
TEXTURE_WIDTH
#define TEXTURE_WIDTH
Definition
ui_node_tbar.cpp:40
UI_RegisterTBarNode
void UI_RegisterTBarNode(uiBehaviour_t *behaviour)
Definition
ui_node_tbar.cpp:85
UI_TBar_SetImage
void UI_TBar_SetImage(uiNode_t *node, const char *name)
Definition
ui_node_tbar.cpp:80
ui_node_tbar.h
ui_nodes.h
UI_GetReferenceString
const char * UI_GetReferenceString(const uiNode_t *const node, const char *ref)
Definition
ui_parse.cpp:1406
ui_parse.h
V_CVAR_OR_STRING
#define V_CVAR_OR_STRING
Definition
ui_parse.h:69
UI_DrawNormImageByName
const image_t * UI_DrawNormImageByName(bool flip, float x, float y, float w, float h, float sh, float th, float sl, float tl, const char *name)
Draws an image or parts of it.
Definition
ui_render.cpp:203
ui_render.h
src
client
ui
node
ui_node_tbar.cpp
Generated on __DATE__ __TIME__ for UFO: Alien Invasion by
1.17.0