Difference between revisions of "on.grabDown"

From Inspired-Lua Wiki
Jump to navigation Jump to search
m (Link)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
+
The event '''on.grabDown''' is used to handle grabbing motions (cursor press & hold).<br /><br />
The event '''on.grabDown''' is used to handle grabbing motions (cursor press & hold).<br />
 
  
 
This routine is called in these situations:
 
This routine is called in these situations:
 
 
 
* When the user presses and holds the Select key on a device
 
* 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 Ctrl + Select on a device
 
* When the user presses the middle mouse button over an active card on the desktop
 
* When the user presses the middle mouse button over an active card on the desktop
 
  
  
Line 36: Line 32:
 
end
 
end
 
</source>
 
</source>
You can see the whole lua example about Ball generation and movements here : [[Balls Example (Class + Events Handling)|Balls_Example]]
+
You can see the whole lua example about Ball generation and movements here : [[Balls_Example|Balls Example (Class + Events Handling)]]
  
 
== See Also ==
 
== See Also ==

Latest revision as of 12:25, 17 June 2012

The event on.grabDown is used to handle grabbing motions (cursor press & hold).

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 grabUp events prevent the generation of a 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 :

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

You can see the whole lua example about Ball generation and movements here : Balls Example (Class + Events Handling)

See Also

on.grabUp