PT-BR/SvgSetDocumentXML

From Multi Theft Auto: Wiki
Revision as of 03:36, 20 February 2022 by LODS (talk | contribs) (Created page with "__NOTOC__ {{BR/Funcao cliente}} {{Added feature/item|1.5.9|1.5.8|20979|Define o documento XML subjacente de um elemento SVG.}} ==Sintaxe== <syntaxhighlight lang="lua">bool svgSetDocumentXML ( svg svgElement, xmlnode xmlDocument [, function callback ( bool didLoad ) ] )</syntaxhighlight> ===Argumentos Necessários=== *'''svgElement:''' Um elemento svg que você deseja definir o documento XML. *'''xmlDocument:''' Um xmlnode contendo os dados para serem definidos...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Template:BR/Funcao cliente Define o documento XML subjacente de um elemento SVG.

Sintaxe

bool svgSetDocumentXML ( svg svgElement, xmlnode xmlDocument [, function callback ( bool didLoad ) ] )

Argumentos Necessários

  • svgElement: Um elemento svg que você deseja definir o documento XML.
  • xmlDocument: Um xmlnode contendo os dados para serem definidos no documento SVG.

Argumentos Opcionais

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.

  • callback: Uma função de callback chamada na criação do documento SVG e na criação da textura, útil para saber se o elemento SVG está carregado.

Retornos

  • Retornatrue se for bem sucedido, false caso dê errado.

Exemplo

Esse exemplo mostra como carregar um SVG por dados brutos (ou arquivo), manipulando um documento subjacente e desenhá-lo com dxDrawImage via onClientRender

IMPORTANTE: Dependendo da sua implementação, o uso de uma função de callback será necessário para garantir que a textura SVG e o documento XML estejam carregados.

-- Isso também pode ser um arquivo, com o diretório do arquivo fornecido no 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()
    -- Cria um círculo em SVG, usando os dados, usando os dados brutos XML acima.
    svg = svgCreate(500, 500, rawSvgData, function(didLoad)
        if (not didLoad) then -- Se o SVG falhou em carregar, essa função não continuará.
            return 
        end

        onSvgLoad(svg)
    end)
end
addEventHandler("onClientResourceStart", resourceRoot, init)


-- Implementando a função de callback para carregar o SVG, para manipular o documento XML subjacente.
function onSvgLoad(svg)
    -- Obter o documento XML do nosso SVG
    local svgXML = svgGetDocumentXML(svg)
    
    -- Adicionar um retangulo, posicionando no centro do documento
    local rect = xmlCreateChild(svgXML, "rect")
    xmlNodeSetAttribute(rect, "x", "25%")
    xmlNodeSetAttribute(rect, "y", "25%")
    xmlNodeSetAttribute(rect, "width", "50%")
    xmlNodeSetAttribute(rect, "height", "50%")
    xmlNodeSetAttribute(rect, "fill", "#00749b")
    
    -- Aplicar o XML para o SVG, e começar a desenhar usando a função de callback
    return svgSetDocumentXML(svg, svgXML, function()
        addEventHandler("onClientRender", root, render)
    end)
end

function render()
    local width, height = svgGetSize(svg)
    dxDrawImage(0, 0, width, height, svg, 0, 0, 0, tocolor(255, 255, 255), false)
end

Requisitos

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" />

Veja também