Weird Derma Mouse-to-Desync Issue

Hey everyone,

I’ve scripted some fairly complex stuff in GMOD, mostly without the use fo Derma or any GUI elements, however I started a few hours ago learning how for a upcoming super addon I’m working on and at some point my collisions for my buttons became totally desync’d with the actual graphics. You can’t see the mouse, however that tooltip box appears when hovering over the buttons, however you can see that in the first image, my mouse (which is invisible) is about 40 pixels below the button and its being highlighted as if its being moused over.

The intensity of the desync gets worse the farther from 0,0 it gets, heres an image and code. I’m trying to read through the documentation for any floating little functions which can solve the issue but I really don’t want to go nuts trying to figure it out by reverse engineering other HUDs. I’m sure I’m missing something here or one of the quick fixes for making a minimal hud using Derma.


local function EOTI_CreateFont(size)
	surface.CreateFont( "EOTI_HUD_"..size, {
	font = "Trebuchet MS",
	size = size,
	weight = 400,
	blursize = 0,
	scanlines = 0,
	antialias = true,
	underline = false,
	italic = false,
	strikeout = false,
	symbol = false,
	rotary = false,
	shadow = false,
	additive = false,
	outline = false,
	} )
end

EOTI_CreateFont(36)

--------------------------------------------------------------------------------------------------------

EOTI = {}
EOTI.Config = {}
EOTI.Menu = {}
EOTI.Title = {}
EOTI.Stats = {}
EOTI.Close = {}
EOTI.StatBox = {}
EOTI.Tooltip = {}

--------------------------------------------------------------------------------------------------------

EOTI.Config.Labels = { "Health", "Movement", "Jump", "Armor", "Evasion", "Reflect", "Salary", "Merchant", "Prison", "Damage", "Resists", "Critical", "Firerate", "Magazine", "Ammo" }

--------------------------------------------------------------------------------------------------------

EOTI.Menu = vgui.Create( "DFrame" )
EOTI.Menu.width = 320
EOTI.Menu.height = 448
EOTI.Menu.color = Color( 34, 37, 42 )
EOTI.Menu.corner = 8

EOTI.Menu:SetSize( EOTI.Menu.width, EOTI.Menu.height )
EOTI.Menu:SetTitle( "" )
EOTI.Menu:SetVisible( true )
EOTI.Menu:SetDraggable( true )
EOTI.Menu:SetScreenLock( true )
EOTI.Menu:ShowCloseButton( false )
EOTI.Menu:SetPaintShadow( false )
EOTI.Menu:MakePopup()
EOTI.Menu:Center()

function EOTI.Menu:Paint( w, h )
	//draw.RoundedBox( EOTI.Menu.corner, 0, 0, w, h, EOTI.Menu.color )
	// kept for debugging purposes
end
--------------------------------------------------------------------------------------------------------
EOTI.Title = vgui.Create( "DPanel", EOTI.Menu )
EOTI.Title.height = 38
EOTI.Title.color = Color( 236, 114, 71 )

EOTI.Title:SetPos( 0, 0 )
EOTI.Title:SetSize( EOTI.Menu.width, EOTI.Menu.height)

function EOTI.Title:Paint( w, h )
	draw.RoundedBoxEx( EOTI.Menu.corner, 0, 0, EOTI.Menu.width, EOTI.Title.height, EOTI.Title.color, true, true, false, false )
end
--------------------------------------------------------------------------------------------------------
EOTI.Stats = vgui.Create( "DIconLayout", EOTI.Menu )
EOTI.Stats.height = EOTI.Menu.height-EOTI.Title.height

EOTI.Stats:SetPos( 0, EOTI.Title.height )
EOTI.Stats:SetSize( EOTI.Menu.width, EOTI.Stats.height)
EOTI.Stats:SetSpaceX( 1 )
EOTI.Stats:SetSpaceY( 1 )

function EOTI.Stats:Paint( w, h )
	draw.RoundedBoxEx( EOTI.Menu.corner, 0, 0, w, h, EOTI.Menu.color, false, false, true, true )
