UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ui_actions.h File Reference

Go to the source code of this file.

Data Structures

union  uiTerminalActionData_s
 Defines the data of a uiAction_t leaf. It allows different kind of data without cast. More...
 
struct  uiAction_s
 Atomic element to store UI scripts The parser use this atom to translate script action into many trees of actions. One function is one tree, and when we call this function, the tree is executed. More...
 
struct  uiValue_s
 Type for uiAction_t It also contain type about type (for example EA_BINARYOPERATOR) More...
 
struct  uiCallContext_s
 Contain the context of the calling of a function. More...
 

Typedefs

typedef enum uiActionType_s uiActionType_t
 Type for uiAction_t It also contain type about type (for example EA_BINARYOPERATOR) More...
 
typedef union
uiTerminalActionData_s 
uiTerminalActionData_t
 Defines the data of a uiAction_t leaf. It allows different kind of data without cast. More...
 
typedef struct uiAction_s uiAction_t
 Atomic element to store UI scripts The parser use this atom to translate script action into many trees of actions. One function is one tree, and when we call this function, the tree is executed. More...
 
typedef struct uiValue_s uiValue_t
 Type for uiAction_t It also contain type about type (for example EA_BINARYOPERATOR) More...
 
typedef struct uiCallContext_s uiCallContext_t
 Contain the context of the calling of a function. More...
 

Enumerations

enum  uiActionType_s {
  EA_NULL = 0, EA_BINARYOPERATOR, EA_UNARYOPERATOR, EA_HIGHT_MASK = 0xFF00,
  EA_ACTION = 0x0100, EA_CMD = EA_ACTION + 1, EA_CALL = EA_ACTION + 2, EA_ASSIGN = EA_ACTION + 3,
  EA_IF = EA_ACTION + 4, EA_ELSE = EA_ACTION + 5, EA_ELIF = EA_ACTION + 6, EA_WHILE = EA_ACTION + 7,
  EA_DELETE = EA_ACTION + 8, EA_LISTENER = EA_ACTION + 9, EA_PUSHVARS = EA_ACTION + 10, EA_POPVARS = EA_ACTION + 11,
  EA_FORCHILDIN = EA_ACTION + 12, EA_BREAK = EA_ACTION + 13, EA_OPERATOR_BOOLEAN2BOOLEAN = 0x0300, EA_OPERATOR_AND = EA_OPERATOR_BOOLEAN2BOOLEAN + 1,
  EA_OPERATOR_OR = EA_OPERATOR_BOOLEAN2BOOLEAN + 2, EA_OPERATOR_XOR = EA_OPERATOR_BOOLEAN2BOOLEAN + 3, EA_OPERATOR_NOT = EA_OPERATOR_BOOLEAN2BOOLEAN + 4, EA_OPERATOR_FLOAT2BOOLEAN = 0x0400,
  EA_OPERATOR_EQ = EA_OPERATOR_FLOAT2BOOLEAN + 1, EA_OPERATOR_LE = EA_OPERATOR_FLOAT2BOOLEAN + 2, EA_OPERATOR_GE = EA_OPERATOR_FLOAT2BOOLEAN + 3, EA_OPERATOR_GT = EA_OPERATOR_FLOAT2BOOLEAN + 4,
  EA_OPERATOR_LT = EA_OPERATOR_FLOAT2BOOLEAN + 5, EA_OPERATOR_NE = EA_OPERATOR_FLOAT2BOOLEAN + 6, EA_OPERATOR_FLOAT2FLOAT = 0x0500, EA_OPERATOR_ADD = EA_OPERATOR_FLOAT2FLOAT + 1,
  EA_OPERATOR_SUB = EA_OPERATOR_FLOAT2FLOAT + 2, EA_OPERATOR_MUL = EA_OPERATOR_FLOAT2FLOAT + 3, EA_OPERATOR_DIV = EA_OPERATOR_FLOAT2FLOAT + 4, EA_OPERATOR_MOD = EA_OPERATOR_FLOAT2FLOAT + 5,
  EA_OPERATOR_STRING2BOOLEAN = 0x0600, EA_OPERATOR_STR_EQ = EA_OPERATOR_STRING2BOOLEAN + 1, EA_OPERATOR_STR_NE = EA_OPERATOR_STRING2BOOLEAN + 2, EA_OPERATOR_UNARY = 0x0700,
  EA_OPERATOR_EXISTS = EA_OPERATOR_UNARY + 1, EA_OPERATOR_PATHFROM = EA_OPERATOR_UNARY + 2, EA_OPERATOR_PATHPROPERTYFROM = EA_OPERATOR_UNARY + 3, EA_VALUE = 0x0A00,
  EA_VALUE_STRING = EA_VALUE + 1, EA_VALUE_STRING_WITHINJECTION = EA_VALUE + 2, EA_VALUE_FLOAT = EA_VALUE + 3, EA_VALUE_RAW = EA_VALUE + 4,
  EA_VALUE_CVARNAME = EA_VALUE + 5, EA_VALUE_CVARNAME_WITHINJECTION = EA_VALUE + 6, EA_VALUE_PATHNODE = EA_VALUE + 7, EA_VALUE_PATHNODE_WITHINJECTION = EA_VALUE + 8,
  EA_VALUE_PATHPROPERTY = EA_VALUE + 9, EA_VALUE_PATHPROPERTY_WITHINJECTION = EA_VALUE + 10, EA_VALUE_NODEPROPERTY = EA_VALUE + 11, EA_VALUE_VAR = EA_VALUE + 12,
  EA_VALUE_CVAR = EA_VALUE + 13, EA_VALUE_NODE = EA_VALUE + 14, EA_VALUE_PARAM = EA_VALUE + 15, EA_VALUE_PARAMCOUNT = EA_VALUE + 16,
  EA_VALUE_THIS = EA_VALUE + 17, EA_VALUE_WINDOW = EA_VALUE + 18, EA_VALUE_PARENT = EA_VALUE + 19, EA_VALUE_CHILD = EA_VALUE + 20
}
 Type for uiAction_t It also contain type about type (for example EA_BINARYOPERATOR) More...
 

