UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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"

Go to the source code of this file.

Macros

#define UI_STARTDRAG_ALREADY_SENT   -1
 Value of pressedNodeLocationX when event already sent. More...
 
#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. More...
 
#define UI_IsMouseInvalidate()   (oldMousePosX == -1)
 

Functions

static bool UI_FocusExecuteActionNode (void)
 Execute the current focused action node. More...
 
static bool UI_FocusNextActionNode (void)
 Set the focus to the next action node. More...
 
void UI_RequestFocus (uiNode_t *node)
 request the focus for a node More...
 
bool UI_HasFocus (const uiNode_t *node)
 check if a node got the focus More...
 
void UI_RemoveFocus (void)
 
static uiKeyBinding_tUI_AllocStaticKeyBinding (void)
 
int UI_GetKeyBindingCount (void)
 
uiKeyBinding_tUI_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. More...
 
void UI_SetKeyBinding (const char *path, int key, const char *description)
 Set a binding from a key to a node to active. More...
 
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. More...
 
bool UI_KeyRelease (unsigned int key, unsigned short unicode)
 Called by the client when the user released a key. More...
 
bool UI_KeyPressed (unsigned int key, unsigned short unicode)
 Called by the client when the user type a key. More...
 
void UI_ReleaseInput (void)
 Release all captured input (keyboard or mouse) More...
 
uiNode_tUI_GetMouseCapture (void)
 Return the captured node. More...
 
void UI_SetMouseCapture (uiNode_t *node)
 Captured the mouse into a node. More...
 
void UI_MouseRelease (void)
 Release the captured node. More...
 
void UI_ResetInput (void)
 
uiNode_tUI_GetHoveredNode (void)
 Get the current hovered node. More...
 
void UI_InvalidateMouse (void)
 Force to invalidate the mouse position and then to update hover nodes... More...
 
bool UI_CheckMouseMove (void)
 Call mouse move only if the mouse position change. More...
 
void UI_MouseMove (int x, int y)
 Is called every time the mouse position change. More...
 
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...) More...
 
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. More...
 
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. More...
 
void UI_MouseUp (int x, int y, int button)
 Called when we are in UI mode and up a mouse button. More...
 

Variables

static uiNode_tfocusNode
 save the node with the focus More...
 
static uiNode_thoveredNode
 save the current hovered node (first node under the mouse) More...
 
static uiNode_toldHoveredNode
 save the previous hovered node More...
 
static int oldMousePosX
 save old position of the mouse More...
 
static int oldMousePosY
 
static uiNode_tcapturedNode
 save the captured node More...
 
static uiNode_tpressedNode
 Store node which receive a mouse down event. More...
 
static int pressedNodeLocationX
 X position of the mouse when pressedNode != nullptr. More...
 
static int pressedNodeLocationY
 Y position of the mouse when pressedNode != nullptr. More...
 
static int pressedNodeButton
 Button pressed when pressedNode != nullptr. More...
 
static uiTimer_tlongPressTimer
 Timer used to manage long press event. More...
 

Macro Definition Documentation

#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().

#define UI_IsMouseInvalidate ( )    (oldMousePosX == -1)

Definition at line 666 of file ui_input.cpp.

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

#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

static uiKeyBinding_t* UI_AllocStaticKeyBinding ( void  )
static
bool UI_CheckMouseMove ( void  )

Call mouse move only if the mouse position change.

Definition at line 569 of file ui_input.cpp.

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

Referenced by UI_Draw().

static 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 uiNode_t::onClick, uiNode_t::onMouseLeave, UI_ExecuteEventActions(), and UI_GetMouseCapture().

Referenced by UI_KeyPressed().

static 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, i, IN_GetMouseSpace, MS_UI, UI_GetLastFullScreenWindow(), UI_GetMouseCapture(), ui_global, UI_RemoveFocus(), uiGlobal_s::windowStack, and uiGlobal_s::windowStackPos.

Referenced by UI_KeyPressed().

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.

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

uiKeyBinding_t* UI_GetKeyBindingByIndex ( int  index)

Definition at line 277 of file ui_input.cpp.

References index, uiGlobal_s::keyBindings, and ui_global.

Referenced by CLMN_AddUIBindings(), and Key_WriteBindings().

int UI_GetKeyBindingCount ( void  )

Definition at line 272 of file ui_input.cpp.

References uiGlobal_s::numKeyBindings, and ui_global.

