window working, I fucking broke it in stupid ways

This commit is contained in:
Fox 2016-04-02 23:33:18 -07:00
parent 6586106a6f
commit 8256bb499a
16 changed files with 116 additions and 68 deletions

View File

@ -4,6 +4,8 @@ local pop
local debugDraw = false local debugDraw = false
function love.load() function love.load()
print(love.getVersion())
pop = require "pop" pop = require "pop"
---[[ ---[[
local c = pop.box():align("center", "center"):setSize(300, 300) local c = pop.box():align("center", "center"):setSize(300, 300)

View File

@ -71,11 +71,11 @@ do
_base_0.__index = _base_0 _base_0.__index = _base_0
setmetatable(_base_0, _parent_0.__base) setmetatable(_base_0, _parent_0.__base)
_class_0 = setmetatable({ _class_0 = setmetatable({
__init = function(self, pop, parent, background) __init = function(self, parent, background)
if background == nil then if background == nil then
background = false background = false
end end
_class_0.__parent.__init(self, pop, parent) _class_0.__parent.__init(self, parent)
self.w = 20 self.w = 20
self.h = 20 self.h = 20
self.background = background self.background = background

View File

@ -206,8 +206,7 @@ do
} }
_base_0.__index = _base_0 _base_0.__index = _base_0
_class_0 = setmetatable({ _class_0 = setmetatable({
__init = function(self, pop, parent) __init = function(self, parent)
self.pop = pop
self.parent = parent self.parent = parent
self.child = { } self.child = { }
self.w = 0 self.w = 0

View File

@ -106,7 +106,7 @@ do
_base_0.__index = _base_0 _base_0.__index = _base_0
setmetatable(_base_0, _parent_0.__base) setmetatable(_base_0, _parent_0.__base)
_class_0 = setmetatable({ _class_0 = setmetatable({
__init = function(self, pop, parent, text, color) __init = function(self, parent, text, color)
if text == nil then if text == nil then
text = "" text = ""
end end
@ -118,10 +118,7 @@ do
255 255
} }
end end
print("---===---") _class_0.__parent.__init(self, parent)
print(self, pop, parent, text, color)
print("---===---")
_class_0.__parent.__init(self, pop, parent)
self.font = graphics.newFont(14) self.font = graphics.newFont(14)
self:setText(text) self:setText(text)
self.color = color self.color = color

View File

@ -26,11 +26,18 @@ do
print(" assuming LÖVE version > 0.10.1 (there may be bugs)") print(" assuming LÖVE version > 0.10.1 (there may be bugs)")
end end
end end
local pop_ref = nil
local window local window
do do
local _class_0 local _class_0
local _parent_0 = element local _parent_0 = element
local _base_0 = { local _base_0 = {
wrap = function(pop)
pop_ref = pop
return function(...)
return pop.create("window", ...)
end
end,
debugDraw = function(self) debugDraw = function(self)
graphics.setLineWidth(0.5) graphics.setLineWidth(0.5)
graphics.setColor(0, 0, 0, 100) graphics.setColor(0, 0, 0, 100)
@ -111,7 +118,7 @@ do
_base_0.__index = _base_0 _base_0.__index = _base_0
setmetatable(_base_0, _parent_0.__base) setmetatable(_base_0, _parent_0.__base)
_class_0 = setmetatable({ _class_0 = setmetatable({
__init = function(self, pop, parent, title, tBackground, tColor, wBackground) __init = function(self, parent, title, tBackground, tColor, wBackground)
if title == nil then if title == nil then
title = "window" title = "window"
end end
@ -139,8 +146,7 @@ do
255 255
} }
end end
print((parent == pop.screen), (title == "Window")) _class_0.__parent.__init(self, parent)
_class_0.__parent.__init(self, pop, parent)
self.head = box(self, tBackground) self.head = box(self, tBackground)
print(self, title, tColor) print(self, title, tColor)
self.title = text(self, title, tColor) self.title = text(self, title, tColor)
@ -157,9 +163,8 @@ do
self.head.selected = false self.head.selected = false
if mousemoved_event then if mousemoved_event then
self.head.mousemoved = function(self, x, y, dx, dy) self.head.mousemoved = function(self, x, y, dx, dy)
print("mousemoved CALLED!")
if self.selected then if self.selected then
self.parent:move(dx, dy) self.parent:move(y, dx)
return true return true
end end
return false return false
@ -175,9 +180,11 @@ do
end end
self.head.mousereleased = function(self, x, y, button) self.head.mousereleased = function(self, x, y, button)
print("mousereleased CALLED!") print("mousereleased CALLED!")
print((button == left))
if button == left then if button == left then
self.selected = false self.selected = false
self.pop.focused = false pop_ref.focused = false
print("SHOULD BE FIXED GOD FUCKING DAMMIT")
return true return true
end end
print("ERROR FELL THROUGH") print("ERROR FELL THROUGH")

View File

@ -87,12 +87,12 @@ pop.create = function(element, parent, ...)
parent = pop.screen parent = pop.screen
end end
if inheritsFromElement(parent) then if inheritsFromElement(parent) then
element = pop.elements[element](pop, parent, ...) element = pop.elements[element](parent, ...)
insert(parent.child, element) insert(parent.child, element)
elseif parent == false then elseif parent == false then
element = pop.elements[element](pop, false, ...) element = pop.elements[element](false, ...)
else else
element = pop.elements[element](pop, pop.screen, parent, ...) element = pop.elements[element](pop.screen, parent, ...)
insert(pop.screen.child, element) insert(pop.screen.child, element)
end end
return element return element
@ -127,6 +127,7 @@ pop.mousemoved = function(self, x, y, dx, dy)
if pop.focused and pop.focused.mousemoved then if pop.focused and pop.focused.mousemoved then
return pop.focused:mousemoved(x, y, dx, dy) return pop.focused:mousemoved(x, y, dx, dy)
end end
print("mousemoved unhandled!")
return false return false
end end
pop.mousepressed = function(x, y, button, element) pop.mousepressed = function(x, y, button, element)
@ -137,11 +138,18 @@ pop.mousepressed = function(x, y, button, element)
local handled = 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 (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h) then
if element.mousepressed then if element.mousepressed then
if element == pop.screen then
error("pop.screen somehow has a fucking mousepressed handler")
end
handled = element:mousepressed(x - element.x, y - element.y, button) handled = element:mousepressed(x - element.x, y - element.y, button)
end end
if handled then if handled then
print("pop.focused has been set!") print("pop.focused has been set!")
pop.focused = element pop.focused = element
pop.events[button] = element
if element == pop.screen then
error("pop.screen fucking focused SOMEHOW")
end
else else
for i = 1, #element.child do for i = 1, #element.child do
handled = pop.mousepressed(x, y, button, element.child[i]) handled = pop.mousepressed(x, y, button, element.child[i])
@ -151,9 +159,6 @@ pop.mousepressed = function(x, y, button, element)
end end
end end
end end
if handled then
pop.events[button] = element
end
return handled return handled
end end
pop.mousereleased = function(x, y, button) pop.mousereleased = function(x, y, button)
@ -163,6 +168,7 @@ pop.mousereleased = function(x, y, button)
do do
local element = pop.events[button] local element = pop.events[button]
if element then if element then
print("mousereleased should be functional")
if element.clicked 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 (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h) then
do do
clickedHandled = element:clicked(x - element.x, y - element.y, button) clickedHandled = element:clicked(x - element.x, y - element.y, button)
@ -171,7 +177,11 @@ pop.mousereleased = function(x, y, button)
end end
end end
end end
for k, v in pairs(element) do
print(k, v)
end
if element.mousereleased then if element.mousereleased then
print("mousereleased SHOULD be called")
do do
mousereleasedHandled = element:mousereleased(x - element.x, y - element.y, button) mousereleasedHandled = element:mousereleased(x - element.x, y - element.y, button)
if mousereleasedHandled then if mousereleasedHandled then

View File

@ -71,11 +71,11 @@ do
_base_0.__index = _base_0 _base_0.__index = _base_0
setmetatable(_base_0, _parent_0.__base) setmetatable(_base_0, _parent_0.__base)
_class_0 = setmetatable({ _class_0 = setmetatable({
__init = function(self, pop, parent, background) __init = function(self, parent, background)
if background == nil then if background == nil then
background = false background = false
end end
_class_0.__parent.__init(self, pop, parent) _class_0.__parent.__init(self, parent)
self.w = 20 self.w = 20
self.h = 20 self.h = 20
self.background = background self.background = background

View File

@ -206,8 +206,7 @@ do
} }
_base_0.__index = _base_0 _base_0.__index = _base_0
_class_0 = setmetatable({ _class_0 = setmetatable({
__init = function(self, pop, parent) __init = function(self, parent)
self.pop = pop
self.parent = parent self.parent = parent
self.child = { } self.child = { }
self.w = 0 self.w = 0

View File

@ -106,7 +106,7 @@ do
_base_0.__index = _base_0 _base_0.__index = _base_0
setmetatable(_base_0, _parent_0.__base) setmetatable(_base_0, _parent_0.__base)
_class_0 = setmetatable({ _class_0 = setmetatable({
__init = function(self, pop, parent, text, color) __init = function(self, parent, text, color)
if text == nil then if text == nil then
text = "" text = ""
end end
@ -118,10 +118,7 @@ do
255 255
} }
end end
print("---===---") _class_0.__parent.__init(self, parent)
print(self, pop, parent, text, color)
print("---===---")
_class_0.__parent.__init(self, pop, parent)
self.font = graphics.newFont(14) self.font = graphics.newFont(14)
self:setText(text) self:setText(text)
self.color = color self.color = color

View File

@ -26,11 +26,18 @@ do
print(" assuming LÖVE version > 0.10.1 (there may be bugs)") print(" assuming LÖVE version > 0.10.1 (there may be bugs)")
end end
end end
local pop_ref = nil
local window local window
do do
local _class_0 local _class_0
local _parent_0 = element local _parent_0 = element
local _base_0 = { local _base_0 = {
wrap = function(pop)
pop_ref = pop
return function(...)
return pop.create("window", ...)
end
end,
debugDraw = function(self) debugDraw = function(self)
graphics.setLineWidth(0.5) graphics.setLineWidth(0.5)
graphics.setColor(0, 0, 0, 100) graphics.setColor(0, 0, 0, 100)
@ -111,7 +118,7 @@ do
_base_0.__index = _base_0 _base_0.__index = _base_0
setmetatable(_base_0, _parent_0.__base) setmetatable(_base_0, _parent_0.__base)
_class_0 = setmetatable({ _class_0 = setmetatable({
__init = function(self, pop, parent, title, tBackground, tColor, wBackground) __init = function(self, parent, title, tBackground, tColor, wBackground)
if title == nil then if title == nil then
title = "window" title = "window"
end end
@ -139,8 +146,7 @@ do
255 255
} }
end end
print((parent == pop.screen), (title == "Window")) _class_0.__parent.__init(self, parent)
_class_0.__parent.__init(self, pop, parent)
self.head = box(self, tBackground) self.head = box(self, tBackground)
print(self, title, tColor) print(self, title, tColor)
self.title = text(self, title, tColor) self.title = text(self, title, tColor)
@ -157,9 +163,8 @@ do
self.head.selected = false self.head.selected = false
if mousemoved_event then if mousemoved_event then
self.head.mousemoved = function(self, x, y, dx, dy) self.head.mousemoved = function(self, x, y, dx, dy)
print("mousemoved CALLED!")
if self.selected then if self.selected then
self.parent:move(dx, dy) self.parent:move(y, dx)
return true return true
end end
return false return false
@ -175,9 +180,11 @@ do
end end
self.head.mousereleased = function(self, x, y, button) self.head.mousereleased = function(self, x, y, button)
print("mousereleased CALLED!") print("mousereleased CALLED!")
print((button == left))
if button == left then if button == left then
self.selected = false self.selected = false
self.pop.focused = false pop_ref.focused = false
print("SHOULD BE FIXED GOD FUCKING DAMMIT")
return true return true
end end
print("ERROR FELL THROUGH") print("ERROR FELL THROUGH")

View File

@ -87,12 +87,12 @@ pop.create = function(element, parent, ...)
parent = pop.screen parent = pop.screen
end end
if inheritsFromElement(parent) then if inheritsFromElement(parent) then
element = pop.elements[element](pop, parent, ...) element = pop.elements[element](parent, ...)
insert(parent.child, element) insert(parent.child, element)
elseif parent == false then elseif parent == false then
element = pop.elements[element](pop, false, ...) element = pop.elements[element](false, ...)
else else
element = pop.elements[element](pop, pop.screen, parent, ...) element = pop.elements[element](pop.screen, parent, ...)
insert(pop.screen.child, element) insert(pop.screen.child, element)
end end
return element return element
@ -127,6 +127,7 @@ pop.mousemoved = function(self, x, y, dx, dy)
if pop.focused and pop.focused.mousemoved then if pop.focused and pop.focused.mousemoved then
return pop.focused:mousemoved(x, y, dx, dy) return pop.focused:mousemoved(x, y, dx, dy)
end end
print("mousemoved unhandled!")
return false return false
end end
pop.mousepressed = function(x, y, button, element) pop.mousepressed = function(x, y, button, element)
@ -137,11 +138,18 @@ pop.mousepressed = function(x, y, button, element)
local handled = 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 (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h) then
if element.mousepressed then if element.mousepressed then
if element == pop.screen then
error("pop.screen somehow has a fucking mousepressed handler")
end
handled = element:mousepressed(x - element.x, y - element.y, button) handled = element:mousepressed(x - element.x, y - element.y, button)
end end
if handled then if handled then
print("pop.focused has been set!") print("pop.focused has been set!")
pop.focused = element pop.focused = element
pop.events[button] = element
if element == pop.screen then
error("pop.screen fucking focused SOMEHOW")
end
else else
for i = 1, #element.child do for i = 1, #element.child do
handled = pop.mousepressed(x, y, button, element.child[i]) handled = pop.mousepressed(x, y, button, element.child[i])
@ -151,9 +159,6 @@ pop.mousepressed = function(x, y, button, element)
end end
end end
end end
if handled then
pop.events[button] = element
end
return handled return handled
end end
pop.mousereleased = function(x, y, button) pop.mousereleased = function(x, y, button)
@ -163,6 +168,7 @@ pop.mousereleased = function(x, y, button)
do do
local element = pop.events[button] local element = pop.events[button]
if element then if element then
print("mousereleased should be functional")
if element.clicked 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 (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h) then
do do
clickedHandled = element:clicked(x - element.x, y - element.y, button) clickedHandled = element:clicked(x - element.x, y - element.y, button)
@ -171,7 +177,11 @@ pop.mousereleased = function(x, y, button)
end end
end end
end end
for k, v in pairs(element) do
print(k, v)
end
if element.mousereleased then if element.mousereleased then
print("mousereleased SHOULD be called")
do do
mousereleasedHandled = element:mousereleased(x - element.x, y - element.y, button) mousereleasedHandled = element:mousereleased(x - element.x, y - element.y, button)
if mousereleasedHandled then if mousereleasedHandled then

View File

@ -5,8 +5,8 @@ path = sub ..., 1, len(...) - len "/box"
element = require "#{path}/element" element = require "#{path}/element"
class box extends element class box extends element
new: (pop, parent, background=false) => new: (parent, background=false) =>
super pop, parent super parent
@w = 20 @w = 20
@h = 20 @h = 20

View File

@ -2,8 +2,7 @@ import graphics from love
import floor from math import floor from math
class element class element
new: (pop, parent) => new: (parent) =>
@pop = pop
@parent = parent @parent = parent
@child = {} @child = {}

View File

@ -4,26 +4,22 @@ import sub, len from string
path = sub ..., 1, len(...) - len "/box" path = sub ..., 1, len(...) - len "/box"
element = require "#{path}/element" element = require "#{path}/element"
util = sub path, 1, len(path) - len "/elements" --util = sub path, 1, len(path) - len "/elements"
import inheritsFromElement from require "#{util}/util" --import inheritsFromElement from require "#{util}/util"
class text extends element class text extends element
wrap: (pop) -> wrap: (pop) ->
return (parent, ...) -> return (parent, ...) ->
if type(parent) == "string" if type(parent) == "string"
return pop.create("text", nil, parent, ...) return pop.create("text", nil, parent, ...)
elseif inheritsFromElement parent else--if inheritsFromElement parent
return pop.create("text", parent, ...) return pop.create("text", parent, ...)
--else --elseif parent == false
-- return pop.create("text", )
-- error "text wrapper failed", parent -- error "text wrapper failed", parent
new: (pop, parent, text="", color={255,255,255,255}) => new: (parent, text="", color={255,255,255,255}) =>
print("---===---") super parent
print(@, pop, parent, text, color)
print(pop.load)
print("---===---")
super pop, parent
@font = graphics.newFont 14 @font = graphics.newFont 14
@setText text @setText text

View File

@ -22,10 +22,17 @@ do
print "elements/window: unrecognized LÖVE version: #{major}.#{minor}.#{revision}" print "elements/window: unrecognized LÖVE version: #{major}.#{minor}.#{revision}"
print " assuming LÖVE version > 0.10.1 (there may be bugs)" print " assuming LÖVE version > 0.10.1 (there may be bugs)"
-- a reference to pop is needed for windows, this is obtained using the wrap function when it is loaded
pop_ref = nil -- yes, this is convoluted and needs a re-design
class window extends element class window extends element
new: (pop, parent, title="window", tBackground={25, 180, 230, 255}, tColor={255, 255, 255, 255}, wBackground={200, 200, 210, 255}) => wrap: (pop) ->
print (parent == pop.screen), (title == "Window") pop_ref = pop -- set our reference to pop (needed for mouse handling)
super pop, parent return (...) -> -- standard wrapper, nothing special needed
return pop.create("window", ...)
new: (parent, title="window", tBackground={25, 180, 230, 255}, tColor={255, 255, 255, 255}, wBackground={200, 200, 210, 255}) =>
super parent
@head = box @, tBackground -- title box at top @head = box @, tBackground -- title box at top
print @, title, tColor print @, title, tColor
@ -50,9 +57,10 @@ class window extends element
if mousemoved_event if mousemoved_event
@head.mousemoved = (x, y, dx, dy) => @head.mousemoved = (x, y, dx, dy) =>
print "mousemoved CALLED!" --print "mousemoved CALLED!", x, y, dx, dy
if @selected if @selected
@parent\move dx, dy -- for some reason, y and dx are actually dx and dy...what the fuck? (note: in version 0.10.0)
@parent\move y, dx --dx, dy
return true return true
return false return false
@ -66,9 +74,11 @@ class window extends element
@head.mousereleased = (x, y, button) => @head.mousereleased = (x, y, button) =>
print "mousereleased CALLED!" print "mousereleased CALLED!"
print (button == left)
if button == left if button == left
@selected = false @selected = false
@pop.focused = false -- we need to have a way to clear pop_ref.focused = false -- we need to have a way to clear
print "SHOULD BE FIXED GOD FUCKING DAMMIT"
return true return true
print "ERROR FELL THROUGH" print "ERROR FELL THROUGH"
return false return false

View File

@ -71,12 +71,12 @@ pop.load = ->
-- creates an element with specified parent (parent can be false or non-existent) -- creates an element with specified parent (parent can be false or non-existent)
pop.create = (element, parent=pop.screen, ...) -> pop.create = (element, parent=pop.screen, ...) ->
if inheritsFromElement parent if inheritsFromElement parent
element = pop.elements[element](pop, parent, ...) element = pop.elements[element](parent, ...)
insert parent.child, element insert parent.child, element
elseif parent == false elseif parent == false
element = pop.elements[element](pop, false, ...) element = pop.elements[element](false, ...)
else else
element = pop.elements[element](pop, pop.screen, parent, ...) element = pop.elements[element](pop.screen, parent, ...)
insert pop.screen.child, element insert pop.screen.child, element
return element return element
@ -101,6 +101,7 @@ pop.mousemoved = (x, y, dx, dy) =>
if pop.focused and pop.focused.mousemoved if pop.focused and pop.focused.mousemoved
return pop.focused\mousemoved x, y, dx, dy return pop.focused\mousemoved x, y, dx, dy
print "mousemoved unhandled!"
return false return false
pop.mousepressed = (x, y, button, element) -> pop.mousepressed = (x, y, button, element) ->
@ -112,18 +113,23 @@ pop.mousepressed = (x, y, button, element) ->
if (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h) if (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h)
if element.mousepressed if element.mousepressed
if element == pop.screen
error "pop.screen somehow has a fucking mousepressed handler"
handled = element\mousepressed x - element.x, y - element.y, button handled = element\mousepressed x - element.x, y - element.y, button
if handled if handled
print "pop.focused has been set!" print "pop.focused has been set!"
pop.focused = element pop.focused = element
pop.events[button] = element
if element == pop.screen
error "pop.screen fucking focused SOMEHOW"
else else
for i = 1, #element.child for i = 1, #element.child
handled = pop.mousepressed x, y, button, element.child[i] handled = pop.mousepressed x, y, button, element.child[i]
if handled if handled
--pop.focused = element.child[i] --pop.focused = element.child[i]
break break
if handled --if handled
pop.events[button] = element -- pop.events[button] = element
return handled return handled
@ -134,14 +140,23 @@ pop.mousereleased = (x, y, button) ->
mousereleasedHandled = false mousereleasedHandled = false
if element = pop.events[button] if element = pop.events[button]
print "mousereleased should be functional"
if element.clicked and (x >= element.x) and (x <= element.x + element.w) and (y >= element.y) and (y <= element.y + element.h) if element.clicked 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 if clickedHandled = element\clicked x - element.x, y - element.y, button
pop.events[button] = nil pop.events[button] = nil
for k,v in pairs element
print k, v
if element.mousereleased if element.mousereleased
print "mousereleased SHOULD be called"
if mousereleasedHandled = element\mousereleased x - element.x, y - element.y, button if mousereleasedHandled = element\mousereleased x - element.x, y - element.y, button
pop.events[button] = nil pop.events[button] = nil
-- temporary, calling it regardless of its existence
--if mousereleasedHandled = element\mousereleased x - element.x, y - element.y, button
-- pop.events[button] = nil
return clickedHandled, mousereleasedHandled return clickedHandled, mousereleasedHandled
pop.keypressed = (key) -> pop.keypressed = (key) ->