PT-BR/svgSetSize

From Multi Theft Auto: Wiki
Revision as of 03:51, 20 February 2022 by LODS (talk | contribs) (Created page with "{{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 svgSetSize( svg svgElement, int width, int height [, function callback ( bool didLoad ) ] )</syntaxhighlight> ===Argumentos Necessários=== *'''svgElement:''' O elemento svg que você deseja definir o tamanho. *'''width:''' Largura, de preferência em potência de dois (16, 32, 64 etc.), o máximo é 4096...")
(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 svgSetSize( svg svgElement, int width, int height [, function callback ( bool didLoad ) ] )

Argumentos Necessários

  • svgElement: O elemento svg que você deseja definir o tamanho.
  • width: Largura, de preferência em potência de dois (16, 32, 64 etc.), o máximo é 4096
  • height : Altura, de preferência em potência de dois (16, 32, 64 etc.), o máximo é 4096

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 que será chamada na criação do documento XML e na criação de textura (depois de redimensionar), útil para saber se o elemento SVG está carregado.

Retornos

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

Exemplo

Esse exmplo cria um elemento svg (usando função de callback para iniciar o desenho) incluindo um keybind para redimensionar o svg aleatoriamente (consulte bindKey).

IMPORTANTE: Dependendo da sua implementação, 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
function onSvgLoad(svg)
    addEventHandler("onClientRender", root, render)
end

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

-- Adicionando um keybind para definir um tamanho aleatorio para o SVG
bindKey("r", "down", function()
    if (not isElement(svg)) or (getElementType(svg) ~= "svg") then
        return false
    end

    local size = math.random(100, 500)
    svgSetSize(svg, size, size)
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