mirror of
https://github.com/TangentFoxy/Pop.Box.git
synced 2024-12-15 12:44:20 +00:00
workin' on stuff, broke the everything (windows only actually..I think)
This commit is contained in:
parent
6c1df2ca55
commit
a0b6d03c2b
@ -17,7 +17,7 @@ function love.load()
|
||||
pop.box(c, {0, 255, 255}):align("right", "bottom"):setSize(50, 100):move(-50)
|
||||
pop.text(nil, "Here's some test text\n(with newlines)\nin the top left corner!")
|
||||
pop.text(nil, "Here's some test text in the bottom right corner!"):align("right", "bottom")
|
||||
pop.skin(pop.text("Here's easier-to-code test text in the center!"):align("center", "center", true)) -- 'true' means align to pixel!
|
||||
--pop.skin(pop.text("Here's easier-to-code test text in the center!"):align("center", "center", true)) -- 'true' means align to pixel!
|
||||
w = pop.box(nil, {255, 255, 255, 255}):align(false, "bottom"):setSize(150, 150)
|
||||
b = pop.box(w, {0, 0, 0, 255}):setMargin(5):setSize(100, 100)
|
||||
--]]
|
||||
|
@ -71,11 +71,11 @@ do
|
||||
_base_0.__index = _base_0
|
||||
setmetatable(_base_0, _parent_0.__base)
|
||||
_class_0 = setmetatable({
|
||||
__init = function(self, parent, background)
|
||||
__init = function(self, pop, parent, background)
|
||||
if background == nil then
|
||||
background = false
|
||||
end
|
||||
_class_0.__parent.__init(self, parent)
|
||||
_class_0.__parent.__init(self, pop, parent)
|
||||
self.w = 20
|
||||
self.h = 20
|
||||
self.background = background
|
||||
|
@ -206,7 +206,8 @@ do
|
||||
}
|
||||
_base_0.__index = _base_0
|
||||
_class_0 = setmetatable({
|
||||
__init = function(self, parent)
|
||||
__init = function(self, pop, parent)
|
||||
self.pop = pop
|
||||
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, parent, text, color)
|
||||
__init = function(self, pop, parent, text, color)
|
||||
if text == nil then
|
||||
text = ""
|
||||
end
|
||||
@ -118,7 +118,10 @@ do
|
||||
255
|
||||
}
|
||||
end
|
||||
_class_0.__parent.__init(self, parent)
|
||||
print("---===---")
|
||||
print(self, pop, parent, text, color)
|
||||
print("---===---")
|
||||
_class_0.__parent.__init(self, pop, parent)
|
||||
self.font = graphics.newFont(14)
|
||||
self:setText(text)
|
||||
self.color = color
|
||||
|
@ -10,7 +10,7 @@ local element = require(tostring(path) .. "/element")
|
||||
local box = require(tostring(path) .. "/box")
|
||||
local text = require(tostring(path) .. "/text")
|
||||
local left = 1
|
||||
local move_event = true
|
||||
local mousemoved_event = true
|
||||
do
|
||||
local major, minor, revision = love.getVersion()
|
||||
if (major == 0) and (minor == 10) and ((revision == 0) or (revision == 1)) then
|
||||
@ -19,7 +19,7 @@ do
|
||||
if (major == 0) and (minor == 9) then
|
||||
left = "l"
|
||||
if revision == 1 then
|
||||
move_event = false
|
||||
mousemoved_event = false
|
||||
end
|
||||
else
|
||||
print("elements/window: unrecognized LÖVE version: " .. tostring(major) .. "." .. tostring(minor) .. "." .. tostring(revision))
|
||||
@ -111,7 +111,7 @@ do
|
||||
_base_0.__index = _base_0
|
||||
setmetatable(_base_0, _parent_0.__base)
|
||||
_class_0 = setmetatable({
|
||||
__init = function(self, parent, title, tBackground, tColor, wBackground)
|
||||
__init = function(self, pop, parent, title, tBackground, tColor, wBackground)
|
||||
if title == nil then
|
||||
title = "window"
|
||||
end
|
||||
@ -139,8 +139,10 @@ do
|
||||
255
|
||||
}
|
||||
end
|
||||
_class_0.__parent.__init(self, parent)
|
||||
print((parent == pop.screen), (title == "Window"))
|
||||
_class_0.__parent.__init(self, pop, parent)
|
||||
self.head = box(self, tBackground)
|
||||
print(self, title, tColor)
|
||||
self.title = text(self, title, tColor)
|
||||
self.window = box(self, wBackground)
|
||||
local height = self.title:getHeight()
|
||||
@ -152,6 +154,56 @@ do
|
||||
self.title,
|
||||
self.window
|
||||
}
|
||||
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)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
self.head.mousepressed = function(self, x, y, button)
|
||||
print("mousepressed CALLED!")
|
||||
if button == left then
|
||||
print("selected!")
|
||||
self.selected = true
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
self.head.mousereleased = function(self, x, y, button)
|
||||
print("mousereleased CALLED!")
|
||||
if button == left then
|
||||
self.selected = false
|
||||
self.pop.focused = false
|
||||
return true
|
||||
end
|
||||
print("ERROR FELL THROUGH")
|
||||
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",
|
||||
|
@ -87,12 +87,12 @@ pop.create = function(element, parent, ...)
|
||||
parent = pop.screen
|
||||
end
|
||||
if inheritsFromElement(parent) then
|
||||
element = pop.elements[element](parent, ...)
|
||||
element = pop.elements[element](pop, parent, ...)
|
||||
insert(parent.child, element)
|
||||
elseif parent == false then
|
||||
element = pop.elements[element](false, ...)
|
||||
element = pop.elements[element](pop, false, ...)
|
||||
else
|
||||
element = pop.elements[element](pop.screen, parent, ...)
|
||||
element = pop.elements[element](pop, pop.screen, parent, ...)
|
||||
insert(pop.screen.child, element)
|
||||
end
|
||||
return element
|
||||
@ -140,12 +140,12 @@ pop.mousepressed = function(x, y, button, element)
|
||||
handled = element:mousepressed(x - element.x, y - element.y, button)
|
||||
end
|
||||
if handled then
|
||||
print("pop.focused has been set!")
|
||||
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
|
||||
|
@ -71,11 +71,11 @@ do
|
||||
_base_0.__index = _base_0
|
||||
setmetatable(_base_0, _parent_0.__base)
|
||||
_class_0 = setmetatable({
|
||||
__init = function(self, parent, background)
|
||||
__init = function(self, pop, parent, background)
|
||||
if background == nil then
|
||||
background = false
|
||||
end
|
||||
_class_0.__parent.__init(self, parent)
|
||||
_class_0.__parent.__init(self, pop, parent)
|
||||
self.w = 20
|
||||
self.h = 20
|
||||
self.background = background
|
||||
|
@ -206,7 +206,8 @@ do
|
||||
}
|
||||
_base_0.__index = _base_0
|
||||
_class_0 = setmetatable({
|
||||
__init = function(self, parent)
|
||||
__init = function(self, pop, parent)
|
||||
self.pop = pop
|
||||
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, parent, text, color)
|
||||
__init = function(self, pop, parent, text, color)
|
||||
if text == nil then
|
||||
text = ""
|
||||
end
|
||||
@ -118,7 +118,10 @@ do
|
||||
255
|
||||
}
|
||||
end
|
||||
_class_0.__parent.__init(self, parent)
|
||||
print("---===---")
|
||||
print(self, pop, parent, text, color)
|
||||
print("---===---")
|
||||
_class_0.__parent.__init(self, pop, parent)
|
||||
self.font = graphics.newFont(14)
|
||||
self:setText(text)
|
||||
self.color = color
|
||||
|
@ -10,7 +10,7 @@ local element = require(tostring(path) .. "/element")
|
||||
local box = require(tostring(path) .. "/box")
|
||||
local text = require(tostring(path) .. "/text")
|
||||
local left = 1
|
||||
local move_event = true
|
||||
local mousemoved_event = true
|
||||
do
|
||||
local major, minor, revision = love.getVersion()
|
||||
if (major == 0) and (minor == 10) and ((revision == 0) or (revision == 1)) then
|
||||
@ -19,7 +19,7 @@ do
|
||||
if (major == 0) and (minor == 9) then
|
||||
left = "l"
|
||||
if revision == 1 then
|
||||
move_event = false
|
||||
mousemoved_event = false
|
||||
end
|
||||
else
|
||||
print("elements/window: unrecognized LÖVE version: " .. tostring(major) .. "." .. tostring(minor) .. "." .. tostring(revision))
|
||||
@ -111,7 +111,7 @@ do
|
||||
_base_0.__index = _base_0
|
||||
setmetatable(_base_0, _parent_0.__base)
|
||||
_class_0 = setmetatable({
|
||||
__init = function(self, parent, title, tBackground, tColor, wBackground)
|
||||
__init = function(self, pop, parent, title, tBackground, tColor, wBackground)
|
||||
if title == nil then
|
||||
title = "window"
|
||||
end
|
||||
@ -139,8 +139,10 @@ do
|
||||
255
|
||||
}
|
||||
end
|
||||
_class_0.__parent.__init(self, parent)
|
||||
print((parent == pop.screen), (title == "Window"))
|
||||
_class_0.__parent.__init(self, pop, parent)
|
||||
self.head = box(self, tBackground)
|
||||
print(self, title, tColor)
|
||||
self.title = text(self, title, tColor)
|
||||
self.window = box(self, wBackground)
|
||||
local height = self.title:getHeight()
|
||||
@ -152,6 +154,56 @@ do
|
||||
self.title,
|
||||
self.window
|
||||
}
|
||||
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)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
self.head.mousepressed = function(self, x, y, button)
|
||||
print("mousepressed CALLED!")
|
||||
if button == left then
|
||||
print("selected!")
|
||||
self.selected = true
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
self.head.mousereleased = function(self, x, y, button)
|
||||
print("mousereleased CALLED!")
|
||||
if button == left then
|
||||
self.selected = false
|
||||
self.pop.focused = false
|
||||
return true
|
||||
end
|
||||
print("ERROR FELL THROUGH")
|
||||
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",
|
||||
|
@ -87,12 +87,12 @@ pop.create = function(element, parent, ...)
|
||||
parent = pop.screen
|
||||
end
|
||||
if inheritsFromElement(parent) then
|
||||
element = pop.elements[element](parent, ...)
|
||||
element = pop.elements[element](pop, parent, ...)
|
||||
insert(parent.child, element)
|
||||
elseif parent == false then
|
||||
element = pop.elements[element](false, ...)
|
||||
element = pop.elements[element](pop, false, ...)
|
||||
else
|
||||
element = pop.elements[element](pop.screen, parent, ...)
|
||||
element = pop.elements[element](pop, pop.screen, parent, ...)
|
||||
insert(pop.screen.child, element)
|
||||
end
|
||||
return element
|
||||
@ -140,12 +140,12 @@ pop.mousepressed = function(x, y, button, element)
|
||||
handled = element:mousepressed(x - element.x, y - element.y, button)
|
||||
end
|
||||
if handled then
|
||||
print("pop.focused has been set!")
|
||||
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
|
||||
|
@ -5,8 +5,8 @@ path = sub ..., 1, len(...) - len "/box"
|
||||
element = require "#{path}/element"
|
||||
|
||||
class box extends element
|
||||
new: (parent, background=false) =>
|
||||
super parent
|
||||
new: (pop, parent, background=false) =>
|
||||
super pop, parent
|
||||
|
||||
@w = 20
|
||||
@h = 20
|
||||
|
@ -2,7 +2,8 @@ import graphics from love
|
||||
import floor from math
|
||||
|
||||
class element
|
||||
new: (parent) =>
|
||||
new: (pop, parent) =>
|
||||
@pop = pop
|
||||
@parent = parent
|
||||
@child = {}
|
||||
|
||||
|
@ -12,8 +12,12 @@ class text extends element
|
||||
else
|
||||
return pop.create("text", parent, ...)
|
||||
|
||||
new: (parent, text="", color={255,255,255,255}) =>
|
||||
super parent
|
||||
new: (pop, parent, text="", color={255,255,255,255}) =>
|
||||
print("---===---")
|
||||
print(@, pop, parent, text, color)
|
||||
print("---===---")
|
||||
|
||||
super pop, parent
|
||||
|
||||
@font = graphics.newFont 14
|
||||
@setText text
|
||||
|
@ -8,7 +8,7 @@ text = require "#{path}/text"
|
||||
|
||||
-- version compatibility
|
||||
left = 1 -- what is the left mouse button?
|
||||
move_event = true -- is the mousemoved event available?
|
||||
mousemoved_event = true -- is the mousemoved event available?
|
||||
|
||||
do
|
||||
major, minor, revision = love.getVersion!
|
||||
@ -17,16 +17,18 @@ do
|
||||
if (major == 0) and (minor == 9)
|
||||
left = "l"
|
||||
if revision == 1
|
||||
move_event = false
|
||||
mousemoved_event = false
|
||||
else
|
||||
print "elements/window: unrecognized LÖVE version: #{major}.#{minor}.#{revision}"
|
||||
print " assuming LÖVE version > 0.10.1 (there may be bugs)"
|
||||
|
||||
class window extends element
|
||||
new: (parent, title="window", tBackground={25, 180, 230, 255}, tColor={255, 255, 255, 255}, wBackground={200, 200, 210, 255}) =>
|
||||
super parent
|
||||
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
|
||||
|
||||
@head = box @, tBackground -- title box at top
|
||||
print @, title, tColor
|
||||
@title = text @, title, tColor -- text at top
|
||||
@window = box @, wBackground -- main window area
|
||||
|
||||
@ -44,6 +46,53 @@ class window extends element
|
||||
--@selected = false -- whether or not the window title (and thus, the window) has been selected
|
||||
--NOTE all of these commented out, because I realized these event handlers should be attached to the title element
|
||||
|
||||
@head.selected = false -- whether or not the window title (and thus, the window) has been selected
|
||||
|
||||
if mousemoved_event
|
||||
@head.mousemoved = (x, y, dx, dy) =>
|
||||
print "mousemoved CALLED!"
|
||||
if @selected
|
||||
@parent\move dx, dy
|
||||
return true
|
||||
return false
|
||||
|
||||
@head.mousepressed = (x, y, button) =>
|
||||
print "mousepressed CALLED!"
|
||||
if button == left
|
||||
print "selected!"
|
||||
@selected = true
|
||||
return true
|
||||
return false
|
||||
|
||||
@head.mousereleased = (x, y, button) =>
|
||||
print "mousereleased CALLED!"
|
||||
if button == left
|
||||
@selected = false
|
||||
@pop.focused = false -- we need to have a way to clear
|
||||
return true
|
||||
print "ERROR FELL THROUGH"
|
||||
return false
|
||||
|
||||
else
|
||||
@head.mx = 0 -- local mouse coordinates when selected
|
||||
@head.my = 0
|
||||
|
||||
@head.update = =>
|
||||
--TODO write me!
|
||||
return false
|
||||
|
||||
@head.mousepressed = (x, y, button) =>
|
||||
if button == left
|
||||
@selected = true
|
||||
@mx = x
|
||||
@my = y
|
||||
|
||||
@head.mousereleased = (x, y, button) => -- this is actually the same for both versions...
|
||||
if button == left
|
||||
@selected = false
|
||||
return true
|
||||
return false
|
||||
|
||||
debugDraw: =>
|
||||
graphics.setLineWidth 0.5
|
||||
graphics.setColor 0, 0, 0, 100
|
||||
|
@ -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](parent, ...)
|
||||
element = pop.elements[element](pop, parent, ...)
|
||||
insert parent.child, element
|
||||
elseif parent == false
|
||||
element = pop.elements[element](false, ...)
|
||||
element = pop.elements[element](pop, false, ...)
|
||||
else
|
||||
element = pop.elements[element](pop.screen, parent, ...)
|
||||
element = pop.elements[element](pop, pop.screen, parent, ...)
|
||||
insert pop.screen.child, element
|
||||
|
||||
return element
|
||||
@ -114,12 +114,13 @@ pop.mousepressed = (x, y, button, element) ->
|
||||
if element.mousepressed
|
||||
handled = element\mousepressed x - element.x, y - element.y, button
|
||||
if handled
|
||||
print "pop.focused has been set!"
|
||||
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]
|
||||
--pop.focused = element.child[i]
|
||||
break
|
||||
if handled
|
||||
pop.events[button] = element
|
||||
|
Loading…
Reference in New Issue
Block a user