end
--------------------------------------------------------------------------------------------------------
EOTI.StatBox.width  = (EOTI.Menu.width - 2) / 3
EOTI.StatBox.height = (EOTI.Stats.height - 2) / 5
EOTI.StatBox.color = Color( 43, 49, 54 )
EOTI.StatBox.hover = Color( 53, 59, 64 )

for i = 1, 15 do 
	EOTI.StatBox* = EOTI.Stats:Add( "DPanel" )
	EOTI.StatBox*:SetSize(EOTI.StatBox.width, EOTI.StatBox.height)

	local a = EOTI.StatBox*
	function a:Paint( w, h )
		if !EOTI.StatBox*:IsHovered() then
			draw.RoundedBox( EOTI.Menu.corner, 0, 0, w, h, EOTI.StatBox.color )
		else
			draw.RoundedBox( EOTI.Menu.corner, 0, 0, w, h, EOTI.StatBox.hover )
		end
	end

	local lbl = EOTI.Config.Labels*
	EOTI.StatBox[lbl] = vgui.Create( "DLabel", EOTI.StatBox* )
	EOTI.StatBox[lbl]:SetFont( "EOTI_HUD_36" )
	EOTI.StatBox[lbl]:SetText( math.random(1,200) )
	EOTI.StatBox[lbl]:SizeToContents()
	EOTI.StatBox[lbl]:Center()
	EOTI.StatBox[lbl]:SetPos(EOTI.StatBox[lbl].x, EOTI.StatBox[lbl].y - 8)

	local labels = vgui.Create( "DLabel", EOTI.StatBox* )
	labels:SetFont( "Trebuchet18" )
	labels:SetText( EOTI.Config.Labels* )
	labels:SetTextColor( Color(114,114,114) )
	labels:SizeToContents()
	labels:Center()
	labels:SetPos(labels.x, labels.y + 16)
end
--------------------------------------------------------------------------------------------------------
EOTI.Close = vgui.Create( "DButton", EOTI.Title )
EOTI.Close:SetPos( 280, 10 )
EOTI.Close:SetText( "" )
EOTI.Close:SetSize( 20, 10 )
EOTI.Close.DoClick = function()
	EOTI.Menu:Close()
	EOTI.Tooltip:Close()
end
function EOTI.Close:Paint( w, h )
	draw.RoundedBox( 0, 0, 0, w, h, EOTI.Menu.color )
end
--------------------------------------------------------------------------------------------------------
EOTI.Tooltip = vgui.Create( "DFrame" )
EOTI.Tooltip:SetSize( 250, 150 )
EOTI.Tooltip:SetTitle( "" )
EOTI.Tooltip:SetVisible( true )
EOTI.Tooltip:ShowCloseButton( false )
EOTI.Tooltip:SetPaintShadow( true )
EOTI.Tooltip:MakePopup()

function EOTI.Tooltip:Paint( w, h )
	local x = gui.MouseX()+10
	local y = gui.MouseY()+24
	EOTI.Tooltip:SetPos( x, y )
	if EOTI.Stats:IsChildHovered() then
		draw.RoundedBoxEx( EOTI.Menu.corner, 0, 0, w, h, EOTI.Menu.color, false, true, true, true )
	end
end

I’ve had issues like this before, trying to think how to explain it so this post’ll probably end up being useless

Basically, gui.MouseY/X whatever starts from the top left corner of your screen, not vgui frame

you could try printing your created panel’s x and y as well as your mouse’s x and y, then compare the two

what niandra’s trying to say is use this instead of gui.mousex/y:

Panel:LocalCursorPos

this is how I’ve had to do a panel that follows the cursor before:

[lua]pnl.cursor = vgui.Create(“EditablePanel”, pnl)
pnl.cursor:SetSize(64, 64)
pnl.cursor:SetZPos(9999)
pnl.cursor:MouseCapture(false)
pnl.cursor:SetMouseInputEnabled(false)

pnl.Think = function(self)
local x, y = self:LocalCursorPos()
self.cursor:SetPos(x + 1, y + 1)
end
[/lua]

This sounds really dumb but I figured out what happened, the Derma panels got desync’d because all my controls got desync’d. Ran GMOD in borderless windowed mode and realized that the game got resized by roughly 1 pixel to 1920 x 1079 which causes all GUI elements to flat out break in response.

Do’h