LoveFrames/loveframes/objects/internal/columnlist/columnlistrow.lua

219 lines
5.3 KiB
Lua
Raw Permalink 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 ----------
-- columnlistrow class
local newobject = loveframes.NewObject("columnlistrow", "loveframes_object_columnlistrow", true)
2012-05-06 00:24:42 +00:00
--[[---------------------------------------------------------
- func: initialize()
- desc: intializes the element
--]]---------------------------------------------------------
function newobject:initialize(parent, data)
2012-05-06 00:24:42 +00:00
self.type = "columnlistrow"
self.parent = parent
self.state = parent.state
self.colorindex = self.parent.rowcolorindex
self.font = loveframes.basicfontsmall
self.width = 80
self.height = 25
self.textx = 5
self.texty = 5
self.selected = false
self.internal = true
self.columndata = {}
for k, v in ipairs(data) do
self.columndata[k] = tostring(v)
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)
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
2014-08-23 08:36:47 +00:00
if not self.visible then
if not self.alwaysupdate then
2012-05-06 00:24:42 +00:00
return
end
end
local parent = self.parent
local update = self.Update
2012-05-06 00:24:42 +00:00
self:CheckHover()
-- move to parent if there is a parent
2014-08-23 08:36:47 +00:00
if parent ~= loveframes.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
if not self.visible then
2012-05-06 00:24:42 +00:00
return
end
2015-10-31 13:40:19 +00:00
if self.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
2019-03-06 23:19:58 +00:00
self:GetParent():GetParent():SelectRow(self, loveframes.IsCtrlDown())
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
if self.hover then
2014-08-23 08:36:47 +00:00
local parent = self:GetParent():GetParent()
2015-10-31 13:40:19 +00:00
if button == 1 then
2014-08-23 08:36:47 +00:00
local onrowclicked = parent.OnRowClicked
if onrowclicked then
2014-08-23 08:36:47 +00:00
onrowclicked(parent, self, self.columndata)
end
2015-10-31 13:40:19 +00:00
elseif button == 2 then
2014-08-23 08:36:47 +00:00
local onrowrightclicked = parent.OnRowRightClicked
if onrowrightclicked then
2014-08-23 08:36:47 +00:00
onrowrightclicked(parent, self, self.columndata)
end
2012-05-06 00:24:42 +00:00
end
end
end
--[[---------------------------------------------------------
- func: SetTextPos(x, y)
- desc: sets the positions of the object's text
2012-05-06 00:24:42 +00:00
--]]---------------------------------------------------------
function newobject:SetTextPos(x, y)
self.textx = x
self.texty = y
2012-05-06 00:24:42 +00:00
end
--[[---------------------------------------------------------
- func: GetTextX()
- desc: gets the object's text x position
--]]---------------------------------------------------------
function newobject:GetTextX()
return self.textx
end
--[[---------------------------------------------------------
- func: GetTextY()
- desc: gets the object's text y position
--]]---------------------------------------------------------
function newobject:GetTextY()
return self.texty
end
2012-05-06 00:24:42 +00:00
--[[---------------------------------------------------------
- func: SetFont(font)
- desc: sets the object's font
2012-05-06 00:24:42 +00:00
--]]---------------------------------------------------------
function newobject:SetFont(font)
2012-05-06 00:24:42 +00:00
self.font = font
end
--[[---------------------------------------------------------
- func: GetFont()
- desc: gets the object's font
--]]---------------------------------------------------------
function newobject:GetFont()
return self.font
end
--[[---------------------------------------------------------
- func: GetColorIndex()
- desc: gets the object's color index
--]]---------------------------------------------------------
function newobject:GetColorIndex()
return self.colorindex
end
--[[---------------------------------------------------------
- func: SetColumnData(data)
- desc: sets the object's column data
--]]---------------------------------------------------------
function newobject:SetColumnData(data)
self.columndata = data
end
--[[---------------------------------------------------------
- func: GetColumnData()
- desc: gets the object's column data
--]]---------------------------------------------------------
function newobject:GetColumnData()
2012-05-06 00:24:42 +00:00
return self.columndata
end
--[[---------------------------------------------------------
- func: SetSelected(selected)
- desc: sets whether or not the object is selected
--]]---------------------------------------------------------
function newobject:SetSelected(selected)
self.selected = true
end
--[[---------------------------------------------------------
- func: GetSelected()
- desc: gets whether or not the object is selected
--]]---------------------------------------------------------
function newobject:GetSelected()
return self.selected
2014-11-09 21:24:10 +00:00
end
2019-03-06 23:19:58 +00:00
---------- module end ----------
end