OnClientGUIMouseDown: Difference between revisions
Jump to navigation
Jump to search
(New page: {{Client event}} __NOTOC__ This event is fired when the user clicks certain mouse button on a GUI element. ==Parameters== <syntaxhighlight lang="lua"> string button, int absoluteX, int absoluteY </code...) |
|||
Line 15: | Line 15: | ||
==Example== | ==Example== | ||
This example show how to add very basic ''click'n'drag'' feature for GUI elements (only for those which parent element is gui-root) | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- | |||
addEventHandler( "onClientGUIMouseDown", getRootElement( ), | |||
function ( btn, x, y ) | |||
if btn == "left" then | |||
clickedElement = source; -- store the clicked element in a global variable | |||
local elementPos = { guiGetPosition( source, false ) }; | |||
offsetPos = { x - elementPos[ 1 ], y - elementPos[ 2 ] }; -- get the offset position | |||
end | |||
end | |||
); | |||
addEventHandler( "onClientGUIMouseUp", getRootElement( ), | |||
function ( btn, x, y ) | |||
if btn == "left" then | |||
clickedElement = nil; | |||
end | |||
end | |||
); | |||
addEventHandler( "onClientCursorMove", getRootElement( ), | |||
function ( _, _, x, y ) | |||
if clickedElement then | |||
guiSetPosition( clickedElement, x - offsetPos[ 1 ], y - offsetPos[ 2 ], false ); | |||
end | |||
end | |||
); | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 24: | Line 51: | ||
===Client event functions=== | ===Client event functions=== | ||
{{Client_event_functions}} | {{Client_event_functions}} | ||
Revision as of 18:42, 5 October 2009
This event is fired when the user clicks certain mouse button on a GUI element.
Parameters
string button, int absoluteX, int absoluteY
- button: the name of the mouse button that the GUI element was clicked with, 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 GUI element that was clicked.
Example
This example show how to add very basic click'n'drag feature for GUI elements (only for those which parent element is gui-root)
addEventHandler( "onClientGUIMouseDown", getRootElement( ), function ( btn, x, y ) if btn == "left" then clickedElement = source; -- store the clicked element in a global variable local elementPos = { guiGetPosition( source, false ) }; offsetPos = { x - elementPos[ 1 ], y - elementPos[ 2 ] }; -- get the offset position end end ); addEventHandler( "onClientGUIMouseUp", getRootElement( ), function ( btn, x, y ) if btn == "left" then clickedElement = nil; end end ); addEventHandler( "onClientCursorMove", getRootElement( ), function ( _, _, x, y ) if clickedElement then guiSetPosition( clickedElement, x - offsetPos[ 1 ], y - offsetPos[ 2 ], false ); end end );
See Also
GUI events
Input
GUI
- onClientGUIAccepted
- onClientGUIBlur
- onClientGUIChanged
- onClientGUIClick
- onClientGUIComboBoxAccepted
- onClientGUIDoubleClick
- onClientGUIFocus
- onClientGUIMouseDown
- onClientGUIMouseUp
- onClientGUIMove
- onClientGUIScroll
- onClientGUISize
- onClientGUITabSwitched
- onClientMouseEnter
- onClientMouseLeave
- onClientMouseMove
- onClientMouseWheel
Client event functions
- triggerLatentServerEvent
- triggerServerEvent
- Shared
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled