Libraries.Interface.Events.GestureEvent Documentation
Inherits from: Libraries.Language.Object
Variables Table
Variables | Description |
---|---|
integer SINGLE_TAP | An event code indicating that this gesture is a (confirmed) single tap. |
integer PINCH | An event code indicating that this gesture is a pinch (typically used for scaling up or down). This event uses the "timingCode" value to indicate when the gesture begins, continues, or finishes. |
integer BEGIN | A code indicating that the event has just begun. Discrete gestures always use this timing code (i.e. gestures that trigger only once when they occur, such as SWIPE or LONG_PRESS). |
integer timingCode | This code indicates if an event has just begun, finished, or is continuing. Most gestures are considered "discrete", or in other words, a gesture will trigger only a single event. The events triggered by discrete gestures always use the BEGIN code. The PINCH gesture is continuous, and will trigger different events when it begins, continues, and finishes. This value can be used to determine what stage of a PINCH gesture is occuring. |
integer eventType | What kind of gesture the event represents, such as DOUBLE_TAP or PAN. |
integer SWIPE | An event code indicating that this gesture is a swipe (a quick flick in a direction). |
integer currentFingerCount | The current amount of fingers that was detected during the GestureEvent |
integer PAN | An event code indicating that this gesture is a pan (a slow, continuous finger drag in a direction). |
integer LEFT | Indicates that this gesture was directed to the left. Used by the SWIPE gesture. |
integer UP | Indicates that this gesture was directed upwards. Used by the SWIPE gesture. |
integer gestureCount | Indicates how many times this gesture has occurred in rapid succession. |
integer CONTINUE | A code indicating that the event is on-going. |
boolean isPinch | If the scale factor is large enough to be considered a pinch, then this will be true. (0.5 < scale factor > 1.5) |
integer FINISH | A code indicating that the event has just finished. |
integer maxFingerCount | The maximum amount of fingers that was detected during the GestureEvent |
integer NO_DIRECTION | Indicates that this gesture has no directionality. The default DIRECTION value for most gestures. |
integer RIGHT | Indicates that this gesture was directed to the right. Used by the SWIPE gesture. |
integer LONG_PRESS | An event code indicating that this gesture is a long press. |
integer DOUBLE_TAP | An event code indicating that this gesture is a double tap. |
integer DOWN | Indicates that this gesture was directed downwards. Used by the SWIPE gesture. |
Actions Documentation
Compare(Libraries.Language.Object object)
This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.
Parameters
- Libraries.Language.Object: The object to compare to.
Return
integer: The Compare result, Smaller, Equal, or Larger.
Example
Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)
Equals(Libraries.Language.Object object)
This action determines if two objects are equal based on their hash code values.
Parameters
- Libraries.Language.Object: The to be compared.
Return
boolean: True if the hash codes are equal and false if they are not equal.
Example
use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)
GetDirection()
Which direction this gesture was performed in. For most gestures, this will be NO_DIRECTION, but for the SWIPE and PAN gestures this will be one of RIGHT, LEFT, UP, or DOWN.
Return
integer: Which direction a SWIPE or PAN gesture was in, or NO_DIRECTION if this is a different gesture type.
GetHashCode()
This action gets the hash code for an object.
Return
integer: The integer hash code of the object.
Example
Object o
integer hash = o:GetHashCode()
GetPanDistanceX()
Indicates how far along the x-axis the user has panned since the last pan event. If this gesture isn't a pan event, this value will be 0.
Return
integer: how much the user's finger has moved along the x-axis since the last pan event.
GetPanDistanceY()
Indicates how far along the y-axis the user has panned since the last pan event. If this gesture isn't a pan event, this value will be 0.
Return
integer: how much the user's finger has moved along the y-axis since the last pan event.
GetScaleFactor()
This value represents the scaling requested by a PINCH gesture. A value greater than one indicates that the user's fingers are moving apart (zoom in), and a value less than one indicates that the user's fingers are coming together (zoom out). The value is calculated relative to the position of the fingers on the last PINCH gesture event. If this gesture isn't a PINCH gesture, this value will always be 1.
Return
number: The new scale factor, relative to the scale factor of the last PINCH event.
GetSource()
This action returns the source item for this event, which is the the target of gesture event which has occurred (or is otherwise relevant to it). In the Game engine, if a gesture occurs directly on top of an Item, it will be stored here. If a gesture is triggered with no such Item available, this will be undefined.
Return
Libraries.Interface.Item: The source Item for this GestureEvent.
Example
use Libraries.Game.Game
use Libraries.Interface.Events.GestureEvent
use Libraries.Interface.Events.GestureListener
use Libraries.Interface.Item
use Libraries.Game.Graphics.Drawable
class Main is Game, GestureListener
Drawable square
action Main
StartGame()
end
action CreateGame
square:LoadFilledRectangle(200, 200)
square:SetPosition(300, 200)
Add(square)
AddGestureListener(me)
end
action OnDoubleTap(GestureEvent event)
Item source = event:GetSource()
if source = undefined
output "The background was tapped!"
elseif source:Equals(square)
output "The square was tapped!"
end
end
end
GetX()
This action returns the x coordinate of where the event was on the screen.
Return
integer: The x coordinate of where the event was on the screen.
Example
use Libraries.Game.Game
use Libraries.Interface.Events.GestureEvent
use Libraries.Interface.Events.GestureListener
class Main is Game, GestureListener
action Main
StartGame()
end
action CreateGame
AddGestureListener(me)
end
action OnDoubleTap(GestureEvent event)
integer x = event:GetX()
integer y = event:GetY()
output "The event was at " + x + ", " + y
end
end
GetY()
This action returns the y coordinate of where the event was on the screen.
Return
integer: The y coordinate of where the event was on the screen.
Example
use Libraries.Game.Game
use Libraries.Interface.Events.GestureEvent
use Libraries.Interface.Events.GestureListener
class Main is Game, GestureListener
action Main
StartGame()
end
action CreateGame
AddGestureListener(me)
end
action OnDoubleTap(GestureEvent event)
integer x = event:GetX()
integer y = event:GetY()
output "The event was at " + x + ", " + y
end
end
SetEventHandled(boolean handled)
This action sets whether this event should be considered handled by any event listeners. In the Game engine, this is set to true just before sending the event to a listener. If the value is reset to false inside the listener, the engine will continue to send the event to other event listeners.
Parameters
- boolean handled: Whether or not this event should be considered handled.
Example
use Libraries.Game.Game
use Libraries.Interface.Events.GestureEvent
use Libraries.Interface.Events.GestureListener
class Main is Game, GestureListener
integer totalClicks = 0
action Main
StartGame()
end
action CreateGame
AddGestureListener(me)
end
action OnDoubleTap(GestureEvent event)
totalClicks = totalClicks + 1
output "The game has been double tapped " + totalClicks + " times."
// By setting the event handled flag to false, we tell the Game engine
// to keep sending the GestureEvent to any other GestureListeners we have.
// In this example, since it's our only GestureListener, it does nothing.
event:SetEventHandled(false)
end
end
SetSource(Libraries.Interface.Item item)
This action sets the source item for this event, which is the the target of gesture event which has occurred (or is otherwise relevant to it). In the Game engine, if a gesture occurs directly on top of an Item, it will be stored here. If a gesture is triggered with no such Item available, this will be undefined. This action is automatically used by the engine when processing input. Most users will never need to call this action directly.
Parameters
- Libraries.Interface.Item: The source Item to be stored for this GestureEvent.
ToText(integer gestureCode)
The ToText action returns a textual representation of the provided gesture code.
Parameters
- integer gestureCode: A gesture code, such as SINGLE_TAP or PAN.
Return
text: A text representation of the given gesture code, or "Unknown" if the code isn't recognized.
WasEventHandled()
This action returns whether or not this event has already been handled. In the Game engine, this is set to true just before sending the event to a listener. If the value is reset to false inside the listener, the engine will continue to send the event to other event listeners.
Return
boolean: Whether or not this event has already been handled.
Example
use Libraries.Game.Game
use Libraries.Interface.Events.GestureEvent
use Libraries.Interface.Events.GestureListener
class Main is Game, GestureListener
action Main
StartGame()
end
action CreateGame
AddGestureListener(me)
end
action OnDoubleTap(GestureEvent event)
// The event handled flag is set to true when the engine finds a gesture
// listener to send the event to, so this should always return true.
boolean handled = event:WasEventHandled()
output "After clicking the mouse, handled = " + handled
end
end