DxGetFontHeight: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Removing all content from page)
No edit summary
 
(16 intermediate revisions by 9 users not shown)
Line 1: Line 1:
__NOTOC__
{{Client function}}
This function retrieves the theoretical height of a certain piece of text, if it were to be drawn using [[dxDrawText]].
{{Note|The returned height will be in logical units which are 1.75 times the actual pixel height.}}


==Syntax==
<syntaxhighlight lang="lua">
int dxGetFontHeight ( [float scale=1, mixed font="default"] )
</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]]:getHeight}}}}
===Required Arguments===
''None''
===Optional Arguments===
{{OptionalArg}}
* '''scale:''' The size of the text.
* '''font:''' Either a custom [[DX font]] element or the name of a built-in dx font:
{{DxFonts}}
===Returns===
Returns an integer of the height of the text.
==Example==
The following example will draw two lines of text one above the other.
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
screenWidth, screenHeight = guiGetScreenSize() -- Get the screen resolution
scale = 2  -- The scale of both texts
-- We add an event handler to keep drawing the text
addEventHandler("onClientRender",root,function()
  -- Draw the first text 400 pixels from the top and left of the screen
  dxDrawText("Hello!", 400, 400, screenWidth,screenHeight,tocolor(255,255,255,255),scale,"pricedown")
  -- Draw the second text above the first one.
  -- The variable "offset" will return the height of the first text, so we can position the second text above the first one.
  -- If we changed the scale, the second text would still be above the first one, since we calculated the height of the font.
  offset = dxGetFontHeight(scale,"pricedown")
  dxDrawText("Hello!", 400, 400 - offset, screenWidth, screenHeight,tocolor(255,255,255,255),scale,"pricedown")
end)
</syntaxhighlight>
</section>
==See Also==
{{Drawing_functions}}
[[hu:dxGetFontHeight]]

Latest revision as of 11:34, 27 November 2018

This function retrieves the theoretical height of a certain piece of text, if it were to be drawn using dxDrawText.

[[{{{image}}}|link=|]] Note: The returned height will be in logical units which are 1.75 times the actual pixel height.

Syntax

int dxGetFontHeight ( [float scale=1, mixed font="default"] )

OOP Syntax Help! I don't understand this!

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

Required Arguments

None

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

Returns

Returns an integer of the height of the text.

Example

The following example will draw two lines of text one above the other.

Click to collapse [-]
Client
screenWidth, screenHeight = guiGetScreenSize() -- Get the screen resolution
scale = 2  -- The scale of both texts

-- We add an event handler to keep drawing the text 
addEventHandler("onClientRender",root,function()

   -- Draw the first text 400 pixels from the top and left of the screen
   dxDrawText("Hello!", 400, 400, screenWidth,screenHeight,tocolor(255,255,255,255),scale,"pricedown")

   -- Draw the second text above the first one.
   -- The variable "offset" will return the height of the first text, so we can position the second text above the first one. 
   -- If we changed the scale, the second text would still be above the first one, since we calculated the height of the font. 
   offset = dxGetFontHeight(scale,"pricedown")
   dxDrawText("Hello!", 400, 400 - offset, screenWidth, screenHeight,tocolor(255,255,255,255),scale,"pricedown")
end)

See Also