Difference between revisions of "D3d.MeasureText"
From Nomad DB
(Created page with "Returns the measurements (width, height) of a text string. Font is set using d3d.SetFont. The measurements can be used to align text (like centering) within rectangles. {...") |
|||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
+ | {{Page_WD2}}{{Page_MDE}}{{Page_WDL}} | ||
Returns the measurements (width, height) of a text string. Font is set using [[d3d.SetFont]]. The measurements can be used to align text (like centering) within rectangles. | Returns the measurements (width, height) of a text string. Font is set using [[d3d.SetFont]]. The measurements can be used to align text (like centering) within rectangles. | ||
{{Warning|This function can only be called from inside [[Event: Script:OnRender|OnRender]] event!}} | {{Warning|This function can only be called from inside [[Event: Script:OnRender|OnRender]] event!}} | ||
− | == Syntax == | + | ==Syntax== |
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
d3d.MeasureText(text) | d3d.MeasureText(text) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | * '''text''': string (Text) | + | *'''text''': string (Text) |
− | * '''Returns''': width (number), height (number) of the given text | + | *'''Returns''': width (number), height (number) of the given text |
− | == Example == | + | ==Example== |
Draws a red text on a white surface. | Draws a red text on a white surface. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
Line 24: | Line 25: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | == Related Pages == | + | ==Related Pages== |
− | * [[ | + | |
− | * [[d3d.SetFont]] | + | *[[ScriptHook: Rendering]] |
− | * [[d3d.DrawText]] | + | *[[d3d.SetFont]] |
− | * [[d3d.SetColor]] | + | *[[d3d.DrawText]] |
+ | *[[d3d.DrawRect]] | ||
+ | *[[d3d.SetColor]] | ||
[[Category:WD2 ScriptHook Lua]] | [[Category:WD2 ScriptHook Lua]] | ||
+ | [[Category:WDL ScriptHook Lua]] |
Latest revision as of 11:13, 15 April 2021
Returns the measurements (width, height) of a text string. Font is set using d3d.SetFont. The measurements can be used to align text (like centering) within rectangles.
This function can only be called from inside OnRender event!
Syntax
d3d.MeasureText(text)
- text: string (Text)
- Returns: width (number), height (number) of the given text
Example
Draws a red text on a white surface.
function script:OnRender()
d3d.SetFont("Arial", 20)
local w, h = d3d.MeasureText("Hello NomadDB!")
d3d.SetColor(255, 255, 255) --white
d3d.DrawRect(50, 50, w, h)
d3d.SetColor(255, 0, 0) --red
d3d.DrawText(50, 50, "Hello NomadDB!")
end