Line 1: |
Line 1: |
| | | |
| + | The event '''on.grabDown''' is used to handle grabbing motions (cursor press & hold).<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 (Class + Events Handling)|Balls_Example]] |
| + | |
| + | == See Also == |
| + | [[on.grabUp]] |
| | | |
| [[Category:Events]] | | [[Category:Events]] |