GuiGetScreenSize: Difference between revisions
mNo edit summary |
|||
Line 44: | Line 44: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local sWidth,sHeight = guiGetScreenSize() -- The variables | local sWidth,sHeight = guiGetScreenSize() -- The variables | ||
dxDrawText( | dxDrawText( "Hello World!",684.0,731.0,732.0,766.0,tocolor(0,255,255,175),1.0,"bankgothic","left","top",false,false,false) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 59: | Line 59: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local sWidth,sHeight = guiGetScreenSize() -- The variables | local sWidth,sHeight = guiGetScreenSize() -- The variables | ||
dxDrawText( | dxDrawText("Hello World!",sWidth-340, sHeight-37, sWidth-292, sHeight-2,tocolor(0,255,255,175),1.0,"bankgothic","left","top",false,false,false) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 66: | Line 66: | ||
function DXtext () | function DXtext () | ||
local sWidth,sHeight = guiGetScreenSize() -- The variables | local sWidth,sHeight = guiGetScreenSize() -- The variables | ||
dxDrawText( | dxDrawText("Hello World!",sWidth-340, sHeight-37, sWidth-292, sHeight-2,tocolor(0,255,255,175),1.0,"bankgothic","left","top",false,false,false) | ||
end | end | ||
Revision as of 16:38, 5 March 2011
This function retrieves the local screen size according to the resolution they are using.
Syntax
float float guiGetScreenSize ()
Returns
This returns two floats representing the player's screen resolution, width and height.
Example
This example checks whether a player is using a low resolution, and warns them that GUI may appear incorrect.
--setup a function when the resource starts function checkResolutionOnStart ( theResource ) --if the resource started isnt this resource, don't bother initiating the function if theResource ~= getThisResource() then return end local x,y = guiGetScreenSize() --get their screen size if ( x <= 640 ) and ( y <= 480 ) then --if their resolution is lower or equal to 640x480 --warn them about GUI problems. outputChatBox ( "WARNING: You are running on a low resolution. Some GUI may be placed or appear incorrectly." ) end end --attach the function to the event handler addEventHandler ( "onClientResourceStart", getRootElement(), checkResolutionOnStart )
Tips
To get the precise coordinates of a GUI element or DX drawings, you need to decide which edges of the screen you want to have them positioned against, then you just need to find the difference between your screen size and your position values.
For example, there is a DX text. It fits on 1024x768 resolution.
function DXtext () dxDrawText(tostring "Hello World!",684.0,731.0,732.0,766.0,tocolor(0,255,255,175),1.0,"bankgothic","left","top",false,false,false) end addEventHandler ( "onClientResourceStart", getRootElement(), DXtext )
Now if you want it to fit on all resolutions. Then follow these steps:
1. Add width and height variables to get GUI's screen size, here we use sWidth and sHeight.
local sWidth,sHeight = guiGetScreenSize() -- The variables dxDrawText( "Hello World!",684.0,731.0,732.0,766.0,tocolor(0,255,255,175),1.0,"bankgothic","left","top",false,false,false)
2. Subtract each of the DX text's position values from the screen size manually (remembering the resolution is 1024x768):
- Left position value is 684, 1024-684 = 340
- Top position value is 731, 768-731 = 37
- Right position values is 732, 1024-732 = 292
- Bottom position value is 766, 768-766 = 2
You may want to use a calculator to help you count.
3. Now with the answer above remove all of the position values and replace it with the width or height variable subtract with the answer. Which would be:
local sWidth,sHeight = guiGetScreenSize() -- The variables dxDrawText("Hello World!",sWidth-340, sHeight-37, sWidth-292, sHeight-2,tocolor(0,255,255,175),1.0,"bankgothic","left","top",false,false,false)
So the final results will be a DX text which will fit on all resolutions which will be:
function DXtext () local sWidth,sHeight = guiGetScreenSize() -- The variables dxDrawText("Hello World!",sWidth-340, sHeight-37, sWidth-292, sHeight-2,tocolor(0,255,255,175),1.0,"bankgothic","left","top",false,false,false) end addEventHandler ( "onClientResourceStart", getRootElement(), DXtext )
See Also
General functions
- guiBringToFront
- getChatboxLayout
- getChatboxCharacterLimit
- guiCreateFont
- guiBlur
- guiFocus
- guiGetAlpha
- guiGetCursorType
- guiGetEnabled
- guiGetFont
- guiGetInputEnabled
- guiGetInputMode
- guiGetPosition
- guiGetProperties
- guiGetProperty
- guiGetScreenSize
- guiGetSize
- guiGetText
- guiGetVisible
- guiMoveToBack
- guiSetAlpha
- guiSetEnabled
- guiSetFont
- guiSetInputEnabled
- guiSetInputMode
- guiSetPosition
- guiSetProperty
- guiSetSize
- guiSetText
- guiSetVisible
- isChatBoxInputActive
- isConsoleActive
- isDebugViewActive
- isMainMenuActive
- isMTAWindowActive
- isTransferBoxActive
- setChatboxCharacterLimit
- setDebugViewActive
Browsers
Buttons
Checkboxes
Comboboxes
- guiCreateComboBox
- guiComboBoxAddItem
- guiComboBoxClear
- guiComboBoxGetItemCount
- guiComboBoxGetItemText
- guiComboBoxGetSelected
- guiComboBoxIsOpen
- guiComboBoxRemoveItem
- guiComboBoxSetItemText
- guiComboBoxSetOpen
- guiComboBoxSetSelected
Edit Boxes
- guiCreateEdit
- guiEditGetCaretIndex
- guiEditGetMaxLength
- guiEditIsMasked
- guiEditIsReadOnly
- guiEditSetCaretIndex
- guiEditSetMasked
- guiEditSetMaxLength
- guiEditSetReadOnly
Gridlists
- guiCreateGridList
- guiGridListAddColumn
- guiGridListAddRow
- guiGridListAutoSizeColumn
- guiGridListClear
- guiGridListGetColumnCount
- guiGridListGetColumnTitle
- guiGridListGetColumnWidth
- guiGridListGetHorizontalScrollPosition
- guiGridListGetItemColor
- guiGridListGetItemData
- guiGridListGetItemText
- guiGridListGetRowCount
- guiGridListGetSelectedCount
- guiGridListGetSelectedItem
- guiGridListGetSelectedItems
- guiGridListGetSelectionMode
- guiGridListIsSortingEnabled
- guiGridListGetVerticalScrollPosition
- guiGridListInsertRowAfter
- guiGridListRemoveColumn
- guiGridListRemoveRow
- guiGridListSetColumnTitle
- guiGridListSetColumnWidth
- guiGridListSetHorizontalScrollPosition
- guiGridListSetItemColor
- guiGridListSetItemData
- guiGridListSetItemText
- guiGridListSetScrollBars
- guiGridListSetSelectedItem
- guiGridListSetSelectionMode
- guiGridListSetSortingEnabled
- guiGridListSetVerticalScrollPosition
Memos
- guiCreateMemo
- guiMemoGetCaretIndex
- guiMemoGetVerticalScrollPosition
- guiMemoSetVerticalScrollPosition
- guiMemoIsReadOnly
- guiMemoSetCaretIndex
- guiMemoSetReadOnly
Progressbars
Radio Buttons
Scrollbars
Scrollpanes
- guiCreateScrollPane
- guiScrollPaneGetHorizontalScrollPosition
- guiScrollPaneGetVerticalScrollPosition
- guiScrollPaneSetHorizontalScrollPosition
- guiScrollPaneSetScrollBars
- guiScrollPaneSetVerticalScrollPosition
Static Images
Tab Panels
Tabs
Text Labels
- guiCreateLabel
- guiLabelGetColor
- guiLabelGetFontHeight
- guiLabelGetTextExtent
- guiLabelSetColor
- guiLabelSetHorizontalAlign
- guiLabelSetVerticalAlign