DxCreateFont: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "{{Client function}} __NOTOC__ {{New feature|3.0110|1.1| Only available in 1.1 }} This function creates a font element that can be used in functions such as dxDrawText and [[g...")
 
m (update example)
(24 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{Client function}}
{{Client function}}
__NOTOC__
__NOTOC__
{{New feature|3.0110|1.1|
{{Note|The size can't be less than 5 or more than 150}}
Only available in 1.1
<br/>
}}
This function creates a [[DX font]] element that can be used in [[dxDrawText]]. Successful font creation is not guaranteed, and may fail due to hardware or memory limitations.
This function creates a font element that can be used in functions such as [[dxDrawText]] and [[guiSetFont]]
 
To see if creation is likely to fail, use [[dxGetStatus]]. (When '''VideoMemoryFreeForMTA''' is zero, failure ''is'' guaranteed.)
=====It is highly recommended that [[dxSetTestMode]] is used when writing and testing scripts using dxCreateFont.=====
 
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
element createFont ( string filepath[, int size=9, bool bold=false ] )
element dxCreateFont ( string filepath[, int size=9, bool bold=false, string quality="proof" ] )
</syntaxhighlight>  
</syntaxhighlight>  
 
{{OOP||[[DX_font|DxFont]]}}
===Required Arguments===  
===Required Arguments===  
*'''filepath:''' the GUI element whose visibility is to be changed
*'''filepath:''' the name of the file containing the font


===Optional Arguments===
===Optional Arguments===
*'''size:''' size of the font
*'''size:''' size of the font
*'''bold:''' flag to indicate if the font should be bold when drawn with [[dxDrawText]]
*'''bold:''' flag to indicate if the font should be bold
*'''quality:''' the font quality
** "default": not the actual default
** "draft"
** "proof": the default
** "nonantialiased"
** "antialiased"
** "cleartype"
** "cleartype_natural"


===Returns===
===Returns===
Returns a [[font]] [[element]] if successful, ''false'' if invalid arguments were passed to the function.
Returns a [[DX font]] element if successful, ''false'' if invalid arguments were passed to the function, or there is insufficient resources available.
 
'''You should always check to see if this function has returned false.'''


==Example==  
==Example==  
An example
<syntaxhighlight lang="lua">
local font = dxCreateFont('myfont.ttf', 20, false, 'proof') or 'default' -- fallback to default


<syntaxhighlight lang="lua"> needs doing</syntaxhighlight>
addEventHandler('onClientRender', root, function()
    dxDrawText('Example Text', 100, 350, 300, 350, tocolor(255, 255, 0), 1, font)
end)
</syntaxhighlight>


==See Also==
==See Also==
{{Drawing_functions}}
[[hu:dxCreateFont]]

Revision as of 23:45, 28 January 2020


[[{{{image}}}|link=|]] Note: The size can't be less than 5 or more than 150


This function creates a DX font element that can be used in dxDrawText. Successful font creation is not guaranteed, and may fail due to hardware or memory limitations.

To see if creation is likely to fail, use dxGetStatus. (When VideoMemoryFreeForMTA is zero, failure is guaranteed.)

It is highly recommended that dxSetTestMode is used when writing and testing scripts using dxCreateFont.

Syntax

element dxCreateFont ( string filepath[, int size=9, bool bold=false, string quality="proof" ] )

OOP Syntax Help! I don't understand this!

Method: DxFont(...)


Required Arguments

  • filepath: the name of the file containing the font

Optional Arguments

  • size: size of the font
  • bold: flag to indicate if the font should be bold
  • quality: the font quality
    • "default": not the actual default
    • "draft"
    • "proof": the default
    • "nonantialiased"
    • "antialiased"
    • "cleartype"
    • "cleartype_natural"

Returns

Returns a DX font element if successful, false if invalid arguments were passed to the function, or there is insufficient resources available.

You should always check to see if this function has returned false.

Example

local font = dxCreateFont('myfont.ttf', 20, false, 'proof') or 'default' -- fallback to default

addEventHandler('onClientRender', root, function()
    dxDrawText('Example Text', 100, 350, 300, 350, tocolor(255, 255, 0), 1, font)
end)

See Also