User Interface Event Handlers: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(missing display support for mouseHolding)
(added warning about crashing the game)
(41 intermediate revisions by 8 users not shown)
Line 1: Line 1:
__NOEDITSECTION__
__NOEDITSECTION__
{{SideTOC}}
{{TOC|side}}
'''U'''ser '''I'''nterface '''E'''vent '''H'''andlers allow you to automatically monitor and then execute custom code upon particular UI events being triggered.
'''U'''ser '''I'''nterface '''E'''vent '''H'''andlers allow you to automatically monitor and then execute custom code upon particular UI events being triggered.


for [[User Interface Event Handlers]]
{{Feature|Warning|Deleting the display or control from within an event handler will crash the game if deleting is not the last line in the event handler's script or the code is not [[Scheduler|spawned]].
{{ic|onButtonClick {{=}} "[[ctrlDelete]] ([[_this]] [[select]] 0); [[systemChat]] 'You will never see this';"; {{cc|Will crash the game}}}}<br/><br/>
{{ic|onButtonClick {{=}} "[[systemChat]] 'Bye bye button!'; [[ctrlDelete]] ([[_this]] [[select]] 0);"; {{cc|Works just fine}}}}<br/><br/>
{{ic|onButtonClick {{=}} "[] [[spawn]] { [[ctrlDelete]] ([[_this]] [[select]] 0); [[systemChat]] 'Bye bye button!'; };"; {{cc|Works just fine as well}}}}
}}


