SvgCreate: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Typography)
mNo edit summary
Line 1: Line 1:
{{Client function}}
{{Client function}}
__NOTOC__
__NOTOC__
{{Added feature/item|1.5.9|1.5.8|20979|Creates an [[svg]] from size (blank document), filepath or raw data.}}
{{Added feature/item|1.5.9|1.5.8|20979|}}
Creates an [[svg]] from size (blank document), filepath or raw data.
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">svg svgCreate ( int width, int height [, string pathOrRawData, function callback ( bool didLoad ) ] )</syntaxhighlight>
<syntaxhighlight lang="lua">svg svgCreate ( int width, int height [, string pathOrRawData, function callback ( bool didLoad ) ] )</syntaxhighlight>

Revision as of 00:10, 15 February 2022


Creates an svg from size (blank document), filepath or raw data.

Syntax

svg svgCreate ( int width, int height [, string pathOrRawData, function callback ( bool didLoad ) ] )

Required Arguments

  • width: Desired width, preferably power of two (16, 32, 64 etc.), maximum is 4096
  • height : Desired height, preferably power of two (16, 32, 64 etc.), maximum is 4096

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.

  • pathOrRawData: A string representing the path to your SVG file, or the raw SVG data
  • callback: A callback function which is invoked upon SVG document and texture creation, useful for knowing when the svg is ready

Returns

  • Returns an svg if created successfully, false otherwise.

Example

The example below shows how you can load an SVG from raw data (or path) and draw it with dxDrawImage via onClientRender.

IMPORTANT: Depending on your implementation, callback usage may be necessary to ensure the SVG texture and XML document are ready.

-- This could also be a file, with the path provided to svgCreate
local rawSvgData = [[
    <svg viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg">
        <circle cx="250" cy="250" r="250" fill="#0fc0fc" />
    </svg>
]]

local svg

function init()
    -- Create an SVG containing a circle, using the raw XML data above
    svg = svgCreate(500, 500, rawSvgData, function(didLoad)
        if (not didLoad) then -- SVG failed to load, so don't continue
            return 
        end

        addEventHandler("onClientRender", root, render)
    end)
end
addEventHandler("onClientResourceStart", resourceRoot, init)

function render()
    dxDrawImage(0, 0, 500, 500, svg, 0, 0, 0, tocolor(255, 255, 255), false)
end

Requirements

Minimum server version n/a
Minimum client version 1.5.8-9.20979

Note: Using this feature requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version client="1.5.8-9.20979" />

See Also