PT-BR/SvgSetDocumentXML: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 51: | Line 51: | ||
-- Adicionar um retangulo, posicionando no centro do documento | -- Adicionar um retangulo, posicionando no centro do documento | ||
local rect = xmlCreateChild(svgXML, "rect") | local rect = xmlCreateChild(svgXML, "rect") | ||
xmlNodeSetAttribute(rect, " | xmlNodeSetAttribute(rect, "cx", "25%") | ||
xmlNodeSetAttribute(rect, " | xmlNodeSetAttribute(rect, "cy", "25%") | ||
xmlNodeSetAttribute(rect, "width", "50%") | xmlNodeSetAttribute(rect, "width", "50%") | ||
xmlNodeSetAttribute(rect, "height", "50%") | xmlNodeSetAttribute(rect, "height", "50%") | ||
Revision as of 02:08, 30 March 2022
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, em seguida 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, "cx", "25%")
xmlNodeSetAttribute(rect, "cy", "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
This template will be deleted.
Veja também