Functions

void UI_ExecuteEventActions (uiNode_t *source, const uiAction_t *firstAction)
 
void UI_ExecuteConFuncActions (uiNode_t *source, const uiAction_t *firstAction)
 allow to inject command param into cmd of confunc command More...
 
void UI_ExecuteEventActionsEx (uiNode_t *source, const uiAction_t *firstAction, linkedList_t *params)
 
bool UI_IsInjectedString (const char *string)
 Test if a string use an injection syntax. More...
 
void UI_FreeStringProperty (void *pointer)
 Free a string property if it is allocated into ui_dynStringPool. More...
 
const char * UI_GenInjectedString (const char *input, bool addNewLine, const uiCallContext_t *context)
 Replace injection identifiers (e.g. <eventParam>) by a value. More...
 
int UI_GetActionTokenType (const char *token, int group)
 return an action type from a token, and a group More...
 
uiValue_tUI_GetVariable (const uiCallContext_t *context, int relativeVarId)
 Return a variable from the context. More...
 
void UI_PoolAllocAction (uiAction_t **action, int type, const void *data)
 Set a new action to a uiAction_t pointer. More...
 
uiAction_tUI_AllocStaticCommandAction (const char *command)
 Allocate and initialize a command action. More...
 
void UI_InitActions (void)
 
void UI_AddListener (uiNode_t *node, const value_t *property, uiNode_t const *functionNode)
 Add a callback of a function into a node event. There can be more than on listener. More...
 
void UI_RemoveListener (uiNode_t *node, const value_t *property, uiNode_t *functionNode)
 Remove a function callback from a node event. There can be more than on listener. More...
 
const char * UI_GetParam (const uiCallContext_t *context, int paramID)
 
int UI_GetParamNumber (const uiCallContext_t *context)
 

Typedef Documentation

typedef struct uiAction_s uiAction_t

Atomic element to store UI scripts The parser use this atom to translate script action into many trees of actions. One function is one tree, and when we call this function, the tree is executed.

An atom can be a command, an operator, or a value:

  • Each command (EA_ACTION like EA_CALL, EA_CMD...) uses its own action structure. It can sometimes use child actions, or can be a leaf.
  • Operators (EA_OPERATOR_*) use binary tree structure (left and right operands), else are unary.
  • A value (EA_VALUE_*) is a terminal action (a leaf).
Todo:
FIXME Merge terminal and nonTerminal, this way is finally stupid. Left can be terminal and right can be non terminal, then the structure make non sens and can create hidden bugs.

