DxGetTextWidth: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(Preventing scripters to think it returns the width in relative because of the Note) |
||
(18 intermediate revisions by 11 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Client function}} | {{Client function}} | ||
This function retrieves the theoretical width of a certain piece of text, if it were to be drawn using [[dxDrawText]]. | This function retrieves the theoretical width (in pixels) of a certain piece of text, if it were to be drawn using [[dxDrawText]]. | ||
'''NOTE:''' This function already takes the client's screen resolution into account. | |||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
float dxGetTextWidth ( string text, [float scale=1, mixed font="default", bool bColorCoded=false] ) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
{{New feature/item|3.0141|1.4.1|6942|{{OOP|This syntax requires you to ignore the font argument above| [[Element/DX font|font]]:getTextWidth}}}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
* '''text:''' A string representing the text for which you wish to retrieve with width for. | * '''text:''' A string representing the text for which you wish to retrieve with width for. | ||
==Optional Arguments== | |||
{{OptionalArg}} | |||
* '''scale:''' The size of the text. | * '''scale:''' The size of the text. | ||
* '''font:''' | * '''font:''' Either a custom [[DX font]] element or the name of a built-in dx font: | ||
{{DxFonts}} | {{DxFonts}} | ||
* '''bColorCoded:''' Should we exclude color codes from the width? (false will include the hex in the length) | |||
===Returns=== | ===Returns=== | ||
Returns | Returns the float of the width of the text (in pixels). | ||
==Example== | ==Example== | ||
<section name="Example" class="client" show="true"> | |||
This will show you the width of a message in a normal chatbox sent by a player | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function dxwidth(msg) | |||
chatbox = getChatboxLayout() | |||
local length = dxGetTextWidth(msg,chatbox["chat_scale"][1]) | |||
outputChatBox(tostring(length)) | |||
end | |||
addEventHandler("onClientChatMessage",root,dxwidth) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | |||
==See Also== | ==See Also== | ||
{{Drawing_functions}} | {{Drawing_functions}} | ||
[[ | |||
[[hu:dxGetTextWidth]] |
Latest revision as of 14:27, 5 April 2020
This function retrieves the theoretical width (in pixels) of a certain piece of text, if it were to be drawn using dxDrawText.
NOTE: This function already takes the client's screen resolution into account.
Syntax
float dxGetTextWidth ( string text, [float scale=1, mixed font="default", bool bColorCoded=false] )
OOP Syntax Help! I don't understand this!
- Note: This syntax requires you to ignore the font argument above
- Method: font:getTextWidth(...)
Required Arguments
- text: A string representing the text for which you wish to retrieve with width for.
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.
- scale: The size of the text.
- font: Either a custom DX font element or the name of a built-in dx font:
- "default": Tahoma
- "default-bold": Tahoma Bold
- "clear": Verdana
- "arial": Arial
- "sans": Microsoft Sans Serif
- "pricedown": Pricedown (GTA's theme text)
- "bankgothic": Bank Gothic Medium
- "diploma": Diploma Regular
- "beckett": Beckett Regular
- "unifont": Unifont
- bColorCoded: Should we exclude color codes from the width? (false will include the hex in the length)
Returns
Returns the float of the width of the text (in pixels).
Example
Click to collapse [-]
ExampleThis will show you the width of a message in a normal chatbox sent by a player
function dxwidth(msg) chatbox = getChatboxLayout() local length = dxGetTextWidth(msg,chatbox["chat_scale"][1]) outputChatBox(tostring(length)) end addEventHandler("onClientChatMessage",root,dxwidth)
See Also
- dxConvertPixels
- dxCreateFont
- dxCreateRenderTarget
- dxCreateScreenSource
- dxCreateShader
- dxCreateTexture
- dxDrawCircle
- dxDrawImage
- dxDrawImageSection
- dxDrawLine
- dxDrawLine3D
- dxDrawMaterialLine3D
- dxDrawMaterialPrimitive
- dxDrawMaterialPrimitive3D
- dxDrawMaterialSectionLine3D
- dxDrawPrimitive
- dxDrawPrimitive3D
- dxDrawRectangle
- dxDrawText
- dxDrawWiredSphere
- dxGetBlendMode
- dxGetFontHeight
- dxGetMaterialSize
- dxGetPixelColor
- dxGetPixelsSize
- dxGetPixelsFormat
- dxGetStatus
- dxGetTextSize
- dxGetTextWidth
- dxGetTexturePixels
- dxIsAspectRatioAdjustmentEnabled
- dxSetAspectRatioAdjustmentEnabled
- dxSetBlendMode
- dxSetPixelColor
- dxSetRenderTarget
- dxSetShaderValue
- dxSetShaderTessellation
- dxSetShaderTransform
- dxSetTestMode
- dxSetTextureEdge
- dxSetTexturePixels
- dxUpdateScreenSource