UFO: Alien Invasion
Loading...
Searching...
No Matches
ui_input.cpp File Reference
#include "ui_main.h"
#include "ui_internal.h"
#include "ui_actions.h"
#include "ui_input.h"
#include "ui_nodes.h"
#include "ui_node.h"
#include "ui_parse.h"
#include "ui_draw.h"
#include "ui_dragndrop.h"
#include "ui_timer.h"
#include "../input/cl_keys.h"
#include "../input/cl_input.h"
#include "../cl_shared.h"
#include "../battlescape/cl_localentity.h"
#include "../battlescape/cl_camera.h"
#include "../battlescape/cl_actor.h"
#include "../battlescape/cl_battlescape.h"
Include dependency graph for ui_input.cpp:

Go to the source code of this file.

Macros

#define UI_STARTDRAG_ALREADY_SENT   -1
 Value of pressedNodeLocationX when event already sent.
#define LONGPRESS_DELAY   800
 Value of the delay to wait before sending a long press event This value is used for Qt 4.7. Maybe we can use a cvar.
#define UI_IsMouseInvalidate()

Functions

static bool UI_FocusExecuteActionNode (void)
 Execute the current focused action node.
static bool UI_FocusNextActionNode (void)
 Set the focus to the next action node.
void UI_RequestFocus (uiNode_t *node)
 request the focus for a node
bool UI_HasFocus (const uiNode_t *node)
 check if a node got the focus
void UI_RemoveFocus (void)
static uiKeyBinding_t * UI_AllocStaticKeyBinding (void)
int UI_GetKeyBindingCount (void)
uiKeyBinding_t * UI_GetKeyBindingByIndex (int index)
static void UI_SetKeyBindingEx (const char *path, int key, const char *description, bool inherited)
 Set a binding from a key to a node to active.
void UI_SetKeyBinding (const char *path, int key, const char *description)
 Set a binding from a key to a node to active.
static bool UI_KeyPressedInWindow (uiNode_t *window, unsigned int key, unsigned int unicode)
 Check if a key binding exists for a window and execute it.
bool UI_KeyRelease (unsigned int key, unsigned short unicode)
 Called by the client when the user released a key.
bool UI_KeyPressed (unsigned int key, unsigned short unicode)
 Called by the client when the user type a key.
void UI_ReleaseInput (void)
 Release all captured input (keyboard or mouse).
uiNode_t * UI_GetMouseCapture (void)
 Return the captured node.
void UI_SetMouseCapture (uiNode_t *node)
 Captured the mouse into a node.
void UI_MouseRelease (void)
 Release the captured node.
void UI_ResetInput (void)
uiNode_t * UI_GetHoveredNode (void)
 Get the current hovered node.
void UI_InvalidateMouse (void)
 Force to invalidate the mouse position and then to update hover nodes...
bool UI_CheckMouseMove (void)
 Call mouse move only if the mouse position change.
void UI_MouseMove (int x, int y)
 Is called every time the mouse position change.
static void UI_LeftClick (int x, int y)
 Is called every time one clicks on a window/screen. Then checks if anything needs to be executed in the area of the click (e.g. button-commands, inventory-handling, geoscape-stuff, etc...).
static void UI_RightClick (int x, int y)
static void UI_MiddleClick (int x, int y)
void UI_MouseScroll (int deltaX, int deltaY)
 Called when we are in UI mode and scroll via mousewheel.
static void UI_LongPressCallback (uiNode_t *, uiTimer_t *timer)
void UI_MouseDown (int x, int y, int button)
 Called when we are in UI mode and down a mouse button.
void UI_MouseUp (int x, int y, int button)
 Called when we are in UI mode and up a mouse button.

Variables

static uiNode_t * focusNode
 save the node with the focus
static uiNode_t * hoveredNode
 save the current hovered node (first node under the mouse)
static uiNode_t * oldHoveredNode
 save the previous hovered node
static int oldMousePosX
 save old position of the mouse
static int oldMousePosY
static uiNode_t * capturedNode
 save the captured node
static uiNode_t * pressedNode
 Store node which receive a mouse down event.
