LoveFrames/objects/internal/columnlist/coulmnlistheader.lua

179 lines
4.1 KiB
Lua
Raw Normal View History

2012-05-06 00:24:42 +00:00
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
-- Copyright (c) 2012 Kenny Shields --
2012-05-06 00:24:42 +00:00
--]]------------------------------------------------
-- columnlistheader class
local newobject = loveframes.NewObject("columnlistheader", "loveframes_object_columnlistheader", true)
2012-05-06 00:24:42 +00:00
--[[---------------------------------------------------------
- func: initialize()
- desc: intializes the element
--]]---------------------------------------------------------
function newobject:initialize(name, parent)
2012-05-06 00:24:42 +00:00
self.type = "columnlistheader"
self.parent = parent
self.name = name
self.width = 80
self.height = self.parent.columnheight
self.hover = false
self.down = false
self.clickable = true
self.enabled = true
2012-05-06 00:24:42 +00:00
self.descending = true
self.internal = true
2012-05-06 00:24:42 +00:00
table.insert(parent.children, self)
local key = 0
for k, v in ipairs(self.parent.children) do
if v == self then
key = k
end
end
self.OnClick = function()
if self.descending == true then
self.descending = false
else
self.descending = true
end
self.parent.internals[1]:Sort(key, self.descending)
end
-- 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
local parent = self.parent
local base = loveframes.base
local update = self.Update
2012-05-06 00:24:42 +00:00
self:CheckHover()
if not self.hover then
self.down = false
else
if loveframes.hoverobject == self then
self.down = true
end
end
if self.down and loveframes.hoverobject == 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.DrawColumnListHeader or skins[defaultskin].DrawColumnListHeader
local draw = self.Draw
local drawcount = loveframes.drawcount
-- 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
if self.hover and button == "l" then
2012-05-06 00:24:42 +00:00
local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" and button == "l" then
baseparent:MakeTop()
end
self.down = true
loveframes.hoverobject = 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
if not self.visible then
2012-05-06 00:24:42 +00:00
return
end
local hover = self.hover
local down = self.down
2012-05-06 00:24:42 +00:00
local clickable = self.clickable
local enabled = self.enabled
local onclick = self.OnClick
2012-05-06 00:24:42 +00:00
if hover and down and clickable and button == "l" then
if enabled then
onclick(self, x, y)
2012-05-06 00:24:42 +00:00
end
end
self.down = false
end
--[[---------------------------------------------------------
- func: GetName()
- desc: gets the object's name
--]]---------------------------------------------------------
function newobject:GetName()
return self.name
2012-05-06 00:24:42 +00:00
end