Added grid span feature, fixes

- Grid span feature
- Added offset from parent to update each element (for correct positioning relative to each parent)
- OnClick event rework
- Multichoice: new function GetChoiceIndex
- Added positioning of items in the grid using the align parameter in AddItem
- Correct positioning of multichoice-arrow image
- Fixed stencil test for list
- Fixed a bug that can trigger OnClick events again, even if the mouse cursor is not already hovering over the object
- Fixed a bug where "backspace" leads to an incorrect positioning of the entry if the text is overflowed 'textinput' element
This commit is contained in:
rozenmad 2021-09-05 20:46:49 +03:00
parent ad3d8a5042
commit edab2be4c7
29 changed files with 515 additions and 316 deletions

View File

@ -12,23 +12,42 @@ function example.func(loveframes, centerarea)
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
grid:SetItemAutoSize(true)
for i=1, 5 do
for n=1, 5 do
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:SetSize(15, 15)
button:SetText(id)
grid:AddItem(button, i, n)
id = id + 1
end
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))

View File

@ -244,13 +244,10 @@ 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
end
--[[---------------------------------------------------------
- func: wheelmoved(x, y)
- desc: called when the player moves a mouse wheel

View File

@ -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,11 +1066,27 @@ 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
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

View File

@ -26,8 +26,11 @@ function newobject:initialize()
self.toggleable = false
self.toggle = false
self.OnClick = nil
self.OnMouseOver = nil
self.OnMouseOut = nil
self.groupIndex = 0
self.checked = false
self.mouseover = false
self:SetDrawFunc()
end
@ -57,18 +60,27 @@ 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
local update = self.Update
local onmouseover = self.OnMouseOver
local onmouseout = self.OnMouseOut
if not hover then
self.down = false
if downobject == self then
self.hover = true
end
if onmouseout and self.mouseover then
onmouseout(self)
self.mouseover = false
end
else
if onmouseover and not self.mouseover then
onmouseover(self)
self.mouseover = true
end
if downobject == self then
self.down = true
end
@ -76,8 +88,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 +119,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 +128,7 @@ function newobject:mousepressed(x, y, button)
loveframes.downobject = self
end
self.pressed_button = button
end
--[[---------------------------------------------------------
@ -143,7 +156,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 +172,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

View File

@ -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

View File

@ -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

View File

@ -75,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
for k, v in ipairs(internals) do
@ -482,7 +482,7 @@ end
- func: GetMouseWheelScrollAmount()
- desc: gets the scroll amount of the mouse wheel
--]]---------------------------------------------------------
function newobject:GetButtonScrollAmount()
function newobject:GetMouseWheelScrollAmount()
return self.mousewheelscrollamount

View File

@ -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,6 +27,8 @@ 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,16 +77,13 @@ 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
@ -96,6 +92,34 @@ function newobject:update(dt)
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,11 +181,77 @@ 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
@ -171,13 +261,21 @@ function newobject:AddItem(object, row, column)
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

View File

@ -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

View File

@ -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

View File

@ -263,7 +263,7 @@ function newobject:CalculateSize()
end
self.extraheight = self.itemheight - height
if not self.vbar then
local newbar = loveframes.objects["scrollbody"]:new(self, "vertical")
local newbar = loveframes.objects["scrollbody"]:new(self, "vertical", true)
table.insert(self.internals, newbar)
self.vbar = true
newbar:GetScrollBar().autoscroll = parent.autoscroll
@ -290,7 +290,7 @@ function newobject:CalculateSize()
end
self.extrawidth = self.itemwidth - width
if not self.hbar then
local newbar = loveframes.objects["scrollbody"]:new(self, "horizontal")
local newbar = loveframes.objects["scrollbody"]:new(self, "horizontal", true)
table.insert(self.internals, newbar)
self.hbar = true
self.itemheight = self.itemheight + newbar.height

View File

@ -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

View File

@ -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
@ -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
--[[---------------------------------------------------------

View File

@ -341,7 +341,7 @@ function newobject:CalculateSize()
if self.itemheight > height then
self.extraheight = self.itemheight - height
if not vbar then
local scroll = loveframes.objects["scrollbody"]:new(self, "vertical")
local scroll = loveframes.objects["scrollbody"]:new(self, "vertical", true)
table.insert(self.internals, scroll)
self.vbar = true
end

View File

@ -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

View File

@ -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
end
self.lastclick = 0
else
self.lastclick = time
end
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

View File

@ -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

View File

@ -39,6 +39,9 @@ function newobject:initialize()
self.children = {}
self.OnScroll = nil
self.scrollx = loveframes.objects["scrollbody"]:new(self, "horizontal")
self.scrolly = loveframes.objects["scrollbody"]:new(self, "vertical")
self:SetDrawFunc()
end
@ -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,9 +146,9 @@ function newobject:draw()
if drawfunc then
drawfunc(self)
end
local scx, scy, scw, sch = love.graphics.getScissor()
love.graphics.stencil(stencilfunc)
love.graphics.setStencilTest("greater", 0)
love.graphics.intersectScissor(x, y, width, height)
local children = self.children
if children then
@ -159,7 +160,7 @@ function newobject:draw()
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

View File

@ -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
@ -134,6 +133,10 @@ function newobject:mousepressed(x, y, button)
return
end
local internals = self.internals
for k, v in ipairs(internals) do
v:mousepressed(x, y, button)
end
end
--[[---------------------------------------------------------

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -125,8 +125,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

View File

@ -183,7 +183,7 @@ function newobject:update(dt)
local itemheight = self.itemheight
if itemheight > height then
if not vbar then
local scrollbody = loveframes.objects["scrollbody"]:new(self, "vertical")
local scrollbody = loveframes.objects["scrollbody"]:new(self, "vertical", true)
scrollbody.internals[1].internals[1].autoscroll = self.autoscroll
table.insert(self.internals, scrollbody)
self.vbar = true
@ -211,7 +211,7 @@ function newobject:update(dt)
if itemwidth > width then
if not hbar then
local scrollbody = loveframes.objects["scrollbody"]:new(self, "horizontal")
local scrollbody = loveframes.objects["scrollbody"]:new(self, "horizontal", true)
scrollbody.internals[1].internals[1].autoscroll = self.autoscroll
table.insert(self.internals, scrollbody)
self.hbar = true
@ -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

View File

@ -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
@ -92,7 +92,7 @@ function newobject:update(dt)
if self.itemheight > self.height then
if not self.vbar then
local scrollbody = loveframes.objects["scrollbody"]:new(self, "vertical")
local scrollbody = loveframes.objects["scrollbody"]:new(self, "vertical", true)
table.insert(self.internals, scrollbody)
self.vbar = true
if self.hbar then
@ -119,7 +119,7 @@ function newobject:update(dt)
if self.itemwidth > self.width then
if not self.hbar then
local scrollbody = loveframes.objects["scrollbody"]:new(self, "horizontal")
local scrollbody = loveframes.objects["scrollbody"]:new(self, "horizontal", true)
table.insert(self.internals, scrollbody)
self.hbar = true
if self.vbar then
@ -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

View File

@ -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 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 i > 1 then
if row > 1 then
ovt = true
end
if n > 1 then
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", cx, cy, cw, ch)
love.graphics.rectangle("fill", x, y, w, h)
love.graphics.setColor(skin.controls.color_back3)
skin.OutlinedRectangle(cx, cy, cw, ch, ovt, false, ovl, false)
cx = cx + cw
skin.OutlinedRectangle(x, y, w, h, ovt, false, ovl, false)
end
cx = x
cy = cy + ch
col = col + 1
end
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)