static int pressedNodeLocationX
 X position of the mouse when pressedNode != nullptr.
static int pressedNodeLocationY
 Y position of the mouse when pressedNode != nullptr.
static int pressedNodeButton
 Button pressed when pressedNode != nullptr.
static uiTimer_t * longPressTimer
 Timer used to manage long press event.

Macro Definition Documentation

◆ LONGPRESS_DELAY

#define LONGPRESS_DELAY   800

Value of the delay to wait before sending a long press event This value is used for Qt 4.7. Maybe we can use a cvar.

Definition at line 107 of file ui_input.cpp.

Referenced by UI_MouseDown().

◆ UI_IsMouseInvalidate

#define UI_IsMouseInvalidate ( )
Value:
(oldMousePosX == -1)
static int oldMousePosX
save old position of the mouse
Definition ui_input.cpp:66

Definition at line 666 of file ui_input.cpp.

Referenced by UI_LeftClick(), UI_MiddleClick(), and UI_RightClick().

◆ UI_STARTDRAG_ALREADY_SENT

#define UI_STARTDRAG_ALREADY_SENT   -1

Value of pressedNodeLocationX when event already sent.

Definition at line 101 of file ui_input.cpp.

Referenced by UI_MouseMove().

Function Documentation

◆ UI_AllocStaticKeyBinding()

◆ UI_CheckMouseMove()

bool UI_CheckMouseMove ( void )

Call mouse move only if the mouse position change.

Definition at line 569 of file ui_input.cpp.

References hoveredNode, uiNode_t::invis, mousePosX, mousePosY, oldMousePosX, oldMousePosY, UI_CheckMouseMove(), UI_CheckVisibility(), UI_InvalidateMouse(), and UI_MouseMove().

Referenced by UI_CheckMouseMove(), and UI_Draw().

◆ UI_FocusExecuteActionNode()

bool UI_FocusExecuteActionNode ( void )
static

Execute the current focused action node.

Note
Action nodes are nodes with click defined
See also
Key_Event
UI_FocusNextActionNode
Todo
need a cleanup

<

Todo
need a cleanup

Definition at line 121 of file ui_input.cpp.

References focusNode, IN_GetMouseSpace, MS_UI, uiNode_t::onClick, uiNode_t::onMouseLeave, UI_ExecuteEventActions(), UI_FocusExecuteActionNode(), and UI_GetMouseCapture().

Referenced by UI_FocusExecuteActionNode(), and UI_KeyPressed().

◆ UI_FocusNextActionNode()

bool UI_FocusNextActionNode ( void )
static

Set the focus to the next action node.

Note
Action nodes are nodes with click defined
See also
Key_Event
UI_FocusExecuteActionNode

<

Todo
need a cleanup

Definition at line 167 of file ui_input.cpp.

References uiNode_t::firstChild, focusNode, i, IN_GetMouseSpace, MS_UI, UI_FocusNextActionNode(), UI_GetLastFullScreenWindow(), UI_GetMouseCapture(), ui_global, UI_MAX_WINDOWSTACK, UI_RemoveFocus(), uiGlobal_t::windowStack, and uiGlobal_t::windowStackPos.

Referenced by UI_FocusNextActionNode(), and UI_KeyPressed().

◆ UI_GetHoveredNode()

uiNode_t * UI_GetHoveredNode ( void )

Get the current hovered node.

Returns
A node, else nullptr if the mouse hover nothing

Definition at line 552 of file ui_input.cpp.

References hoveredNode, and UI_GetHoveredNode().

Referenced by UI_BeforeDeletingNode(), UI_Draw(), UI_GetHoveredNode(), and UI_IsMouseOnWindow().

◆ UI_GetKeyBindingByIndex()

uiKeyBinding_t * UI_GetKeyBindingByIndex ( int index)

◆ UI_GetKeyBindingCount()

int UI_GetKeyBindingCount ( void )

◆ UI_GetMouseCapture()

◆ UI_HasFocus()

bool UI_HasFocus ( const uiNode_t * node)

check if a node got the focus

Definition at line 230 of file ui_input.cpp.

