mirror of
https://github.com/linux-man/LoveFrames.git
synced 2024-11-18 16:04:22 +00:00
Merge pull request #18 from rozenmad/master
Added grid span feature, and other fixes
This commit is contained in:
commit
773321041c
@ -3,37 +3,56 @@ example.title = "Grid"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Grid")
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
|
||||
local grid = loveframes.Create("grid", frame)
|
||||
grid:SetPos(5, 30)
|
||||
grid:SetRows(5)
|
||||
grid:SetColumns(5)
|
||||
grid:SetCellWidth(25)
|
||||
grid:SetCellHeight(25)
|
||||
grid:SetCellPadding(5)
|
||||
grid:SetCellWidth(45)
|
||||
grid:SetCellHeight(45)
|
||||
grid:SetCellPadding(2)
|
||||
grid:SetItemAutoSize(true)
|
||||
|
||||
local id = 1
|
||||
|
||||
for i=1, 5 do
|
||||
for n=1, 5 do
|
||||
local button = loveframes.Create("button")
|
||||
button:SetSize(15, 15)
|
||||
button:SetText(id)
|
||||
grid:AddItem(button, i, n)
|
||||
id = id + 1
|
||||
end
|
||||
|
||||
grid:SetItemAutoSize(true)
|
||||
|
||||
grid:ColSpanAt(1, 1, 5)
|
||||
grid:RowSpanAt(1, 1, 3)
|
||||
|
||||
grid:RowSpanAt(4, 1, 2)
|
||||
grid:ColSpanAt(4, 1, 2)
|
||||
|
||||
grid:ColSpanAt(5, 3, 2)
|
||||
|
||||
local list = loveframes.Create('list')
|
||||
grid:AddItem(list, 1, 1)
|
||||
|
||||
for i = 1, 10 do
|
||||
local button = loveframes.Create("button")
|
||||
button:SetText(tostring(i))
|
||||
list:AddItem(button)
|
||||
end
|
||||
|
||||
|
||||
local button = loveframes.Create("button")
|
||||
button:SetText('4, 1')
|
||||
grid:AddItem(button, 4, 1, 'center')
|
||||
|
||||
local button = loveframes.Create("button")
|
||||
button:SetText('5, 5')
|
||||
grid:AddItem(button, 5, 5, 'left')
|
||||
|
||||
local button = loveframes.Create("button")
|
||||
button:SetText(('5, 3'))
|
||||
grid:AddItem(button, 5, 3, 'right')
|
||||
|
||||
grid.OnSizeChanged = function(object)
|
||||
frame:SetSize(object:GetWidth() + 10, object:GetHeight() + 35)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
return example
|
@ -244,11 +244,8 @@ function loveframes.mousereleased(x, y, button)
|
||||
base:mousereleased(x, y, button)
|
||||
|
||||
-- reset the hover object
|
||||
if button == 1 then
|
||||
loveframes.downobject = false
|
||||
loveframes.selectedobject = false
|
||||
end
|
||||
|
||||
loveframes.downobject = false
|
||||
loveframes.selectedobject = false
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
|
@ -251,9 +251,9 @@ end
|
||||
function loveframes.Round(num, idp)
|
||||
local mult = 10^(idp or 0)
|
||||
|
||||
if num >= 0 then
|
||||
if num >= 0 then
|
||||
return math.floor(num * mult + 0.5) / mult
|
||||
else
|
||||
else
|
||||
return math.ceil(num * mult - 0.5) / mult
|
||||
end
|
||||
end
|
||||
|
@ -797,7 +797,7 @@ function newobject:CheckHover()
|
||||
local visible = self.visible
|
||||
local type = self.type
|
||||
local hoverobject = loveframes.hoverobject
|
||||
|
||||
|
||||
-- check if the mouse is colliding with the object
|
||||
if state == curstate and visible then
|
||||
local collide = self.collide
|
||||
@ -820,7 +820,7 @@ function newobject:CheckHover()
|
||||
end
|
||||
|
||||
-- check if the object is being hovered
|
||||
if hoverobject == self and type ~= "base" then
|
||||
if selfcol and hoverobject == self and type ~= "base" then
|
||||
self.hover = true
|
||||
else
|
||||
self.hover = false
|
||||
@ -1066,13 +1066,29 @@ end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetAlwaysUpdate(bool)
|
||||
- desc: sets the object's skin
|
||||
- desc: sets the object will always update
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetAlwaysUpdate(bool)
|
||||
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
|
||||
self.alwaysupdate = bool
|
||||
return self
|
||||
|
||||
if children then
|
||||
for k, v in ipairs(children) do
|
||||
v:SetAlwaysUpdate(bool)
|
||||
end
|
||||
end
|
||||
|
||||
if internals then
|
||||
for k, v in ipairs(internals) do
|
||||
v:SetAlwaysUpdate(bool)
|
||||
end
|
||||
end
|
||||
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
|
@ -57,7 +57,6 @@ function newobject:update(dt)
|
||||
self:CheckHover()
|
||||
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
local downobject = loveframes.downobject
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
@ -76,8 +75,8 @@ function newobject:update(dt)
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
|
||||
self.y = self.parent.y + self.staticy - (parent.offsety or 0)
|
||||
end
|
||||
|
||||
if update then
|
||||
@ -107,7 +106,7 @@ function newobject:mousepressed(x, y, button)
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover and button == 1 then
|
||||
if hover then
|
||||
local baseparent = self:GetBaseParent()
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
@ -116,6 +115,7 @@ function newobject:mousepressed(x, y, button)
|
||||
loveframes.downobject = self
|
||||
end
|
||||
|
||||
self.pressed_button = button
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -143,7 +143,7 @@ function newobject:mousereleased(x, y, button)
|
||||
local enabled = self.enabled
|
||||
local onclick = self.OnClick
|
||||
|
||||
if hover and down and clickable and button == 1 then
|
||||
if hover and down and clickable and self.pressed_button == button then
|
||||
if enabled then
|
||||
if self.groupIndex ~= 0 then
|
||||
local baseparent = self.parent
|
||||
@ -159,7 +159,7 @@ function newobject:mousereleased(x, y, button)
|
||||
self.checked = true
|
||||
end
|
||||
if onclick then
|
||||
onclick(self, x, y)
|
||||
onclick(self, x, y, self.pressed_button)
|
||||
end
|
||||
if self.toggleable then
|
||||
local ontoggle = self.OnToggle
|
||||
@ -170,7 +170,7 @@ function newobject:mousereleased(x, y, button)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
self.down = false
|
||||
|
||||
end
|
||||
|
@ -15,8 +15,8 @@ local newobject = loveframes.NewObject("checkbox", "loveframes_object_checkbox",
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:initialize()
|
||||
self.type = "checkbox"
|
||||
self.width = 0
|
||||
self.height = 0
|
||||
self.width = 16
|
||||
self.height = 16
|
||||
self.boxwidth = 16
|
||||
self.boxheight = 16
|
||||
self.font = loveframes.basicfont
|
||||
|
@ -62,9 +62,9 @@ function newobject:update(dt)
|
||||
self:CheckHover()
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base and parent.type ~= "list" then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
if parent ~= base then
|
||||
self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
|
||||
self.y = self.parent.y + self.staticy - (parent.offsety or 0)
|
||||
end
|
||||
|
||||
if open and curobject then
|
||||
|
@ -14,7 +14,7 @@ local newobject = loveframes.NewObject("columnlist", "loveframes_object_columnli
|
||||
- desc: intializes the element
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:initialize()
|
||||
|
||||
|
||||
self.type = "columnlist"
|
||||
self.width = 300
|
||||
self.height = 100
|
||||
@ -39,7 +39,7 @@ function newobject:initialize()
|
||||
|
||||
local list = loveframes.objects["columnlistarea"]:new(self)
|
||||
table.insert(self.internals, list)
|
||||
|
||||
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
@ -48,48 +48,48 @@ end
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:update(dt)
|
||||
|
||||
|
||||
local state = loveframes.state
|
||||
local selfstate = self.state
|
||||
|
||||
|
||||
if state ~= selfstate then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
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 children = self.children
|
||||
local internals = self.internals
|
||||
local update = self.Update
|
||||
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
|
||||
self.y = self.parent.y + self.staticy - (parent.offsety or 0)
|
||||
end
|
||||
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
v.columnid = k
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
|
||||
self.startadjustment = false
|
||||
|
||||
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
@ -108,49 +108,49 @@ function newobject:draw()
|
||||
if not self.visible then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
local vbody = self.internals[1]:GetVerticalScrollBody()
|
||||
local hbody = self.internals[1]:GetHorizontalScrollBody()
|
||||
local width = self.width
|
||||
local height = self.height
|
||||
|
||||
|
||||
if vbody then
|
||||
width = width - vbody.width
|
||||
end
|
||||
|
||||
|
||||
if hbody then
|
||||
height = height - hbody.height
|
||||
end
|
||||
|
||||
|
||||
local stencilfunc = function()
|
||||
love.graphics.rectangle("fill", self.x, self.y, width, height)
|
||||
end
|
||||
|
||||
|
||||
-- set the object's draw order
|
||||
self:SetDrawOrder()
|
||||
|
||||
|
||||
local drawfunc = self.Draw or self.drawfunc
|
||||
if drawfunc then
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
|
||||
local internals = self.internals
|
||||
if internals then
|
||||
for k, v in ipairs(internals) do
|
||||
v:draw()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
love.graphics.stencil(stencilfunc)
|
||||
love.graphics.setStencilTest("greater", 0)
|
||||
|
||||
|
||||
local children = self.children
|
||||
if children then
|
||||
for k, v in ipairs(children) do
|
||||
v:draw()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local drawfunc = self.DrawOver or self.drawoverfunc
|
||||
if drawfunc then
|
||||
drawfunc(self)
|
||||
@ -167,36 +167,36 @@ function newobject:mousepressed(x, y, button)
|
||||
|
||||
local state = loveframes.state
|
||||
local selfstate = self.state
|
||||
|
||||
|
||||
if state ~= selfstate then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
local hover = self.hover
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
|
||||
|
||||
if hover and button == 1 then
|
||||
local baseparent = self:GetBaseParent()
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -207,28 +207,28 @@ function newobject:mousereleased(x, y, button)
|
||||
|
||||
local state = loveframes.state
|
||||
local selfstate = self.state
|
||||
|
||||
|
||||
if state ~= selfstate then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
v:mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -236,16 +236,16 @@ end
|
||||
- desc: positions the object's columns
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:PositionColumns()
|
||||
|
||||
|
||||
local x = 0
|
||||
|
||||
|
||||
for k, v in ipairs(self.children) do
|
||||
v:SetPos(x, 0)
|
||||
x = x + v.width
|
||||
end
|
||||
|
||||
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -259,15 +259,15 @@ function newobject:AddColumn(name)
|
||||
local list = internals[1]
|
||||
local width = self.width
|
||||
local height = self.height
|
||||
|
||||
|
||||
loveframes.objects["columnlistheader"]:new(name, self)
|
||||
self:PositionColumns()
|
||||
|
||||
|
||||
list:SetSize(width, height)
|
||||
list:SetPos(0, 0)
|
||||
|
||||
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -279,10 +279,10 @@ function newobject:AddRow(...)
|
||||
local arg = {...}
|
||||
local internals = self.internals
|
||||
local list = internals[1]
|
||||
|
||||
|
||||
list:AddRow(arg)
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -293,7 +293,7 @@ function newobject:GetColumnSize()
|
||||
|
||||
local children = self.children
|
||||
local numchildren = #self.children
|
||||
|
||||
|
||||
if numchildren > 0 then
|
||||
local column = self.children[1]
|
||||
local colwidth = column.width
|
||||
@ -302,7 +302,7 @@ function newobject:GetColumnSize()
|
||||
else
|
||||
return 0, 0
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -310,31 +310,31 @@ end
|
||||
- desc: sets the object's size
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetSize(width, height, r1, r2)
|
||||
|
||||
|
||||
local internals = self.internals
|
||||
local list = internals[1]
|
||||
|
||||
|
||||
if r1 then
|
||||
self.width = self.parent.width * width
|
||||
else
|
||||
self.width = width
|
||||
end
|
||||
|
||||
|
||||
if r2 then
|
||||
self.height = self.parent.height * height
|
||||
else
|
||||
self.height = height
|
||||
end
|
||||
|
||||
|
||||
self:PositionColumns()
|
||||
|
||||
|
||||
list:SetSize(width, height)
|
||||
list:SetPos(0, 0)
|
||||
list:CalculateSize()
|
||||
list:RedoLayout()
|
||||
|
||||
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -342,25 +342,25 @@ end
|
||||
- desc: sets the object's width
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetWidth(width, relative)
|
||||
|
||||
|
||||
local internals = self.internals
|
||||
local list = internals[1]
|
||||
|
||||
|
||||
if relative then
|
||||
self.width = self.parent.width * width
|
||||
else
|
||||
self.width = width
|
||||
end
|
||||
|
||||
|
||||
self:PositionColumns()
|
||||
|
||||
|
||||
list:SetSize(width)
|
||||
list:SetPos(0, 0)
|
||||
list:CalculateSize()
|
||||
list:RedoLayout()
|
||||
|
||||
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -368,25 +368,25 @@ end
|
||||
- desc: sets the object's height
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetHeight(height, relative)
|
||||
|
||||
|
||||
local internals = self.internals
|
||||
local list = internals[1]
|
||||
|
||||
|
||||
if relative then
|
||||
self.height = self.parent.height * height
|
||||
else
|
||||
self.height = height
|
||||
end
|
||||
|
||||
|
||||
self:PositionColumns()
|
||||
|
||||
|
||||
list:SetSize(height)
|
||||
list:SetPos(0, 0)
|
||||
list:CalculateSize()
|
||||
list:RedoLayout()
|
||||
|
||||
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -398,10 +398,10 @@ function newobject:SetMaxColorIndex(num)
|
||||
|
||||
local internals = self.internals
|
||||
local list = internals[1]
|
||||
|
||||
|
||||
list.colorindexmax = num
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -412,10 +412,10 @@ function newobject:Clear()
|
||||
|
||||
local internals = self.internals
|
||||
local list = internals[1]
|
||||
|
||||
|
||||
list:Clear()
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -429,17 +429,17 @@ function newobject:SetAutoScroll(bool)
|
||||
local internals = self.internals
|
||||
local list = internals[1]
|
||||
local scrollbar = list:GetScrollBar()
|
||||
|
||||
|
||||
self.autoscroll = bool
|
||||
|
||||
|
||||
if list then
|
||||
if scrollbar then
|
||||
scrollbar.autoscroll = bool
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -452,7 +452,7 @@ function newobject:SetButtonScrollAmount(amount)
|
||||
self.buttonscrollamount = amount
|
||||
self.internals[1].buttonscrollamount = amount
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -463,7 +463,7 @@ end
|
||||
function newobject:GetButtonScrollAmount()
|
||||
|
||||
return self.buttonscrollamount
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -475,17 +475,17 @@ function newobject:SetMouseWheelScrollAmount(amount)
|
||||
self.mousewheelscrollamount = amount
|
||||
self.internals[1].mousewheelscrollamount = amount
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetMouseWheelScrollAmount()
|
||||
- desc: gets the scroll amount of the mouse wheel
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetButtonScrollAmount()
|
||||
function newobject:GetMouseWheelScrollAmount()
|
||||
|
||||
return self.mousewheelscrollamount
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -497,17 +497,17 @@ function newobject:SetColumnHeight(height)
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
local list = internals[1]
|
||||
|
||||
|
||||
self.columnheight = height
|
||||
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
v:SetHeight(height)
|
||||
end
|
||||
|
||||
|
||||
list:CalculateSize()
|
||||
list:RedoLayout()
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -520,7 +520,7 @@ function newobject:SetDTScrolling(bool)
|
||||
self.dtscrolling = bool
|
||||
self.internals[1].dtscrolling = bool
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -531,7 +531,7 @@ end
|
||||
function newobject:GetDTScrolling()
|
||||
|
||||
return self.dtscrolling
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -542,16 +542,16 @@ end
|
||||
function newobject:SelectRow(row, ctrl)
|
||||
|
||||
local selectionenabled = self.selectionenabled
|
||||
|
||||
|
||||
if not selectionenabled then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
local list = self.internals[1]
|
||||
local children = list.children
|
||||
local multiselect = self.multiselect
|
||||
local onrowselected = self.OnRowSelected
|
||||
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
if v == row then
|
||||
if v.selected and ctrl then
|
||||
@ -568,9 +568,9 @@ function newobject:SelectRow(row, ctrl)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -582,7 +582,7 @@ function newobject:DeselectRow(row)
|
||||
|
||||
row.selected = false
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -590,19 +590,19 @@ end
|
||||
- desc: gets the object's selected rows
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetSelectedRows()
|
||||
|
||||
|
||||
local rows = {}
|
||||
local list = self.internals[1]
|
||||
local children = list.children
|
||||
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
if v.selected then
|
||||
table.insert(rows, v)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return rows
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -614,7 +614,7 @@ function newobject:SetSelectionEnabled(bool)
|
||||
|
||||
self.selectionenabled = bool
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -625,7 +625,7 @@ end
|
||||
function newobject:GetSelectionEnabled()
|
||||
|
||||
return self.selectionenabled
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -637,7 +637,7 @@ function newobject:SetMultiselectEnabled(bool)
|
||||
|
||||
self.multiselect = bool
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -648,7 +648,7 @@ end
|
||||
function newobject:GetMultiselectEnabled()
|
||||
|
||||
return self.multiselect
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -658,15 +658,15 @@ end
|
||||
function newobject:RemoveColumn(id)
|
||||
|
||||
local children = self.children
|
||||
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
if k == id then
|
||||
v:Remove()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -676,15 +676,15 @@ end
|
||||
function newobject:SetColumnName(id, name)
|
||||
|
||||
local children = self.children
|
||||
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
if k == id then
|
||||
v.name = name
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -694,15 +694,15 @@ end
|
||||
function newobject:GetColumnName(id)
|
||||
|
||||
local children = self.children
|
||||
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
if k == id then
|
||||
return v.name
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return false
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -714,7 +714,7 @@ end
|
||||
modifications.
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SizeToChildren(max)
|
||||
|
||||
|
||||
local oldheight = self.height
|
||||
local list = self.internals[1]
|
||||
local listchildren = list.children
|
||||
@ -724,15 +724,15 @@ function newobject:SizeToChildren(max)
|
||||
local h = listchildren[1].height
|
||||
local c = #listchildren
|
||||
local height = buf + h*c
|
||||
|
||||
|
||||
if max then
|
||||
height = math.min(max, oldheight)
|
||||
height = math.min(max, oldheight)
|
||||
end
|
||||
|
||||
|
||||
self:SetSize(width, height)
|
||||
self:PositionColumns()
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -744,11 +744,11 @@ function newobject:RemoveRow(id)
|
||||
local list = self.internals[1]
|
||||
local listchildren = list.children
|
||||
local row = listchildren[id]
|
||||
|
||||
|
||||
if row then
|
||||
row:Remove()
|
||||
end
|
||||
|
||||
|
||||
list:CalculateSize()
|
||||
list:RedoLayout()
|
||||
return self
|
||||
@ -760,17 +760,17 @@ end
|
||||
- desc: sets a cell's text
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetCellText(text, rowid, columnid)
|
||||
|
||||
|
||||
local list = self.internals[1]
|
||||
local listchildren = list.children
|
||||
local row = listchildren[rowid]
|
||||
|
||||
|
||||
if row and row.columndata[columnid]then
|
||||
row.columndata[columnid] = text
|
||||
end
|
||||
|
||||
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -778,15 +778,15 @@ end
|
||||
- desc: gets a cell's text
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetCellText(rowid, columnid)
|
||||
|
||||
|
||||
local row = self.internals[1].children[rowid]
|
||||
|
||||
|
||||
if row and row.columndata[columnid] then
|
||||
return row.columndata[columnid]
|
||||
else
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -798,15 +798,15 @@ function newobject:SetRowColumnData(rowid, columndata)
|
||||
local list = self.internals[1]
|
||||
local listchildren = list.children
|
||||
local row = listchildren[rowid]
|
||||
|
||||
|
||||
if row then
|
||||
for k, v in ipairs(columndata) do
|
||||
row.columndata[k] = tostring(v)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -816,13 +816,13 @@ end
|
||||
function newobject:GetTotalColumnWidth()
|
||||
|
||||
local width = 0
|
||||
|
||||
|
||||
for k, v in ipairs(self.children) do
|
||||
width = width + v.width
|
||||
end
|
||||
|
||||
|
||||
return width
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -842,9 +842,9 @@ function newobject:SetColumnWidth(id, width)
|
||||
self.internals[1]:CalculateSize()
|
||||
self.internals[1]:RedoLayout()
|
||||
end
|
||||
|
||||
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -857,9 +857,9 @@ function newobject:GetColumnWidth(id)
|
||||
if column then
|
||||
return column.width
|
||||
end
|
||||
|
||||
|
||||
return false
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -872,22 +872,22 @@ function newobject:ResizeColumns()
|
||||
local children = self.children
|
||||
local width = 0
|
||||
local vbody = self.internals[1]:GetVerticalScrollBody()
|
||||
|
||||
|
||||
if vbody then
|
||||
width = (self:GetWidth() - vbody:GetWidth())/#children
|
||||
else
|
||||
width = self:GetWidth()/#children
|
||||
end
|
||||
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
v:SetWidth(width)
|
||||
self:PositionColumns()
|
||||
self.internals[1]:CalculateSize()
|
||||
self.internals[1]:RedoLayout()
|
||||
end
|
||||
|
||||
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -898,7 +898,7 @@ function newobject:SetDefaultColumnWidth(width)
|
||||
|
||||
self.defaultcolumnwidth = width
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -908,7 +908,7 @@ end
|
||||
function newobject:GetDefaultColumnWidth()
|
||||
|
||||
return self.defaultcolumnwidth
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -920,7 +920,7 @@ function newobject:SetColumnResizeEnabled(bool)
|
||||
|
||||
self.canresizecolumns = bool
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -931,7 +931,7 @@ end
|
||||
function newobject:GetColumnResizeEnabled()
|
||||
|
||||
return self.canresizecolumns
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -944,21 +944,21 @@ function newobject:SizeColumnToData(columnid)
|
||||
local column = self.children[columnid]
|
||||
local list = self.internals[1]
|
||||
local largest = 0
|
||||
|
||||
|
||||
for k, v in ipairs(list.children) do
|
||||
local width = v:GetFont():getWidth(self:GetCellText(k, columnid))
|
||||
if width > largest then
|
||||
largest = width + v.textx
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if largest <= 0 then
|
||||
largest = 10
|
||||
end
|
||||
|
||||
|
||||
self:SetColumnWidth(columnid, largest)
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -969,15 +969,15 @@ function newobject:SetColumnOrder(curid, newid)
|
||||
|
||||
local column = self.children[curid]
|
||||
local totalcolumns = #self.children
|
||||
|
||||
|
||||
if column and totalcolumns > 1 and newid <= totalcolumns and newid >= 1 then
|
||||
column:Remove()
|
||||
table.insert(self.children, newid, column)
|
||||
self:PositionColumns()
|
||||
end
|
||||
|
||||
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
|
@ -14,7 +14,6 @@ local newobject = loveframes.NewObject("grid", "loveframes_object_grid", true)
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:initialize()
|
||||
|
||||
self.type = "grid"
|
||||
self.width = 100
|
||||
self.height = 100
|
||||
@ -28,7 +27,9 @@ function newobject:initialize()
|
||||
self.itemautosize = false
|
||||
self.children = {}
|
||||
self.OnSizeChanged = nil
|
||||
|
||||
self.rowspans = {}
|
||||
self.colspans = {}
|
||||
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
@ -62,12 +63,10 @@ function newobject:update(dt)
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
|
||||
self.y = self.parent.y + self.staticy - (parent.offsety or 0)
|
||||
end
|
||||
|
||||
local cw = self.cellwidth + (self.cellpadding * 2)
|
||||
local ch = self.cellheight + (self.cellpadding * 2)
|
||||
local prevwidth = self.prevwidth
|
||||
local prevheight = self.prevheight
|
||||
|
||||
@ -78,24 +77,49 @@ function newobject:update(dt)
|
||||
local onsizechanged = self.OnSizeChanged
|
||||
self.prevwidth = self.width
|
||||
self.prevheight = self.height
|
||||
self:_update_children_position()
|
||||
if onsizechanged then
|
||||
onsizechanged(self)
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
local x = 0 + ((cw * v.gridcolumn) - cw ) + (cw/2 - v.width/2)
|
||||
local y = 0 + ((ch * v.gridrow) - ch) + (ch/2 - v.height/2)
|
||||
v.staticx = x
|
||||
v.staticy = y
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
|
||||
local update = self.Update
|
||||
if update then update(self, dt) end
|
||||
|
||||
end
|
||||
|
||||
function newobject:_update_children_position()
|
||||
for k, v in ipairs(self.children) do
|
||||
local rs, cs = self:GetCellSpanSize(v.gridrow, v.gridcolumn)
|
||||
local csw = cs * self.cellwidth + (cs * self.cellpadding * 2)
|
||||
local csh = rs * self.cellheight + (rs * self.cellpadding * 2)
|
||||
|
||||
local cw = self.cellwidth + (self.cellpadding * 2)
|
||||
local ch = self.cellheight + (self.cellpadding * 2)
|
||||
|
||||
local x
|
||||
local y = ((ch * v.gridrow) - ch) + (csh/2 - v.height/2)
|
||||
|
||||
if
|
||||
v.align == 'center' then
|
||||
x = (cw * (v.gridcolumn - 1)) + (csw/2 - v.width/2)
|
||||
elseif
|
||||
v.align == 'right' then
|
||||
x = (cw * (v.gridcolumn - 1)) + (csw - v.width) - self.cellpadding
|
||||
elseif
|
||||
v.align == 'left' then
|
||||
x = self.cellpadding + (cw * (v.gridcolumn - 1))
|
||||
end
|
||||
|
||||
v.staticx = x
|
||||
v.staticy = y
|
||||
end
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
@ -157,31 +181,105 @@ function newobject:mousereleased(x, y, button)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: RowSpanAt(row, col, size)
|
||||
- desc: expands the size of the row at position
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:RowSpanAt(row, col, size)
|
||||
|
||||
self.colspans[col] = self.colspans[col] or {}
|
||||
local colsize = self.colspans[col][row]
|
||||
local s = colsize or 1
|
||||
|
||||
for i = col, col + s - 1 do
|
||||
for j = row, row + size - 1 do
|
||||
self.rowspans[i] = self.rowspans[i] or {}
|
||||
self.colspans[i] = self.colspans[i] or {}
|
||||
|
||||
self.rowspans[i][j] = -1
|
||||
self.colspans[i][j] = -1
|
||||
end
|
||||
end
|
||||
|
||||
self.rowspans[col][row] = size
|
||||
self.colspans[col][row] = colsize
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: ColSpanAt(row, col, size)
|
||||
- desc: expands the size of the column at position
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:ColSpanAt(row, col, size)
|
||||
|
||||
self.rowspans[col] = self.rowspans[col] or {}
|
||||
local rowsize = self.rowspans[col][row]
|
||||
local s = rowsize or 1
|
||||
|
||||
for i = col, col + size - 1 do
|
||||
for j = row, row + s - 1 do
|
||||
self.rowspans[i] = self.rowspans[i] or {}
|
||||
self.colspans[i] = self.colspans[i] or {}
|
||||
|
||||
self.rowspans[i][j] = -1
|
||||
self.colspans[i][j] = -1
|
||||
end
|
||||
end
|
||||
|
||||
self.rowspans[col][row] = rowsize
|
||||
self.colspans[col][row] = size
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetCellSpanSize(row, col, size)
|
||||
- desc: get span size of cell
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetCellSpanSize(row, col)
|
||||
|
||||
self.rowspans[col] = self.rowspans[col] or {}
|
||||
local rs = self.rowspans[col][row] or 1
|
||||
self.colspans[col] = self.colspans[col] or {}
|
||||
local cs = self.colspans[col][row] or 1
|
||||
return rs, cs
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: AddItem(object, row, column)
|
||||
- desc: adds and item to the object
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:AddItem(object, row, column)
|
||||
function newobject:AddItem(object, row, col, align)
|
||||
|
||||
local itemautosize = self.itemautosize
|
||||
local children = self.children
|
||||
|
||||
|
||||
object:Remove()
|
||||
|
||||
|
||||
table.insert(children, object)
|
||||
object.parent = self
|
||||
object.gridrow = row
|
||||
object.gridcolumn = column
|
||||
|
||||
object.gridcolumn = col
|
||||
object.align = align or 'center'
|
||||
|
||||
if itemautosize then
|
||||
local cw = self.cellwidth + (self.cellpadding * 2)
|
||||
local ch = self.cellheight + (self.cellpadding * 2)
|
||||
if object.type == 'text' or object.type == 'checkbox' then
|
||||
return self
|
||||
end
|
||||
local rs, cs = self:GetCellSpanSize(row, col)
|
||||
local cw = cs * self.cellwidth + (self.cellpadding * 2)
|
||||
local ch = rs * self.cellheight + (self.cellpadding * 2)
|
||||
object.width = cw - (self.cellpadding * 2)
|
||||
object.height = ch - (self.cellpadding * 2)
|
||||
|
||||
if object.CalculateSize then object:CalculateSize() end
|
||||
if object.RedoLayout then object:RedoLayout() end
|
||||
end
|
||||
|
||||
|
||||
return self
|
||||
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
|
@ -62,8 +62,8 @@ function newobject:update(dt)
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
|
||||
self.y = self.parent.y + self.staticy - (parent.offsety or 0)
|
||||
end
|
||||
|
||||
if update then
|
||||
|
@ -77,8 +77,8 @@ function newobject:update(dt)
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
|
||||
self.y = self.parent.y + self.staticy - (parent.offsety or 0)
|
||||
end
|
||||
|
||||
if update then
|
||||
|
@ -55,8 +55,8 @@ function newobject:update(dt)
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
|
||||
self.y = self.parent.y + self.staticy - (parent.offsety or 0)
|
||||
end
|
||||
|
||||
if parentinternals[1] ~= self then
|
||||
|
@ -53,9 +53,10 @@ function newobject:update(dt)
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
local hover = self.hover
|
||||
self:CheckHover()
|
||||
|
||||
local parent = self.parent
|
||||
local option_type = self.option_type
|
||||
local activated = self.activated
|
||||
@ -96,8 +97,8 @@ function newobject:update(dt)
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
|
||||
self.y = self.parent.y + self.staticy - (parent.offsety or 0)
|
||||
end
|
||||
|
||||
if update then
|
||||
@ -111,7 +112,7 @@ end
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousepressed(x, y, button)
|
||||
|
||||
|
||||
local state = loveframes.state
|
||||
local selfstate = self.state
|
||||
|
||||
@ -125,6 +126,7 @@ function newobject:mousepressed(x, y, button)
|
||||
return
|
||||
end
|
||||
|
||||
self.down = true
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -148,7 +150,7 @@ function newobject:mousereleased(x, y, button)
|
||||
|
||||
local hover = self.hover
|
||||
local option_type = self.option_type
|
||||
if hover and option_type ~= "divider" and button == 1 then
|
||||
if hover and option_type ~= "divider" and button == 1 and self.down then
|
||||
local func = self.func
|
||||
if func then
|
||||
local text = self.text
|
||||
@ -156,8 +158,9 @@ function newobject:mousereleased(x, y, button)
|
||||
end
|
||||
local basemenu = self.parent:GetBaseMenu()
|
||||
basemenu:SetVisible(false)
|
||||
self.hover = false
|
||||
end
|
||||
|
||||
self.down = false
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
|
@ -125,8 +125,9 @@ function newobject:initialize(parent, bartype)
|
||||
-- apply template properties to the object
|
||||
loveframes.ApplyTemplatesToObject(self)
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
self:SetAlwaysUpdate(true)
|
||||
end
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
|
@ -145,10 +145,12 @@ function newobject:mousepressed(x, y, button)
|
||||
|
||||
if self.hover and button == 1 then
|
||||
local time = os.time()
|
||||
if self.lastclick + 0.40 > time then
|
||||
if self.lastclick + 0.30 > time then
|
||||
self.open = not self.open
|
||||
self.lastclick = 0
|
||||
else
|
||||
self.lastclick = time
|
||||
end
|
||||
self.lastclick = time
|
||||
local onselectnode = self.tree.OnSelectNode
|
||||
self.tree.selectednode = self
|
||||
if onselectnode then
|
||||
@ -181,6 +183,16 @@ function newobject:mousereleased(x, y, button)
|
||||
v:mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
if self.hover then
|
||||
if button == 2 then
|
||||
local onselectnoderightclick = self.tree.OnSelectNodeRightClick
|
||||
self.tree.selectednode = self
|
||||
if onselectnoderightclick then
|
||||
onselectnoderightclick(self.parent, self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
@ -271,6 +283,13 @@ function newobject:RemoveNode(id)
|
||||
|
||||
end
|
||||
|
||||
function newobject:SetSelected()
|
||||
|
||||
self.tree.selectednode = self
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetOpen(bool)
|
||||
- desc: sets whether or not the object is open
|
||||
|
@ -53,8 +53,8 @@ function newobject:update(dt)
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
|
||||
self.y = self.parent.y + self.staticy - (parent.offsety or 0)
|
||||
end
|
||||
|
||||
if update then
|
||||
@ -98,8 +98,8 @@ function newobject:mousepressed(x, y, button)
|
||||
end
|
||||
end
|
||||
self.parent:SetOpen(bool)
|
||||
print("!")
|
||||
print(self.parent.level)
|
||||
--print("!")
|
||||
--print(self.parent.level)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -38,7 +38,10 @@ function newobject:initialize()
|
||||
self.internals = {}
|
||||
self.children = {}
|
||||
self.OnScroll = nil
|
||||
|
||||
|
||||
self.scrollx = loveframes.objects["scrollbody"]:new(self, "horizontal")
|
||||
self.scrolly = loveframes.objects["scrollbody"]:new(self, "vertical")
|
||||
|
||||
self:SetDrawFunc()
|
||||
end
|
||||
|
||||
@ -56,7 +59,7 @@ function newobject:update(dt)
|
||||
end
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if not visible then
|
||||
if not alwaysupdate then
|
||||
@ -76,34 +79,35 @@ function newobject:update(dt)
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
|
||||
self.y = self.parent.y + self.staticy - (parent.offsety or 0)
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:update(dt)
|
||||
for _, p in pairs(self:GetParents()) do
|
||||
--[[for _, p in pairs(self:GetParents()) do
|
||||
v.x = v.x - (p.offsetx or 0)
|
||||
v.y = v.y - (p.offsety or 0)
|
||||
end
|
||||
end]]
|
||||
end
|
||||
|
||||
local x = self.x
|
||||
local y = self.y
|
||||
local width = self.width
|
||||
local height = self.height
|
||||
local offsetx = self.offsetx
|
||||
local offsety = self.offsety
|
||||
local width = self.width
|
||||
local height = self.height
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
v:update(dt)
|
||||
v:SetClickBounds(x, y, width, height)
|
||||
v.x = (v.parent.x + v.staticx) - offsetx
|
||||
v.y = (v.parent.y + v.staticy) - offsety
|
||||
for _, p in pairs(self:GetParents()) do
|
||||
--v.x = (v.parent.x + v.staticx) - offsetx
|
||||
--v.y = (v.parent.y + v.staticy) - offsety
|
||||
|
||||
--[[for _, p in pairs(self:GetParents()) do
|
||||
v.x = v.x - (p.offsetx or 0)
|
||||
v.y = v.y - (p.offsety or 0)
|
||||
end
|
||||
end]]
|
||||
if display == "vertical" then
|
||||
if v.lastheight ~= v.height then
|
||||
self:CalculateSize()
|
||||
@ -135,9 +139,6 @@ function newobject:draw()
|
||||
local y = self.y
|
||||
local width = self.width
|
||||
local height = self.height
|
||||
local stencilfunc = function()
|
||||
love.graphics.rectangle("fill", x, y, width, height)
|
||||
end
|
||||
|
||||
self:SetDrawOrder()
|
||||
|
||||
@ -145,10 +146,10 @@ function newobject:draw()
|
||||
if drawfunc then
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
love.graphics.stencil(stencilfunc)
|
||||
love.graphics.setStencilTest("greater", 0)
|
||||
|
||||
local scx, scy, scw, sch = love.graphics.getScissor()
|
||||
|
||||
love.graphics.intersectScissor(x, y, width, height)
|
||||
|
||||
local children = self.children
|
||||
if children then
|
||||
for k, v in ipairs(children) do
|
||||
@ -158,8 +159,8 @@ function newobject:draw()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
love.graphics.setStencilTest()
|
||||
|
||||
love.graphics.setScissor(scx, scy, scw, sch)
|
||||
|
||||
local drawfunc = self.DrawOver or self.drawoverfunc
|
||||
if drawfunc then
|
||||
@ -348,15 +349,16 @@ function newobject:CalculateSize()
|
||||
if itemheight > height then
|
||||
self.extraheight = itemheight - height
|
||||
if not vbar then
|
||||
local scrollbar = loveframes.objects["scrollbody"]:new(self, display)
|
||||
table.insert(internals, scrollbar)
|
||||
table.insert(internals, self.scrolly)
|
||||
self.vbar = true
|
||||
self:GetScrollBar().autoscroll = self.autoscroll
|
||||
local bar = self:GetScrollBar()
|
||||
bar.autoscroll = self.autoscroll
|
||||
bar:ScrollTo(0)
|
||||
self.scrolly:update(0)
|
||||
end
|
||||
else
|
||||
if vbar then
|
||||
local bar = internals[1]
|
||||
bar:Remove()
|
||||
self.scrolly:Remove()
|
||||
self.vbar = false
|
||||
self.offsety = 0
|
||||
end
|
||||
@ -416,13 +418,13 @@ function newobject:RedoLayout()
|
||||
end
|
||||
|
||||
if #children > 0 then
|
||||
local scrollbar = self:GetScrollBar()
|
||||
if display == "vertical" then
|
||||
if horizontalstacking then
|
||||
local curwidth = padding
|
||||
local curheight = padding
|
||||
local maxwidth = self.width - padding * 2
|
||||
local prevheight = 0
|
||||
local scrollbar = self:GetScrollBar()
|
||||
if scrollbar then
|
||||
maxwidth = maxwidth - scrollbar.width
|
||||
end
|
||||
@ -451,7 +453,7 @@ function newobject:RedoLayout()
|
||||
v.staticx = padding
|
||||
v.staticy = starty
|
||||
v.lastheight = itemheight
|
||||
if vbar then
|
||||
if vbar and scrollbar.visible then
|
||||
if itemwidth + padding > (width - scrollbodywidth) then
|
||||
v:SetWidth((width - scrollbodywidth) - (padding * 2))
|
||||
end
|
||||
@ -476,7 +478,7 @@ function newobject:RedoLayout()
|
||||
local retainsize = v.retainsize
|
||||
v.staticx = startx
|
||||
v.staticy = padding
|
||||
if hbar then
|
||||
if hbar and scrollbar.visible then
|
||||
if itemheight + padding > (height - scrollbodyheight) then
|
||||
v:SetHeight((height - scrollbodyheight) - (padding * 2))
|
||||
end
|
||||
@ -743,7 +745,7 @@ end
|
||||
- func: GetMouseWheelScrollAmount()
|
||||
- desc: gets the scroll amount of the mouse wheel
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetButtonScrollAmount()
|
||||
function newobject:GetMouseWheelScrollAmount()
|
||||
|
||||
return self.mousewheelscrollamount
|
||||
|
||||
|
@ -60,8 +60,8 @@ function newobject:update(dt)
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
|
||||
self.y = self.parent.y + self.staticy - (parent.offsety or 0)
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
@ -120,7 +120,6 @@ end
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:mousepressed(x, y, button)
|
||||
|
||||
local state = loveframes.state
|
||||
local selfstate = self.state
|
||||
|
||||
@ -133,7 +132,11 @@ function newobject:mousepressed(x, y, button)
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
local internals = self.internals
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
|
@ -65,8 +65,8 @@ function newobject:update(dt)
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
|
||||
self.y = self.parent.y + self.staticy - (parent.offsety or 0)
|
||||
end
|
||||
|
||||
if update then
|
||||
@ -251,6 +251,21 @@ function newobject:GetChoice()
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetChoiceIndex()
|
||||
- desc: gets the current choice index
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetChoiceIndex()
|
||||
|
||||
local choices = self.choices
|
||||
for i, v in ipairs(choices) do
|
||||
if self.choice == v then
|
||||
return i
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetText(text)
|
||||
- desc: sets the object's text
|
||||
@ -310,7 +325,7 @@ end
|
||||
- func: GetMouseWheelScrollAmount()
|
||||
- desc: gets the scroll amount of the mouse wheel
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetButtonScrollAmount()
|
||||
function newobject:GetMouseWheelScrollAmount()
|
||||
|
||||
return self.mousewheelscrollamount
|
||||
|
||||
|
@ -109,8 +109,8 @@ function newobject:update(dt)
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
|
||||
self.y = self.parent.y + self.staticy - (parent.offsety or 0)
|
||||
end
|
||||
|
||||
-- completion check
|
||||
|
@ -80,8 +80,8 @@ function newobject:update(dt)
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
|
||||
self.y = self.parent.y + self.staticy - (parent.offsety or 0)
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
@ -642,7 +642,7 @@ end
|
||||
- func: GetMouseWheelScrollAmount()
|
||||
- desc: gets the scroll amount of the mouse wheel
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetButtonScrollAmount()
|
||||
function newobject:GetMouseWheelScrollAmount()
|
||||
|
||||
return self.mousewheelscrollamount
|
||||
|
||||
|
@ -122,13 +122,13 @@ function newobject:update(dt)
|
||||
end
|
||||
self.linkcol = linkcol
|
||||
end
|
||||
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
|
||||
self.y = self.parent.y + self.staticy - (parent.offsety or 0)
|
||||
end
|
||||
|
||||
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
@ -567,7 +567,6 @@ function newobject:RunKey(key, istext)
|
||||
local numlines = #lines
|
||||
local curline = lines[line]
|
||||
local text = curline
|
||||
local ckey = ""
|
||||
local font = self.font
|
||||
local swidth = self.width
|
||||
local textoffsetx = self.textoffsetx
|
||||
@ -663,14 +662,14 @@ function newobject:RunKey(key, istext)
|
||||
|
||||
-- key input checking system
|
||||
if key == "backspace" then
|
||||
ckey = key
|
||||
if alltextselected then
|
||||
self:Clear()
|
||||
self.alltextselected = false
|
||||
indicatornum = self.indicatornum
|
||||
else
|
||||
local removed_text = ''
|
||||
if text ~= "" and indicatornum ~= 0 then
|
||||
text = self:RemoveFromText(indicatornum)
|
||||
text, removed_text = self:RemoveFromText(indicatornum)
|
||||
self:MoveIndicator(-1)
|
||||
lines[line] = text
|
||||
end
|
||||
@ -693,9 +692,9 @@ function newobject:RunKey(key, istext)
|
||||
local cwidth = 0
|
||||
if masked then
|
||||
local maskchar = self.maskchar
|
||||
cwidth = font:getWidth(loveframes.utf8.gsub(text, ".", maskchar))
|
||||
cwidth = font:getWidth(loveframes.utf8.gsub(removed_text, ".", maskchar))
|
||||
else
|
||||
cwidth = font:getWidth(text)
|
||||
cwidth = font:getWidth(removed_text)
|
||||
end
|
||||
if self.offsetx > 0 then
|
||||
self.offsetx = self.offsetx - cwidth
|
||||
@ -707,7 +706,6 @@ function newobject:RunKey(key, istext)
|
||||
if not editable then
|
||||
return
|
||||
end
|
||||
ckey = key
|
||||
if alltextselected then
|
||||
self:Clear()
|
||||
self.alltextselected = false
|
||||
@ -727,7 +725,6 @@ function newobject:RunKey(key, istext)
|
||||
end
|
||||
end
|
||||
elseif key == "return" or key == "kpenter" then
|
||||
ckey = key
|
||||
-- call onenter if it exists
|
||||
if onenter then
|
||||
onenter(self, text)
|
||||
@ -765,7 +762,6 @@ function newobject:RunKey(key, istext)
|
||||
if alltextselected then
|
||||
return
|
||||
end
|
||||
ckey = key
|
||||
self.lines[self.line] = self:AddIntoText(self.tabreplacement, self.indicatornum)
|
||||
self:MoveIndicator(loveframes.utf8.len(self.tabreplacement))
|
||||
end
|
||||
@ -1031,9 +1027,10 @@ function newobject:RemoveFromText(p)
|
||||
local curline = lines[line]
|
||||
local text = curline
|
||||
local part1 = loveframes.utf8.sub(text, 1, p - 1)
|
||||
local removed_part = loveframes.utf8.sub(text, p, p + 1)
|
||||
local part2 = loveframes.utf8.sub(text, p + 1)
|
||||
local new = part1 .. part2
|
||||
return new
|
||||
return new, removed_part
|
||||
|
||||
end
|
||||
|
||||
|
@ -66,8 +66,8 @@ function newobject:update(dt)
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if parent ~= base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
|
||||
self.y = self.parent.y + self.staticy - (parent.offsety or 0)
|
||||
end
|
||||
|
||||
self.itemwidth = 0
|
||||
@ -174,6 +174,8 @@ function newobject:draw()
|
||||
stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height - 16) end
|
||||
elseif self.vbar and self.hbar then
|
||||
stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width - 16, self.height - 16) end
|
||||
else
|
||||
stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height) end
|
||||
end
|
||||
|
||||
self:SetDrawOrder()
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 212 B After Width: | Height: | Size: 177 B |
Binary file not shown.
Before Width: | Height: | Size: 223 B After Width: | Height: | Size: 176 B |
@ -853,7 +853,7 @@ function skin.multichoice(object)
|
||||
skin.PrintText(choice, x + 5, y + height/2 - theight/2)
|
||||
end
|
||||
|
||||
love.graphics.draw(image, x + width - 20, y + 5)
|
||||
love.graphics.draw(image, x + width - 20, y + (height - 16) / 2)
|
||||
|
||||
love.graphics.setColor(border)
|
||||
skin.OutlinedRectangle(x, y, width, height)
|
||||
@ -1540,8 +1540,6 @@ function skin.grid(object)
|
||||
local skin = object:GetSkin()
|
||||
local x = object:GetX()
|
||||
local y = object:GetY()
|
||||
local width = object:GetWidth()
|
||||
local height = object:GetHeight()
|
||||
|
||||
--love.graphics.setColor(colors.hl4)
|
||||
--love.graphics.rectangle("fill", x-1, y-1, width+2, height+2)
|
||||
@ -1551,24 +1549,37 @@ function skin.grid(object)
|
||||
local cw = object.cellwidth + (object.cellpadding * 2)
|
||||
local ch = object.cellheight + (object.cellpadding * 2)
|
||||
|
||||
for i=1, object.rows do
|
||||
for n=1, object.columns do
|
||||
local ovt = false
|
||||
local ovl = false
|
||||
if i > 1 then
|
||||
ovt = true
|
||||
local row = 1
|
||||
while row <= object.rows do
|
||||
local col = 1
|
||||
while col <= object.columns do
|
||||
local cs = (object.colspans[col] or {})[row] or 1
|
||||
local rs = (object.rowspans[col] or {})[row] or 1
|
||||
|
||||
if rs ~= -1 and cs ~= -1 then
|
||||
local ovt = false
|
||||
local ovl = false
|
||||
if row > 1 then
|
||||
ovt = true
|
||||
end
|
||||
if col > 1 then
|
||||
ovl = true
|
||||
end
|
||||
|
||||
local x = cx + (col - 1) * cw
|
||||
local y = cy + (row - 1) * ch
|
||||
local w = cw * cs
|
||||
local h = ch * rs
|
||||
|
||||
love.graphics.setColor(skin.controls.color_back1)
|
||||
love.graphics.rectangle("fill", x, y, w, h)
|
||||
love.graphics.setColor(skin.controls.color_back3)
|
||||
skin.OutlinedRectangle(x, y, w, h, ovt, false, ovl, false)
|
||||
end
|
||||
if n > 1 then
|
||||
ovl = true
|
||||
end
|
||||
love.graphics.setColor(skin.controls.color_back1)
|
||||
love.graphics.rectangle("fill", cx, cy, cw, ch)
|
||||
love.graphics.setColor(skin.controls.color_back3)
|
||||
skin.OutlinedRectangle(cx, cy, cw, ch, ovt, false, ovl, false)
|
||||
cx = cx + cw
|
||||
col = col + 1
|
||||
|
||||
end
|
||||
cx = x
|
||||
cy = cy + ch
|
||||
row = row + 1
|
||||
end
|
||||
|
||||
end
|
||||
@ -1723,15 +1734,18 @@ function skin.treenodebutton(object)
|
||||
local leftpadding = 15 * object.parent.level
|
||||
local image
|
||||
|
||||
local fore = skin.controls.color_fore0
|
||||
if object.parent.tree.selectednode == object.parent then
|
||||
fore = {1, 1, 1, 1}
|
||||
end
|
||||
if object.parent.open then
|
||||
image = skin.images["tree-node-button-close.png"]
|
||||
else
|
||||
image = skin.images["tree-node-button-open.png"]
|
||||
end
|
||||
|
||||
--image:setFilter("nearest", "nearest")
|
||||
|
||||
love.graphics.setColor(skin.controls.color_image)
|
||||
love.graphics.setColor(fore)
|
||||
--love.graphics.setColor(skin.controls.color_image)
|
||||
love.graphics.draw(image, object.x, object.y)
|
||||
|
||||
object:SetPos(2 + leftpadding, 3)
|
||||
|
Loading…
Reference in New Issue
Block a user