Jump to content

[HELP]DxDrawRectangle button


TheSmart

Recommended Posts

Posted

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?

Posted
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 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted

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 

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

  • 2 weeks later...
Posted
  
  
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 
  

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

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...