References focusNode, and UI_HasFocus().

Referenced by uiTextEntryNode::draw(), uiTextEntryNode::onLeftClick(), UI_HasFocus(), UI_TextEntryNodeFocus(), and UI_TextEntryNodeUnFocus().

◆ UI_InvalidateMouse()

void UI_InvalidateMouse ( void )

Force to invalidate the mouse position and then to update hover nodes...

Definition at line 560 of file ui_input.cpp.

References oldMousePosX, oldMousePosY, and UI_InvalidateMouse().

Referenced by UI_BeforeDeletingNode(), UI_CheckMouseMove(), UI_CloseWindowByRef(), UI_DeleteWindowFromStack(), UI_DNDAbort(), UI_DNDDrop(), UI_InvalidateMouse(), UI_MouseRelease(), UI_PushWindow(), and UI_Reinit().

◆ UI_KeyPressed()

bool UI_KeyPressed ( unsigned int key,
unsigned short unicode )

Called by the client when the user type a key.

Parameters
[in]keykey code, either K_ value or lowercase ascii
[in]unicodetranslated meaning of keypress in unicode
Returns
true, if we used the event
Todo
think about what we should do when the mouse is captured

Definition at line 430 of file ui_input.cpp.

References le_t::actorMode, CL_ActorFireModeActivated(), CL_ActorSetMode(), CL_BattlescapeRunning(), focusNode, K_ENTER, K_ESCAPE, K_KP_ENTER, K_TAB, M_MOVE, selActor, UI_DNDAbort(), UI_DNDIsDragging(), UI_FocusExecuteActionNode(), UI_FocusNextActionNode(), UI_GetLastFullScreenWindow(), UI_GetMouseCapture(), ui_global, UI_KeyPressed(), UI_KeyPressedInWindow(), UI_MouseRelease(), UI_Node_KeyPressed(), UI_PopWindowWithEscKey(), UI_WindowIsModal(), uiGlobal_t::windowStack, and uiGlobal_t::windowStackPos.

Referenced by Key_Event(), and UI_KeyPressed().

◆ UI_KeyPressedInWindow()

bool UI_KeyPressedInWindow ( uiNode_t * window,
unsigned int key,
unsigned int unicode )
static

◆ UI_KeyRelease()

bool UI_KeyRelease ( unsigned int key,
unsigned short unicode )

Called by the client when the user released a key.

Parameters
[in]keykey code, either K_ value or lowercase ascii
[in]unicodetranslated meaning of keypress in unicode
Returns
true, if we used the event

Definition at line 413 of file ui_input.cpp.

References focusNode, UI_KeyRelease(), and UI_Node_KeyReleased().

Referenced by Key_Event(), and UI_KeyRelease().

◆ UI_LeftClick()

void UI_LeftClick ( int x,
int y )
static

Is called every time one clicks on a window/screen. Then checks if anything needs to be executed in the area of the click (e.g. button-commands, inventory-handling, geoscape-stuff, etc...).

See also
UI_ExecuteEventActions
UI_RightClick
Key_Message
Todo
need to refactoring it with the focus code (cleaner)
Todo
at least should be moved on the mouse down event (when the focus should change)
Todo
this code must be on mouse down

Definition at line 675 of file ui_input.cpp.

References capturedNode, uiNode_t::disabled, uiNode_t::parent, pressedNode, ui_global, UI_IsMouseInvalidate, UI_LeftClick(), UI_Node_LeftClick(), UI_PopWindow(), UI_WindowIsDropDown(), uiGlobal_t::windowStack, and uiGlobal_t::windowStackPos.

Referenced by UI_LeftClick(), and UI_MouseUp().

◆ UI_LongPressCallback()

void UI_LongPressCallback ( uiNode_t * ,
uiTimer_t * timer )
static

Callback function waked up to send long click event

Definition at line 779 of file ui_input.cpp.

References uiNode_t::parent, pressedNode, pressedNodeButton, pressedNodeLocationX, pressedNodeLocationY, UI_LongPressCallback(), UI_Node_MouseLongPress(), and UI_TimerStop().

