mirror of
https://github.com/TangentFoxy/Pop.Box.git
synced 2024-12-15 12:44:20 +00:00
window working, I fucking broke it in stupid ways
This commit is contained in:
parent
6586106a6f
commit
8256bb499a
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -2,8 +2,7 @@ import graphics from love
|
||||
import floor from math
|
||||
|
||||
class element
|
||||
new: (pop, parent) =>
|
||||
@pop = pop
|
||||
new: (parent) =>
|
||||
@parent = parent
|
||||
@child = {}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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) ->
|
||||
|
Loading…
Reference in New Issue
Block a user