UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ui_node_controls.cpp
Go to the documentation of this file.
1 
8 /*
9 Copyright (C) 2002-2020 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)
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 
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 }
void onCapturedMouseMove(uiNode_t *node, int x, int y) override
Called when the node is captured by the mouse.
vec2_t size
Definition: ui_nodes.h:52
void UI_RegisterControlsNode(uiBehaviour_t *behaviour)
static int deltaMouseY
const char * name
Definition: ui_behaviour.h:41
UINodePtr manager
Definition: ui_behaviour.h:43
viddef_t viddef
Definition: cl_video.cpp:34
int virtualHeight
Definition: cl_video.h:74
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
void UI_MouseRelease(void)
Release the captured node.
Definition: ui_input.cpp:526
uiNode_t * root
Definition: ui_nodes.h:93
SharedPtr< uiNode > UINodePtr
void * lua_SWIG_typeinfo
Definition: ui_behaviour.h:57
void UI_SetMouseCapture(uiNode_t *node)
Captured the mouse into a node.
Definition: ui_input.cpp:516
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 onMouseUp(uiNode_t *node, int x, int y, int button) override
void UI_NodeAbsoluteToRelativePos(const uiNode_t *node, int *x, int *y)
Update an absolute position to a relative one.
Definition: ui_node.cpp:592
node behaviour, how a node work
Definition: ui_behaviour.h:39
const char * extends
Definition: ui_behaviour.h:42
int virtualWidth
Definition: cl_video.h:74
uiBox_t box
Definition: ui_nodes.h:96
void onMouseDown(uiNode_t *node, int x, int y, int button) override
static int deltaMouseX
vec2_t pos
Definition: ui_nodes.h:51