Referenced by UI_LongPressCallback(), and UI_MouseDown().

◆ UI_MiddleClick()

void UI_MiddleClick ( int x,
int y )
static

◆ UI_MouseDown()

void UI_MouseDown ( int x,
int y,
int button )

◆ UI_MouseMove()

◆ UI_MouseRelease()

◆ UI_MouseScroll()

void UI_MouseScroll ( int deltaX,
int deltaY )

Called when we are in UI mode and scroll via mousewheel.

Note
The geoscape zooming code is here, too (also in
See also
CL_ParseInput)
UI_LeftClick
UI_RightClick
UI_MiddleClick

Definition at line 756 of file ui_input.cpp.

References capturedNode, hoveredNode, uiNode_t::parent, UI_MouseScroll(), and UI_Node_Scroll().

Referenced by CL_WheelDown_f(), CL_WheelUp_f(), and UI_MouseScroll().

◆ UI_MouseUp()

void UI_MouseUp ( int x,
int y,
int button )

Called when we are in UI mode and up a mouse button.

See also
UI_LeftClick
UI_RightClick
UI_MiddleClick
Todo
it is really need to clean up this subfunctions

Definition at line 839 of file ui_input.cpp.

References capturedNode, hoveredNode, K_MOUSE1, K_MOUSE2, K_MOUSE3, longPressTimer, pressedNode, UI_LeftClick(), UI_MiddleClick(), UI_MouseUp(), UI_Node_MouseUp(), UI_RightClick(), and UI_TimerStop().

Referenced by CL_LeftClickUp_f(), CL_MiddleClickUp_f(), CL_RightClickUp_f(), and UI_MouseUp().

◆ UI_ReleaseInput()

void UI_ReleaseInput ( void )

Release all captured input (keyboard or mouse).

Definition at line 496 of file ui_input.cpp.

References UI_DNDAbort(), UI_DNDIsDragging(), UI_MouseRelease(), UI_ReleaseInput(), and UI_RemoveFocus().

Referenced by IN_Frame(), Key_SetDest(), UI_CloseWindowByRef(), UI_PushWindow(), UI_Reinit(), and UI_ReleaseInput().

◆ UI_RemoveFocus()

◆ UI_RequestFocus()

void UI_RequestFocus ( uiNode_t * node)

request the focus for a node

Definition at line 206 of file ui_input.cpp.

References focusNode, UI_Node_FocusGained(), UI_Node_FocusLost(), and UI_RequestFocus().

Referenced by uiTextEntryNode::onLeftClick(), UI_RequestFocus(), and UI_TextEntryNodeFocus().

◆ UI_ResetInput()

void UI_ResetInput ( void )

◆ UI_RightClick()

◆ UI_SetKeyBinding()

void UI_SetKeyBinding ( const char * path,
int key,
const char * description )

Set a binding from a key to a node to active.

Parameters
pathPath to a node, or a node method
keyThe key number to use (see for example the K_* names are matched up.)
descriptionTextual description of what the key/cmd does (for tooltip)
Todo

check: only one binding per nodes?

check: key per window must be unique

check: key used into UI_KeyPressed can't be used

Definition at line 362 of file ui_input.cpp.

References UI_SetKeyBinding(), and UI_SetKeyBindingEx().

Referenced by Key_Bind_f(), and UI_SetKeyBinding().

◆ UI_SetKeyBindingEx()

void UI_SetKeyBindingEx ( const char * path,
int key,
const char * description,
bool inherited )
static

Set a binding from a key to a node to active.

This command creates a relation between a key and a node.

The relation is stored with the node (to display the shortcut in the tooltip) and with the parent window of the node (for faster search of all available shortcuts).

The storage on the node is not a list, so if there is more than one shortcut to a node we can't display all shortcuts in the tooltip, but the binding will still work.

If the parent window is inherited, the binding is duped to other extended windows and the relation is flagged as "inherited".

Parameters
pathPath to a node, or a node method
keyThe key number to use (see for example the K_* names are matched up.)
descriptionTextual description of what the key/cmd does (for tooltip)
inheritedTrue if this binding is inherited from another binding.
Todo

