Jump to content

create buttons with dxDraw?


Recommended Posts

Posted

Just think about it...

A rectangle doesn't react to clicks obviously. So you have to check if that click happened on that reactangle.

If thats true, you can handle the click.

Posted (edited)

use

guiCreateLabel -- recognition function to the mouse 
dxDrawRectangle -- appearance  and design 
dxDrawText -- text the button  
  

for create buttons with dxDraw

Edited by Guest
Posted (edited)
use
guiCreateLabel 
dxDrawRetangle 
  

for create buttons with dxDraw

GUI is not DX guy ...

Edited by Guest
Posted

@Sr.Zika you put a label on top of the rectangle to the panel? That is not to create a panel in DX ... you just is giving a false appearance to the panel. Since the panel always work with functions in GUI :roll:

Posted

XeroxMTA: Use this code and edit it the way you want, don't know if it's without bugs because I haven't tested.

local dxButtons = {} 
local state = false 
  
addEventHandler( "onClientResourceStart", resourceRoot, 
    function() 
        dxButtons.acceptX, dxButtons.acceptY = 0, 0 -- dx-button pos 
        dxButtons.acceptW, dxButtons.acceptH = 0, 0 
        -- 
        dxButtons.cancelX, dxButtons.cancelY = 0, 0 
        dxButtons.cancelW, dxButtons.cancelH = 0, 0 
        addEventHandler("onClientClick", root, onClick) 
    end 
) 
  
addCommandHandler( "togglebuttons", 
    function() 
        _G[ (state and "add" or "remove").."EventHandler" ]( "onClientRender", root, drawDXButtons ) 
        showCursor( state ) 
        state = not state 
    end 
) 
  
function drawDXButtons() 
    dxDrawRectangle(dxButtons.acceptX, dxButtons.acceptY, dxButtons.acceptW, dxButtons.acceptH, tocolor(0, 0, 0, 190)) 
    dxDrawRectangle(dxButtons.cancelX, dxButtons.cancelY, dxButtons.cancelW, dxButtons.cancelH, tocolor(0, 0, 0, 190)) 
end 
  
addEvent( "onDXButtonClick" ) 
function onClick(button, state) 
    if (button == "left") and (state == "up") then 
        if isMouseWithinDxButton("accept") then 
            triggerEvent("onDXButtonClick", resourceRoot, "accept") 
        elseif isMouseWithinDxButton("cancel") then 
            triggerEvent("onDXButtonClick", resourceRoot, "cancel") 
        end 
    end 
end 
  
addEventHandler( "onDXButtonClick", root 
    function (buttonName) 
        if buttonName == "accept" then 
            -- 
        elseif buttonName == "cancel" then 
            -- 
        end 
    end 
) 
  
function isMouseWithinDxButton(dxButtonName) 
    if not dxButtonName then return false end 
    if (dxButtonName == "accept") then 
        return isMouseWithinRangeOf(dxButtons.acceptX, dxButtons.acceptW, dxButtons.acceptY, dxButtons.acceptH) 
    elseif (dxButtonName == "cancel") then 
        return isMouseWithinRangeOf(dxButtons.cancelX, dxButtons.cancelW, dxButtons.cancelY, dxButtons.cancelH) 
    end 
    return false 
end 
  
function isMouseWithinRangeOf(psx,pssx,psy,pssy) 
  if not isCursorShowing() then 
    return false 
  end 
  local cx,cy = getCursorPosition() 
  local screenX, screenY = guiGetScreenSize() 
  cx,cy = cx*screenX,cy*screenY 
  if cx >= psx and cx <= psx+pssx and cy >= psy and cy <= psy+pssy then 
    return true 
  end 
  return false 
end 
  

Posted

I have made this simple script...

Tell me if its ok please :D

addEventHandler("onClientRender", root, 
    function() 
        dxDrawText("ES", 500, 431, 583, 467, tocolor(255, 255, 255, 255), 1.50, "default", "center", "center", false, false, true, false, false) 
        dxDrawText("EN", 593, 431, 676, 467, tocolor(255, 255, 255, 255), 1.50, "default", "center", "center", false, false, true, false, false) 
    end 
) 
  
sx, sy = getCursorPosition() 
language = es  
addEventHandler("onClientClick", getRootElement(),  
function 
if sx == 500 and sy == 431 then  
language = es 
outputChatBox("El lenguaje del anuncio ahora es: ES (Español)", getRootElement(), 255, 255, 255, true) 
elseif sx == 593 and sy == 431 then 
language = en 
outputChatBox("The language of the announce is now: EN (English) ", getRootElement(), 255, 255, 255, true) 
        end 
    end 
end 

Posted
I have made this simple script...

Tell me if its ok please :D

addEventHandler("onClientRender", root, 
    function() 
        dxDrawText("ES", 500, 431, 583, 467, tocolor(255, 255, 255, 255), 1.50, "default", "center", "center", false, false, true, false, false) 
        dxDrawText("EN", 593, 431, 676, 467, tocolor(255, 255, 255, 255), 1.50, "default", "center", "center", false, false, true, false, false) 
    end 
) 
  
sx, sy = getCursorPosition() 
language = es  
addEventHandler("onClientClick", getRootElement(),  
function 
if sx == 500 and sy == 431 then  
language = es 
outputChatBox("El lenguaje del anuncio ahora es: ES (Español)", getRootElement(), 255, 255, 255, true) 
elseif sx == 593 and sy == 431 then 
language = en 
outputChatBox("The language of the announce is now: EN (English) ", getRootElement(), 255, 255, 255, true) 
        end 
    end 
end 

Maybe you should try to understand the basics first before trying something like this.

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