UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ui_node_zone.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_parse.h"
30 #include "../ui_behaviour.h"
31 #include "../ui_input.h"
32 #include "../ui_timer.h"
33 #include "../ui_actions.h"
34 #include "ui_node_zone.h"
35 #include "ui_node_window.h"
36 
37 #include "../../input/cl_keys.h"
38 
39 #include "../../../common/scripts_lua.h"
40 
41 #define EXTRADATA_TYPE zoneExtraData_t
42 #define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
43 
45 
47 {
48  if (node->onClick) {
49  UI_ExecuteEventActions(node, node->onClick);
50  }
51 }
52 
53 void uiZoneNode::onMouseDown (uiNode_t* node, int x, int y, int button)
54 {
55  if (!EXTRADATA(node).repeat)
56  return;
57  if (button == K_MOUSE1) {
58  UI_SetMouseCapture(node);
59  capturedTimer = UI_AllocTimer(node, EXTRADATA(node).clickDelay, UI_ZoneNodeRepeat);
60  UI_TimerStart(capturedTimer);
61  }
62 }
63 
64 void uiZoneNode::onMouseUp (uiNode_t* node, int x, int y, int button)
65 {
66  if (!EXTRADATA(node).repeat)
67  return;
68  if (button == K_MOUSE1) {
70  }
71 }
72 
78 {
79  if (capturedTimer) {
80  UI_TimerRelease(capturedTimer);
81  capturedTimer = nullptr;
82  }
83 }
84 
89 {
90  EXTRADATA(node).clickDelay = 1000;
91 }
92 
94 {
95  behaviour->name = "zone";
96  behaviour->manager = UINodePtr(new uiZoneNode());
97  behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
98  behaviour->lua_SWIG_typeinfo = UI_SWIG_TypeQuery("uiZoneNode_t *");
99 
100  /* If true, the <code>onclick</code> call back is called more than one time if the user does not release the button. */
101  UI_RegisterExtradataNodeProperty(behaviour, "repeat", V_BOOL, zoneExtraData_t, repeat);
102  /* Delay is used between 2 calls of <code>onclick</code>. */
103  UI_RegisterExtradataNodeProperty(behaviour, "clickdelay", V_INT, zoneExtraData_t, clickDelay);
104 }
static void UI_ZoneNodeRepeat(uiNode_t *node, uiTimer_t *timer)
void onCapturedMouseLost(uiNode_t *node) override
Called when the node have lost the captured node We clean cached data.
const char * name
Definition: ui_behaviour.h:41
UINodePtr manager
Definition: ui_behaviour.h:43
uiTimer_t * UI_AllocTimer(uiNode_t *node, int firstDelay, timerCallback_t callback)
Allocate a new time for a node.
Definition: ui_timer.cpp:123
void UI_RegisterZoneNode(uiBehaviour_t *behaviour)
struct uiAction_s * onClick
Definition: ui_nodes.h:135
#define EXTRADATA(node)
Definition: common.cpp:82
void UI_MouseRelease(void)
Release the captured node.
Definition: ui_input.cpp:526
#define UI_RegisterExtradataNodeProperty(BEHAVIOUR, NAME, TYPE, EXTRADATATYPE, ATTRIBUTE)
Initialize a property from extradata of node.
Definition: ui_behaviour.h:109
void onMouseUp(uiNode_t *node, int x, int y, int button) override
static uiTimer_t * capturedTimer
SharedPtr< uiNode > UINodePtr
void UI_TimerRelease(uiTimer_t *timer)
Release the timer. It no more exists.
Definition: ui_timer.cpp:176
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
void UI_ExecuteEventActions(uiNode_t *source, const uiAction_t *firstAction)
Definition: ui_actions.cpp:726
Atomic structure used to define most of the UI.
Definition: ui_nodes.h:80
uiNode_t * node
Definition: ui_input.h:33
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 onMouseDown(uiNode_t *node, int x, int y, int button) override
intptr_t extraDataSize
Definition: ui_behaviour.h:54
Definition: scripts.h:50
node behaviour, how a node work
Definition: ui_behaviour.h:39
#define EXTRADATA_TYPE
Definition: scripts.h:52
void UI_TimerStart(uiTimer_t *timer)
Restart a timer.
Definition: ui_timer.cpp:150
void onLoading(uiNode_t *node) override
Call before the script initialized the node.