Jump to content

[HELP]DxDrawRectangle button


TheSmart

Recommended Posts

Hello guys!

today i need little help im making dx help panel but i don't know how to make dxDrawRectangle button can anybody can tell me how i can do it?

All what you need is

-- Functions 
dxDrawRectangle() 
  
-- Events 
onClientClick 
onClientRender 

Link to comment

It's rather simple, you check if the cursor's position is within the rectangle.

You take the starting X position of the rectangle and add the width of the rectangle to that. Repeat the process with the starting Y position, and then add the height of the rectangle.

This way, you'll check if the cursor is within the rectangle, then you can use onClientClick to detect if the left-mouse button was clicked while inside the rectangle.

Or you can use a utility function such as this one;

function isCursorWithin(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
  • 2 weeks later...
  
  
function onClick(x, y, absX, absY) 
         if isCursorWithin(absX, absY, width, height) then -- width , height are width height of dx draw (text / rectangle) 
        -- do some codde 
 end 
end 
addEventHandler("onClientClick", root, onClick) 
  
function isCursorWithin(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...