LoveFrames/objects/internal/closebutton.lua

155 lines
3.4 KiB
Lua
Raw Normal View History

2012-05-06 00:24:42 +00:00
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2013 Kenny Shields --
2012-05-06 00:24:42 +00:00
--]]------------------------------------------------
-- 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
self.OnClick = function() end
2012-05-06 00:24:42 +00:00
-- apply template properties to the object
loveframes.templates.ApplyToObject(self)
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
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: draw()
- desc: draws the object
--]]---------------------------------------------------------
function newobject:draw()
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 skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawCloseButton or skins[defaultskin].DrawCloseButton
local draw = self.Draw
-- set the object's draw order
self:SetDrawOrder()
if draw then
draw(self)
2012-05-06 00:24:42 +00:00
else
drawfunc(self)
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
if hover and button == "l" 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
2012-05-06 00:24:42 +00:00
if button == "l" then
onclick(x, y, self)
2012-05-06 00:24:42 +00:00
end
end
self.down = false
end