mirror of
https://github.com/TangentFoxy/Pop.Box.git
synced 2024-12-15 12:44:20 +00:00
wip events n stuff
This commit is contained in:
parent
8e3622c0c4
commit
51bb8f581a
@ -1,5 +1,8 @@
|
||||
local graphics
|
||||
graphics = love.graphics
|
||||
local graphics, mouse
|
||||
do
|
||||
local _obj_0 = love
|
||||
graphics, mouse = _obj_0.graphics, _obj_0.mouse
|
||||
end
|
||||
local insert, remove
|
||||
do
|
||||
local _obj_0 = table
|
||||
@ -141,6 +144,9 @@ do
|
||||
setTitle = function(self, title)
|
||||
self.title:setText(title)
|
||||
return self
|
||||
end,
|
||||
getTitle = function(self)
|
||||
return self.title:getText()
|
||||
end
|
||||
}
|
||||
_base_0.__index = _base_0
|
||||
@ -203,6 +209,23 @@ do
|
||||
end
|
||||
return false
|
||||
end
|
||||
else
|
||||
self.head.mx = 0
|
||||
self.head.my = 0
|
||||
self.head.update = function(self)
|
||||
local x, y = mouse.getPosition()
|
||||
return self:setPosition(x - mx, y - my)
|
||||
end
|
||||
self.head.mousepressed = function(self, x, y, button)
|
||||
if button == left then
|
||||
self.selected = true
|
||||
self.mx = x
|
||||
self.my = y
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
self.head.mousereleased = function(self, x, y, button)
|
||||
if button == left then
|
||||
self.selected = false
|
||||
@ -211,27 +234,6 @@ do
|
||||
end
|
||||
return false
|
||||
end
|
||||
else
|
||||
self.head.mx = 0
|
||||
self.head.my = 0
|
||||
self.head.update = function(self)
|
||||
return false
|
||||
end
|
||||
self.head.mousepressed = function(self, x, y, button)
|
||||
if button == left then
|
||||
self.selected = true
|
||||
self.mx = x
|
||||
self.my = y
|
||||
end
|
||||
end
|
||||
self.head.mousereleased = function(self, x, y, button)
|
||||
if button == left then
|
||||
self.selected = false
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
end,
|
||||
__base = _base_0,
|
||||
__name = "window",
|
||||
|
@ -163,7 +163,7 @@ pop.mousereleased = function(x, y, button)
|
||||
do
|
||||
local element = pop.events[button]
|
||||
if element then
|
||||
if element.clicked and (not element.excludeDraw) and (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h) then
|
||||
if element.clicked and (not element.excludeDraw) then
|
||||
do
|
||||
clickedHandled = element:clicked(x - element.x, y - element.y, button)
|
||||
if clickedHandled then
|
||||
@ -171,7 +171,7 @@ pop.mousereleased = function(x, y, button)
|
||||
end
|
||||
end
|
||||
end
|
||||
if element.mousereleased and (not element.excludeDraw) then
|
||||
if element.mousereleased then
|
||||
do
|
||||
mousereleasedHandled = element:mousereleased(x - element.x, y - element.y, button)
|
||||
if mousereleasedHandled then
|
||||
@ -185,14 +185,26 @@ pop.mousereleased = function(x, y, button)
|
||||
end
|
||||
pop.keypressed = function(key)
|
||||
print("keypressed", key)
|
||||
local element = pop.focused
|
||||
if element and element.keypressed and (not element.excludeDraw) then
|
||||
return element.keypressed(key)
|
||||
end
|
||||
return false
|
||||
end
|
||||
pop.keyreleased = function(key)
|
||||
print("keyreleased", key)
|
||||
local element = pop.focused
|
||||
if element and element.keyreleased then
|
||||
return element.keyreleased(key)
|
||||
end
|
||||
return false
|
||||
end
|
||||
pop.textinput = function(text)
|
||||
print("textinput", text)
|
||||
local element = pop.focused
|
||||
if element and element.textinput and (not element.excludeDraw) then
|
||||
return element.textinput(text)
|
||||
end
|
||||
return false
|
||||
end
|
||||
pop.skin = function(element, skin, depth)
|
||||
|
@ -10,5 +10,14 @@ Note that any element using one of these excludes its children as well.
|
||||
- `excludeUpdate` Excludes an element from being updated (by `pop.update()`).
|
||||
- `excludeDraw` Excludes being rendered (by `pop.draw()`).
|
||||
|
||||
**Note**: `excludeDraw` also excludes an element from accepting events (it
|
||||
wouldn't make sense to have an invisible element capturing text input).
|
||||
**Note**: `excludeDraw` also excludes an element from accepting the following
|
||||
events:
|
||||
|
||||
- `mousepressed`
|
||||
- `clicked`
|
||||
- `keypressed`
|
||||
- `textinput`
|
||||
|
||||
The reason for this is that it wouldn't make sense for an invisible element to
|
||||
be capturing input. However, some events are passed through in case an element
|
||||
becomes invisible while processing input.
|
||||
|
@ -10,6 +10,6 @@ TODO: Write me.
|
||||
- `pop.mousereleased()` Handling a click maybe should *not* check bounds.
|
||||
Handling a mouse release should maybe *not* check for `excludeDraw`. If an
|
||||
element was already selected and then went invisible, I'm probably breaking
|
||||
things worse by doing this.
|
||||
things worse by doing this. This has been changed.
|
||||
|
||||
[1]: ../Pop.md
|
||||
|
@ -1,5 +1,8 @@
|
||||
local graphics
|
||||
graphics = love.graphics
|
||||
local graphics, mouse
|
||||
do
|
||||
local _obj_0 = love
|
||||
graphics, mouse = _obj_0.graphics, _obj_0.mouse
|
||||
end
|
||||
local insert, remove
|
||||
do
|
||||
local _obj_0 = table
|
||||
@ -141,6 +144,9 @@ do
|
||||
setTitle = function(self, title)
|
||||
self.title:setText(title)
|
||||
return self
|
||||
end,
|
||||
getTitle = function(self)
|
||||
return self.title:getText()
|
||||
end
|
||||
}
|
||||
_base_0.__index = _base_0
|
||||
@ -203,6 +209,23 @@ do
|
||||
end
|
||||
return false
|
||||
end
|
||||
else
|
||||
self.head.mx = 0
|
||||
self.head.my = 0
|
||||
self.head.update = function(self)
|
||||
local x, y = mouse.getPosition()
|
||||
return self:setPosition(x - mx, y - my)
|
||||
end
|
||||
self.head.mousepressed = function(self, x, y, button)
|
||||
if button == left then
|
||||
self.selected = true
|
||||
self.mx = x
|
||||
self.my = y
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
self.head.mousereleased = function(self, x, y, button)
|
||||
if button == left then
|
||||
self.selected = false
|
||||
@ -211,27 +234,6 @@ do
|
||||
end
|
||||
return false
|
||||
end
|
||||
else
|
||||
self.head.mx = 0
|
||||
self.head.my = 0
|
||||
self.head.update = function(self)
|
||||
return false
|
||||
end
|
||||
self.head.mousepressed = function(self, x, y, button)
|
||||
if button == left then
|
||||
self.selected = true
|
||||
self.mx = x
|
||||
self.my = y
|
||||
end
|
||||
end
|
||||
self.head.mousereleased = function(self, x, y, button)
|
||||
if button == left then
|
||||
self.selected = false
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
end,
|
||||
__base = _base_0,
|
||||
__name = "window",
|
||||
|
@ -163,7 +163,7 @@ pop.mousereleased = function(x, y, button)
|
||||
do
|
||||
local element = pop.events[button]
|
||||
if element then
|
||||
if element.clicked and (not element.excludeDraw) and (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h) then
|
||||
if element.clicked and (not element.excludeDraw) then
|
||||
do
|
||||
clickedHandled = element:clicked(x - element.x, y - element.y, button)
|
||||
if clickedHandled then
|
||||
@ -171,7 +171,7 @@ pop.mousereleased = function(x, y, button)
|
||||
end
|
||||
end
|
||||
end
|
||||
if element.mousereleased and (not element.excludeDraw) then
|
||||
if element.mousereleased then
|
||||
do
|
||||
mousereleasedHandled = element:mousereleased(x - element.x, y - element.y, button)
|
||||
if mousereleasedHandled then
|
||||
@ -185,14 +185,26 @@ pop.mousereleased = function(x, y, button)
|
||||
end
|
||||
pop.keypressed = function(key)
|
||||
print("keypressed", key)
|
||||
local element = pop.focused
|
||||
if element and element.keypressed and (not element.excludeDraw) then
|
||||
return element.keypressed(key)
|
||||
end
|
||||
return false
|
||||
end
|
||||
pop.keyreleased = function(key)
|
||||
print("keyreleased", key)
|
||||
local element = pop.focused
|
||||
if element and element.keyreleased then
|
||||
return element.keyreleased(key)
|
||||
end
|
||||
return false
|
||||
end
|
||||
pop.textinput = function(text)
|
||||
print("textinput", text)
|
||||
local element = pop.focused
|
||||
if element and element.textinput and (not element.excludeDraw) then
|
||||
return element.textinput(text)
|
||||
end
|
||||
return false
|
||||
end
|
||||
pop.skin = function(element, skin, depth)
|
||||
|
@ -1,4 +1,4 @@
|
||||
import graphics from love
|
||||
import graphics, mouse from love
|
||||
import insert, remove from table
|
||||
import sub, len from string
|
||||
|
||||
@ -64,30 +64,27 @@ class window extends element
|
||||
return true
|
||||
return false
|
||||
|
||||
@head.mousereleased = (x, y, button) =>
|
||||
if button == left
|
||||
@selected = false
|
||||
pop_ref.focused = false -- clear our focus
|
||||
return true
|
||||
return false
|
||||
|
||||
else
|
||||
@head.mx = 0 -- local mouse coordinates when selected
|
||||
@head.my = 0
|
||||
|
||||
@head.update = =>
|
||||
--TODO write me!
|
||||
return false
|
||||
x, y = mouse.getPosition!
|
||||
@setPosition x - mx, y - my
|
||||
--return false -- why?
|
||||
|
||||
@head.mousepressed = (x, y, button) =>
|
||||
if button == left
|
||||
@selected = true
|
||||
@mx = x
|
||||
@my = y
|
||||
return true
|
||||
return false
|
||||
|
||||
@head.mousereleased = (x, y, button) => -- this is actually the same for both versions...
|
||||
@head.mousereleased = (x, y, button) =>
|
||||
if button == left
|
||||
@selected = false
|
||||
pop_ref.focused = false -- clear our focus
|
||||
return true
|
||||
return false
|
||||
|
||||
@ -128,18 +125,6 @@ class window extends element
|
||||
|
||||
return @
|
||||
|
||||
--update: =>
|
||||
-- if selected, set position based on current mouse position relative to position it was when mousepressed
|
||||
|
||||
--mousemoved: (x, y, dx, dy) =>
|
||||
-- if selected, set position based on new mouse position relative to position it was when mousepressed
|
||||
|
||||
--mousepressed: (x, y, button) =>
|
||||
-- if button == "l" -> selected = true, mouse position saved
|
||||
|
||||
--mousereleased: (x, y, button) =>
|
||||
-- if button == "l" -> set position based on position relative to when mousepressed, selected == false
|
||||
|
||||
setSize: (w, h) =>
|
||||
x = 0
|
||||
y = 0
|
||||
@ -221,3 +206,6 @@ class window extends element
|
||||
setTitle: (title) =>
|
||||
@title\setText title
|
||||
return @
|
||||
|
||||
getTitle: =>
|
||||
return @title\getText!
|
||||
|
@ -136,11 +136,11 @@ pop.mousereleased = (x, y, button) ->
|
||||
mousereleasedHandled = false
|
||||
|
||||
if element = pop.events[button]
|
||||
if element.clicked and (not element.excludeDraw) and (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h)
|
||||
if element.clicked and (not element.excludeDraw) --and (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h)
|
||||
if clickedHandled = element\clicked x - element.x, y - element.y, button
|
||||
pop.events[button] = nil
|
||||
|
||||
if element.mousereleased and (not element.excludeDraw)
|
||||
if element.mousereleased
|
||||
if mousereleasedHandled = element\mousereleased x - element.x, y - element.y, button
|
||||
pop.events[button] = nil
|
||||
|
||||
@ -148,15 +148,30 @@ pop.mousereleased = (x, y, button) ->
|
||||
|
||||
pop.keypressed = (key) ->
|
||||
print "keypressed", key
|
||||
return false --TODO event handlers return if they have handled the event!
|
||||
|
||||
element = pop.focused
|
||||
if element and element.keypressed and (not element.excludeDraw)
|
||||
return element.keypressed key
|
||||
|
||||
return false
|
||||
|
||||
pop.keyreleased = (key) ->
|
||||
print "keyreleased", key
|
||||
return false --TODO event handlers return if they have handled the event!
|
||||
|
||||
element = pop.focused
|
||||
if element and element.keyreleased
|
||||
return element.keyreleased key
|
||||
|
||||
return false
|
||||
|
||||
pop.textinput = (text) ->
|
||||
print "textinput", text
|
||||
return false --TODO event handlers return if they have handled the event!
|
||||
|
||||
element = pop.focused
|
||||
if element and element.textinput and (not element.excludeDraw)
|
||||
return element.textinput text
|
||||
|
||||
return false
|
||||
|
||||
--TODO rewrite skin system to not rely on knowing internals of elements,
|
||||
-- instead call functions like setColor and setBackground
|
||||
|
Loading…
Reference in New Issue
Block a user