User:StrixG/dxGetTextSize: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ {{Client function}} This function retrieves the theoretical width and height (in pixels) of a certain piece of text, if it were to be drawn using dxDrawText....")
 
No edit summary
Line 7: Line 7:
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
float dxGetTextSize ( string text, [float scale=1, mixed font="default", bool bColorCoded=false] )
float, float dxGetTextSize ( string text, [float width=0, float scaleXY=1.0, float=scaleY=1.0, mixed font="default", bool wordBreak=false, bool colorCoded=false] )
</syntaxhighlight>
</syntaxhighlight>
{{OOP|This syntax requires you to ignore the font argument above| [[Element/DX font|font]]:getTextWidth}}}}
{{OOP|This syntax requires you to ignore the font argument above| [[Element/DX font|font]]:getSize}}}}
===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.
Line 15: Line 15:
==Optional Arguments==
==Optional Arguments==
{{OptionalArg}}
{{OptionalArg}}
* '''scale:''' The size of the text.
* '''width:''' The width of the text. Use with ''wordBreak = true''.
* '''scale:''' The size of the text. Can (optionally) be specified as two floats. i.e. '''scaleX, scaleY'''
* '''font:''' Either a custom [[DX font]] element or the name of a built-in dx font:
* '''font:''' Either a custom [[DX font]] element or the name of a built-in dx font:
{{DxFonts}}
{{DxFonts}}
* '''wordBreak:''' If set to ''true'', the text will wrap to a new line whenever it reaches the right side of the bounding box. If ''false'', the text will always be completely on one line.
* '''bColorCoded:''' Should we exclude color codes from the width? (false will include the hex in the length)
* '''bColorCoded:''' Should we exclude color codes from the width? (false will include the hex in the length)


===Returns===
===Returns===
Returns the float of the width of the text (in pixels).  
Returns two floats representing the width and height of the text (in pixels).  


==Example==  
==Example==  
<section name="Example" class="client" show="true">
<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)
-- TODO
    chatbox = getChatboxLayout()
    local length = dxGetTextWidth(msg,chatbox["chat_scale"][1])
    outputChatBox(tostring(length))
end
addEventHandler("onClientChatMessage",root,dxwidth)
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>
Line 38: Line 34:
==See Also==
==See Also==
{{Drawing_functions}}
{{Drawing_functions}}
[[hu:dxGetTextWidth]]

Revision as of 18:57, 28 April 2020

This function retrieves the theoretical width and height (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, float dxGetTextSize ( string text, [float width=0, float scaleXY=1.0, float=scaleY=1.0, mixed font="default", bool wordBreak=false, bool colorCoded=false] )

OOP Syntax Help! I don't understand this!

Note: This syntax requires you to ignore the font argument above
Method: font:getSize(...)

}}

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.

  • width: The width of the text. Use with wordBreak = true.
  • scale: The size of the text. Can (optionally) be specified as two floats. i.e. scaleX, scaleY
  • 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
  • wordBreak: If set to true, the text will wrap to a new line whenever it reaches the right side of the bounding box. If false, the text will always be completely on one line.
  • bColorCoded: Should we exclude color codes from the width? (false will include the hex in the length)

Returns

Returns two floats representing the width and height of the text (in pixels).

Example

Click to collapse [-]
Example
-- TODO

See Also