Jump to content

Problem with dx, mouse hover.


McDeKi

Recommended Posts

Hello!

I have problem with dx,

  
                        local x,y = guiGetScreenSize() 
function test() 
            local xMysz,yMysz,cos1,cos2,cos3 = getCursorPosition() 
            realneX,realneY = fullx*xMysz,fully*xMysz 
                        kameraHusta = dxDrawRectangle(x*0,y*0,x*1,y*0.20,tocolor(0,0,0,255)) 
                        if realneX > 0 and realneX < 0 + 1280 and realneY > 0 and realneY < 0 + 144 then 
                        outputChatBox("test") 
          end 
end 
addEventHandler("onClientRender",root,test) 
  

It works, but it doesn't suit all resolutions, I know why (if realneX > 0 and realneX < 0 + 1280 and realneY > 0 and realneY < 0 + 144 then) , but I don't know how can fix it.

Link to comment
  
local x,y = guiGetScreenSize() 
function test() 
            local xMysz,yMysz,cos1,cos2,cos3 = getCursorPosition() 
            realneX,realneY = fullx*xMysz,fully*xMysz 
                        kameraHusta = dxDrawRectangle(x*0,y*0,x*1,y*0.20,tocolor(0,0,0,255)) 
                        if realneX > 0 and realneX < 0 + x*1 and realneY > 0 and realneY < 0 + y*0.20 then 
                        outputChatBox("test") 
          end 
end 
addEventHandler("onClientRender",root,test) 

Pretty easy :P

Link to comment

Should be working, but it's untested.

local x,y = guiGetScreenSize() 
local topSize = 144 
  
function renderRectangle() 
  local range = isMouseWithinRangeOf(0,x,0,topSize) -- startX,sizeX,startY,sizeY 
  if range then -- if the mouse is in the area 
    dxDrawRectangle(0,0,x,topSize,tocolor(0,0,0,200)) -- 200 alpha if you hover it 
  else 
    dxDrawRectangle(0,0,x,topSize,tocolor(0,0,0,40)) -- 40 otherwise 
  end 
end 
addEventHandler("onClientRender",getRootElement(),renderRectangle) 
  
  
function isMouseWithinRangeOf(psx,pssx,psy,pssy) 
  if not isCursorShowing() then 
    return false 
  end 
  local cx,cy = getCursorPosition() 
  cx,cy = cx*x,cy*y 
  if cx >= psx and cx <= psx+pssx and cy >= psy and cy <= psy+pssy then 
    return true,cx,cy 
  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...