UFO: Alien Invasion
Loading...
Searching...
No Matches
ui_dragndrop.cpp
Go to the documentation of this file.
1
4
5/*
6Copyright (C) 2002-2025 UFO: Alien Invasion.
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17See the GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23*/
24
25#include "ui_internal.h"
26#include "ui_dragndrop.h"
27#include "ui_input.h"
28#include "ui_node.h"
29#include "ui_sound.h"
30
33
34#include "../input/cl_input.h"
35
36static int oldMousePosX = -1;
37static int oldMousePosY = -1;
38
39static bool nodeAcceptDND = false;
40static bool positionAcceptDND = false;
41
44
47
48
53{
54 return objectType != DND_NOTHING;
55}
56
61{
62 if (!UI_DNDIsDragging())
63 return false;
64 return targetNode == node;
65}
66
71{
72 if (!UI_DNDIsDragging())
73 return false;
74 return sourceNode == node;
75}
76
80int UI_DNDGetType (void)
81{
82 return objectType;
83}
84
89{
90 assert(UI_DNDIsDragging());
91 return targetNode;
92}
93
98{
99 assert(UI_DNDIsDragging());
100 return sourceNode;
101}
102
109static void UI_DNDDrag (uiNode_t* node)
110{
111 assert(!UI_DNDIsDragging());
113 sourceNode = node;
114
115 UI_PlaySound("item-drag");
116}
117
124void UI_DNDDragItem (uiNode_t* node, const Item* item)
125{
126 UI_DNDDrag(node);
127 assert(UI_DNDIsDragging());
129 draggingItem = *item;
130}
131
135static inline void UI_DNDCleanup (void)
136{
138 targetNode = nullptr;
139 sourceNode = nullptr;
140}
141
147void UI_DNDAbort (void)
148{
149 assert(UI_DNDIsDragging());
150 assert(objectType != DND_NOTHING);
151 assert(sourceNode != nullptr);
152
153 if (nodeAcceptDND && targetNode) {
155 }
157
160}
161
167void UI_DNDDrop (void)
168{
169 bool result = false;
170 assert(UI_DNDIsDragging());
171 assert(objectType != DND_NOTHING);
172 assert(sourceNode != nullptr);
173
174 if (!positionAcceptDND) {
175 UI_DNDAbort();
176 return;
177 }
178
179 if (targetNode) {
181 }
183
184 UI_PlaySound("item-drop");
185
188}
189
191{
192 assert(objectType == DND_ITEM);
193 return &draggingItem;
194}
195
199static void UI_DNDMouseMove (int mousePosX, int mousePosY)
200{
202
203 if (node != targetNode) {
204 if (nodeAcceptDND && targetNode) {
206 }
207 targetNode = node;
208 if (targetNode) {
210 }
211 }
212
213 if (targetNode == nullptr) {
214 nodeAcceptDND = false;
215 positionAcceptDND = false;
216 return;
217 }
218
219 if (!nodeAcceptDND) {
220 positionAcceptDND = false;
221 return;
222 }
223
225}
226
231{
232 const vec3_t scale = { 3.5, 3.5, 3.5 };
233 vec3_t orgine;
234 vec4_t color = { 1, 1, 1, 1 };
235
236 /* check mouse move */
241 }
242
243 /* draw the dragging item */
244
245 VectorSet(orgine, mousePosX, mousePosY, -50);
246
247 /* Tune down the opacity of the cursor-item if the preview item is drawn. */
249 color[3] = 0.2;
250
251 switch (objectType) {
252 case DND_ITEM:
253 UI_DrawItem(nullptr, orgine, &draggingItem, -1, -1, scale, color);
254 break;
255
256 default:
257 assert(false);
258 }
259}
int mousePosY
Definition cl_input.cpp:76
static int oldMousePosX
Definition cl_input.cpp:77
int mousePosX
Definition cl_input.cpp:76
static int oldMousePosY
Definition cl_input.cpp:77
External (non-keyboard) input devices.
item instance data, with linked list capability
Definition inv_shared.h:402
Atomic structure used to define most of the UI.
Definition ui_nodes.h:80
vec_t vec3_t[3]
Definition ufotypes.h:39
vec_t vec4_t[4]
Definition ufotypes.h:40
bool UI_DNDIsDragging(void)
Return true if we are dragging something.
static uiNode_t * targetNode
static void UI_DNDDrag(uiNode_t *node)
Private function to initialize a the start of a DND.
void UI_DNDDrop(void)
Drop the object at the current position.
bool UI_DNDIsTargetNode(uiNode_t *node)
Return true if the requested node is the current target of the DND.
static uiNode_t * sourceNode
static bool positionAcceptDND
static Item draggingItem
static uiDNDType_t objectType
Item * UI_DNDGetItem(void)
static void UI_DNDCleanup(void)
Cleanup data about DND.
uiNode_t * UI_DNDGetTargetNode(void)
Return target of the DND.
void UI_DNDAbort(void)
Drop the object at the current position.
static bool nodeAcceptDND
void UI_DNDDragItem(uiNode_t *node, const Item *item)
Start to drag an item.
int UI_DNDGetType(void)
Return the current type of the dragging object, else DND_NOTHING.
bool UI_DNDIsSourceNode(uiNode_t *node)
Return true if the requested node is the source of the DND.
uiNode_t * UI_DNDGetSourceNode(void)
Return source of the DND.
void UI_DrawDragAndDrop(int mousePosX, int mousePosY)
Draw to dragging object and catch mouse move event.
static void UI_DNDMouseMove(int mousePosX, int mousePosY)
Manage the DND when we move the mouse.
uiDNDType_t
@ DND_ITEM
@ DND_NOTHING
@ DND_SOMETHING
void UI_InvalidateMouse(void)
Force to invalidate the mouse position and then to update hover nodes...
Definition ui_input.cpp:560
Internal data use by the UI package.
bool UI_Node_DndEnter(uiNode_t *node)
Definition ui_node.cpp:303
bool UI_Node_DndFinished(uiNode_t *node, bool isDroped)
Definition ui_node.cpp:327
bool UI_Node_DndDrop(uiNode_t *node, int x, int y)
Definition ui_node.cpp:321
void UI_Node_DndLeave(uiNode_t *node)
Definition ui_node.cpp:315
bool UI_Node_DndMove(uiNode_t *node, int x, int y)
Definition ui_node.cpp:309
C interface to allow to access to cpp node code.
static const vec3_t scale
void UI_DrawItem(uiNode_t *node, const vec3_t org, const Item *item, int x, int y, const vec3_t scale, const vec4_t color)
Draws an item to the screen.
uiNode_t * UI_GetNodeAtPosition(int x, int y)
Return the first visible node at a position.
Definition ui_nodes.cpp:527
void UI_PlaySound(const char *soundFile)
Plays a ui sound.
Definition ui_sound.cpp:35
#define VectorSet(v, x, y, z)
Definition vector.h:59