DgsGetPosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 11: Line 11:
*'''guiElement:''' The dgs element of which you wish to retrieve the position.
*'''guiElement:''' The dgs element of which you wish to retrieve the position.
*'''relative:''' This is whether sizes and positioning are relative. If this is true, then all x,y,width,height floats must be between 0 and 1, representing sizes relative to the parent.
*'''relative:''' This is whether sizes and positioning are relative. If this is true, then all x,y,width,height floats must be between 0 and 1, representing sizes relative to the parent.
===Optional Arguments===
*'''includeParent''' A boolean representing whether the position is relative to the screen rather than the parent.
*'''includeParent''' A boolean representing whether the position is relative to the screen rather than the parent.



Revision as of 08:08, 14 July 2019

This function allows retrieval of a DGS element's current position, relative to its parent.

Syntax

float, float dgsGetPosition ( element dgsElement, bool relative [, bool includeParent = false ] )

Required Arguments

  • guiElement: The dgs element of which you wish to retrieve the position.
  • relative: This is whether sizes and positioning are relative. If this is true, then all x,y,width,height floats must be between 0 and 1, representing sizes relative to the parent.

Optional Arguments

  • includeParent A boolean representing whether the position is relative to the screen rather than the parent.

Returns

Returns floats representing the x and y position of the element, or false if the position could not be retrieved.

Example

This example checks which corner a dgs element exists in

DGS = exports.dgs

function positionCheck ( dgsElement )
	local x,y = DGS:dgsGetPosition ( dgsElement, 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 dgs element's position is "..position.."!" )
end

See Also

Custom Cursor Functions

Multi Language Supports

Animation

3D Element

3D Interface

3D Line

3D Image

3D Text

Browser

Button

Check Box

Combo Box

Custom Renderer

Edit

Detect Area

Drag'N Drop

Grid List

Image

Memo

Menu

Label

Layout

Line

Progress Bar

Radio Button

Scale Pane

Scroll Bar

Scroll Pane

Selector

Style

Switch Button

Tab Panel

Window

Basic Shape Plugins

Circle

Quadrilateral

Rounded Rectangle

Other Plugins

Blur Box

Canvas

Chart

Color Picker

Effect 3D

Gradient

Mask

Media Browser

Nine Slice

Object Preview Supports

Paste Handler

QRCode

Remote Image

Screen Source

SVG

Tooltips