User Interface Event Handlers: Difference between revisions
Killzone Kid (talk | contribs) No edit summary |
Killzone Kid (talk | contribs) No edit summary |
||
Line 58: | Line 58: | ||
{{GVI|arma3|2.14}} | {{GVI|arma3|2.14}} | ||
* '''Use on:''' Control | * '''Use on:''' Control | ||
* '''Fired on:''' | * '''Fired on:''' Any changes to the CT_EDIT field text content | ||
* '''Returns:''' Returns the control and the changed text | * '''Returns:''' Returns the control and the changed text | ||
<sqf>params ["_control", "_newText"];</sqf> | <sqf>params ["_control", "_newText"];</sqf> |
Revision as of 11:59, 2 April 2023
User Interface Event Handlers allow you to automatically monitor and then execute custom code upon particular UI events being triggered.
for User Interface Event Handlers
Reference List
Generic Events
onLoad
- Use on: Display, Control
- Fired on: Fires when UI container is created, but no action is taken. onLoad event for display fires after onLoad events for all controls it contains are fired.
- Returns: Display or control, for controls it also returns the control's config (since 1.56)
onUnload
- Use on: Display
- Fired on: Display is closed, but no controls are destroyed yet.
- Returns: Returns the display and exit code.
onChildDestroyed
- Use on: Display
- Fired on: Child display is closed.
- Returns: Returns the display, which child display was closed and exit code.
onCommitted
- Use on: Control
- Fired on: ctrlSetFade, ctrlSetScale, ctrlSetAngle, ctrlSetPosition + ctrlCommit
- Returns: Returns the control, type of animation (one of "alpha", "scale", "rotation", "position") and the committed time.
onEditChanged
- Use on: Control
- Fired on: Any changes to the CT_EDIT field text content
- Returns: Returns the control and the changed text
onMouseEnter
- Use on: Control
- Fired on: The mouse pointer enters the control area.
- Returns: Returns control.
onMouseExit
- Use on: Control
- Fired on: The mouse pointer exits the control area.
- Returns: Returns control.
onSetFocus
- Use on: Control
- Fired on: Input focus is on control. It now begins to accept keyboard input.
- Returns: Returns control.
onKillFocus
- Use on: Control
- Fired on: Input focus is no longer on control. It no longer accepts keyboard input.
- Returns: Returns control.
onTimer
- Use on: Control
- Fired on: N/A.
- Returns: N/A.
onKeyDown
- Use on: Display, Control
- Fired on: Pressing any keyboard key. Fired before the onKeyUp event.
- Returns: Returns the display or control, the keyboard code and the state of Shift, Ctrl and Alt.
In Arma 3, in order to be able to intercept key events during gameplay, the event handler should be added to Display 46:
In general, one should never return true in the keyDown EH, especially if it's added to Display 46, otherwise all input will be overridden and there will be no way to do anything in the game anymore.
onKeyUp
- Use on: Display, Control
- Fired on: Releasing any keyboard key. Fired after the onKeyDown event.
- Returns: Returns the display or control, the keyboard code and the state of Shift, Ctrl and Alt.
onChar
- Use on: Display, Control
- Fired on: When some readable characters is recognised.
- Returns: Returns the display or control and the char code.
onIMEChar
- Use on: Control
- Fired on: When IME character is recognized (used in Korean and other eastern languages).
- Returns: Returns the control and the char code.
onIMEComposition
- Use on: Control
- Fired on: When partial IME character is recognized (used in Korean and other eastern languages).
- Returns: Returns the control and the char code.
onMouseButtonDown
- Use on: Display, Control
- Fired on: Pressing a mouse button. Followed by the onMouseButtonUp event.
- Returns: Returns the display or control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.
onMouseButtonUp
- Use on: Display, Control
- Fired on: Releasing a mouse button. Follows the onMouseButtonDown event.
- Returns: Returns the display or control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.
onMouseButtonClick
- Use on: ListBox, ComboBox, TextBox, Button, ActiveText
- Fired on: Pressing and releasing a mouse button.
- Returns: Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.
onMouseButtonDblClick
- Use on: Control
- Fired on: Pressing and releasing a mouse button twice within very short time.
- Returns: Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.
onMouseMoving
- Fired on: Fires continuously while moving the mouse with a certain interval.
- Use on: Control
- Returns: Returns the control, the x and y coordinates relative to the controls parent and mouseOver.
If the controls parent is its display then x and y will be the same as getMousePosition else it will be relative to its parent control for instance if inside a CT_CONTROLS_GROUP
- Use on: Display
- Returns: Returns the display, and some kind of x and y delta position.
onMouseHolding
- Fired on: Fires continuously while mouse is not moving with a certain interval.
- Use on: Control
- Returns: Returns the control, the x and y coordinates relative to the controls parent and mouseOver.
If the controls parent is its display then x and y will be the same as getMousePosition else it will be relative to its parent control for instance if inside a CT_CONTROLS_GROUP
- Use on: Display
- Returns: Returns the display, and some kind of x and y delta position.
onMouseZChanged
- Use on: Display, Control
- Fired on: Fires when mouse wheel position is changed. Does not fire on disabled control.
- Returns: Returns the display or control and the change of the scrollwheel.
onCanDestroy
- Use on: Control
- Fired on: Ask this control if dialog can be closed (used for validation of contained data).
- Returns: Returns the control and exit code.
onDestroy
- Use on: Control
- Fired on: Destroying control
- Returns: Returns the control and exit code.
Button Events
onButtonClick
- Use on: Button
- Fired on: The attached button action is performed. When returned value is true, button's display remains opened.
- Returns: Returns control.
onButtonDblClick
- Use on: Button
- Fired on: Button double clicked.
- Returns: Returns control.
onButtonDown
- Use on: Button
- Fired on: The left mouse button is pressed over the button area or a key on the keyboard is pressed.
- Returns: Returns control.
onButtonUp
- Use on: Button
- Fired on: The left mouse button is released outside the button area and the attached button action is not performed.
- Returns: Returns control.
Listbox Events
onLBSelChanged
- Use on: Listbox, Combobox
- Fired on: The selection in a listbox is changed. The left mouse button has been released and the new selection is fully made.
- Returns: Returns the control and the selected element index.
onLBListSelChanged
- Use on: Combobox
- Fired on: Selection in XCombo box changed (but value is not stored yet).
- Returns: Returns the control and the selected element index.
onLBDblClick
- Use on: Listbox
- Fired on: Double click on some row in listbox.
- Returns: Returns the control and the selected element index.
onLBDrag
- Use on: Listbox
- Fired on: Drag & drop operation started.
- Returns: Returns the control and an array of arrays of information on the dragged item/s (if listbox is of style LB_MULTI then multiple items can be dragged and dropped at the same time).
Control must have unique IDC and canDrag parameter enabled in its class in order to work.
onLBDragging
- Use on: Listbox
- Fired on: Drag & drop operation is in progress.
- Returns: Returns the control, the x and y coordinates in screen space, listbox idc where item/s were dragged from and an array of arrays of information on the dragged item/s (if listbox is of style LB_MULTI then multiple items can be dragged and dropped at the same time).
onLBDrop
- Use on: Listbox, Combobox, Textbox, ActiveText, Button, ControlsGroup
- Fired on: Drag & drop operation finished.
- Returns: Returns the control, the x and y coordinates in screen space, listbox idc where item/s were dragged from and an array of arrays of information on the dropped item/s (if listbox is of style LB_MULTI then multiple items can be dragged and dropped at the same time).
When the Listbox is inside a CT_CONTROLS_GROUP the eventhandler need to be added to the CT_CONTROLS_GROUP.
Will not work for CT_CONTROLS_GROUP that is subordinate to another group.
Tree Events
onTreeSelChanged
- Use on: Tree
- Fired on: Changing the selection in a tree.
- Returns: Returns the control and the new selection path.
onTreeLButtonDown
- Use on: Tree
- Fired on: Pressing and releasing left mouse button on a tree.
- Returns: Returns the control.
onTreeDblClick
- Use on: Tree
- Fired on: Pressing and releasing twice on a tree entry.
- Returns: Returns the control and the current selection path.
onTreeExpanded
- Use on: Tree
- Fired on: The tree folder structure has been expanded.
- Returns: Returns the control and path.
onTreeCollapsed
- Use on: Tree
- Fired on: The tree folder structure has been collapsed.
- Returns: Returns the control and path.
onTreeMouseMove
- Use on: Tree
- Fired on: Fires continuously while moving the mouse with a certain interval.
- Returns: Returns the control. Also returns the path, probably since Eden Editor update.
onTreeMouseHold
- Use on: Tree
- Fired on: Fires continuously while mouse is not moving with a certain interval.
- Returns: Returns the control. Also returns the path, probably since Eden Editor update.
onTreeMouseExit
- Use on: Tree
- Fired on: The mouse pointer exits the tree control area
- Returns: Returns the control.
onTreeFilterUpdated
- Use on: Tree
- Fired on: A search/filter done on the tree
- Returns: Returns the control.
Checkbox Events
onChecked
- Use on: Checkbox (CT_CHECKBOX).
- Fired on: N/A
- Returns: N/A
onCheckedChanged
- Use on: Checkbox (CT_CHECKBOX).
- Fired on: Checked state of CheckBox changed.
- Returns: Returns control and the checked state (0 or 1, not boolean).
onCheckBoxesSelChanged
- Use on: Checkboxes (CT_CHECKBOXES).
- Fired on: Changed the selection of checkboxes.
- Returns: Returns the control, the selected element index and the current state.
Misc. Events
onToolBoxSelChanged
- Use on: Toolbox
- Fired on: Changed the selection in a toolbox.
- Returns: Returns the control and the selected element index.
onHTMLLink
- Use on: HTML
- Fired on: Pressing and releasing a HTML link.
- Returns: Returns the control and href.
onSliderPosChanged
- Use on: Slider
- Fired on: Changing the position of a slider.
- Returns: Returns the control and the change.
onObjectMoved
- Use on: Object
- Fired on: Moving an object.
- Returns: Returns the control and the offset on the x, y and z axes.
onMenuSelected
- Use on: Context menu
- Fired on: Some item in context menu (used now only in new mission editor) was selected.
- Returns: Returns the control and the command id.
onDraw
- Use on: Map, Display (only on UIOnTexture Display 2.12)
- Fired on: Fires when the map is drawn or the UI On Texture Display received a draw request (can occur more than once per second).
- Returns: Returns the map control.
onVideoStopped
- Use on: Control
- Fired on: Activated every time the video ends (when looped, handler is executed after every finished loop).
- Returns: Returns the control.
Event Parameters
The events handlers receive parameters in the _this variable. Each event passes a different set of parameters (listed in the table above) in an array. The control or display that the event was assigned to is always found in _this select 0.
Scope
1.00 In Armed Assault, most control-specific events work for controls and do not work for displays. The two exceptions being: onKeyDown and onKeyUp.
1.00 Since Arma 2, most control-specific events now work for both displays and controls.
Defining Events
User Interface Event Handlers can be assigned in two ways: via class property definitions or via scripting commands.
Class-Defined Events
Events can be defined in the Dialog (display) or Control classes (in config.cpp or description.ext). The event property value (string) is executed as a line of code.
An example line (this would be put within a control or dialog class):
onMouseButtonDown = "hint str _this";
Full Example:
class RscControlsGroup
{
type = 15;
idc = -1;
style = 0;
x = 0;
y = 0;
w = 1;
h = 1;
class VScrollbar
{
color[] = { 1, 1, 1, 1 };
width = 0.021;
autoScrollSpeed = -1;
autoScrollDelay = 5;
autoScrollRewind = 0;
};
class HScrollbar
{
color[] = { 1, 1, 1, 1 };
height = 0.028;
};
class ScrollBar // >= Arma 2
{
color[] = { 1, 1, 1, 0.6 };
colorActive[] = { 1, 1, 1, 1 };
colorDisabled[] = { 1, 1, 1, 0.3 };
thumb = "#(argb,8,8,3)color(1,1,1,1)";
arrowEmpty = "#(argb,8,8,3)color(1,1,1,1)";
arrowFull = "#(argb,8,8,3)color(1,1,1,1)";
border = "#(argb,8,8,3)color(1,1,1,1)";
};
class Controls {};
};
class mouseHandler : RscControlsGroup
{
onMouseHolding = "[0, _this] call myEventFunction";
onMouseButtonDown = "[1, _this] call myEventFunction";
onMouseButtonUp = "[2, _this] call myEventFunction";
onMouseZChanged = "[3, _this] call myEventFunction";
onMouseEnter = "[4, _this] call myEventFunction";
idc = 123;
x = 0.0;
y = 0.0;
w = 1.0;
h = 1.0;
colorBackground[] = { 0.2, 0.0, 0.0, 0.0 };
};
Script-Defined Events
These events can also be given to dialogs/controls using the ctrlSetEventHandler scripting command. For the event handler to be called enable the control using the ctrlEnable scripting command.