Changes

Jump to navigation Jump to search

on.grabDown

1,400 bytes added, 13:25, 17 June 2012
m
Link
Line 1: Line 1:  +
The event '''on.grabDown''' is used to handle grabbing motions (cursor press & hold).<br /><br />
    +
This routine is called in these situations:
 +
* When the user presses and holds the Select key on a device
 +
* When the user presses Ctrl + Select on a device
 +
* When the user presses the middle mouse button over an active card on the desktop
    +
 +
The passed coordinated, x and y, are always 0 and 0.
 +
The ''grabDown'' and [[on.grabUp|''grabUp'']] events prevent the generation of a [[on.mouseUp|''mouseUp'']] event in all cases.
 +
 +
They will be preceded by a [[on.mouseDown]] event when generated by pressing and holding the Select key on a device.
 +
 +
 +
== Example ==
 +
Below is an example of a program that handles the grabbing motion to move an object :
 +
<source lang="lua">function Ball:move(x,y)
 +
    self.x = x
 +
    self.y = y
 +
    platform.window:invalidate()
 +
end
 +
 +
function on.grabDown(x,y)
 +
    isGrabbing = not isGrabbing -- makes the variable switch from true to false and vice versa
 +
    platform.window:invalidate()
 +
end
 +
 +
function on.mouseMove(x,y)
 +
    if isGrabbing and (trackedBall and trackedBall.isActive) then  -- assuming trackedBall is defined etc.
 +
        trackedBall:move(x-trackedBall.r/2,y-trackedBall.r/2)
 +
    end
 +
end
 +
</source>
 +
You can see the whole lua example about Ball generation and movements here : [[Balls_Example|Balls Example (Class + Events Handling)]]
 +
 +
== See Also ==
 +
[[on.grabUp]]
    
[[Category:Events]]
 
[[Category:Events]]

Navigation menu