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...")
 
(Added example)
Line 21: Line 21:


==Example==  
==Example==  
An example
<syntaxhighlight lang="lua">
-- Display a gui label
local myLabel = guiCreateLabel( 100, 300, 400, 50, "GUI label", false )


<syntaxhighlight lang="lua"> needs doing</syntaxhighlight>
-- Display text using dxDrawText
addEventHandler( "onClientRender", root,
    function()
        dxDrawText( "dxDrawText", 100, 350, 300, 350, tocolor(255,255,0), 1, myFont )
    end
)
 
-- Use 'toggle' command to switch custom font on and off
addCommandHandler( "toggle",
    function()
        if not myFont then
            myFont = createFont( "segoeui.ttf", 20 )  -- Create custom font
            guiSetFont( myLabel, myFont )            -- Apply to a gui label
        else       
            destroyElement( myFont )                  -- Destroy custom font
            myFont = nil
        end
    end
)
</syntaxhighlight>


==See Also==
==See Also==

Revision as of 09:56, 7 June 2011

Only available in 1.1 This function creates a font element that can be used in functions such as dxDrawText and guiSetFont

Syntax

element createFont ( string filepath[, int size=9, bool bold=false ] )

Required Arguments

  • filepath: the GUI element whose visibility is to be changed

Optional Arguments

  • size: size of the font
  • bold: flag to indicate if the font should be bold when drawn with dxDrawText

Returns

Returns a font element if successful, false if invalid arguments were passed to the function.

Example

-- Display a gui label
local myLabel = guiCreateLabel( 100, 300, 400, 50, "GUI label", false )

-- Display text using dxDrawText
addEventHandler( "onClientRender", root,
    function()
        dxDrawText( "dxDrawText", 100, 350, 300, 350, tocolor(255,255,0), 1, myFont )
    end
)

-- Use 'toggle' command to switch custom font on and off
addCommandHandler( "toggle",
    function()
        if not myFont then
            myFont = createFont( "segoeui.ttf", 20 )  -- Create custom font
            guiSetFont( myLabel, myFont )             -- Apply to a gui label
        else        
            destroyElement( myFont )                  -- Destroy custom font
            myFont = nil
        end
    end
)

See Also