fork/m-overlay

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

BkacjiosMore class changes27686d7

settings-overhaul
1.6 KiB71 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:SetTextAlignment("center")
15	
16	self.m_pClose = self:Add("Button")
17	self.m_pClose:SetText("x")
18	
19	gui.skinHook("Init", "ExitButton", self.m_pClose)
20	
21	self.m_pClose.OnClick = function(this, but)
22		self:OnClosed()
23		if self.m_bHideOnClose then
24			self:SetVisible(false)
25		else
26			self:Remove()
27		end
28	end
29end
30
31function PANEL:SetTitle(s)
32	self.m_pTitle:SetText(s)
33end
34
35function PANEL:PerformLayout()
36	self.m_pTitle:SetPos(2, 2)
37	self.m_pTitle:SetSize(self:GetWidth() -  48, 28)
38	
39	self.m_pClose:SetPos(self:GetWidth() - 46, 4)
40	self.m_pClose:SetSize(42, 24)
41end
42
43function PANEL:Paint(w, h)
44	gui.skinHook("Paint", "Frame", self, w, h)
45end
46
47function PANEL:OnMousePressed(x, y, but)
48	self:BringToFront()
49	if not self.m_bDraggable or not self:HasFocus() then return end
50	if y > 32 then return end -- Only allow them to move using the top bar
51	self:SetGrabbed(true)
52	self.m_tGrabbedOffset = { x = x, y = y }
53end
54
55function PANEL:OnMouseReleased(x, y, but)
56	if not self.m_bDraggable then return end
57	self:SetGrabbed(false)
58end
59
60function PANEL:Think(dt)
61	if not self:IsGrabbed() then return end
62
63	local mx, my = love.mouse.getPosition()
64	local gx, gy = self.m_tGrabbedOffset.x, self.m_tGrabbedOffset.y
65	
66	self:SetPos(mx - gx, my - gy)
67end
68
69function PANEL:OnClosed()
70	-- Override
71end