Jump to content

Mudar a cor do DX quando o mouse estiver em cima


Recommended Posts

21 hours ago, SciptNovato said:

eu quero que quando o cursor estiver em cima do retangulo ele mude de cor, como faço isso?

function isCursorInPosition ( x, y, width, height )
	if ( not isCursorShowing( ) ) then
		return false
	end
	local sx, sy = guiGetScreenSize ( )
	local cx, cy = getCursorPosition ( )
	local cx, cy = ( cx * sx ), ( cy * sy )
	
	return ( ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) )
end

--[[EXEMPLO]]--

if isCursorInPosition(x, y, w, h) then -- Se o cursor estiver na posição tal, então:

else -- ou se o cursor não estiver na posição, então:
  
end

 

Link to comment
  • Other Languages Moderators

Basicamente você cria uma condição com isCursorInPosition da mesma forma que você fez na condição de clicar no botão. Porém dessa vez você coloca diretamente na função onde está os dxDraw do painel.

function render_DX() -- Função que é chamada por um onClientRender.
    -- Aqui em cima ficam os dxDrawRectangle da janela do painel.
    if isCursorInPosition(x, y, w, h) then -- Condição igual ao do clique do botão, com os mesmos parâmetros.
        dxDrawRectangle() -- botão com a cor do mouse em cima.
    else
        dxDrawRectangle() -- botão normal.
    end
    -- Faz o mesmo com os outros botões, com os parâmetros deles.
    -- Aqui ficam os dxDrawText que ficam em cima dos botões.
end

 

Link to comment
function render_DX()
    if isCursorOnElement(screenW * 0.7331, screenH * 0.4433, screenW * 0.2081, screenH * 0.0267) then
        dxDrawRectangle(screenW * 0.7331, screenH * 0.4433, screenW * 0.2081, screenH * 0.0267, tocolor(143, 9, 237, 255), false) -- Dinheiro
    else
        dxDrawRectangle(screenW * 0.7331, screenH * 0.4433, screenW * 0.2081, screenH * 0.0267, tocolor(21, 21, 21, 255), false) -- Dinheiro
    end
end

function isCursorOnElement( posX, posY, width, height )
    if isCursorShowing( ) then
        local mouseX, mouseY = getCursorPosition( )
        local clientW, clientH = guiGetScreenSize( )
        local mouseX, mouseY = mouseX * clientW, mouseY * clientH
        if ( mouseX > posX and mouseX < ( posX + width ) and mouseY > posY and mouseY < ( posY + height ) ) then
            return true
        end
    end
    return false
end

porque não ta funcionando?

Edited by SciptNovato
Link to comment
7 hours ago, SciptNovato said:

bem, quando eu passo o mouse por cima nao acontece nada, nem da erros...

Tenta usar o exemplo que mandei em cima, utilizo em todos os meus projetos, também acredito que usar x * posição seria melhor para adpatar a resolução maiores e menores, Antigamente já tinha tentado usar o isCursorOnElement mas não deu por alguma razão, por isso enviei este.

local screen = { guiGetScreenSize() }
local x, y = (screen[1]/1336), (screen[2]/768) 

addEventHandler("onClientRender", root, function()
    if isCursorInPosition(x * 500, y * 500, x * 500, y * 500) then
        dxDrawRectangle(x * 500, y * 500, x * 500, y * 500, tocolor(143, 9, 237, 255), false)
    else
        dxDrawRectangle(x * 500, y * 500, x * 500, y * 500, tocolor(21, 21, 21, 255), false)
    end
end)

function isCursorInPosition ( x, y, width, height )
	if ( not isCursorShowing( ) ) then
		return false
	end
	local sx, sy = guiGetScreenSize ( )
	local cx, cy = getCursorPosition ( )
	local cx, cy = ( cx * sx ), ( cy * sy )
	
	return ( ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) )
end
Link to comment
  • Other Languages Moderators
On 07/03/2023 at 00:15, SciptNovato said:

porque não ta funcionando?

Testei seu script e funcionou aqui.

Porém precisa usar showCursor(true) para mostrar o cursor.
Não funciona se o cursor estiver visível por abrir o chatBox ou o Client Console (F8). Ele não considera o cursor visível ao apertar T ou F8.

Você também pode testar abrindo o painel admin, já que ele tem um showCursor(true) ao abrir.

Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...