mirror of
https://github.com/TangentFoxy/Pop.Box.git
synced 2024-12-15 12:44:20 +00:00
working on mouse handler
This commit is contained in:
parent
b06ecde97b
commit
5047d4443d
@ -10,6 +10,7 @@ local pop = { }
|
|||||||
pop.elements = { }
|
pop.elements = { }
|
||||||
pop.skins = { }
|
pop.skins = { }
|
||||||
pop.screen = false
|
pop.screen = false
|
||||||
|
pop.focused = false
|
||||||
pop.load = function()
|
pop.load = function()
|
||||||
local elements = filesystem.getDirectoryItems(tostring(path) .. "/elements")
|
local elements = filesystem.getDirectoryItems(tostring(path) .. "/elements")
|
||||||
for i = 1, #elements do
|
for i = 1, #elements do
|
||||||
@ -99,7 +100,24 @@ pop.mousepressed = function(x, y, button, element)
|
|||||||
element = pop.screen
|
element = pop.screen
|
||||||
end
|
end
|
||||||
print("mousepressed", x, y, button, element)
|
print("mousepressed", x, y, button, element)
|
||||||
return false
|
local handled = false
|
||||||
|
if (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h) then
|
||||||
|
if element.mousepressed then
|
||||||
|
handled = element:mousepressed(x - element.x, y - element.y, button)
|
||||||
|
end
|
||||||
|
if handled then
|
||||||
|
pop.focused = element
|
||||||
|
else
|
||||||
|
for i = 1, #element.child do
|
||||||
|
handled = pop.mousepressed(x, y, button, element.child[i])
|
||||||
|
if handled then
|
||||||
|
pop.focused = element.child[i]
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return handled
|
||||||
end
|
end
|
||||||
pop.mousereleased = function(x, y, button, element)
|
pop.mousereleased = function(x, y, button, element)
|
||||||
if element == nil then
|
if element == nil then
|
||||||
|
@ -10,6 +10,7 @@ local pop = { }
|
|||||||
pop.elements = { }
|
pop.elements = { }
|
||||||
pop.skins = { }
|
pop.skins = { }
|
||||||
pop.screen = false
|
pop.screen = false
|
||||||
|
pop.focused = false
|
||||||
pop.load = function()
|
pop.load = function()
|
||||||
local elements = filesystem.getDirectoryItems(tostring(path) .. "/elements")
|
local elements = filesystem.getDirectoryItems(tostring(path) .. "/elements")
|
||||||
for i = 1, #elements do
|
for i = 1, #elements do
|
||||||
@ -99,7 +100,24 @@ pop.mousepressed = function(x, y, button, element)
|
|||||||
element = pop.screen
|
element = pop.screen
|
||||||
end
|
end
|
||||||
print("mousepressed", x, y, button, element)
|
print("mousepressed", x, y, button, element)
|
||||||
return false
|
local handled = false
|
||||||
|
if (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h) then
|
||||||
|
if element.mousepressed then
|
||||||
|
handled = element:mousepressed(x - element.x, y - element.y, button)
|
||||||
|
end
|
||||||
|
if handled then
|
||||||
|
pop.focused = element
|
||||||
|
else
|
||||||
|
for i = 1, #element.child do
|
||||||
|
handled = pop.mousepressed(x, y, button, element.child[i])
|
||||||
|
if handled then
|
||||||
|
pop.focused = element.child[i]
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return handled
|
||||||
end
|
end
|
||||||
pop.mousereleased = function(x, y, button, element)
|
pop.mousereleased = function(x, y, button, element)
|
||||||
if element == nil then
|
if element == nil then
|
||||||
|
@ -9,7 +9,7 @@ pop.elements = {}
|
|||||||
pop.skins = {}
|
pop.skins = {}
|
||||||
|
|
||||||
pop.screen = false -- initialized in pop.load()
|
pop.screen = false -- initialized in pop.load()
|
||||||
--pop.focused ?
|
pop.focused = false
|
||||||
|
|
||||||
-- loads elements and skins, creates pop.screen (intended to only be called once at the beginning)
|
-- loads elements and skins, creates pop.screen (intended to only be called once at the beginning)
|
||||||
pop.load = ->
|
pop.load = ->
|
||||||
@ -72,10 +72,27 @@ pop.draw = (element=pop.screen) ->
|
|||||||
|
|
||||||
pop.mousepressed = (x, y, button, element=pop.screen) ->
|
pop.mousepressed = (x, y, button, element=pop.screen) ->
|
||||||
print "mousepressed", x, y, button, element
|
print "mousepressed", x, y, button, element
|
||||||
return false --TODO event handlers return if they have handled the event!
|
handled = false
|
||||||
|
if (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h)
|
||||||
|
if element.mousepressed
|
||||||
|
handled = element\mousepressed x - element.x, y - element.y, button
|
||||||
|
if handled
|
||||||
|
pop.focused = element
|
||||||
|
else
|
||||||
|
for i = 1, #element.child
|
||||||
|
handled = pop.mousepressed x, y, button, element.child[i]
|
||||||
|
if handled
|
||||||
|
pop.focused = element.child[i]
|
||||||
|
break
|
||||||
|
return handled
|
||||||
|
|
||||||
pop.mousereleased = (x, y, button, element=pop.screen) ->
|
pop.mousereleased = (x, y, button, element=pop.screen) ->
|
||||||
print "mousereleased", x, y, button, element
|
print "mousereleased", x, y, button, element
|
||||||
|
--clickHandled = false
|
||||||
|
--mouseReleaseHandled = false
|
||||||
|
--if (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h)
|
||||||
|
-- efw
|
||||||
|
--
|
||||||
return false --TODO event handlers return if they have handled the event!
|
return false --TODO event handlers return if they have handled the event!
|
||||||
|
|
||||||
pop.keypressed = (key) ->
|
pop.keypressed = (key) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user