Jump to content

Direct X Rectangle problem


Hero192

Recommended Posts

Hello guys,

i want to let the rectangle and Text color be changed after you the Cursor(Mouse) hit it and when it leave the color back like the first time.

NOTE: If this way works for both of them TEXT & Rectangle its okay please give me just one example and i'll understand

dxDrawText("BUY",538.0,380.0,611.0,398.0,tocolor(255,255,255,255),1.0,"arial","left","top",false,false,true) 

dxDrawRectangle(661.0,296.0,19.0,16.0,tocolor(0,0,0,200),false) 

Link to comment
function isMouseInPosition(a, b, c, d) 
    if not isCursorShowing() then return end 
    local x, y = getCursorPosition() 
    x, y = x*sx, y*sy 
    if x >= a and y >= b and x <= a+c and y <= b+d then 
        return true 
    end 
    return false 
end 

if isMouseInPosition(661, 296, 19, 16) then 
    -- Do your thing 
end 

Link to comment

I tried that but it gives me an Error (IT was giving the error before i add anything on it)

ERROR: attempt to perform arithmetic on global 'sx' (a nil value)

function isMouseInPosition(a, b, c, d) 
    if not isCursorShowing() then return end 
    local x, y = getCursorPosition() 
    x, y = x*sx, y*sy 
    if x >= a and y >= b and x <= a+c and y <= b+d then 
        return true 
    end 
    return false 
end 
  
if isMouseInPosition(661, 296, 19, 16) then 
tocolor(150, 0, 0, 200) 
else 
tocolor(0, 0, 0, 200) 
end 

Link to comment

Didn't know that function was on wiki, lol. I copied it from another topic, where I helped someone and yeah, I forgot to add that. Anyways;

if isMouseInPosition(661, 296, 19, 16) then 
    dxDrawRectangle(661.0,296.0,19.0,16.0,tocolor(150,0,0,200),false) 
else 
    dxDrawRectangle(661.0,296.0,19.0,16.0,tocolor(0,0,0,200),false) 
end 
  
function isMouseInPosition ( 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 ) 
    if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then 
        return true 
    else 
        return false 
    end 
end 

Link to comment
function renderUI() 
    dxDrawText("BUY",538.0,380.0,611.0,398.0,tocolor(255,255,255,255),1.0,"arial","left","top",false,false,true) 
    if isMouseInPosition(661, 296, 19, 16) then 
        dxDrawRectangle(661.0,296.0,19.0,16.0,tocolor(150,0,0,200),false) 
    else 
        dxDrawRectangle(661.0,296.0,19.0,16.0,tocolor(0,0,0,200),false) 
    end 
end 
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        addEventHandler("onClientRender", root, renderUI) 
    end 
) 
  
function isMouseInPosition ( 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 ) 
    if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then 
        return true 
    else 
        return false 
    end 
end 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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