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. {...") |
|||
Line 3: | Line 3: | ||
{{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 24: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | == Related Pages == | + | ==Related Pages== |
− | * [[WD2 ScriptHook: Rendering]] | + | |
− | * [[d3d.SetFont]] | + | *[[WD2 ScriptHook: Rendering]] |
− | * [[d3d.DrawText]] | + | *[[d3d.SetFont]] |
− | * [[d3d.SetColor]] | + | *[[d3d.DrawText]] |
+ | *[[d3d.DrawRect]] | ||
+ | *[[d3d.SetColor]] | ||
[[Category:WD2 ScriptHook Lua]] | [[Category:WD2 ScriptHook Lua]] |
Revision as of 22:20, 2 August 2020
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