== Reference List ==
== Reference List ==
<div style="max-width: 72%;">{{Important|When using the event names listed below with the [[ctrlAddEventHandler]], [[ctrlSetEventHandler]], [[displayAddEventHandler]] or [[displaySetEventHandler]] commands, the prefix "on" in the name must be removed (e.g. ''''ButtonDown'''' instead of ''''onButtonDown'''').}}</div>


=== Generic events ===
<div><!-- used to limit Sticky range -->
{{ConfigPage|start}}
{{ConfigPage|abc}}


=== Generic events ===
{{Cfg ref|start}}
{{Cfg ref|abc}}
==== onLoad ====
==== onLoad ====
* '''Priority:''' 1
* '''Use on:''' Display, Control
* '''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.
* '''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:''' Returns the display or control in format [[Array]].
* '''Returns:''' Display or control, for controls it also returns the control's config (since {{GVI|arma3|1.56}})
<syntaxhighlight lang="cpp">params ["_uiElement"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_displayOrControl", ["_config", configNull]];</syntaxhighlight>  
 
{{Feature|Informative|The order of initialisation is as follows:
# Top most config class (control class)
# Last config class
# Display
This means that during the onLoad event of the upper controls the lower controls do not exist!}}


==== onUnload ====
==== onUnload ====
* '''Priority:''' 1
* '''Use on:''' Display
* '''Use on:''' Display
* '''Fired on:''' Display is closed, but no controls are destroyed yet.
* '''Fired on:''' Display is closed, but no controls are destroyed yet.
* '''Returns:''' Returns the display and exit code.
* '''Returns:''' Returns the display and exit code.
<syntaxhighlight lang="cpp">params ["_display", "_exitCode"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_display", "_exitCode"];</syntaxhighlight>
{{note|onUnload event doesn't fire for RscTitles displays started with [[cutRsc]]}}
{{Feature | Informative | onUnload event doesn't fire for RscTitles displays started with [[cutRsc]].}}
 
{{Feature | Warning| Code or function should be [[call]]ed, otherwise controls might be destroyed before [[spawn]]ed code or function is executed!}}


==== onChildDestroyed ====
==== onChildDestroyed ====
* '''Priority:''' 1
* '''Use on:''' Display
* '''Use on:''' Display
* '''Fired on:''' Child display is closed.
* '''Fired on:''' Child display is closed.
Line 37: Line 46:


==== onMouseEnter ====
==== onMouseEnter ====
* '''Priority:''' 1
* '''Use on:''' Control
* '''Use on:''' Control
* '''Fired on:''' The mouse pointer enters the control area.
* '''Fired on:''' The mouse pointer enters the control area.
* '''Returns:''' Returns control.
* '''Returns:''' Returns control.
<syntaxhighlight lang="cpp">params ["_control"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_control"];</syntaxhighlight>
{{Feature | Informative | onMouseEnter does not fire for buttons disabled with [[ctrlEnable]].}}




==== onMouseExit ====
==== onMouseExit ====
* '''Priority:''' 1
* '''Use on:''' Control
* '''Use on:''' Control
* '''Fired on:''' The mouse pointer exits the control area.
* '''Fired on:''' The mouse pointer exits the control area.
Line 53: Line 61:


==== onSetFocus ====
==== onSetFocus ====
* '''Priority:''' 2
* '''Use on:''' Control
* '''Use on:''' Control
* '''Fired on:''' Input focus is on control. It now begins to accept keyboard input.
* '''Fired on:''' Input focus is on control. It now begins to accept keyboard input.
Line 61: Line 68:


==== onKillFocus ====
==== onKillFocus ====
* '''Priority:''' 2
* '''Use on:''' Control
* '''Use on:''' Control
* '''Fired on:''' Input focus is no longer on control. It no longer accepts keyboard input.
* '''Fired on:''' Input focus is no longer on control. It no longer accepts keyboard input.
Line 69: Line 75:


==== onTimer ====
==== onTimer ====
* '''Priority:''' 3
* '''Use on:''' Control
* '''Use on:''' Control
* '''Fired on:''' After amount of time given by setTimer function.
* '''Fired on:''' N/A.
* '''Returns:''' Returns control.
* '''Returns:''' N/A.
<syntaxhighlight lang="cpp">params ["_control"];</syntaxhighlight>
{{Feature | Informative | This feature has not been implemented}}




==== onKeyDown ====
==== onKeyDown ====
* '''Priority:''' 2
* '''Use on:''' Display, Control
* '''Use on:''' Display, Control
* '''Fired on:''' Pressing any keyboard key. Fired before the [[#onKeyUp|onKeyUp]] event.
* '''Fired on:''' Pressing any keyboard key. Fired before the [[#onKeyUp|onKeyUp]] event.
* '''Returns:''' Returns the control, the [[DIK_KeyCodes|keyboard code]] and the state of Shift, Ctrl and Alt.
* '''Returns:''' Returns the display or control, the [[DIK_KeyCodes|keyboard code]] and the state of Shift, Ctrl and Alt.
<syntaxhighlight lang="cpp">params ["_displayorcontrol", "_key", "_shift", "_ctrl", "_alt"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_displayorcontrol", "_key", "_shift", "_ctrl", "_alt"];
true // Intercepts the default action, eg. pressing escape won't close the dialog.</syntaxhighlight>




==== onKeyUp ====
==== onKeyUp ====
* '''Priority:''' 2
* '''Use on:''' Display, Control
* '''Use on:''' Display, Control
* '''Fired on:''' Releasing any keyboard key. Fired after the [[#onKeyDown|onKeyDown]] event.
* '''Fired on:''' Releasing any keyboard key. Fired after the [[#onKeyDown|onKeyDown]] event.
* '''Returns:''' Returns the control, the [[DIK_KeyCodes|keyboard code]] and the state of Shift, Ctrl and Alt.
* '''Returns:''' Returns the display or control, the [[DIK_KeyCodes|keyboard code]] and the state of Shift, Ctrl and Alt.
<syntaxhighlight lang="cpp">params ["_displayorcontrol", "_key", "_shift", "_ctrl", "_alt"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_displayorcontrol", "_key", "_shift", "_ctrl", "_alt"];</syntaxhighlight>




==== onChar ====
==== onChar ====
* '''Priority:''' 2
* '''Use on:''' Display, Control
* '''Use on:''' Control
* '''Fired on:''' When some readable characters is recognised.
* '''Fired on:''' When some readable characters is recognised.
* '''Returns:''' Returns the control and the char code.
* '''Returns:''' Returns the display or control and the [https://www.ascii-code.com/ char code].
<syntaxhighlight lang="cpp">params ["_control", "_charCode"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_displayorcontrol", "_charCode"];</syntaxhighlight>




==== onIMEChar ====
==== onIMEChar ====
* '''Priority:''' 2
* '''Use on:''' Control
* '''Use on:''' Control
* '''Fired on:''' When IME character is recognized (used in Korean and other eastern languages).
* '''Fired on:''' When IME character is recognized (used in Korean and other eastern languages).
Line 109: Line 111:


==== onIMEComposition ====
==== onIMEComposition ====
* '''Priority:''' 2
* '''Use on:''' Control
* '''Use on:''' Control
* '''Fired on:''' When partial IME character is recognized (used in Korean and other eastern languages).
* '''Fired on:''' When partial IME character is recognized (used in Korean and other eastern languages).
* '''Returns:''' Returns the control and the char code.
* '''Returns:''' Returns the control and the char code.
<syntaxhighlight lang="cpp">params ["_control", "_charCode"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_control", "_charCode"];</syntaxhighlight>
==== onJoystickButton ====
* '''Priority:''' 3
* '''Use on:''' Control
* '''Fired on:''' Pressing and releasing any joystick button.
* '''Returns:''' Returns the control and the the pressed button.
<syntaxhighlight lang="cpp">private ["_control", "_button"];
_control = _this select 0;
_button = _this select 1;</syntaxhighlight>
{{note|Not present in {{arma2}} or {{arma3}}}}




==== onMouseButtonDown ====
==== onMouseButtonDown ====
* '''Priority:''' 2
* '''Use on:''' Display, Control
* '''Use on:''' Control
* '''Fired on:''' Pressing a mouse button. Followed by the [[#onMouseButtonUp|onMouseButtonUp]] event.
* '''Fired on:''' Pressing a mouse button. Followed by the [[#onMouseButtonUp|onMouseButtonUp]] event.
* '''Returns:''' Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.
* '''Returns:''' Returns the display or control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.
<syntaxhighlight lang="cpp">params ["_control", "_button", "_xPos", "_yPos", "_shift", "_ctrl", "_alt"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_displayorcontrol", "_button", "_xPos", "_yPos", "_shift", "_ctrl", "_alt"];</syntaxhighlight>




==== onMouseButtonUp ====
==== onMouseButtonUp ====
* '''Priority:''' 2
* '''Use on:''' Display, Control
* '''Use on:''' Control
* '''Fired on:''' Releasing a mouse button. Follows the [[#onMouseButtonDown|onMouseButtonDown]] event.
* '''Fired on:''' Releasing a mouse button. Follows the [[#onMouseButtonDown|onMouseButtonDown]] event.
* '''Returns:''' Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.
* '''Returns:''' Returns the display or control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.
<syntaxhighlight lang="cpp">params ["_control", "_button", "_xPos", "_yPos", "_shift", "_ctrl", "_alt"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_displayorcontrol", "_button", "_xPos", "_yPos", "_shift", "_ctrl", "_alt"];</syntaxhighlight>




==== onMouseButtonClick ====
==== onMouseButtonClick ====
* '''Priority:''' 2
* '''Use on:''' ListBox, ComboBox, TextBox, Button, ActiveText
* '''Use on:''' ListBox, ComboBox, TextBox, Button, ActiveText
* '''Fired on:''' Pressing and releasing a mouse button.
* '''Fired on:''' Pressing and releasing a mouse button.
Line 152: Line 139:


==== onMouseButtonDblClick ====
==== onMouseButtonDblClick ====
* '''Priority:''' 2
* '''Use on:''' Control
* '''Use on:''' Control
* '''Fired on:''' Pressing and releasing a mouse button twice within very short time.
* '''Fired on:''' Pressing and releasing a mouse button twice within very short time.
Line 160: Line 146:


==== onMouseMoving ====
==== onMouseMoving ====
* '''Priority:''' 2
* '''Fired on:''' Fires continuously while moving the mouse with a certain interval.
* '''Fired on:''' Fires continuously while moving the mouse with a certain interval.
<hr />
<hr />
* '''Use on:''' Control
* '''Use on:''' Control
* '''Returns:''' Returns the control, the x and y coordinates relative to the controls parent and mouseOver.<br />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 [[DialogControls-ControlsGroup|controlsGroup]]
* '''Returns:''' Returns the control, the x and y coordinates relative to the controls parent and mouseOver.<br>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]]
<syntaxhighlight lang="cpp">params ["_control", "_xPos", "_yPos", "_mouseOver"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_control", "_xPos", "_yPos", "_mouseOver"];</syntaxhighlight>
<hr />
<hr />
Line 173: Line 158:


==== onMouseHolding ====
==== onMouseHolding ====
* '''Priority:''' 2
* '''Fired on:''' Fires continuously while mouse is not moving with a certain interval.
* '''Fired on:''' Fires continuously while mouse is not moving with a certain interval.
<hr />
<hr />
* '''Use on:''' Control
* '''Use on:''' Control
* '''Returns:''' Returns the control, the x and y coordinates relative to the controls parent and mouseOver.<br />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 [[DialogControls-ControlsGroup|controlsGroup]]
* '''Returns:''' Returns the control, the x and y coordinates relative to the controls parent and mouseOver.<br>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]]
<syntaxhighlight lang="cpp">params ["_control", "_xPos", "_yPos", "_mouseOver"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_control", "_xPos", "_yPos", "_mouseOver"];</syntaxhighlight>
<hr />
<hr />
Line 185: Line 169:


==== onMouseZChanged ====
==== onMouseZChanged ====
* '''Priority:''' 2
* '''Use on:''' Display, Control
* '''Use on:''' Display, Control
* '''Fired on:''' Fires when mouse wheel position is changed. Does not fire on disabled control.
* '''Fired on:''' Fires when mouse wheel position is changed. Does not fire on disabled control.
Line 193: Line 176:


==== onCanDestroy ====
==== onCanDestroy ====
* '''Priority:''' 3
* '''Use on:''' Control
* '''Use on:''' Control
* '''Fired on:''' Ask this control if dialog can be closed (used for validation of contained data).
* '''Fired on:''' Ask this control if dialog can be closed (used for validation of contained data).
Line 201: Line 183:


==== onDestroy ====
==== onDestroy ====
* '''Priority:''' 3
* '''Use on:''' Control
* '''Use on:''' Control
* '''Fired on:''' Destroying control
* '''Fired on:''' Destroying control
* '''Returns:''' Returns the control and exit code.
* '''Returns:''' Returns the control and exit code.
<syntaxhighlight lang="cpp">params ["_control", "_exitCode"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_control", "_exitCode"];</syntaxhighlight>
{{Cfg ref|end}}
{{ConfigPage|end}}




=== Button events ===
=== Button events ===
{{Cfg ref|start}}
{{ConfigPage|start}}
{{Cfg ref|abc}}
{{ConfigPage|abc}}
==== onButtonClick ====
==== onButtonClick ====
* '''Priority:''' 1
* '''Use on:''' Button
* '''Use on:''' Button
* '''Fired on:''' The attached button action is performed. When returned value is [[true]], button's display remains opened.
* '''Fired on:''' The attached button action is performed. When returned value is [[true]], button's display remains opened.
Line 223: Line 203:
==== onButtonDblClick ====
==== onButtonDblClick ====
</div>
</div>
* '''Priority:''' ?
* '''Use on:''' Button
* '''Use on:''' Button
* '''Fired on:''' button double click?
* '''Fired on:''' Button double clicked.
* '''Returns:''' ?
* '''Returns:''' Returns control.
<syntaxhighlight lang="cpp">params ["_control"];</syntaxhighlight>




==== onButtonDown ====
==== onButtonDown ====
* '''Priority:''' 1
* '''Use on:''' Button
* '''Use on:''' Button
* '''Fired on:''' The left mouse button is pressed over the button area or a key on the keyboard is pressed.
* '''Fired on:''' The left mouse button is pressed over the button area or a key on the keyboard is pressed.
Line 238: Line 217:


==== onButtonUp ====
==== onButtonUp ====
* '''Priority:''' 1
* '''Use on:''' Button
* '''Use on:''' Button
* '''Fired on:''' The left mouse button is released outside the button area and the attached button action '''is not performed'''.
* '''Fired on:''' The left mouse button is released outside the button area and the attached button action '''is not performed'''.
* '''Returns:''' Returns control.
* '''Returns:''' Returns control.
<syntaxhighlight lang="cpp">params ["_control"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_control"];</syntaxhighlight>
{{Cfg ref|end}}
{{ConfigPage|end}}




=== Listbox events ===
=== Listbox events ===
{{Cfg ref|start}}
{{ConfigPage|start}}
{{Cfg ref|abc}}
{{ConfigPage|abc}}
==== onLBSelChanged ====
==== onLBSelChanged ====
* '''Priority:''' 2
* '''Use on:''' Listbox, Combobox
* '''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.
* '''Fired on:''' The selection in a listbox is changed. The left mouse button has been released and the new selection is fully made.
Line 258: Line 235:


==== onLBListSelChanged ====
==== onLBListSelChanged ====
* '''Priority:''' 2
* '''Use on:''' Listbox
* '''Use on:''' Listbox
* '''Fired on:''' Selection in XCombo box changed (but value is not stored yet).
* '''Fired on:''' Selection in XCombo box changed (but value is not stored yet).
Line 266: Line 242:


==== onLBDblClick ====
==== onLBDblClick ====
* '''Priority:''' 2
* '''Use on:''' Listbox
* '''Use on:''' Listbox
* '''Fired on:''' Double click on some row in listbox.
* '''Fired on:''' Double click on some row in listbox.
Line 274: Line 249:


==== onLBDrag ====
==== onLBDrag ====
* '''Priority:''' 2
* '''Use on:''' Listbox
* '''Use on:''' Listbox
* '''Fired on:''' Drag & drop operation started.
* '''Fired on:''' Drag & drop operation started.
* '''Returns:''' Returns the control and the selected element index.
* '''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).<br>Control must have unique IDC and '''canDrag''' parameter enabled in its class in order to work.
<syntaxhighlight lang="cpp">params ["_control", "_selectedIndex"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_control", "_listboxInfo"];
//Get info of first item being dragged
(_listboxInfo select 0) params ["_lbText", "_lbValue", "_lbData"];</syntaxhighlight>




==== onLBDragging ====
==== onLBDragging ====
* '''Priority:''' 2
* '''Use on:''' Listbox
* '''Use on:''' Listbox
* '''Fired on:''' Drag & drop operation is in progress.
* '''Fired on:''' Drag & drop operation is in progress.
* '''Returns:''' Returns the control and the x and y coordinates.
* '''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).
<syntaxhighlight lang="cpp">params ["_control", "_xPos", "_yPos"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_control", "_xPos", "_yPos", "_listboxIDC", "_listboxInfo"];
//Get info of first item being dragged
(_listboxInfo select 0) params ["_lbText", "_lbValue", "_lbData"];</syntaxhighlight>




==== onLBDrop ====
==== onLBDrop ====
* '''Priority:''' 2
* '''Use on:''' Listbox, Combobox, Textbox, ActiveText, Button, ControlsGroup
* '''Use on:''' Listbox, Combobox, Textbox, ActiveText, Button
* '''Fired on:''' Drag & drop operation finished.
* '''Fired on:''' Drag & drop operation finished.
* '''Returns:''' Returns the control and the x and y coordinates.<br />When the Listbox is inside a ctrlGroup the eventhandler need to be added to the ctrlGroup.
* '''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).<br>When the Listbox is inside a [[CT_CONTROLS_GROUP]] the eventhandler need to be added to the [[CT_CONTROLS_GROUP]].<br>Will not work for [[CT_CONTROLS_GROUP]] that is subordinate to another group.
<syntaxhighlight lang="cpp">params ["_control", "_xPos", "_yPos"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_control", "_xPos", "_yPos", "_listboxIDC", "_listboxInfo"];
{{Cfg ref|end}}
//Get info of first item being dropped
(_listboxInfo select 0) params ["_lbText", "_lbValue", "_lbData"];</syntaxhighlight>
{{ConfigPage|end}}




=== Tree events ===
=== Tree events ===
{{Cfg ref|start}}
{{ConfigPage|start}}
{{Cfg ref|abc}}
{{ConfigPage|abc}}
==== onTreeSelChanged ====
==== onTreeSelChanged ====
* '''Priority:''' 2
* '''Use on:''' Tree
* '''Use on:''' Tree
* '''Fired on:''' Changing the selection in a tree.
* '''Fired on:''' Changing the selection in a tree.
Line 310: Line 287:


==== onTreeLButtonDown ====
==== onTreeLButtonDown ====
* '''Priority:''' 2
* '''Use on:''' Tree
* '''Use on:''' Tree
* '''Fired on:''' Pressing and releasing left mouse button on a tree.
* '''Fired on:''' Pressing and releasing left mouse button on a tree.
Line 318: Line 294:


==== onTreeDblClick ====
==== onTreeDblClick ====
* '''Priority:''' 2
* '''Use on:''' Tree
* '''Use on:''' Tree
* '''Fired on:''' Pressing and releasing twice on a tree entry.
* '''Fired on:''' Pressing and releasing twice on a tree entry.
Line 326: Line 301:


==== onTreeExpanded ====
==== onTreeExpanded ====
* '''Priority:''' 3
* '''Use on:''' Tree
* '''Use on:''' Tree
* '''Fired on:''' The tree folder structure has been expanded.
* '''Fired on:''' The tree folder structure has been expanded.
* '''Returns:''' Returns the control.
* '''Returns:''' Returns the control and path.
<syntaxhighlight lang="cpp">params ["_control"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_control", "_selectionPath"];</syntaxhighlight>




==== onTreeCollapsed ====
==== onTreeCollapsed ====
* '''Priority:''' 3
* '''Use on:''' Tree
* '''Use on:''' Tree
* '''Fired on:''' The tree folder structure has been collapsed.
* '''Fired on:''' The tree folder structure has been collapsed.
* '''Returns:''' Returns the control.
* '''Returns:''' Returns the control and path.
<syntaxhighlight lang="cpp">params ["_control"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_control", "_selectionPath"];</syntaxhighlight>




==== onTreeMouseMove ====
==== onTreeMouseMove ====
* '''Priority:''' 2
* '''Use on:''' Tree
* '''Use on:''' Tree
* '''Fired on:''' Fires continuously while moving the mouse with a certain interval.
* '''Fired on:''' Fires continuously while moving the mouse with a certain interval.
* '''Returns:''' Returns the control.
* '''Returns:''' Returns the control. Also returns the path, probably since [[Eden Editor]] update.
<syntaxhighlight lang="cpp">params ["_control"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_control", "_path"];</syntaxhighlight>




==== onTreeMouseHold ====
==== onTreeMouseHold ====
* '''Priority:''' 2
* '''Use on:''' Tree
* '''Use on:''' Tree
* '''Fired on:''' Fires continuously while mouse is not moving with a certain interval.
* '''Fired on:''' Fires continuously while mouse is not moving with a certain interval.
* '''Returns:''' Returns the control.
* '''Returns:''' Returns the control. Also returns the path, probably since [[Eden Editor]] update.
<syntaxhighlight lang="cpp">params ["_control"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_control", "_path"];</syntaxhighlight>




==== onTreeMouseExit ====
==== onTreeMouseExit ====
* '''Priority:''' 2
* '''Use on:''' Tree
* '''Use on:''' Tree
* '''Fired on:''' The mouse pointer exits the tree control area
* '''Fired on:''' The mouse pointer exits the tree control area
* '''Returns:''' Returns the control.
* '''Returns:''' Returns the control.
<syntaxhighlight lang="cpp">params ["_control"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_control"];</syntaxhighlight>
{{Cfg ref|end}}
{{ConfigPage|end}}




=== Checkbox events ===
=== Checkbox events ===
{{Cfg ref|start}}
{{ConfigPage|start}}
{{Cfg ref|abc}}
{{ConfigPage|abc}}
<div><div style="float: left; margin-right: 0.5em;">{{GVI|arma3|1.00}}</div>
<div><div style="float: left; margin-right: 0.5em;">{{GVI|arma3|1.00}}</div>
==== onChecked ====
==== onChecked ====
</div>
</div>
* '''Use on:''' Checkbox
* '''Use on:''' Checkbox (CT_CHECKBOX type 77 of [[Arma: GUI Configuration]]).
* '''Priority:''' ?
* '''Fired on:''' N/A
* '''Fired on:''' CheckBox checked
* '''Returns:''' N/A
* '''Returns:''' ?
{{Feature | Informative | This feature has not been implemented}}




Line 381: Line 351:
==== onCheckedChanged ====
==== onCheckedChanged ====
</div>
</div>
* '''Priority:''' ?
* '''Use on:''' Checkbox (CT_CHECKBOX type 77 of [[Arma: GUI Configuration]]).
* '''Use on:''' Checkbox
* '''Fired on:''' Checked state of CheckBox changed.
* '''Fired on:''' Checked state of CheckBox changed.
* '''Returns:''' Returns control and the checked state (0 or 1, not boolean).
* '''Returns:''' Returns control and the checked state (0 or 1, not boolean).
Line 389: Line 358:


==== onCheckBoxesSelChanged ====
==== onCheckBoxesSelChanged ====
* '''Priority:''' 2
* '''Use on:''' Checkboxes (CT_CHECKBOXES type 7 of [[Arma: GUI Configuration]])
* '''Use on:''' Checkbox
* '''Fired on:''' Changed the selection of checkboxes.
* '''Fired on:''' Changed the selection in a checkbox.
* '''Returns:''' Returns the control, the selected element index and the current state.
* '''Returns:''' Returns the control, the selected element index and the current state.
<syntaxhighlight lang="cpp">params ["_control", "_selectedIndex", "_currentState"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_control", "_selectedIndex", "_currentState"];</syntaxhighlight>
{{Cfg ref|end}}
{{ConfigPage|end}}




=== Misc. events ===
=== Misc. events ===
{{Cfg ref|start}}
{{ConfigPage|start}}
{{Cfg ref|abc}}
{{ConfigPage|abc}}
==== onToolBoxSelChanged ====
==== onToolBoxSelChanged ====
* '''Priority:''' 2
* '''Use on:''' Toolbox
* '''Use on:''' Toolbox
* '''Fired on:''' Changed the selection in a toolbox.
* '''Fired on:''' Changed the selection in a toolbox.
Line 409: Line 376:


==== onHTMLLink ====
==== onHTMLLink ====
* '''Priority:''' 2
* '''Use on:''' HTML
* '''Use on:''' HTML
* '''Fired on:''' Pressing and releasing a HTML link.
* '''Fired on:''' Pressing and releasing a HTML link.
Line 417: Line 383:


==== onSliderPosChanged ====
==== onSliderPosChanged ====
* '''Priority:''' 2
* '''Use on:''' Slider
* '''Use on:''' Slider
* '''Fired on:''' Changing the position of a slider.
* '''Fired on:''' Changing the position of a slider.
Line 425: Line 390:


==== onObjectMoved ====
==== onObjectMoved ====
* '''Priority:''' 2
* '''Use on:''' Object
* '''Use on:''' Object
* '''Fired on:''' Moving an object.
* '''Fired on:''' Moving an object.
Line 433: Line 397:


==== onMenuSelected ====
==== onMenuSelected ====
* '''Priority:''' 2
* '''Use on:''' Context menu
* '''Use on:''' Context menu
* '''Fired on:''' Some item in context menu (used now only in new mission editor) was selected.
* '''Fired on:''' Some item in context menu (used now only in new mission editor) was selected.
Line 441: Line 404:


==== onDraw ====
==== onDraw ====
* '''Priority:''' ?
* '''Use on:''' Map
* '''Use on:''' Map
* '''Fired on:''' Fires when the map is drawn (can occur more than once per second).
* '''Fired on:''' Fires when the map is drawn (can occur more than once per second).
* '''Returns:''' Returns the map control.
* '''Returns:''' Returns the map control.
{{Feature | important | Saving and loading of the game have no effect on this event handler. It doesn't get saved or loaded or even reset on game loading from save like some other event handlers do}}
<syntaxhighlight lang="cpp">params ["_control"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_control"];</syntaxhighlight>


Line 451: Line 414:
==== onVideoStopped ====
==== onVideoStopped ====
</div>
</div>
* '''Priority:''' 2
* '''Use on:''' Control
* '''Use on:''' Control
* '''Fired on:''' Activated every time the video ends (when looped, handler is executed after every finished loop).
* '''Fired on:''' Activated every time the video ends (when looped, handler is executed after every finished loop).
* '''Returns:''' Returns the control.
* '''Returns:''' Returns the control.
<syntaxhighlight lang="cpp">params ["_control"];</syntaxhighlight>
<syntaxhighlight lang="cpp">params ["_control"];</syntaxhighlight>
{{Cfg ref|end}}
{{ConfigPage|end}}
 
{{Sticky|
{{Feature|warning|When using the event names ''via'' [[:Category:Command Group: GUI Control - Event_Handlers|GUI scripting commands]] (e.g [[ctrlAddEventHandler]], [[displayAddEventHandler]]), the prefix "on" in the name '''must be removed!''' (e.g. <tt>ButtonDown</tt> instead of <tt>onButtonDown</tt>)}}
|bottom}}
</div><!-- used to limit Sticky range -->




== Event parameters ==
== Event parameters ==
The events handlers receive parameters in the ''[[_this]]'' variable.
 
The events handlers receive parameters in the ''[[Magic Variables#this|_this]]'' variable.
Each event passes a different set of parameters (listed in the table above) in an array.
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 {{Inline code|[[_this]] [[select]] 0}}.
The control or display that the event was assigned to is always found in {{ic|[[Magic Variables#this|_this]] [[select]] 0}}.




== Scope ==
== Scope ==
{{GVI|arma1|1.00}} In ArmA, most control-specific events work for controls and do not work for displays. The two exceptions being: '''''onKeyDown''''' and '''''onKeyUp'''''.<br />
 
{{GVI|arma2|1.00}} Since Arma 2, most control-specific events now work for both displays and controls.
{{GVI|arma1|1.00}} In {{arma1}}, most control-specific events work for controls and do not work for displays. The two exceptions being: '''''onKeyDown''''' and '''''onKeyUp'''''.<br>
{{GVI|arma2|1.00}} Since {{arma2}}, most control-specific events now work for both displays and controls.




== Defining events ==
== Defining events ==
User Interface Event Handlers can be assigned in two ways: via class property definitions or via [[:Category:Scripting Commands|scripting commands]].
User Interface Event Handlers can be assigned in two ways: via class property definitions or via [[:Category:Scripting Commands|scripting commands]].


=== Class defined events ===


=== Class defined events ===
Events can be defined in the Dialog (display) or Control classes (in [[Config.cpp|config.cpp]] or [[description.ext]]).
Events can be defined in the Dialog (display) or Control classes (in [[Config.cpp|config.cpp]] or [[description.ext]]).
The event property value (string) is executed as a line of code.
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):
An example line (this would be put within a control or dialog class):
<syntaxhighlight lang="cpp">onMouseDown = "hint str _this";</syntaxhighlight>
<syntaxhighlight lang="cpp">
onMouseDown = "hint str _this";
</syntaxhighlight>


Full Example:
Full Example:
<syntaxhighlight lang="cpp">class RscControlsGroup {
<syntaxhighlight lang="cpp">
class RscControlsGroup {
type = 15;
type = 15;
idc = -1;
idc = -1;
Line 530: Line 503:
h = 1.0;
h = 1.0;
colorBackground[] = { 0.2, 0.0, 0.0, 0.0 };
colorBackground[] = { 0.2, 0.0, 0.0, 0.0 };
};</syntaxhighlight>
};
</syntaxhighlight>


=== Script defined events ===


=== Script defined events ===
These events can also be given to dialogs/controls using the [[ctrlSetEventHandler]] scripting command.
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.
For the event handler to be called enable the control using the [[ctrlEnable]] scripting command.


  {{codecomment|// adding event handler}}
  {{cc|adding event handler}}
  ([[findDisplay]] 46) [[displayAddEventHandler]] ["keyDown", "[[_this]] [[call]] functionName_keyDown"];
  ([[findDisplay]] 46) [[displayAddEventHandler]] ["keyDown", "[[Magic Variables#this|_this]] [[call]] functionName_keyDown"];
   
   
  {{codecomment|// function definition}}
  {{cc|function definition}}
  functionName_keyDown = {
  functionName_keyDown = {
  [[params]] ["_ctrl", "_dikCode", "_shift", "_ctrlKey", "_alt"];
  [[params]] ["_ctrl", "_dikCode", "_shift", "_ctrlKey", "_alt"];
Line 547: Line 521:
  [[if]] (!_shift && !_ctrlKey && !_alt) [[then]] {
  [[if]] (!_shift && !_ctrlKey && !_alt) [[then]] {
  [[if]] (_dikCode [[in]] ([[actionKeys]] "NetworkStats")) [[then]] {
  [[if]] (_dikCode [[in]] ([[actionKeys]] "NetworkStats")) [[then]] {
  [] [[execVM]] "path\script.sqf";
  [[systemChat]] [[format]] ["EH fired for %1", _ctrl];
  _handled = [[true]];
  _handled = [[true]];
  };
  };
Line 555: Line 529:




[[Category:ArmA: Mission Editing]]
[[Category:Event Handlers]]
[[Category:Event Handlers]]
[[Category: Dialogs]]
[[Category:GUI Topics|GUI Topics]]

Revision as of 12:41, 17 May 2021

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

Deleting the display or control from within an event handler will crash the game if deleting is not the last line in the event handler's script or the code is not spawned.

onButtonClick = "ctrlDelete (_this select 0); systemChat 'You will never see this';"; // Will crash the game

onButtonClick = "systemChat 'Bye bye button!'; ctrlDelete (_this select 0);"; // Works just fine

onButtonClick = "[] spawn { ctrlDelete (_this select 0); systemChat 'Bye bye button!'; };"; // Works just fine as well

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 Arma 3 logo black.png1.56)
params ["_displayOrControl", ["_config", configNull]];
The order of initialisation is as follows:
  1. Top most config class (control class)
  2. Last config class
  3. Display
This means that during the onLoad event of the upper controls the lower controls do not exist!

onUnload

  • Use on: Display
  • Fired on: Display is closed, but no controls are destroyed yet.
  • Returns: Returns the display and exit code.
params ["_display", "_exitCode"];
onUnload event doesn't fire for RscTitles displays started with cutRsc.
Code or function should be called, otherwise controls might be destroyed before spawned code or function is executed!

onChildDestroyed

  • Use on: Display
  • Fired on: Child display is closed.
  • Returns: Returns the display, which child display was closed and exit code.
params ["_display", "_closedChildDisplay", "_exitCode"];


onMouseEnter

  • Use on: Control
  • Fired on: The mouse pointer enters the control area.
  • Returns: Returns control.
params ["_control"];
onMouseEnter does not fire for buttons disabled with ctrlEnable.


onMouseExit

  • Use on: Control
  • Fired on: The mouse pointer exits the control area.
  • Returns: Returns control.
params ["_control"];


onSetFocus

  • Use on: Control
  • Fired on: Input focus is on control. It now begins to accept keyboard input.
  • Returns: Returns control.
params ["_control"];


onKillFocus

  • Use on: Control
  • Fired on: Input focus is no longer on control. It no longer accepts keyboard input.
  • Returns: Returns control.
params ["_control"];


onTimer

  • Use on: Control
  • Fired on: N/A.
  • Returns: N/A.
This feature has not been implemented


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.
params ["_displayorcontrol", "_key", "_shift", "_ctrl", "_alt"];
true // Intercepts the default action, eg. pressing escape won't close the dialog.


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.
params ["_displayorcontrol", "_key", "_shift", "_ctrl", "_alt"];


onChar

  • Use on: Display, Control
  • Fired on: When some readable characters is recognised.
  • Returns: Returns the display or control and the char code.
params ["_displayorcontrol", "_charCode"];


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.
params ["_control", "_charCode"];


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.
params ["_control", "_charCode"];


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.
params ["_displayorcontrol", "_button", "_xPos", "_yPos", "_shift", "_ctrl", "_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.
params ["_displayorcontrol", "_button", "_xPos", "_yPos", "_shift", "_ctrl", "_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.
params ["_control", "_button", "_xPos", "_yPos", "_shift", "_ctrl", "_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.
params ["_control", "_button", "_xPos", "_yPos", "_shift", "_ctrl", "_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
params ["_control", "_xPos", "_yPos", "_mouseOver"];

  • Use on: Display
  • Returns: Returns the display, and some kind of x and y delta position.
params ["_display", "_xPos", "_yPos"];


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
params ["_control", "_xPos", "_yPos", "_mouseOver"];

  • Use on: Display
  • Returns: Returns the display, and some kind of x and y delta position.
params ["_display", "_xPos", "_yPos"];

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.
params ["_displayorcontrol", "_scroll"];


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.
params ["_control", "_exitCode"];


onDestroy

  • Use on: Control
  • Fired on: Destroying control
  • Returns: Returns the control and exit code.
params ["_control", "_exitCode"];


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.
params ["_control"];


onButtonDblClick

  • Use on: Button
  • Fired on: Button double clicked.
  • Returns: Returns control.
params ["_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.
params ["_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.
params ["_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.
params ["_control", "_selectedIndex"];


onLBListSelChanged

  • Use on: Listbox
  • Fired on: Selection in XCombo box changed (but value is not stored yet).
  • Returns: Returns the control and the selected element index.
params ["_control", "_selectedIndex"];


onLBDblClick

  • Use on: Listbox
  • Fired on: Double click on some row in listbox.
  • Returns: Returns the control and the selected element index.
params ["_control", "_selectedIndex"];


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.
params ["_control", "_listboxInfo"];
//Get info of first item being dragged
(_listboxInfo select 0) params ["_lbText", "_lbValue", "_lbData"];


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).
params ["_control", "_xPos", "_yPos", "_listboxIDC", "_listboxInfo"];
//Get info of first item being dragged
(_listboxInfo select 0) params ["_lbText", "_lbValue", "_lbData"];


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.
params ["_control", "_xPos", "_yPos", "_listboxIDC", "_listboxInfo"];
//Get info of first item being dropped
(_listboxInfo select 0) params ["_lbText", "_lbValue", "_lbData"];


Tree events

onTreeSelChanged

  • Use on: Tree
  • Fired on: Changing the selection in a tree.
  • Returns: Returns the control and the new selection path.
params ["_control", "_selectionPath"];


onTreeLButtonDown

  • Use on: Tree
  • Fired on: Pressing and releasing left mouse button on a tree.
  • Returns: Returns the control.
params ["_control"];


onTreeDblClick

  • Use on: Tree
  • Fired on: Pressing and releasing twice on a tree entry.
  • Returns: Returns the control and the current selection path.
params ["_control", "_selectionPath"];


onTreeExpanded

  • Use on: Tree
  • Fired on: The tree folder structure has been expanded.
  • Returns: Returns the control and path.
params ["_control", "_selectionPath"];


onTreeCollapsed

  • Use on: Tree
  • Fired on: The tree folder structure has been collapsed.
  • Returns: Returns the control and path.
params ["_control", "_selectionPath"];


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.
params ["_control", "_path"];


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.
params ["_control", "_path"];


onTreeMouseExit

  • Use on: Tree
  • Fired on: The mouse pointer exits the tree control area
  • Returns: Returns the control.
params ["_control"];


Checkbox events

onChecked

This feature has not been implemented


onCheckedChanged

  • Use on: Checkbox (CT_CHECKBOX type 77 of Arma: GUI Configuration).
  • Fired on: Checked state of CheckBox changed.
  • Returns: Returns control and the checked state (0 or 1, not boolean).
params ["_control", "_checked"];


onCheckBoxesSelChanged

  • Use on: Checkboxes (CT_CHECKBOXES type 7 of Arma: GUI Configuration)
  • Fired on: Changed the selection of checkboxes.
  • Returns: Returns the control, the selected element index and the current state.
params ["_control", "_selectedIndex", "_currentState"];


Misc. events

onToolBoxSelChanged

  • Use on: Toolbox
  • Fired on: Changed the selection in a toolbox.
  • Returns: Returns the control and the selected element index.
params ["_control", "_selectedIndex"];


onHTMLLink

  • Use on: HTML
  • Fired on: Pressing and releasing a HTML link.
  • Returns: Returns the control and href.
params ["_control", "_url"];


onSliderPosChanged

  • Use on: Slider
  • Fired on: Changing the position of a slider.
  • Returns: Returns the control and the change.
params ["_control", "_newValue"];


onObjectMoved

  • Use on: Object
  • Fired on: Moving an object.
  • Returns: Returns the control and the offset on the x, y and z axes.
params ["_control", "_offset"];


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.
params ["_control", "_commandId"];


onDraw

  • Use on: Map
  • Fired on: Fires when the map is drawn (can occur more than once per second).
  • Returns: Returns the map control.
Saving and loading of the game have no effect on this event handler. It doesn't get saved or loaded or even reset on game loading from save like some other event handlers do
params ["_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.
params ["_control"];
When using the event names via GUI scripting commands (e.g ctrlAddEventHandler, displayAddEventHandler), the prefix "on" in the name must be removed! (e.g. ButtonDown instead of onButtonDown)


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

Logo A1 black.png1.00 In Armed Assault, most control-specific events work for controls and do not work for displays. The two exceptions being: onKeyDown and onKeyUp.
Logo A2.png1.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):

onMouseDown = "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.

// adding event handler
(findDisplay 46) displayAddEventHandler ["keyDown", "_this call functionName_keyDown"];

// function definition
functionName_keyDown = {
	params ["_ctrl", "_dikCode", "_shift", "_ctrlKey", "_alt"];
	private _handled = false;

	if (!_shift && !_ctrlKey && !_alt) then {
		if (_dikCode in (actionKeys "NetworkStats")) then {
			systemChat format ["EH fired for %1", _ctrl];
			_handled = true;
		};
	};
	_handled;
};