GuiGetPosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Client function}}
This function allows retrieval of a GUI element's current position on the screen
This function allows retrieval of a GUI element's current position on the screen


Line 15: Line 16:


==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
This example checks which corner a gui element exists in
This example does...
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
function positionCheck ( guiElement )
blabhalbalhb --abababa
local x,y = guiGetPosition ( guiElement, true ) --get the position
--This line does this...
local position --define the position
mooo
if ( x == 0.5 ) and ( y == 0.5 ) then --if its bang in the middle
position = "middle" --set position to middle
elseif ( x > 0.5 ) and ( y > 0.5 ) then --if its in the right bottom
position = "right-bottom"
elseif ( x < 0.5 ) and ( y < 0.5 ) then --if its in the left top
position = "left-top"
elseif ( x < 0.5 ) and ( y > 0.5 ) then --if its in the left bottom
position = "left-bottom"
elseif ( x > 0.5 ) and ( y < 0.5 ) then --if its in the right top
position = "right-top"
else --if it couldnt be retrieved
position = "unknown"
end
--announce this into the chatbox
outputChatBox ( "The gui element's position is "..position.."!" )
end
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{GUI_functions}}
{{GUI_functions}}
[[Category:Incomplete]] -- leave this unless you complete the function

Revision as of 15:19, 15 August 2007

This function allows retrieval of a GUI element's current position on the screen

Syntax

float float guiGetPosition ( element guiElement, bool relative )

Required Arguments

  • guiElement: The gui element of which you wish to retrieve the position.
  • relative: A boolean representing whether the position should be relative to the element's parent, or absolute pixel position.

Returns

Returns two floats of the x and y positions of the position of the element on the screen, or false if the position could not be retrieved.

Example

This example checks which corner a gui element exists in

function positionCheck ( guiElement )
	local x,y = guiGetPosition ( guiElement, true ) --get the position
	local position --define the position
	if ( x == 0.5 ) and ( y == 0.5 ) then --if its bang in the middle
		position = "middle" --set position to middle
	elseif ( x > 0.5 ) and ( y > 0.5 ) then --if its in the right bottom
		position = "right-bottom" 
	elseif ( x < 0.5 ) and ( y < 0.5 ) then --if its in the left top
		position = "left-top"
	elseif ( x < 0.5 ) and ( y > 0.5 ) then --if its in the left bottom
		position = "left-bottom"
	elseif ( x > 0.5 ) and ( y < 0.5 ) then --if its in the right top
		position = "right-top" 
	else --if it couldnt be retrieved
		position = "unknown"
	end
	--announce this into the chatbox
	outputChatBox ( "The gui element's position is "..position.."!" )
end

See Also

General functions

Browsers

Buttons

Checkboxes

Comboboxes

Edit Boxes

Gridlists

Memos

Progressbars

Radio Buttons

Scrollbars

Scrollpanes

Static Images

Tab Panels

Tabs

Text Labels

Windows