UFO: Alien Invasion
Toggle main menu visibility
Loading...
Searching...
No Matches
ui_node_controls.cpp
Go to the documentation of this file.
1
7
8
/*
9
Copyright (C) 2002-2025 UFO: Alien Invasion.
10
11
This program is free software; you can redistribute it and/or
12
modify it under the terms of the GNU General Public License
13
as published by the Free Software Foundation; either version 2
14
of the License, or (at your option) any later version.
15
16
This program is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19
20
See the GNU General Public License for more details.
21
22
You should have received a copy of the GNU General Public License
23
along with this program; if not, write to the Free Software
24
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26
*/
27
28
#include "
../ui_nodes.h
"
29
#include "
../ui_behaviour.h
"
30
#include "
../ui_parse.h
"
31
#include "
../ui_input.h
"
32
#include "
../ui_main.h
"
33
#include "
ui_node_image.h
"
34
#include "
ui_node_controls.h
"
35
#include "
ui_node_abstractnode.h
"
36
37
#include "
../../input/cl_keys.h
"
38
#include "
../../cl_video.h
"
39
40
#include "
../../../common/scripts_lua.h
"
41
42
static
int
deltaMouseX
;
43
static
int
deltaMouseY
;
44
45
void
uiControlNode::onMouseDown
(
uiNode_t
* node,
int
x,
int
y,
int
button)
46
{
47
if
(button ==
K_MOUSE1
) {
48
UI_SetMouseCapture
(node);
49
50
/* save position between mouse and node pos */
51
UI_NodeAbsoluteToRelativePos
(node, &x, &y);
52
deltaMouseX
= x + node->
box
.
pos
[0];
53
deltaMouseY
= y + node->
box
.
pos
[1];
54
}
55
}
56
57
void
uiControlNode::onMouseUp
(
uiNode_t
* node,
int
x,
int
y,
int
button)
58
{
59
if
(button ==
K_MOUSE1
)
60
UI_MouseRelease
();
61
}
62
66
void
uiControlNode::onCapturedMouseMove
(
uiNode_t
* node,
int
x,
int
y)
67
{
68
/* compute new x position of the window */
69
x -=
deltaMouseX
;
70
if
(x < 0)
71
x = 0;
72
if
(x + node->
root
->
box
.
size
[0] >
viddef
.virtualWidth)
73
x =
viddef
.virtualWidth - node->
root
->
box
.
size
[0];
74
75
/* compute new y position of the window */
76
y -=
deltaMouseY
;
77
if
(y < 0)
78
y = 0;
79
if
(y + node->
root
->
box
.
size
[1] >
viddef
.virtualHeight)
80
y =
viddef
.virtualHeight - node->
root
->
box
.
size
[1];
81
82
UI_SetNewWindowPos
(node->
root
, x, y);
83
}
84
85
void
UI_RegisterControlsNode
(
uiBehaviour_t
* behaviour)
86
{
87
behaviour->
name
=
"controls"
;
88
behaviour->
extends
=
"image"
;
89
behaviour->
manager
=
UINodePtr
(
new
uiControlNode
());
90
/* in lua, this class is renamed 'widget' since the generic name 'control' is reserved for a child
91
node in a component/window node */
92
behaviour->
lua_SWIG_typeinfo
=
UI_SWIG_TypeQuery
(
"uiWidgetNode_t *"
);
93
}
cl_keys.h
Header file for keyboard handler.
K_MOUSE1
@ K_MOUSE1
Definition
cl_keys.h:46
viddef
viddef_t viddef
Definition
cl_video.cpp:34
cl_video.h
Video driver defs.
uiControlNode
Definition
ui_node_controls.h:29
uiControlNode::onMouseDown
void onMouseDown(uiNode_t *node, int x, int y, int button) override
Definition
ui_node_controls.cpp:45
uiControlNode::onCapturedMouseMove
void onCapturedMouseMove(uiNode_t *node, int x, int y) override
Called when the node is captured by the mouse.
Definition
ui_node_controls.cpp:66
uiControlNode::onMouseUp
void onMouseUp(uiNode_t *node, int x, int y, int button) override
Definition
ui_node_controls.cpp:57
scripts_lua.h
Header for lua script functions.
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
uiBox_t::size
vec2_t size
Definition
ui_nodes.h:52
uiBox_t::pos
vec2_t pos
Definition
ui_nodes.h:51
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::root
uiNode_t * root
Definition
ui_nodes.h:93
ui_behaviour.h
UI_SetMouseCapture
void UI_SetMouseCapture(uiNode_t *node)
Captured the mouse into a node.
Definition
ui_input.cpp:516
UI_MouseRelease
void UI_MouseRelease(void)
Release the captured node.
Definition
ui_input.cpp:526
ui_input.h
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_main.h
UI_NodeAbsoluteToRelativePos
void UI_NodeAbsoluteToRelativePos(const uiNode_t *node, int *x, int *y)
Update an absolute position to a relative one.
Definition
ui_node.cpp:604
ui_node_abstractnode.h
UINodePtr
SharedPtr< uiNode > UINodePtr
Definition
ui_node_abstractnode.h:66
deltaMouseY
static int deltaMouseY
Definition
ui_node_controls.cpp:43
deltaMouseX
static int deltaMouseX
Definition
ui_node_controls.cpp:42
UI_RegisterControlsNode
void UI_RegisterControlsNode(uiBehaviour_t *behaviour)
Definition
ui_node_controls.cpp:85
ui_node_controls.h
ui_node_image.h
ui_nodes.h
ui_parse.h
UI_SetNewWindowPos
void UI_SetNewWindowPos(uiNode_t *window, int x, int y)
Sets new x and y coordinates for a given window.
Definition
ui_windows.cpp:606
src
client
ui
node
ui_node_controls.cpp
Generated on __DATE__ __TIME__ for UFO: Alien Invasion by
1.17.0