Jump to content

[HELP] Clicking on a dx Text


Recommended Posts

Posted

So I made this dx window and I've drawn an "X" to be used as a button to close the window.

function isCursorOverText(posX, posY, sizeX, sizeY) 
    if(isCursorShowing()) then 
        local cX, cY = getCursorPosition() 
        local screenWidth, screenHeight = guiGetScreenSize() 
        local cX, cY = (cX*screenWidth), (cY*screenHeight) 
        if(cX >= posX and cX <= posX+(sizeX - posX)) and (cY >= posY and cY <= posY+(sizeY - posY)) then 
            return true 
        else 
            return false 
        end 
    else 
        return false     
    end 
end    
  
function renderCmdsPanel() 
    dxDrawText("X", s[1]*1265/1920, s[2]*239/1080, s[1]*1318/1920, s[2]*260/1080, tocolor(255, 255, 255, 255), textFont, "bankgothic", "center", "center", false, false, false, false, false) 
end 
addEventHandler("onClientRender", getRootElement(), renderCmdsPanel) 
addEventHandler("onClientClick", getRootElement(), closeXButton) 
         
function closeXButton(button, state) 
    local xButton = isCursorOverText(s[1]*1265/1920, s[2]*239/1080, s[1]*1318/1920, s[2]*260/1080) 
    if (button == "left" and state == "down" and xButton) then 
        guiSetVisible(tabPanel, false) 
        showCursor (false) 
        guiSetInputEnabled(false) 
        tabPanel = nil 
        removeEventHandler("onClientRender", getRootElement(), renderCmdsPanel) 
        removeEventHandler("onClientClick", getRootElement(), closeXButton) 
    end 
end 

I've used the same method for for my other windows and it works, but here, it only works when I have gui editor active, as if the "onClientClick" event is triggered only when in guieditor...

Any ideas?

Thanks.

Posted

That was just the main things I have in the code, but it goes like this:

function closeXButton(button, state) 
    local xButton = isCursorOverText(s[1]*1265/1920, s[2]*239/1080, s[1]*1318/1920, s[2]*260/1080) 
    if (button == "left" and state == "down" and xButton) then 
        guiSetVisible(tabPanel, false) 
        showCursor (false) 
        guiSetInputEnabled(false) 
        tabPanel = nil 
        removeEventHandler("onClientRender", getRootElement(), renderCmdsPanel) 
        removeEventHandler("onClientClick", getRootElement(), closeXButton) 
    end 
end 
  
function commandsHelp() 
    local loggedIn = getElementData(sourcePlayer, "loggedin") 
    if (loggedIn == 1) then 
        guiSetInputEnabled(true) 
        addEventHandler("onClientRender", getRootElement(), renderCmdsPanel) 
        addEventHandler("onClientClick", getRootElement(), closeXButton)   
............. 

So I don't think that would be the problem.

Posted

[quote name=..:D&G:..]

local s = {guiGetScreenSize()} 
  
function renderCmdsPanel() 
    textFont2 = 1.30/1920*s[1] 
    textFont = 1.00/1920*s[1] 
    local r, g, b = exports.gui:getPlayerBaseColor(getLocalPlayer())  
    dxDrawText("X", s[1]*(1265 - 1)/1920, s[2]*(239 - 1)/1080, s[1]*(1318 - 1)/1920, s[2]*(260 - 1)/1080, tocolor(0, 0, 0, 255), textFont, "bankgothic", "center", "center", false, false, false, false, false) 
    dxDrawText("X", s[1]*(1265 + 1)/1920, s[2]*(239 - 1)/1080, s[1]*(1318 + 1)/1920, s[2]*(260 - 1)/1080, tocolor(0, 0, 0, 255), textFont, "bankgothic", "center", "center", false, false, false, false, false) 
    dxDrawText("X", s[1]*(1265 - 1)/1920, s[2]*(239 + 1)/1080, s[1]*(1318 - 1)/1920, s[2]*(260 + 1)/1080, tocolor(0, 0, 0, 255), textFont, "bankgothic", "center", "center", false, false, false, false, false) 
    dxDrawText("X", s[1]*(1265 + 1)/1920, s[2]*(239 + 1)/1080, s[1]*(1318 + 1)/1920, s[2]*(260 + 1)/1080, tocolor(0, 0, 0, 255), textFont, "bankgothic", "center", "center", false, false, false, false, false) 
    dxDrawText("X", s[1]*1265/1920, s[2]*239/1080, s[1]*1318/1920, s[2]*260/1080, tocolor(255, 255, 255, 255), textFont, "bankgothic", "center", "center", false, false, false, false, false) 
    dxDrawText("Welcome to the commands panel!", s[1]*574/1920, s[2]*271/1080, s[1]*1243/1920, s[2]*318/1080, tocolor(255, 255, 255, 255), textFont2, "default-bold", "center", "center", false, false, false, false, false) 
    dxDrawText("Commands Panel", s[1]*849/1920, s[2]*239/1080, s[1]*969/1920, s[2]*261/1080, tocolor(255, 255, 255, 255), textFont, "default-bold", "center", "center", false, false, false, false, false) 
    dxDrawText("© World Gaming", s[1]*497/1920, s[2]*239/1080, s[1]*665/1920, s[2]*261/1080, tocolor(255, 255, 255, 255), textFont, "default", "center", "center", false, false, false, false, false) 
end 
  
function closeXButton(button, state) 
    local xButton = isCursorOverText(s[1]*1265/1920, s[2]*239/1080, s[1]*1318/1920, s[2]*260/1080) 
    if (button == "left" and state == "down" and xButton) then 
        guiSetVisible(tabPanel, false) 
        showCursor (false) 
        guiSetInputEnabled(false) 
        tabPanel = nil 
        removeEventHandler("onClientRender", getRootElement(), renderCmdsPanel) 
        removeEventHandler("onClientClick", getRootElement(), closeXButton) 
    end 
end 
  
function commandsHelp() 
    local loggedIn = getElementData(sourcePlayer, "loggedin") 
    if (loggedIn == 1) then 
        guiSetInputEnabled(true) 
        addEventHandler("onClientRender", getRootElement(), renderCmdsPanel) 
        addEventHandler("onClientClick", getRootElement(), closeXButton)   
............. 

This IS the complete code. The bit with dots is just a gridlist ...

Posted
Apart from guiSetInputEnabled, did you use showCursor?

Lol, after I read your post, I noticed that I didn't use showCursor when opening the window, as I have an external script which shows the cursor when I press M, but after adding showCursor to the window, it works :D Thanks!

Posted

Also, showCursor is a resource based, if you use showCursor in another resource you have to hide it from the same resource else it won't be hidden.

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