OnDgsMouseDown: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
__NOTOC__ | __NOTOC__ | ||
This event is fired when the user clicks certain mouse button on a DGS element. | This event is fired when the user clicks certain mouse button on a DGS element. | ||
{{Note|This event will not trigger when [[onDgsMousePreClick]] is cancelled.}} | |||
==Parameters== | ==Parameters== | ||
Line 18: | Line 19: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
DGS = exports.dgs | DGS = exports.dgs | ||
addEventHandler( "onDgsMouseDown", | addEventHandler( "onDgsMouseDown", root, | ||
function ( btn, x, y ) | function ( btn, x, y ) | ||
if btn == "left" then | if btn == "left" then | ||
clickedElement = source; -- store the clicked element in a global variable | clickedElement = source; -- store the clicked element in a global variable | ||
local elementPos = { | local elementPos = { DGS:dgsGetPosition( source, false ) }; | ||
offsetPos = { x - elementPos[ 1 ], y - elementPos[ 2 ] }; -- get the offset position | offsetPos = { x - elementPos[ 1 ], y - elementPos[ 2 ] }; -- get the offset position | ||
end | end | ||
Line 28: | Line 29: | ||
); | ); | ||
addEventHandler( "onDgsMouseUp", | addEventHandler( "onDgsMouseUp", root, | ||
function ( btn, x, y ) | function ( btn, x, y ) | ||
if btn == "left" then | if btn == "left" then | ||
Line 36: | Line 37: | ||
); | ); | ||
addEventHandler( "onDgsMouseMove", | addEventHandler( "onDgsMouseMove", root, | ||
function ( x, y ) | function ( x, y ) | ||
if clickedElement then | if clickedElement then | ||
Line 44: | Line 45: | ||
); | ); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
===DGS events=== | ===DGS events=== | ||
{{DGSEVENTS}} | {{DGSEVENTS}} |
Latest revision as of 14:17, 16 February 2021
This event is fired when the user clicks certain mouse button on a DGS element.
Parameters
string button, int absoluteX, int absoluteY
- button: the name of the mouse button that was released on a DGS element, can be left, right, or middle.
- absoluteX: the X position of the mouse cursor, in pixels, measured from the left side of the screen.
- absoluteY: the Y position of the mouse cursor, in pixels, measured from the top of the screen.
Source
The source of this event is the DGS element on top of which the mouse button was released.
Example
This example show how to add very basic click'n'drag feature for DGS elements (only for those which parent element is dgs-root)
DGS = exports.dgs addEventHandler( "onDgsMouseDown", root, function ( btn, x, y ) if btn == "left" then clickedElement = source; -- store the clicked element in a global variable local elementPos = { DGS:dgsGetPosition( source, false ) }; offsetPos = { x - elementPos[ 1 ], y - elementPos[ 2 ] }; -- get the offset position end end ); addEventHandler( "onDgsMouseUp", root, function ( btn, x, y ) if btn == "left" then clickedElement = nil; end end ); addEventHandler( "onDgsMouseMove", root, function ( x, y ) if clickedElement then DGS:dgsSetPosition( clickedElement, x - offsetPos[ 1 ], y - offsetPos[ 2 ], false ); end end );
See Also
DGS events
General
- onDgsBlur
- onDgsCreate
- onDgsCursorTypeChange
- onDgsCursorStateChange
- onDgsDestroy
- onDgsElementRender
- onDgsElementMove
- onDgsElementSize
- onDgsElementEnter
- onDgsElementLeave
- onDgsFocus
- onDgsKey
- onDgsPositionChange
- onDgsPreRender
- onDgsRender
- onDgsElementScroll
- onDgsSizeChange
- onDgsTextChange
- onDgsWindowClose
- onDgsPropertyChange
Check Box
Combo Box
Drag'N Drop
Edit
Grid List
Menu
Selector
Mouse
- onDgsMousePreClick
- onDgsMouseClick
- onDgsMouseClickDown
- onDgsMouseClickUp
- onDgsMouseDrag
- onDgsMouseDoubleClick
- onDgsMouseDoubleClickDown
- onDgsMouseDoubleClickUp
- onDgsMouseDown
- onDgsMouseHover
- onDgsMouseEnter
- onDgsMouseLeave
- onDgsMouseMultiClick
- onDgsMouseMove
- onDgsMouseStay
- onDgsMouseUp
- onDgsMouseWheel
Radio Button
Switch Button
Tab
Animation
Plugin
Media
- onDgsMediaPlay
- onDgsMediaPause
- onDgsMediaStop
- onDgsMediaLoaded
- onDgsMediaTimeUpdate
- onDgsMediaBrowserReturn