Type for uiAction_t It also contain type about type (for example EA_BINARYOPERATOR)

See also
uiAction_t

Contain the context of the calling of a function.

Defines the data of a uiAction_t leaf. It allows different kind of data without cast.

See also
uiAction_t
typedef struct uiValue_s uiValue_t

Type for uiAction_t It also contain type about type (for example EA_BINARYOPERATOR)

See also
uiAction_t

Enumeration Type Documentation

Type for uiAction_t It also contain type about type (for example EA_BINARYOPERATOR)

See also
uiAction_t
Enumerator
EA_NULL 
EA_BINARYOPERATOR 
EA_UNARYOPERATOR 
EA_HIGHT_MASK 
EA_ACTION 
EA_CMD 
EA_CALL 
EA_ASSIGN 
EA_IF 
EA_ELSE 
EA_ELIF 
EA_WHILE 
EA_DELETE 
EA_LISTENER 
EA_PUSHVARS 
EA_POPVARS 
EA_FORCHILDIN 
EA_BREAK 
EA_OPERATOR_BOOLEAN2BOOLEAN 
EA_OPERATOR_AND 
EA_OPERATOR_OR 
EA_OPERATOR_XOR 
EA_OPERATOR_NOT 
EA_OPERATOR_FLOAT2BOOLEAN 
EA_OPERATOR_EQ 

==

EA_OPERATOR_LE 

<=

EA_OPERATOR_GE 

>=

EA_OPERATOR_GT 

>

EA_OPERATOR_LT 

<

EA_OPERATOR_NE 

!=

EA_OPERATOR_FLOAT2FLOAT 
EA_OPERATOR_ADD 
EA_OPERATOR_SUB 
EA_OPERATOR_MUL 
EA_OPERATOR_DIV 
EA_OPERATOR_MOD 
EA_OPERATOR_STRING2BOOLEAN 
EA_OPERATOR_STR_EQ 

eq

EA_OPERATOR_STR_NE 

ne

EA_OPERATOR_UNARY 
EA_OPERATOR_EXISTS 

only cvar given - check for existence

EA_OPERATOR_PATHFROM 

apply a relative path to a node an return a node

EA_OPERATOR_PATHPROPERTYFROM 

apply a relative path to a node an return a property

EA_VALUE 
EA_VALUE_STRING 

reference to a string

EA_VALUE_STRING_WITHINJECTION 

reference to a injected string

EA_VALUE_FLOAT 

embedded float

EA_VALUE_RAW 

reference to a binary value

EA_VALUE_CVARNAME 

reference to a cvarname

EA_VALUE_CVARNAME_WITHINJECTION 

should be into an extra action type

EA_VALUE_PATHNODE 

reference to a path, without property

EA_VALUE_PATHNODE_WITHINJECTION 

should be into an extra action type

EA_VALUE_PATHPROPERTY 

reference to a path, and a property

EA_VALUE_PATHPROPERTY_WITHINJECTION 

should be into an extra action type

EA_VALUE_NODEPROPERTY 

reference to a node, and a property (not a string)

EA_VALUE_VAR 

reference to a var

EA_VALUE_CVAR 

reference to a cvar

EA_VALUE_NODE 

reference to a node

EA_VALUE_PARAM 

reference to a param

EA_VALUE_PARAMCOUNT 

reference to the number of params

EA_VALUE_THIS 

reference to the current node

EA_VALUE_WINDOW 

reference to the window node

EA_VALUE_PARENT 

reference to the parent node

EA_VALUE_CHILD 

reference to the current child in a forchildin block

Definition at line 33 of file ui_actions.h.

Function Documentation

void UI_AddListener ( uiNode_t node,
const value_t property,
const uiNode_t functionNode 
)

Add a callback of a function into a node event. There can be more than on listener.

Parameters
[in,out]nodeThe node to add the listener to.
[in]propertyThe property of the node to add the listener to.
[in]functionNodeThe node of the listener callback.
Todo:
It is a hack, we should remove that

Definition at line 835 of file ui_actions.cpp.

References uiAction_s::d, EA_LISTENER, Mem_PoolAllocType, Mem_PoolStrDup, uiAction_s::next, uiAction_s::nonTerminal, uiNode_t::onClick, uiAction_s::terminal, uiAction_s::type, UI_GetPath(), and ui_sysPool.

