fork/m-overlay

git clone https://git.julia.blue/fork/m-overlay

BkacjiosBugfixes + Dark Mode skina8034e9

master
1.6 KiB73 linesraw
1local PANEL = class.create("Frame", "Panel")
2
3PANEL:ACCESSOR("Grabbed", "m_bGrabbed", false)
4PANEL:ACCESSOR("Draggable", "m_bDraggable", true)
5PANEL:ACCESSOR("HideOnClose", "m_bHideOnClose", false)
6
7function PANEL:Frame()
8	self:super() -- Initialize our baseclass
9
10	self:DockPadding(4, 36, 4, 4)
11	
12	self.m_pTitle = self:Add("Label")
13	self.m_pTitle:SetText("Window")
14	self.m_pTitle:SetTextAlignmentX("center")
15	
16	self.m_pClose = self:Add("Button")
17	self.m_pClose:SetText("x")
18	
19	self.m_pClose.OnClick = function(this, but)
20		self:OnClosed()
21		if self.m_bHideOnClose then
22			self:SetVisible(false)
23		else
24			self:Remove()
25		end
26	end
27end
28
29function PANEL:Skin()
30	gui.skinHook("Init", "ExitButton", self.m_pClose)
31end
32
33function PANEL:SetTitle(s)
34	self.m_pTitle:SetText(s)
35end
36
37function PANEL:PerformLayout()
38	self.m_pTitle:SetPos(2, 2)
39	self.m_pTitle:SetSize(self:GetWidth() -  48, 28)
40	
41	self.m_pClose:SetPos(self:GetWidth() - 46, 4)
42	self.m_pClose:SetSize(42, 24)
43end
44
45function PANEL:Paint(w, h)
46	gui.skinHook("Paint", "Frame", self, w, h)
47end
48
49function PANEL:OnMousePressed(x, y, but)
50	self:BringToFront()
51	if not self.m_bDraggable or not self:HasFocus() then return end
52	if y > 32 then return end -- Only allow them to move using the top bar
53	self:SetGrabbed(true)
54	self.m_tGrabbedOffset = { x = x, y = y }
55end
56
57function PANEL:OnMouseReleased(x, y, but)
58	if not self.m_bDraggable then return end
59	self:SetGrabbed(false)
60end
61
62function PANEL:Think(dt)
63	if not self:IsGrabbed() then return end
64
65	local mx, my = love.mouse.getPosition()
66	local gx, gy = self.m_tGrabbedOffset.x, self.m_tGrabbedOffset.y
67	
68	self:SetPos(mx - gx, my - gy)
69end
70
71function PANEL:OnClosed()
72	-- Override
73end