UFO: Alien Invasion
Loading...
Searching...
No Matches
ui_node_controls.cpp
Go to the documentation of this file.
1
7
8/*
9Copyright (C) 2002-2025 UFO: Alien Invasion.
10
11This program is free software; you can redistribute it and/or
12modify it under the terms of the GNU General Public License
13as published by the Free Software Foundation; either version 2
14of the License, or (at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19
20See the GNU General Public License for more details.
21
22You should have received a copy of the GNU General Public License
23along with this program; if not, write to the Free Software
24Foundation, 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"
36
37#include "../../input/cl_keys.h"
38#include "../../cl_video.h"
39
41
42static int deltaMouseX;
43static int deltaMouseY;
44
45void uiControlNode::onMouseDown (uiNode_t* node, int x, int y, int button)
46{
47 if (button == K_MOUSE1) {
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
57void uiControlNode::onMouseUp (uiNode_t* node, int x, int y, int button)
58{
59 if (button == K_MOUSE1)
61}
62
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}
Header file for keyboard handler.
@ K_MOUSE1
Definition cl_keys.h:46
viddef_t viddef
Definition cl_video.cpp:34
Video driver defs.
void onMouseDown(uiNode_t *node, int x, int y, int button) override
void onCapturedMouseMove(uiNode_t *node, int x, int y) override
Called when the node is captured by the mouse.
void onMouseUp(uiNode_t *node, int x, int y, int button) override
Header for lua script functions.
node behaviour, how a node work
const char * name
void * lua_SWIG_typeinfo
UINodePtr manager
const char * extends
vec2_t size
Definition ui_nodes.h:52
vec2_t pos
Definition ui_nodes.h:51
Atomic structure used to define most of the UI.
Definition ui_nodes.h:80
uiBox_t box
Definition ui_nodes.h:96
uiNode_t * root
Definition ui_nodes.h:93
void UI_SetMouseCapture(uiNode_t *node)
Captured the mouse into a node.
Definition ui_input.cpp:516
void UI_MouseRelease(void)
Release the captured node.
Definition ui_input.cpp:526
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_NodeAbsoluteToRelativePos(const uiNode_t *node, int *x, int *y)
Update an absolute position to a relative one.
Definition ui_node.cpp:604
SharedPtr< uiNode > UINodePtr
static int deltaMouseY
static int deltaMouseX
void UI_RegisterControlsNode(uiBehaviour_t *behaviour)
void UI_SetNewWindowPos(uiNode_t *window, int x, int y)
Sets new x and y coordinates for a given window.