Referenced by uiConFuncNode::onWindowOpened(), and UI_AddListener_f().

uiAction_t* UI_AllocStaticCommandAction ( const char *  command)

Allocate and initialize a command action.

Parameters
[in]commandA command for the action
Returns
An initialised action

Definition at line 796 of file ui_actions.cpp.

References uiAction_s::d, EA_CMD, uiAction_s::terminal, uiAction_s::type, and UI_AllocStaticAction().

Referenced by UI_Window_SetCloseButton().

void UI_ExecuteConFuncActions ( uiNode_t source,
const uiAction_t firstAction 
)

allow to inject command param into cmd of confunc command

Definition at line 717 of file ui_actions.cpp.

References OBJZERO, uiCallContext_s::source, UI_ExecuteActions(), and uiCallContext_s::useCmdParam.

Referenced by UI_ConfuncCommand_f().

void UI_ExecuteEventActions ( uiNode_t source,
const uiAction_t firstAction 
)

Definition at line 726 of file ui_actions.cpp.

References OBJZERO, uiCallContext_s::source, UI_ExecuteActions(), and uiCallContext_s::useCmdParam.

Referenced by uiSequenceNode::draw(), uiTimerNode::draw(), uiVideoNode::drawOverWindow(), uiRadioButtonNode::onActivate(), uiNode::onActivate(), uiOptionTreeNode::onCapturedMouseMove(), uiOptionListNode::onCapturedMouseMove(), uiContainerNode::onDndFinished(), uiTextListNode::onLeftClick(), uiRadioButtonNode::onLeftClick(), uiTextNode::onLeftClick(), uiText2Node::onLeftClick(), uiTextEntryNode::onLeftClick(), uiCheckBoxNode::onLeftClick(), uiLocatedNode::onLeftClick(), uiLocatedNode::onMiddleClick(), uiMaterialEditorNode::onMouseDown(), uiBaseInventoryNode::onMouseDown(), uiContainerNode::onMouseDown(), uiLocatedNode::onMouseEnter(), uiLocatedNode::onMouseLeave(), uiTextListNode::onRightClick(), uiTextNode::onRightClick(), uiText2Node::onRightClick(), uiLocatedNode::onRightClick(), uiMessageListNode::onScroll(), uiOptionTreeNode::onScroll(), uiOptionListNode::onScroll(), uiTextNode::onScroll(), uiPanelNode::onScroll(), uiLocatedNode::onScroll(), uiWindowNode::onWindowActivate(), uiWindowNode::onWindowClosed(), uiAbstractScrollableNode::setScrollY(), uiAbstractValueNode::setValue(), UI_AbstractOption_SetCurrentValue(), UI_AbstractScrollbarNodeSet(), UI_AbstractValue_SetValueCvar(), UI_BaseInventoryNodeUpdateScroll(), UI_ClientLayout(), UI_ColumnLayout(), UI_ContainerNodeAutoPlaceItem(), UI_FinishWindowsInit(), UI_FocusExecuteActionNode(), UI_OptionListNodeUpdateScroll(), UI_OptionTree_SelectValue(), UI_OptionTreeNodeUpdateScroll(), UI_TextEntryNodeAbortEdition(), UI_TextEntryNodeValidateEdition(), UI_TextNodeSelectLine(), UI_TextScrollEnd(), UI_TopDownFlowLayout(), and UI_ZoneNodeRepeat().

const char* UI_GenInjectedString ( const char *  input,
bool  addNewLine,
const uiCallContext_t context 
)

Replace injection identifiers (e.g. <eventParam>) by a value.

Note
The injection identifier can be every node value - e.g. <image> or <width>. It's also possible to do something like
1 cmd "set someCvar &lt;min&gt;/&lt;max&gt;"

Definition at line 209 of file ui_actions.cpp.

References uiNode_t::behaviour, Com_Printf(), Cvar_Get(), length, uiNode_t::parent, Q_streq, Q_strstart(), uiNode_t::root, uiCallContext_s::source, cvar_s::string, UI_GenCommandReadProperty(), UI_GetParam(), UI_GetParamNumber(), UI_GetPath(), UI_GetPropertyFromBehaviour(), UI_GetStringFromNodeProperty(), UI_ReadNodePath(), and va().

