2012-09-02 00:56:32 +00:00
|
|
|
--[[------------------------------------------------
|
2012-09-29 23:20:41 +00:00
|
|
|
-- Love Frames - A GUI library for LOVE --
|
|
|
|
-- Copyright (c) 2012 Kenny Shields --
|
2012-09-02 00:56:32 +00:00
|
|
|
--]]------------------------------------------------
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
-- tabbutton class
|
2012-11-24 22:42:16 +00:00
|
|
|
local newobject = loveframes.NewObject("tabbutton", "loveframes_object_tabbutton", true)
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: initialize()
|
|
|
|
- desc: initializes the object
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:initialize(parent, text, tabnumber, tip, image)
|
2012-09-02 00:56:32 +00:00
|
|
|
|
2012-12-28 12:19:02 +00:00
|
|
|
self.type = "tabbutton"
|
|
|
|
self.font = loveframes.smallfont
|
|
|
|
self.text = text
|
|
|
|
self.tabnumber = tabnumber
|
|
|
|
self.parent = parent
|
|
|
|
self.staticx = 0
|
|
|
|
self.staticy = 0
|
|
|
|
self.width = 50
|
|
|
|
self.height = 25
|
|
|
|
self.internal = true
|
|
|
|
self.down = false
|
|
|
|
self.image = nil
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
if tip then
|
2012-11-24 22:42:16 +00:00
|
|
|
self.tooltip = loveframes.objects["tooltip"]:new(self, tip)
|
2012-09-02 00:56:32 +00:00
|
|
|
self.tooltip:SetFollowCursor(false)
|
|
|
|
self.tooltip:SetOffsets(0, -5)
|
|
|
|
end
|
|
|
|
|
|
|
|
if image then
|
|
|
|
self:SetImage(image)
|
|
|
|
end
|
|
|
|
|
2012-10-22 14:19:02 +00:00
|
|
|
-- apply template properties to the object
|
|
|
|
loveframes.templates.ApplyToObject(self)
|
|
|
|
|
2012-09-02 00:56:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: update(deltatime)
|
|
|
|
- desc: updates the object
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:update(dt)
|
2012-09-02 00:56:32 +00:00
|
|
|
|
2012-12-28 12:19:02 +00:00
|
|
|
local visible = self.visible
|
2012-09-02 00:56:32 +00:00
|
|
|
local alwaysupdate = self.alwaysupdate
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if not visible then
|
|
|
|
if not alwaysupdate then
|
2012-09-02 00:56:32 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
local parent = self.parent
|
2012-12-28 12:19:02 +00:00
|
|
|
local base = loveframes.base
|
2012-09-29 23:20:41 +00:00
|
|
|
local update = self.Update
|
|
|
|
|
2012-09-02 00:56:32 +00:00
|
|
|
self:CheckHover()
|
2012-09-29 23:20:41 +00:00
|
|
|
self:SetClickBounds(parent.x, parent.y, parent.width, parent.height)
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
-- move to parent if there is a parent
|
2012-09-29 23:20:41 +00:00
|
|
|
if parent ~= base then
|
2012-09-02 00:56:32 +00:00
|
|
|
self.x = self.parent.x + self.staticx
|
|
|
|
self.y = self.parent.y + self.staticy
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if update then
|
|
|
|
update(self, dt)
|
2012-09-02 00:56:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: draw()
|
|
|
|
- desc: draws the object
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:draw()
|
2012-09-02 00:56:32 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if not self.visible then
|
2012-09-02 00:56:32 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-12-28 12:19:02 +00:00
|
|
|
local image = self.image
|
|
|
|
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.DrawTabButton or skins[defaultskin].DrawTabButton
|
|
|
|
local draw = self.Draw
|
|
|
|
local drawcount = loveframes.drawcount
|
2012-09-29 23:20:41 +00:00
|
|
|
|
2012-10-22 14:19:02 +00:00
|
|
|
-- set the object's draw order
|
|
|
|
self:SetDrawOrder()
|
2012-09-02 00:56:32 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if draw then
|
|
|
|
draw(self)
|
2012-09-02 00:56:32 +00:00
|
|
|
else
|
|
|
|
drawfunc(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: mousepressed(x, y, button)
|
|
|
|
- desc: called when the player presses a mouse button
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:mousepressed(x, y, button)
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
local visible = self.visible
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if not visible then
|
2012-09-02 00:56:32 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local hover = self.hover
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if hover and button == "l" then
|
2012-09-02 00:56:32 +00:00
|
|
|
local baseparent = self:GetBaseParent()
|
|
|
|
if baseparent and baseparent.type == "frame" then
|
|
|
|
baseparent:MakeTop()
|
|
|
|
end
|
|
|
|
self.down = true
|
|
|
|
loveframes.hoverobject = self
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: mousereleased(x, y, button)
|
|
|
|
- desc: called when the player releases a mouse button
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:mousereleased(x, y, button)
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
local visible = self.visible
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if not visible then
|
2012-09-02 00:56:32 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-12-28 12:19:02 +00:00
|
|
|
local hover = self.hover
|
|
|
|
local parent = self.parent
|
2012-09-02 00:56:32 +00:00
|
|
|
local tabnumber = self.tabnumber
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if hover and button == "l" then
|
2012-09-02 00:56:32 +00:00
|
|
|
if button == "l" then
|
|
|
|
parent:SwitchToTab(tabnumber)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
self.down = false
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetText(text)
|
|
|
|
- desc: sets the object's text
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetText(text)
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
self.text = text
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetText()
|
|
|
|
- desc: gets the object's text
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:GetText()
|
2012-09-29 23:20:41 +00:00
|
|
|
|
|
|
|
return self.text
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-09-02 00:56:32 +00:00
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetImage(image)
|
|
|
|
- desc: adds an image to the object
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetImage(image)
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
if type(image) == "string" then
|
|
|
|
self.image = love.graphics.newImage(image)
|
|
|
|
else
|
|
|
|
self.image = image
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetImage()
|
|
|
|
- desc: gets the object's image
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:GetImage()
|
2012-09-29 23:20:41 +00:00
|
|
|
|
|
|
|
return self.image
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetTabNumber()
|
|
|
|
- desc: gets the object's tab number
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:GetTabNumber()
|
2012-09-29 23:20:41 +00:00
|
|
|
|
|
|
|
return self.tabnumber
|
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|