2013-02-11 21:15:40 +00:00
|
|
|
--[[------------------------------------------------
|
|
|
|
-- Love Frames - A GUI library for LOVE --
|
2014-01-14 11:29:11 +00:00
|
|
|
-- Copyright (c) 2012-2014 Kenny Shields --
|
2013-02-11 21:15:40 +00:00
|
|
|
--]]------------------------------------------------
|
|
|
|
|
2019-03-06 23:19:58 +00:00
|
|
|
return function(loveframes)
|
|
|
|
---------- module start ----------
|
2014-10-23 22:36:16 +00:00
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
-- tabbutton class
|
|
|
|
local newobject = loveframes.NewObject("tabbutton", "loveframes_object_tabbutton", true)
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: initialize()
|
|
|
|
- desc: initializes the object
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:initialize(parent, text, tabnumber, tip, image, onopened, onclosed)
|
|
|
|
|
|
|
|
self.type = "tabbutton"
|
|
|
|
self.font = loveframes.smallfont
|
|
|
|
self.text = text
|
|
|
|
self.tabnumber = tabnumber
|
|
|
|
self.parent = parent
|
2013-06-24 15:11:02 +00:00
|
|
|
self.state = parent.state
|
2013-02-11 21:15:40 +00:00
|
|
|
self.staticx = 0
|
|
|
|
self.staticy = 0
|
|
|
|
self.width = 50
|
|
|
|
self.height = 25
|
|
|
|
self.internal = true
|
|
|
|
self.down = false
|
|
|
|
self.image = nil
|
|
|
|
self.OnOpened = nil
|
|
|
|
self.OnClosed = nil
|
|
|
|
|
|
|
|
if tip then
|
|
|
|
self.tooltip = loveframes.objects["tooltip"]:new(self, tip)
|
|
|
|
self.tooltip:SetFollowCursor(false)
|
|
|
|
self.tooltip:SetFollowObject(true)
|
2013-09-18 02:22:11 +00:00
|
|
|
self.tooltip:SetOffsets(0, -(self.tooltip.internals[1]:GetHeight() + 12))
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if image then
|
|
|
|
self:SetImage(image)
|
|
|
|
end
|
|
|
|
|
|
|
|
if onopened then
|
|
|
|
self.OnOpened = onopened
|
|
|
|
end
|
|
|
|
|
|
|
|
if onclosed then
|
|
|
|
self.OnClosed = onclosed
|
|
|
|
end
|
|
|
|
|
|
|
|
-- apply template properties to the object
|
2019-03-06 23:19:58 +00:00
|
|
|
loveframes.ApplyTemplatesToObject(self)
|
2013-02-11 21:15:40 +00:00
|
|
|
|
2019-03-06 23:19:58 +00:00
|
|
|
self:SetDrawFunc()
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: update(deltatime)
|
|
|
|
- desc: updates the object
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:update(dt)
|
|
|
|
|
|
|
|
local visible = self.visible
|
|
|
|
local alwaysupdate = self.alwaysupdate
|
|
|
|
|
|
|
|
if not visible then
|
|
|
|
if not alwaysupdate then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local parent = self.parent
|
|
|
|
local base = loveframes.base
|
|
|
|
local update = self.Update
|
|
|
|
|
|
|
|
self:CheckHover()
|
|
|
|
self:SetClickBounds(parent.x, parent.y, parent.width, parent.height)
|
|
|
|
|
|
|
|
if update then
|
|
|
|
update(self, dt)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: mousepressed(x, y, button)
|
|
|
|
- desc: called when the player presses a mouse button
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:mousepressed(x, y, button)
|
|
|
|
|
|
|
|
local visible = self.visible
|
|
|
|
|
|
|
|
if not visible then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local hover = self.hover
|
|
|
|
local internals = self.internals
|
|
|
|
|
2015-10-31 13:40:19 +00:00
|
|
|
if hover and button == 1 then
|
2013-02-11 21:15:40 +00:00
|
|
|
local baseparent = self:GetBaseParent()
|
|
|
|
if baseparent and baseparent.type == "frame" then
|
|
|
|
baseparent:MakeTop()
|
|
|
|
end
|
|
|
|
self.down = true
|
2013-10-30 23:05:10 +00:00
|
|
|
loveframes.downobject = self
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: mousereleased(x, y, button)
|
|
|
|
- desc: called when the player releases a mouse button
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:mousereleased(x, y, button)
|
|
|
|
|
|
|
|
local visible = self.visible
|
|
|
|
|
|
|
|
if not visible then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local hover = self.hover
|
|
|
|
local parent = self.parent
|
|
|
|
local tabnumber = self.tabnumber
|
|
|
|
|
2015-10-31 13:40:19 +00:00
|
|
|
if hover and button == 1 then
|
|
|
|
if button == 1 then
|
2013-05-05 23:51:20 +00:00
|
|
|
local tab = parent.tab
|
2013-02-11 21:15:40 +00:00
|
|
|
local internals = parent.internals
|
|
|
|
local onopened = self.OnOpened
|
|
|
|
local prevtab = internals[tab]
|
|
|
|
local onclosed = prevtab.OnClosed
|
|
|
|
parent:SwitchToTab(tabnumber)
|
|
|
|
if onopened then
|
|
|
|
onopened(self)
|
|
|
|
end
|
|
|
|
if onclosed then
|
|
|
|
onclosed(prevtab)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
self.down = false
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetText(text)
|
|
|
|
- desc: sets the object's text
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetText(text)
|
|
|
|
|
|
|
|
self.text = text
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetText()
|
|
|
|
- desc: gets the object's text
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetText()
|
|
|
|
|
|
|
|
return self.text
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetImage(image)
|
|
|
|
- desc: adds an image to the object
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetImage(image)
|
|
|
|
|
|
|
|
if type(image) == "string" then
|
|
|
|
self.image = love.graphics.newImage(image)
|
2019-03-06 23:19:58 +00:00
|
|
|
self.image:setFilter("nearest", "nearest")
|
2013-02-11 21:15:40 +00:00
|
|
|
else
|
|
|
|
self.image = image
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetImage()
|
|
|
|
- desc: gets the object's image
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetImage()
|
|
|
|
|
|
|
|
return self.image
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetTabNumber()
|
|
|
|
- desc: gets the object's tab number
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetTabNumber()
|
|
|
|
|
|
|
|
return self.tabnumber
|
|
|
|
|
2014-11-09 21:24:10 +00:00
|
|
|
end
|
2019-03-06 23:19:58 +00:00
|
|
|
|
|
|
|
---------- module end ----------
|
|
|
|
end
|