From 8256bb499aedc7c458de88ffb3a439a78632d235 Mon Sep 17 00:00:00 2001 From: Fox Date: Sat, 2 Apr 2016 23:33:18 -0700 Subject: [PATCH] window working, I fucking broke it in stupid ways --- demo/main.lua | 2 ++ demo/pop/elements/box.lua | 4 ++-- demo/pop/elements/element.lua | 3 +-- demo/pop/elements/text.lua | 7 ++----- demo/pop/elements/window.lua | 19 +++++++++++++------ demo/pop/init.lua | 22 ++++++++++++++++------ lib/pop/elements/box.lua | 4 ++-- lib/pop/elements/element.lua | 3 +-- lib/pop/elements/text.lua | 7 ++----- lib/pop/elements/window.lua | 19 +++++++++++++------ lib/pop/init.lua | 22 ++++++++++++++++------ src/pop/elements/box.moon | 4 ++-- src/pop/elements/element.moon | 3 +-- src/pop/elements/text.moon | 18 +++++++----------- src/pop/elements/window.moon | 22 ++++++++++++++++------ src/pop/init.moon | 25 ++++++++++++++++++++----- 16 files changed, 116 insertions(+), 68 deletions(-) diff --git a/demo/main.lua b/demo/main.lua index 3099637..9c34f31 100644 --- a/demo/main.lua +++ b/demo/main.lua @@ -4,6 +4,8 @@ local pop local debugDraw = false function love.load() + print(love.getVersion()) + pop = require "pop" ---[[ local c = pop.box():align("center", "center"):setSize(300, 300) diff --git a/demo/pop/elements/box.lua b/demo/pop/elements/box.lua index 292164d..6b9fb2f 100644 --- a/demo/pop/elements/box.lua +++ b/demo/pop/elements/box.lua @@ -71,11 +71,11 @@ do _base_0.__index = _base_0 setmetatable(_base_0, _parent_0.__base) _class_0 = setmetatable({ - __init = function(self, pop, parent, background) + __init = function(self, parent, background) if background == nil then background = false end - _class_0.__parent.__init(self, pop, parent) + _class_0.__parent.__init(self, parent) self.w = 20 self.h = 20 self.background = background diff --git a/demo/pop/elements/element.lua b/demo/pop/elements/element.lua index ed5b479..60ab9df 100644 --- a/demo/pop/elements/element.lua +++ b/demo/pop/elements/element.lua @@ -206,8 +206,7 @@ do } _base_0.__index = _base_0 _class_0 = setmetatable({ - __init = function(self, pop, parent) - self.pop = pop + __init = function(self, parent) self.parent = parent self.child = { } self.w = 0 diff --git a/demo/pop/elements/text.lua b/demo/pop/elements/text.lua index eecd15b..44ee6a3 100644 --- a/demo/pop/elements/text.lua +++ b/demo/pop/elements/text.lua @@ -106,7 +106,7 @@ do _base_0.__index = _base_0 setmetatable(_base_0, _parent_0.__base) _class_0 = setmetatable({ - __init = function(self, pop, parent, text, color) + __init = function(self, parent, text, color) if text == nil then text = "" end @@ -118,10 +118,7 @@ do 255 } end - print("---===---") - print(self, pop, parent, text, color) - print("---===---") - _class_0.__parent.__init(self, pop, parent) + _class_0.__parent.__init(self, parent) self.font = graphics.newFont(14) self:setText(text) self.color = color diff --git a/demo/pop/elements/window.lua b/demo/pop/elements/window.lua index 3e896fd..a35645a 100644 --- a/demo/pop/elements/window.lua +++ b/demo/pop/elements/window.lua @@ -26,11 +26,18 @@ do print(" assuming LÖVE version > 0.10.1 (there may be bugs)") end end +local pop_ref = nil local window do local _class_0 local _parent_0 = element local _base_0 = { + wrap = function(pop) + pop_ref = pop + return function(...) + return pop.create("window", ...) + end + end, debugDraw = function(self) graphics.setLineWidth(0.5) graphics.setColor(0, 0, 0, 100) @@ -111,7 +118,7 @@ do _base_0.__index = _base_0 setmetatable(_base_0, _parent_0.__base) _class_0 = setmetatable({ - __init = function(self, pop, parent, title, tBackground, tColor, wBackground) + __init = function(self, parent, title, tBackground, tColor, wBackground) if title == nil then title = "window" end @@ -139,8 +146,7 @@ do 255 } end - print((parent == pop.screen), (title == "Window")) - _class_0.__parent.__init(self, pop, parent) + _class_0.__parent.__init(self, parent) self.head = box(self, tBackground) print(self, title, tColor) self.title = text(self, title, tColor) @@ -157,9 +163,8 @@ do self.head.selected = false if mousemoved_event then self.head.mousemoved = function(self, x, y, dx, dy) - print("mousemoved CALLED!") if self.selected then - self.parent:move(dx, dy) + self.parent:move(y, dx) return true end return false @@ -175,9 +180,11 @@ do end self.head.mousereleased = function(self, x, y, button) print("mousereleased CALLED!") + print((button == left)) if button == left then self.selected = false - self.pop.focused = false + pop_ref.focused = false + print("SHOULD BE FIXED GOD FUCKING DAMMIT") return true end print("ERROR FELL THROUGH") diff --git a/demo/pop/init.lua b/demo/pop/init.lua index 37f7aef..87e7d6b 100644 --- a/demo/pop/init.lua +++ b/demo/pop/init.lua @@ -87,12 +87,12 @@ pop.create = function(element, parent, ...) parent = pop.screen end if inheritsFromElement(parent) then - element = pop.elements[element](pop, parent, ...) + element = pop.elements[element](parent, ...) insert(parent.child, element) elseif parent == false then - element = pop.elements[element](pop, false, ...) + element = pop.elements[element](false, ...) else - element = pop.elements[element](pop, pop.screen, parent, ...) + element = pop.elements[element](pop.screen, parent, ...) insert(pop.screen.child, element) end return element @@ -127,6 +127,7 @@ pop.mousemoved = function(self, x, y, dx, dy) if pop.focused and pop.focused.mousemoved then return pop.focused:mousemoved(x, y, dx, dy) end + print("mousemoved unhandled!") return false end pop.mousepressed = function(x, y, button, element) @@ -137,11 +138,18 @@ pop.mousepressed = function(x, y, button, element) 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 + 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) end if handled then print("pop.focused has been set!") pop.focused = element + pop.events[button] = element + if element == pop.screen then + error("pop.screen fucking focused SOMEHOW") + end else for i = 1, #element.child do handled = pop.mousepressed(x, y, button, element.child[i]) @@ -151,9 +159,6 @@ pop.mousepressed = function(x, y, button, element) end end end - if handled then - pop.events[button] = element - end return handled end pop.mousereleased = function(x, y, button) @@ -163,6 +168,7 @@ pop.mousereleased = function(x, y, button) do local element = pop.events[button] 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 do clickedHandled = element:clicked(x - element.x, y - element.y, button) @@ -171,7 +177,11 @@ pop.mousereleased = function(x, y, button) end end end + for k, v in pairs(element) do + print(k, v) + end if element.mousereleased then + print("mousereleased SHOULD be called") do mousereleasedHandled = element:mousereleased(x - element.x, y - element.y, button) if mousereleasedHandled then diff --git a/lib/pop/elements/box.lua b/lib/pop/elements/box.lua index 292164d..6b9fb2f 100644 --- a/lib/pop/elements/box.lua +++ b/lib/pop/elements/box.lua @@ -71,11 +71,11 @@ do _base_0.__index = _base_0 setmetatable(_base_0, _parent_0.__base) _class_0 = setmetatable({ - __init = function(self, pop, parent, background) + __init = function(self, parent, background) if background == nil then background = false end - _class_0.__parent.__init(self, pop, parent) + _class_0.__parent.__init(self, parent) self.w = 20 self.h = 20 self.background = background diff --git a/lib/pop/elements/element.lua b/lib/pop/elements/element.lua index ed5b479..60ab9df 100644 --- a/lib/pop/elements/element.lua +++ b/lib/pop/elements/element.lua @@ -206,8 +206,7 @@ do } _base_0.__index = _base_0 _class_0 = setmetatable({ - __init = function(self, pop, parent) - self.pop = pop + __init = function(self, parent) self.parent = parent self.child = { } self.w = 0 diff --git a/lib/pop/elements/text.lua b/lib/pop/elements/text.lua index eecd15b..44ee6a3 100644 --- a/lib/pop/elements/text.lua +++ b/lib/pop/elements/text.lua @@ -106,7 +106,7 @@ do _base_0.__index = _base_0 setmetatable(_base_0, _parent_0.__base) _class_0 = setmetatable({ - __init = function(self, pop, parent, text, color) + __init = function(self, parent, text, color) if text == nil then text = "" end @@ -118,10 +118,7 @@ do 255 } end - print("---===---") - print(self, pop, parent, text, color) - print("---===---") - _class_0.__parent.__init(self, pop, parent) + _class_0.__parent.__init(self, parent) self.font = graphics.newFont(14) self:setText(text) self.color = color diff --git a/lib/pop/elements/window.lua b/lib/pop/elements/window.lua index 3e896fd..a35645a 100644 --- a/lib/pop/elements/window.lua +++ b/lib/pop/elements/window.lua @@ -26,11 +26,18 @@ do print(" assuming LÖVE version > 0.10.1 (there may be bugs)") end end +local pop_ref = nil local window do local _class_0 local _parent_0 = element local _base_0 = { + wrap = function(pop) + pop_ref = pop + return function(...) + return pop.create("window", ...) + end + end, debugDraw = function(self) graphics.setLineWidth(0.5) graphics.setColor(0, 0, 0, 100) @@ -111,7 +118,7 @@ do _base_0.__index = _base_0 setmetatable(_base_0, _parent_0.__base) _class_0 = setmetatable({ - __init = function(self, pop, parent, title, tBackground, tColor, wBackground) + __init = function(self, parent, title, tBackground, tColor, wBackground) if title == nil then title = "window" end @@ -139,8 +146,7 @@ do 255 } end - print((parent == pop.screen), (title == "Window")) - _class_0.__parent.__init(self, pop, parent) + _class_0.__parent.__init(self, parent) self.head = box(self, tBackground) print(self, title, tColor) self.title = text(self, title, tColor) @@ -157,9 +163,8 @@ do self.head.selected = false if mousemoved_event then self.head.mousemoved = function(self, x, y, dx, dy) - print("mousemoved CALLED!") if self.selected then - self.parent:move(dx, dy) + self.parent:move(y, dx) return true end return false @@ -175,9 +180,11 @@ do end self.head.mousereleased = function(self, x, y, button) print("mousereleased CALLED!") + print((button == left)) if button == left then self.selected = false - self.pop.focused = false + pop_ref.focused = false + print("SHOULD BE FIXED GOD FUCKING DAMMIT") return true end print("ERROR FELL THROUGH") diff --git a/lib/pop/init.lua b/lib/pop/init.lua index 37f7aef..87e7d6b 100644 --- a/lib/pop/init.lua +++ b/lib/pop/init.lua @@ -87,12 +87,12 @@ pop.create = function(element, parent, ...) parent = pop.screen end if inheritsFromElement(parent) then - element = pop.elements[element](pop, parent, ...) + element = pop.elements[element](parent, ...) insert(parent.child, element) elseif parent == false then - element = pop.elements[element](pop, false, ...) + element = pop.elements[element](false, ...) else - element = pop.elements[element](pop, pop.screen, parent, ...) + element = pop.elements[element](pop.screen, parent, ...) insert(pop.screen.child, element) end return element @@ -127,6 +127,7 @@ pop.mousemoved = function(self, x, y, dx, dy) if pop.focused and pop.focused.mousemoved then return pop.focused:mousemoved(x, y, dx, dy) end + print("mousemoved unhandled!") return false end pop.mousepressed = function(x, y, button, element) @@ -137,11 +138,18 @@ pop.mousepressed = function(x, y, button, element) 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 + 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) end if handled then print("pop.focused has been set!") pop.focused = element + pop.events[button] = element + if element == pop.screen then + error("pop.screen fucking focused SOMEHOW") + end else for i = 1, #element.child do handled = pop.mousepressed(x, y, button, element.child[i]) @@ -151,9 +159,6 @@ pop.mousepressed = function(x, y, button, element) end end end - if handled then - pop.events[button] = element - end return handled end pop.mousereleased = function(x, y, button) @@ -163,6 +168,7 @@ pop.mousereleased = function(x, y, button) do local element = pop.events[button] 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 do clickedHandled = element:clicked(x - element.x, y - element.y, button) @@ -171,7 +177,11 @@ pop.mousereleased = function(x, y, button) end end end + for k, v in pairs(element) do + print(k, v) + end if element.mousereleased then + print("mousereleased SHOULD be called") do mousereleasedHandled = element:mousereleased(x - element.x, y - element.y, button) if mousereleasedHandled then diff --git a/src/pop/elements/box.moon b/src/pop/elements/box.moon index 73421c2..2450eb3 100644 --- a/src/pop/elements/box.moon +++ b/src/pop/elements/box.moon @@ -5,8 +5,8 @@ path = sub ..., 1, len(...) - len "/box" element = require "#{path}/element" class box extends element - new: (pop, parent, background=false) => - super pop, parent + new: (parent, background=false) => + super parent @w = 20 @h = 20 diff --git a/src/pop/elements/element.moon b/src/pop/elements/element.moon index c37de2b..b3f8c83 100644 --- a/src/pop/elements/element.moon +++ b/src/pop/elements/element.moon @@ -2,8 +2,7 @@ import graphics from love import floor from math class element - new: (pop, parent) => - @pop = pop + new: (parent) => @parent = parent @child = {} diff --git a/src/pop/elements/text.moon b/src/pop/elements/text.moon index 03a1287..3b481db 100644 --- a/src/pop/elements/text.moon +++ b/src/pop/elements/text.moon @@ -4,26 +4,22 @@ import sub, len from string path = sub ..., 1, len(...) - len "/box" element = require "#{path}/element" -util = sub path, 1, len(path) - len "/elements" -import inheritsFromElement from require "#{util}/util" +--util = sub path, 1, len(path) - len "/elements" +--import inheritsFromElement from require "#{util}/util" class text extends element wrap: (pop) -> return (parent, ...) -> if type(parent) == "string" return pop.create("text", nil, parent, ...) - elseif inheritsFromElement parent + else--if inheritsFromElement parent return pop.create("text", parent, ...) - --else + --elseif parent == false + -- return pop.create("text", ) -- error "text wrapper failed", parent - new: (pop, parent, text="", color={255,255,255,255}) => - print("---===---") - print(@, pop, parent, text, color) - print(pop.load) - print("---===---") - - super pop, parent + new: (parent, text="", color={255,255,255,255}) => + super parent @font = graphics.newFont 14 @setText text diff --git a/src/pop/elements/window.moon b/src/pop/elements/window.moon index b635006..6c8b8a0 100644 --- a/src/pop/elements/window.moon +++ b/src/pop/elements/window.moon @@ -22,10 +22,17 @@ do print "elements/window: unrecognized LÖVE version: #{major}.#{minor}.#{revision}" 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 - new: (pop, parent, title="window", tBackground={25, 180, 230, 255}, tColor={255, 255, 255, 255}, wBackground={200, 200, 210, 255}) => - print (parent == pop.screen), (title == "Window") - super pop, parent + wrap: (pop) -> + pop_ref = pop -- set our reference to pop (needed for mouse handling) + 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 print @, title, tColor @@ -50,9 +57,10 @@ class window extends element if mousemoved_event @head.mousemoved = (x, y, dx, dy) => - print "mousemoved CALLED!" + --print "mousemoved CALLED!", x, y, dx, dy 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 false @@ -66,9 +74,11 @@ class window extends element @head.mousereleased = (x, y, button) => print "mousereleased CALLED!" + print (button == left) if button == left @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 print "ERROR FELL THROUGH" return false diff --git a/src/pop/init.moon b/src/pop/init.moon index dfbde72..f0a0e65 100644 --- a/src/pop/init.moon +++ b/src/pop/init.moon @@ -71,12 +71,12 @@ pop.load = -> -- creates an element with specified parent (parent can be false or non-existent) pop.create = (element, parent=pop.screen, ...) -> if inheritsFromElement parent - element = pop.elements[element](pop, parent, ...) + element = pop.elements[element](parent, ...) insert parent.child, element elseif parent == false - element = pop.elements[element](pop, false, ...) + element = pop.elements[element](false, ...) else - element = pop.elements[element](pop, pop.screen, parent, ...) + element = pop.elements[element](pop.screen, parent, ...) insert pop.screen.child, element return element @@ -101,6 +101,7 @@ pop.mousemoved = (x, y, dx, dy) => if pop.focused and pop.focused.mousemoved return pop.focused\mousemoved x, y, dx, dy + print "mousemoved unhandled!" return false 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 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 if handled print "pop.focused has been set!" pop.focused = element + pop.events[button] = element + if element == pop.screen + error "pop.screen fucking focused SOMEHOW" else for i = 1, #element.child handled = pop.mousepressed x, y, button, element.child[i] if handled --pop.focused = element.child[i] break - if handled - pop.events[button] = element + --if handled + -- pop.events[button] = element return handled @@ -134,14 +140,23 @@ pop.mousereleased = (x, y, button) -> mousereleasedHandled = false 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 clickedHandled = element\clicked x - element.x, y - element.y, button pop.events[button] = nil + for k,v in pairs element + print k, v + if element.mousereleased + print "mousereleased SHOULD be called" if mousereleasedHandled = element\mousereleased x - element.x, y - element.y, button 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 pop.keypressed = (key) ->