check: only one binding per nodes

check: key per window must be unique

check: key used into UI_KeyPressed can't be used

Definition at line 306 of file ui_input.cpp.

References binding, Com_Error(), Com_Printf(), uiKeyBinding_t::description, ERR_FATAL, uiKeyBinding_t::inherited, uiKeyBinding_t::key, uiNode_t::key, Key_KeynumToString(), Mem_PoolStrDup, uiNode_t::name, uiKeyBinding_t::node, uiGlobal_t::numWindows, uiKeyBinding_t::property, Q_strcat(), Q_strnull(), uiNode_t::root, uiNode_t::super, UI_AllocStaticKeyBinding(), ui_dynPool, ui_global, UI_ReadNodePath(), UI_SetKeyBindingEx(), UI_WindowNodeRegisterKeyBinding(), V_UI_NODEMETHOD, and uiGlobal_t::windows.

Referenced by UI_SetKeyBinding(), and UI_SetKeyBindingEx().

◆ UI_SetMouseCapture()

Variable Documentation

◆ capturedNode

uiNode_t* capturedNode
static

save the captured node

See also
UI_SetMouseCapture
UI_GetMouseCapture
UI_MouseRelease
Todo
think about replacing it by a boolean. When capturedNode != nullptr => hoveredNode == capturedNode it create unneed case

Definition at line 76 of file ui_input.cpp.

Referenced by UI_GetMouseCapture(), UI_LeftClick(), UI_MiddleClick(), UI_MouseDown(), UI_MouseMove(), UI_MouseRelease(), UI_MouseScroll(), UI_MouseUp(), UI_ResetInput(), UI_RightClick(), and UI_SetMouseCapture().

◆ focusNode

uiNode_t* focusNode
static

◆ hoveredNode

uiNode_t* hoveredNode
static

save the current hovered node (first node under the mouse)

See also
UI_GetHoveredNode
UI_MouseMove
UI_CheckMouseMove

Definition at line 56 of file ui_input.cpp.

Referenced by UI_CheckMouseMove(), UI_GetHoveredNode(), UI_MouseDown(), UI_MouseMove(), UI_MouseScroll(), UI_MouseUp(), and UI_ResetInput().

◆ longPressTimer

uiTimer_t* longPressTimer
static

Timer used to manage long press event.

Definition at line 112 of file ui_input.cpp.

Referenced by UI_MouseDown(), UI_MouseMove(), UI_MouseUp(), and UI_ResetInput().

◆ oldHoveredNode

uiNode_t* oldHoveredNode
static

save the previous hovered node

Definition at line 61 of file ui_input.cpp.

Referenced by UI_MouseMove(), and UI_ResetInput().

◆ oldMousePosX

int oldMousePosX
static

save old position of the mouse

Definition at line 66 of file ui_input.cpp.

◆ oldMousePosY

int oldMousePosY
static

Definition at line 66 of file ui_input.cpp.

◆ pressedNode

uiNode_t* pressedNode
static

Store node which receive a mouse down event.

Definition at line 81 of file ui_input.cpp.

Referenced by UI_LeftClick(), UI_LongPressCallback(), UI_MiddleClick(), UI_MouseDown(), UI_MouseMove(), UI_MouseUp(), UI_ResetInput(), and UI_RightClick().

◆ pressedNodeButton

int pressedNodeButton
static

Button pressed when pressedNode != nullptr.

Definition at line 96 of file ui_input.cpp.

Referenced by UI_LongPressCallback(), UI_MouseDown(), and UI_MouseMove().

◆ pressedNodeLocationX

int pressedNodeLocationX
static

X position of the mouse when pressedNode != nullptr.

Definition at line 86 of file ui_input.cpp.

Referenced by UI_LongPressCallback(), UI_MouseDown(), and UI_MouseMove().

◆ pressedNodeLocationY

int pressedNodeLocationY
static

Y position of the mouse when pressedNode != nullptr.

Definition at line 91 of file ui_input.cpp.

Referenced by UI_LongPressCallback(), UI_MouseDown(), and UI_MouseMove().