• Gmod Derma: make a function execute whenever the mouse is over an DImageButton
    4 replies, posted
So what i basically want is when your mouse hits the Image button it would execute a function like highlighting it or making a sound thanks for anyone that can help function FMenu() ------- local function inQuad( fraction, beginning, change ) return change * ( fraction ^ 2 ) + beginning end local Frame = vgui.Create( "DFrame" ) Frame:SetTitle( "SELECT YOUR MODE" ) Frame:SetSize( 536, 269 ) Frame:SetDraggable( false ) Frame:Center() Frame:MakePopup() Frame:ShowCloseButton( false ) Frame.Paint = function( self, w, h ) Derma_DrawBackgroundBlur( self, self.startTime ) draw.RoundedBox( 0, 0, 0, w, h, Color( 0, 7, 10, 230 ) ) end local build_img = vgui.Create( "DImageButton", Frame ) -- Build button build_img:SetPos( 10, 27 ) build_img:SetSize( 514, 115 ) build_img:SetImage( "materials/ui/bm.png") print(input.GetCursorPos() ) local pvp_img = vgui.Create( "DImageButton", Frame ) -- PVP button pvp_img:SetPos( 10, 146 ) pvp_img:SetSize( 514, 115 ) pvp_img:SetImage( "materials/ui/pm.png") surface.PlaySound( "buttons/button18.wav" ) build_img.DoClick = function() net.Start("InitBuild") net.WriteEntity(LocalPlayer()) net.SendToServer() surface.PlaySound( "buttons/button18.wav" ) Frame:Close() end pvp_img.DoClick = function() net.Start("InitPVP") net.WriteEntity(LocalPlayer()) net.SendToServer() surface.PlaySound( "buttons/button18.wav" ) Frame:Close() end ------ end hook.Add("InitPostEntity", "PlayerLoads",FMenu) concommand.Add("fmenu",FMenu)
Use Panel/IsHovered inside a Paint function, atleast that's how i do it.
Highlight     build_img.Paint = function(this, w, h)         if build_img:IsHovered() then             surface.SetDrawColor(Color(255,255,255,255))             surface.DrawRect( 0, 0, w, h )         else             surface.SetDrawColor(Color(0,0,0,255))             surface.DrawRect( 0, 0, w, h )         end     end
Thank you for your quick reply, appriciate it my man
PANEL/OnCursorEntered
Sorry, you need to Log In to post a reply to this thread.