Referenced by CLMN_AddUIBindings(), and Key_WriteBindings().

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.

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

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, and oldMousePosY.

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

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_s::actorMode, CL_ActorFireModeActivated(), CL_ActorSetMode(), CL_BattlescapeRunning(), 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_KeyPressedInWindow(), UI_MouseRelease(), UI_Node_KeyPressed(), UI_PopWindowWithEscKey(), UI_WindowIsModal(), uiGlobal_s::windowStack, and uiGlobal_s::windowStackPos.

Referenced by Key_Event().

static bool UI_KeyPressedInWindow ( uiNode_t window,
unsigned int  key,
unsigned int  unicode 
)
static
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 UI_Node_KeyReleased().

Referenced by Key_Event().

static 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 uiNode_t::disabled, uiNode_t::parent, ui_global, UI_IsMouseInvalidate, UI_Node_LeftClick(), UI_PopWindow(), UI_WindowIsDropDown(), uiGlobal_s::windowStack, and uiGlobal_s::windowStackPos.

Referenced by UI_MouseUp().

static 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_Node_MouseLongPress(), and UI_TimerStop().

Referenced by UI_MouseDown().

static void UI_MiddleClick ( int  x,
int  y 
)
static
See also
UI_LeftClick
UI_RightClick
UI_MouseWheel

Definition at line 732 of file ui_input.cpp.

References uiNode_t::disabled, uiNode_t::parent, UI_IsMouseInvalidate, and UI_Node_MiddleClick().

Referenced by UI_MouseUp().

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

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

See also
UI_LeftClick
UI_RightClick
UI_MiddleClick
Todo:
find a way to create the timer when UI loading and remove "if (longPressTimer)"

Definition at line 801 of file ui_input.cpp.

References hoveredNode, LONGPRESS_DELAY, pressedNodeButton, pressedNodeLocationX, pressedNodeLocationY, uiNode_t::root, UI_AllocTimer(), UI_LongPressCallback(), UI_MoveWindowOnTop(), UI_Node_MouseDown(), UI_TimerStart(), and UI_TimerStop().

Referenced by CL_LeftClickDown_f(), CL_MiddleClickDown_f(), and CL_RightClickDown_f().

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 hoveredNode, uiNode_t::parent, and UI_Node_Scroll().

Referenced by CL_WheelDown_f(), and CL_WheelUp_f().

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, UI_LeftClick(), UI_MiddleClick(), UI_Node_MouseUp(), UI_RightClick(), and UI_TimerStop().

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

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(), and UI_RemoveFocus().

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

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(), and UI_Node_FocusLost().

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

void UI_ResetInput ( void  )

Definition at line 538 of file ui_input.cpp.

Referenced by UI_Shutdown().

static void UI_RightClick ( int  x,
int  y 
)
static
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_SetKeyBindingEx().

Referenced by Key_Bind_f().

static 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_s::description, ERR_FATAL, uiKeyBinding_s::inherited, uiKeyBinding_s::key, key, uiNode_t::key, Key_KeynumToString(), Mem_PoolStrDup, uiNode_t::name, uiKeyBinding_s::node, uiGlobal_s::numWindows, uiKeyBinding_s::property, Q_strcat(), Q_strnull(), uiNode_t::root, uiNode_t::super, UI_AllocStaticKeyBinding(), ui_dynPool, ui_global, UI_ReadNodePath(), UI_WindowNodeRegisterKeyBinding(), V_UI_NODEMETHOD, and uiGlobal_s::windows.

Referenced by UI_SetKeyBinding().

Variable Documentation

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_MouseRelease(), and UI_MouseUp().

uiNode_t* focusNode
static

save the node with the focus

Definition at line 48 of file ui_input.cpp.

Referenced by UI_HasFocus(), UI_RemoveFocus(), and UI_RequestFocus().

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_GetHoveredNode(), UI_MouseDown(), UI_MouseMove(), UI_MouseScroll(), and UI_MouseUp().

uiTimer_t* longPressTimer
static

Timer used to manage long press event.

Definition at line 112 of file ui_input.cpp.

uiNode_t* oldHoveredNode
static

save the previous hovered node

Definition at line 61 of file ui_input.cpp.

Referenced by UI_MouseMove().

int oldMousePosX
static

save old position of the mouse

Definition at line 66 of file ui_input.cpp.

Referenced by UI_CheckMouseMove(), and UI_InvalidateMouse().

int oldMousePosY
static

Definition at line 66 of file ui_input.cpp.

Referenced by UI_CheckMouseMove(), and UI_InvalidateMouse().

uiNode_t* pressedNode
static

Store node which receive a mouse down event.

Definition at line 81 of file ui_input.cpp.

Referenced by UI_LongPressCallback(), and UI_MouseMove().

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().

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().

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().