LoveFrames/loveframes/objects/internal/closebutton.lua

160 lines
3.6 KiB
Lua
Raw Normal View History

2012-05-06 00:24:42 +00:00
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
2014-01-14 11:29:11 +00:00
-- Copyright (c) 2012-2014 Kenny Shields --
2012-05-06 00:24:42 +00:00
--]]------------------------------------------------
2019-03-06 23:19:58 +00:00
return function(loveframes)
---------- module start ----------
-- closebutton class
local newobject = loveframes.NewObject("closebutton", "loveframes_object_closebutton", true)
2012-05-06 00:24:42 +00:00
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function newobject:initialize()
2012-05-06 00:24:42 +00:00
self.type = "closebutton"
self.width = 16
self.height = 16
self.internal = true
self.hover = false
self.down = false
2014-01-25 03:48:42 +00:00
self.autoposition = true
self.OnClick = function() end
2012-05-06 00:24:42 +00:00
-- apply template properties to the object
2019-03-06 23:19:58 +00:00
loveframes.ApplyTemplatesToObject(self)
2019-03-06 23:19:58 +00:00
self:SetDrawFunc()
2012-05-06 00:24:42 +00:00
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the object
--]]---------------------------------------------------------
function newobject:update(dt)
2012-05-06 00:24:42 +00:00
local visible = self.visible
local alwaysupdate = self.alwaysupdate
if not visible then
if not alwaysupdate then
2012-05-06 00:24:42 +00:00
return
end
end
self:CheckHover()
local hover = self.hover
local down = self.down
local downobject = loveframes.downobject
local parent = self.parent
local base = loveframes.base
local update = self.Update
if not hover then
self.down = false
else
if loveframes.downobject == self then
self.down = true
end
end
if not down and downobject == self then
self.hover = true
end
2014-01-25 03:48:42 +00:00
if self.autoposition then
self.staticx = self.parent.width - self.width - 4
self.staticy = 4
end
2012-05-06 00:24:42 +00:00
-- move to parent if there is a parent
if parent ~= base then
self.x = parent.x + self.staticx
self.y = parent.y + self.staticy
2012-05-06 00:24:42 +00:00
end
if update then
update(self, dt)
2012-05-06 00:24:42 +00:00
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function newobject:mousepressed(x, y, button)
2012-05-06 00:24:42 +00:00
local visible = self.visible
if not visible then
2012-05-06 00:24:42 +00:00
return
end
local hover = self.hover
2015-10-31 13:40:19 +00:00
if hover and button == 1 then
2012-05-06 00:24:42 +00:00
local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" then
baseparent:MakeTop()
end
self.down = true
loveframes.downobject = self
2012-05-06 00:24:42 +00:00
end
end
--[[---------------------------------------------------------
- func: mousereleased(x, y, button)
- desc: called when the player releases a mouse button
--]]---------------------------------------------------------
function newobject:mousereleased(x, y, button)
2012-05-06 00:24:42 +00:00
local visible = self.visible
if not visible then
2012-05-06 00:24:42 +00:00
return
end
local hover = self.hover
local onclick = self.OnClick
if hover and self.down then
2015-10-31 13:40:19 +00:00
if button == 1 then
onclick(x, y, self)
2012-05-06 00:24:42 +00:00
end
end
self.down = false
end
--[[---------------------------------------------------------
- func: SetAutoPosition(bool)
- desc: sets whether or not the object should be
positioned automatically
--]]---------------------------------------------------------
function newobject:SetAutoPosition(bool)
self.autoposition = bool
end
--[[---------------------------------------------------------
- func: GetAutoPosition()
- desc: gets whether or not the object should be
positioned automatically
--]]---------------------------------------------------------
function newobject:GetAutoPosition()
return self.autoposition
2014-11-09 21:24:10 +00:00
end
2019-03-06 23:19:58 +00:00
---------- module end ----------
end