Referenced by UI_ExecuteAction(), UI_ExecuteCallAction(), UI_ExecuteSetAction(), UI_GetBooleanFromExpression(), UI_GetFloatFromExpression(), UI_GetNodeFromExpression(), and UI_GetStringFromExpression().

int UI_GetActionTokenType ( const char *  token,
int  group 
)

return an action type from a token, and a group

Parameters
[in]tokenRequested token
[in]groupRequested group, EA_ACTION, EA_BINARYOPERATOR, or EA_UNARYOPERATOR
See also
actionTokens
Returns
a action type from the requested group, else EA_NULL

Definition at line 113 of file ui_actions.cpp.

References EA_NULL, lengthof, and ui_typedActionToken_s::type.

Referenced by UI_ParseActionList(), and UI_ParseExpression().

const char* UI_GetParam ( const uiCallContext_t context,
int  paramID 
)

Get a param from an execution context

Parameters
[in]contextThe execution context
[in]paramIDThe ID of the requested param (first param is integer 1)
Returns
The requested param

Definition at line 179 of file ui_actions.cpp.

References Cmd_Argv(), Com_Printf(), linkedList_t::data, linkedList_t::next, uiCallContext_s::paramNumber, uiCallContext_s::params, and uiCallContext_s::useCmdParam.

Referenced by UI_AbstractNodeCallCreateChild(), UI_AbstractNodeCallDeleteTimed(), UI_GenInjectedString(), UI_GetFloatFromExpression(), UI_GetStringFromExpression(), and UI_OptionTreeSetSelectedValue().

int UI_GetParamNumber ( const uiCallContext_t context)
uiValue_t* UI_GetVariable ( const uiCallContext_t context,
int  relativeVarId 
)

Return a variable from the context.

Parameters
contextCall context
relativeVarIdid of the variable relative to the context

Definition at line 517 of file ui_actions.cpp.

References ui_global, uiGlobal_s::variableStack, and uiCallContext_s::varPosition.

Referenced by UI_GetFloatFromExpression(), UI_GetNodeFromExpression(), and UI_GetStringFromExpression().

void UI_InitActions ( void  )
Todo:
rework these commands to use a script language way

Definition at line 1034 of file ui_actions.cpp.

References Cmd_AddCommand(), UI_AddCvarListener_f(), UI_AddListener_f(), UI_CheckActionTokenTypeSanity(), UI_RemoveCvarListener_f(), and UI_RemoveListener_f().

Referenced by UI_Init().

bool UI_IsInjectedString ( const char *  string)

Test if a string use an injection syntax.

Parameters
[in]stringThe string to check for injection
Returns
True if we find the following syntax in the string "<" {thing without space} ">"

Definition at line 751 of file ui_actions.cpp.

Referenced by UI_ParseSetAction(), and UI_ParseValueExpression().

void UI_PoolAllocAction ( uiAction_t **  action,
int  type,
const void data 
)

Set a new action to a uiAction_t pointer.

Parameters
[in,out]actionAllocated action
[in]typeOnly EA_CMD is supported
[in]dataThe data for this action - in case of EA_CMD this is the commandline
Note
You first have to free existing node actions - only free those that are not static in ui_global.actions array
Todo:
we should create a function to free the memory. We can use a tag in the Mem_PoolAlloc calls and use use Mem_FreeTag.

Definition at line 814 of file ui_actions.cpp.

References Com_Error(), EA_CMD, ERR_FATAL, Mem_PoolAllocType, Mem_PoolStrDup, type, and ui_sysPool.

Referenced by UI_PopupList(), and UI_SetOneButton().

void UI_RemoveListener ( uiNode_t node,
const value_t property,
uiNode_t functionNode 
)

Remove a function callback from a node event. There can be more than on listener.

Parameters
[in,out]nodeThe node to remove the listener from.
[in]propertyThe property of the node to remove the listener from.
[in]functionNodeThe node of the listener callback.

Definition at line 906 of file ui_actions.cpp.

References Cmd_Argv(), Com_Printf(), uiAction_s::d, EA_LISTENER, Mem_Free, uiAction_s::next, uiAction_s::nonTerminal, uiNode_t::onClick, and uiAction_s::terminal.

Referenced by uiConFuncNode::onWindowClosed(), and UI_RemoveListener_f().