|
|
(2 intermediate revisions by one other user not shown) |
Line 1: |
Line 1: |
− | ==registerEventHandler==
| + | #REDIRECT [[Global Command: registerEventHandler]] |
− | | |
− | <div class="command-min-version-info">Available since: <span class="command-min-version">v3.6</span></div>
| |
− | | |
− | <div class="command-doc">Registers an event handler function for a specific event.</div>
| |
− | | |
− | Lua Syntax:
| |
− | <pre class="command-syntax">registerEventHandler(event, eventHandler [, eventFlags])</pre>
| |
− | ===Arguments===
| |
− | ====event====
| |
− | :'''"string"''' - The event which triggers the event handler to be called. Currently supported events: "mainLoop", "mouseEvent", "animationStarted", "animationStopped", "textStarted", "textStopped".
| |
− | ====eventHandler====
| |
− | :'''"string"''' - The name of the lua function which is called when the event occurs. The function for the events "animationStarted", "animationStopped", "textStarted" and "textStopped" should take exactly one argument which is the affected visionaire object.
| |
− | :There are no arguments for the "mainLoop" event handler.
| |
− | :The function for the "mouseEvent" takes two arguments, the first one is the mouse event (see "eventFlags" parameter) and the second argument is the current mouse position (a table containing x- and y-position).
| |
− | ====eventFlags====
| |
− | :'''{int,...}''' - Can only be specified for event "mouseEvent": a list of mouse events where the event handler is called.
| |
− | :Currently the following mouse events are supported: eEvtMouseMove, eEvtMouseLeftButtonDoubleClick, eEvtMouseLeftButtonDown, eEvtMouseLeftButtonUp, eEvtMouseLeftButtonHold, eEvtMouseLeftButtonHolding, eEvtMouseRightButtonDoubleClick, eEvtMouseRightButtonDown, eEvtMouseRightButtonUp, eEvtMouseMiddleButtonDown, eEvtMouseMiddleButtonUp, eEvtMouseWheelUp and eEvtMouseWheelDown. If no mouse event is specified then the event handler is registered for all mouse events.
| |
− | ===Flags===
| |
− | ===Return Values===
| |
− | None.
| |
− | ===Examples===
| |
− | Example 1: mainLoop
| |
− | <syntaxhighlight>
| |
− | function onMainLoop()
| |
− | -- do something
| |
− | end
| |
− | | |
− | registerEventHandler("mainLoop", "onMainLoop")
| |
− | </syntaxhighlight>
| |
− | Example 2: mouseEvent
| |
− | <syntaxhighlight>
| |
− | function onMouseEvent(eventType, mousePosition)
| |
− | if eventType == eEvtMouseWheelUp or eventType == eEvtMouseWheelDown then
| |
− | -- mouse wheel was activated, do something
| |
− | end
| |
− | end
| |
− | | |
− | registerEventHandler("mouseEvent", "onMouseEvent", {eEvtMouseMove, eEvtMouseLeftButtonDoubleClick, eEvtMouseLeftButtonDown, eEvtMouseLeftButtonUp, eEvtMouseLeftButtonHold, eEvtMouseLeftButtonHolding, eEvtMouseRightButtonDoubleClick, eEvtMouseRightButtonDown, eEvtMouseRightButtonUp, eEvtMouseMiddleButtonDown, eEvtMouseMiddleButtonUp, eEvtMouseWheelUp, eEvtMouseWheelDown})
| |
− | </syntaxhighlight>
| |