Jump to content

onClientMouseEnter


John Smith

Recommended Posts

hi im having this code(its not full code but i'm posting everything regarding this button)

  
menuButton = guiCreateButton( 873, 720, 150, 40, "Exit to Menu", false ) 
  
function drawRooms() 
guiSetAlpha(menuButton,0) 
end 
  
addEventHandler( "onClientMouseEnter", getRootElement(), 
    function () 
      if source == menuButton then -- also tried replacing this with 'guielement' 
         dxDrawImage(screenWidth/2.20,screenHeight/1.50, 150,40,'images/exitmenu_hover.png') 
       end 
    end 
) 
  
addEventHandler( "onClientMouseLeave", getRootElement(), 
    function () 
      if source == menuButton then 
         dxDrawImage(screenWidth/2.20,screenHeight/1.50, 150,40,'images/exitmenu.png') 
       end 
    end 
) 
  

no debug errors

Link to comment

umm maybe im doing it wrong but it doesnt work

function buttonEnter () 
      if source == menuButton then 
         dxDrawImage(screenWidth/2.20,screenHeight/1.50, 150,40,'images/exitmenu_hover.png') 
         addEventHandler("onClientRender",root,buttonEnter) 
       end 
    end 
addEventHandler( "onClientMouseEnter", getRootElement(),buttonEnter) 
  
function buttonExit () 
      if source == menuButton then 
         removeEventHandler("onClientRender",root,buttonEnter) 
end 
end 
addEventHandler( "onClientMouseLeave", getRootElement(),buttonExit) 

Link to comment

If you wanna make dxButtons I suggest you to get the cursor position and check if its over one button.

Using gui buttons to fake that is a kinda dirty solution, at least in my opinion.

Anyway, if you wanna stick to this, I would do something like this:

- a function that sets some variable whether cursor is on button or not onClientMouseEnter/onClientMouseLeave

- a function that handles the drawing depending on that variable

Link to comment

i have made outputChatBox debugs and events work fine for exactly my button, but the problem is in setting the new image

i am trying to overlap current image because if i remove event handler of original image, everything will be fucked up due to my low scripting skills and not knowing how to avoid onclientrender is already handled error

Link to comment
function renderHandler() 
    dxDrawImage(screenWidth/2.20,screenHeight/1.50, 150,40,'images/exitmenu_hover.png') 
end 
  
function buttonEnter () 
      if source == menuButton then 
         addEventHandler("onClientRender",root,renderHandler) 
       end 
    end 
addEventHandler( "onClientMouseEnter", getRootElement(),buttonEnter) 
  
function buttonExit () 
      if source == menuButton then 
         removeEventHandler("onClientRender",root,renderHandler) 
end 
end 
addEventHandler( "onClientMouseLeave", getRootElement(),buttonExit) 

Link to comment
onClientMouseEnter: This event is fired when the user moves the mouse over a GUI element.

onClientMouseLeave: This event is fired when the user moves the mouse away from a GUI element.

https://wiki.multitheftauto.com/wiki/Element_tree

You could also make it even faster by only ataching the event to the menuButton instead of guiRoot.

  
local RenderHandler = function() 
    dxDrawImage(screenWidth/2.20,screenHeight/1.50,150,40,'images/exitmenu_hover.png'); 
end; 
  
local ButtonEnter = function() 
    addEventHandler("onClientRender",root,RenderHandler); 
end; 
addEventHandler("onClientMouseEnter",menuButton,ButtonEnter,false); 
local ButtonExit = function() 
    removeEventHandler("onClientRender",root,RenderHandler); 
end; 
addEventHandler("onClientMouseLeave",menuButton,ButtonExit,false) 
  

That 4th false in the addEventHandler will make sure the event will not propagate trough the parent and the children of the button.

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