mirror of
https://github.com/linux-man/LoveFrames.git
synced 2024-11-18 16:04:22 +00:00
Use wheelmoved function
This commit is contained in:
parent
a5fd850adb
commit
4ef34ccc5b
11
init.lua
11
init.lua
@ -244,6 +244,17 @@ function loveframes.mousereleased(x, y, button)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: wheelmoved(x, y)
|
||||
- desc: called when the player moves a mouse wheel
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.wheelmoved(x, y)
|
||||
|
||||
local base = loveframes.base
|
||||
base:wheelmoved(x, y)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: keypressed(key, isrepeat)
|
||||
- desc: called when the player presses a key
|
||||
|
@ -164,6 +164,41 @@ function newobject:mousereleased(x, y, button)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: wheelmoved(x, y)
|
||||
- desc: called when the player moves a mouse wheel
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:wheelmoved(x, y)
|
||||
|
||||
local state = loveframes.state
|
||||
local selfstate = self.state
|
||||
|
||||
if state ~= selfstate then
|
||||
return
|
||||
end
|
||||
|
||||
local visible = self.visible
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
|
||||
if not visible then
|
||||
return
|
||||
end
|
||||
|
||||
if children then
|
||||
for k, v in ipairs(children) do
|
||||
v:wheelmoved(x, y)
|
||||
end
|
||||
end
|
||||
|
||||
if internals then
|
||||
for k, v in ipairs(internals) do
|
||||
v:wheelmoved(x, y)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: keypressed(key, isrepeat)
|
||||
- desc: called when the player presses a key
|
||||
|
@ -168,32 +168,6 @@ function newobject:mousepressed(x, y, button)
|
||||
end
|
||||
end
|
||||
|
||||
local bar = false
|
||||
if self.vbar and self.hbar then
|
||||
bar = self:GetVerticalScrollBody():GetScrollBar()
|
||||
elseif self.vbar and not self.hbar then
|
||||
bar = self:GetVerticalScrollBody():GetScrollBar()
|
||||
elseif not self.var and self.hbar then
|
||||
bar = self:GetHorizontalScrollBody():GetScrollBar()
|
||||
end
|
||||
|
||||
if self:IsTopList() and bar then
|
||||
if self.dtscrolling then
|
||||
local dt = love.timer.getDelta()
|
||||
if button == "wu" then
|
||||
bar:Scroll(-scrollamount * dt)
|
||||
elseif button == "wd" then
|
||||
bar:Scroll(scrollamount * dt)
|
||||
end
|
||||
else
|
||||
if button == "wu" then
|
||||
bar:Scroll(-scrollamount)
|
||||
elseif button == "wd" then
|
||||
bar:Scroll(scrollamount)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
@ -223,6 +197,41 @@ function newobject:mousereleased(x, y, button)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: wheelmoved(x, y)
|
||||
- desc: called when the player moves a mouse wheel
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:wheelmoved(x, y)
|
||||
|
||||
local scrollamount = self.mousewheelscrollamount
|
||||
|
||||
if self.hover and button == 1 then
|
||||
local baseparent = self:GetBaseParent()
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
end
|
||||
|
||||
local bar = false
|
||||
if self.vbar and self.hbar then
|
||||
bar = self:GetVerticalScrollBody():GetScrollBar()
|
||||
elseif self.vbar and not self.hbar then
|
||||
bar = self:GetVerticalScrollBody():GetScrollBar()
|
||||
elseif not self.vbar and self.hbar then
|
||||
bar = self:GetHorizontalScrollBody():GetScrollBar()
|
||||
end
|
||||
|
||||
if self:IsTopList() and bar then
|
||||
if self.dtscrolling then
|
||||
local dt = love.timer.getDelta()
|
||||
bar:Scroll(-y * scrollamount * dt)
|
||||
else
|
||||
bar:Scroll(-y * scrollamount)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: CalculateSize()
|
||||
- desc: calculates the size of the object's children
|
||||
|
@ -210,34 +210,13 @@ function newobject:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height)
|
||||
local toplist = self:IsTopList()
|
||||
local internals = self.internals
|
||||
local children = self.children
|
||||
local scrollamount = self.mousewheelscrollamount
|
||||
|
||||
if not selfcol and self.canremove and button == 1 then
|
||||
self:Close()
|
||||
end
|
||||
|
||||
if self.vbar and toplist then
|
||||
local bar = internals[1].internals[1].internals[1]
|
||||
local dtscrolling = self.dtscrolling
|
||||
if dtscrolling then
|
||||
local dt = love.timer.getDelta()
|
||||
if button == "wu" then
|
||||
bar:Scroll(-scrollamount * dt)
|
||||
elseif button == "wd" then
|
||||
bar:Scroll(scrollamount * dt)
|
||||
end
|
||||
else
|
||||
if button == "wu" then
|
||||
bar:Scroll(-scrollamount)
|
||||
elseif button == "wd" then
|
||||
bar:Scroll(scrollamount)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
@ -282,6 +261,29 @@ function newobject:mousereleased(x, y, button)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: wheelmoved(x, y)
|
||||
- desc: called when the player moves a mouse wheel
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:wheelmoved(x, y)
|
||||
|
||||
local toplist = self:IsTopList()
|
||||
local internals = self.internals
|
||||
local scrollamount = self.mousewheelscrollamount
|
||||
|
||||
if self.vbar and toplist then
|
||||
local bar = internals[1].internals[1].internals[1]
|
||||
local dtscrolling = self.dtscrolling
|
||||
if dtscrolling then
|
||||
local dt = love.timer.getDelta()
|
||||
bar:Scroll(-y * scrollamount * dt)
|
||||
else
|
||||
bar:Scroll(-y * scrollamount)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: AddItem(object)
|
||||
- desc: adds an item to the object
|
||||
|
@ -203,11 +203,7 @@ function newobject:mousepressed(x, y, button)
|
||||
return
|
||||
end
|
||||
|
||||
local toplist = self:IsTopList()
|
||||
local hover = self.hover
|
||||
local vbar = self.vbar
|
||||
local hbar = self.hbar
|
||||
local scrollamount = self.mousewheelscrollamount
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
|
||||
@ -218,27 +214,6 @@ function newobject:mousepressed(x, y, button)
|
||||
end
|
||||
end
|
||||
|
||||
if vbar or hbar then
|
||||
if toplist then
|
||||
local bar = self:GetScrollBar()
|
||||
local dtscrolling = self.dtscrolling
|
||||
if dtscrolling then
|
||||
local dt = love.timer.getDelta()
|
||||
if button == "wu" then
|
||||
bar:Scroll(-scrollamount * dt)
|
||||
elseif button == "wd" then
|
||||
bar:Scroll(scrollamount * dt)
|
||||
end
|
||||
else
|
||||
if button == "wu" then
|
||||
bar:Scroll(-scrollamount)
|
||||
elseif button == "wd" then
|
||||
bar:Scroll(scrollamount)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
@ -249,6 +224,30 @@ function newobject:mousepressed(x, y, button)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: wheelmoved(x, y)
|
||||
- desc: called when the player moves a mouse wheel
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:wheelmoved(x, y)
|
||||
|
||||
local toplist = self:IsTopList()
|
||||
local vbar = self.vbar
|
||||
local hbar = self.hbar
|
||||
local scrollamount = self.mousewheelscrollamount
|
||||
|
||||
if (vbar or hbar) and toplist then
|
||||
local bar = self:GetScrollBar()
|
||||
local dtscrolling = self.dtscrolling
|
||||
if dtscrolling then
|
||||
local dt = love.timer.getDelta()
|
||||
bar:Scroll(-y * scrollamount * dt)
|
||||
else
|
||||
bar:Scroll(-y * scrollamount)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: AddItem(object)
|
||||
- desc: adds an item to the object
|
||||
|
@ -218,45 +218,6 @@ function newobject:mousepressed(x, y, button)
|
||||
end
|
||||
end
|
||||
|
||||
if button == "wu" then
|
||||
local buttonheight = self:GetHeightOfButtons()
|
||||
local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1)
|
||||
local visible = internals[numinternals - 1]:GetVisible()
|
||||
if col and visible then
|
||||
local scrollamount = self.mousewheelscrollamount
|
||||
local dtscrolling = self.dtscrolling
|
||||
if dtscrolling then
|
||||
local dt = love.timer.getDelta()
|
||||
self.offsetx = self.offsetx + scrollamount * dt
|
||||
else
|
||||
self.offsetx = self.offsetx + scrollamount
|
||||
end
|
||||
if self.offsetx > 0 then
|
||||
self.offsetx = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if button == "wd" then
|
||||
local buttonheight = self:GetHeightOfButtons()
|
||||
local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1)
|
||||
local visible = internals[numinternals]:GetVisible()
|
||||
if col and visible then
|
||||
local bwidth = self:GetWidthOfButtons()
|
||||
local scrollamount = self.mousewheelscrollamount
|
||||
local dtscrolling = self.dtscrolling
|
||||
if dtscrolling then
|
||||
local dt = love.timer.getDelta()
|
||||
self.offsetx = self.offsetx - scrollamount * dt
|
||||
else
|
||||
self.offsetx = self.offsetx - scrollamount
|
||||
end
|
||||
if ((self.offsetx + bwidth) + self.width) < self.width then
|
||||
self.offsetx = -(bwidth + 10)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
@ -300,6 +261,54 @@ function newobject:mousereleased(x, y, button)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: wheelmoved(x, y)
|
||||
- desc: called when the player moves a mouse wheel
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:wheelmoved(x, y)
|
||||
|
||||
local internals = self.internals
|
||||
local numinternals = #internals
|
||||
|
||||
if y < 0 then
|
||||
local buttonheight = self:GetHeightOfButtons()
|
||||
local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1)
|
||||
local visible = internals[numinternals - 1]:GetVisible()
|
||||
if col and visible then
|
||||
local scrollamount = -y * self.mousewheelscrollamount
|
||||
local dtscrolling = self.dtscrolling
|
||||
if dtscrolling then
|
||||
local dt = love.timer.getDelta()
|
||||
self.offsetx = self.offsetx + scrollamount * dt
|
||||
else
|
||||
self.offsetx = self.offsetx + scrollamount
|
||||
end
|
||||
if self.offsetx > 0 then
|
||||
self.offsetx = 0
|
||||
end
|
||||
end
|
||||
elseif y > 0 then
|
||||
local buttonheight = self:GetHeightOfButtons()
|
||||
local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1)
|
||||
local visible = internals[numinternals]:GetVisible()
|
||||
if col and visible then
|
||||
local bwidth = self:GetWidthOfButtons()
|
||||
local scrollamount = y * self.mousewheelscrollamount
|
||||
local dtscrolling = self.dtscrolling
|
||||
if dtscrolling then
|
||||
local dt = love.timer.getDelta()
|
||||
self.offsetx = self.offsetx - scrollamount * dt
|
||||
else
|
||||
self.offsetx = self.offsetx - scrollamount
|
||||
end
|
||||
if ((self.offsetx + bwidth) + self.width) < self.width then
|
||||
self.offsetx = -(bwidth + 10)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: AddTab(name, object, tip, image)
|
||||
- desc: adds a new tab to the tab panel
|
||||
|
Loading…
Reference in New Issue
Block a user