workin' on stuff, broke the everything (windows only actually..I think)

This commit is contained in:
Paul Liverman III 2016-04-01 23:31:05 -07:00
parent 6c1df2ca55
commit a0b6d03c2b
16 changed files with 207 additions and 40 deletions

View File

@ -17,7 +17,7 @@ function love.load()
pop.box(c, {0, 255, 255}):align("right", "bottom"):setSize(50, 100):move(-50) 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\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.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) 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) b = pop.box(w, {0, 0, 0, 255}):setMargin(5):setSize(100, 100)
--]] --]]

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, parent, background) __init = function(self, pop, parent, background)
if background == nil then if background == nil then
background = false background = false
end end
_class_0.__parent.__init(self, parent) _class_0.__parent.__init(self, pop, parent)
self.w = 20 self.w = 20
self.h = 20 self.h = 20
self.background = background self.background = background

View File

@ -206,7 +206,8 @@ do
} }
_base_0.__index = _base_0 _base_0.__index = _base_0
_class_0 = setmetatable({ _class_0 = setmetatable({
__init = function(self, parent) __init = function(self, pop, 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, parent, text, color) __init = function(self, pop, parent, text, color)
if text == nil then if text == nil then
text = "" text = ""
end end
@ -118,7 +118,10 @@ do
255 255
} }
end 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.font = graphics.newFont(14)
self:setText(text) self:setText(text)
self.color = color self.color = color

View File

@ -10,7 +10,7 @@ local element = require(tostring(path) .. "/element")
local box = require(tostring(path) .. "/box") local box = require(tostring(path) .. "/box")
local text = require(tostring(path) .. "/text") local text = require(tostring(path) .. "/text")
local left = 1 local left = 1
local move_event = true local mousemoved_event = true
do do
local major, minor, revision = love.getVersion() local major, minor, revision = love.getVersion()
if (major == 0) and (minor == 10) and ((revision == 0) or (revision == 1)) then 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 if (major == 0) and (minor == 9) then
left = "l" left = "l"
if revision == 1 then if revision == 1 then
move_event = false mousemoved_event = false
end end
else else
print("elements/window: unrecognized LÖVE version: " .. tostring(major) .. "." .. tostring(minor) .. "." .. tostring(revision)) print("elements/window: unrecognized LÖVE version: " .. tostring(major) .. "." .. tostring(minor) .. "." .. tostring(revision))
@ -111,7 +111,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, parent, title, tBackground, tColor, wBackground) __init = function(self, pop, parent, title, tBackground, tColor, wBackground)
if title == nil then if title == nil then
title = "window" title = "window"
end end
@ -139,8 +139,10 @@ do
255 255
} }
end 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) self.head = box(self, tBackground)
print(self, title, tColor)
self.title = text(self, title, tColor) self.title = text(self, title, tColor)
self.window = box(self, wBackground) self.window = box(self, wBackground)
local height = self.title:getHeight() local height = self.title:getHeight()
@ -152,6 +154,56 @@ do
self.title, self.title,
self.window 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, end,
__base = _base_0, __base = _base_0,
__name = "window", __name = "window",

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](parent, ...) element = pop.elements[element](pop, parent, ...)
insert(parent.child, element) insert(parent.child, element)
elseif parent == false then elseif parent == false then
element = pop.elements[element](false, ...) element = pop.elements[element](pop, false, ...)
else else
element = pop.elements[element](pop.screen, parent, ...) element = pop.elements[element](pop, pop.screen, parent, ...)
insert(pop.screen.child, element) insert(pop.screen.child, element)
end end
return element return element
@ -140,12 +140,12 @@ pop.mousepressed = function(x, y, button, element)
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!")
pop.focused = element pop.focused = element
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])
if handled then if handled then
pop.focused = element.child[i]
break break
end end
end end

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, parent, background) __init = function(self, pop, parent, background)
if background == nil then if background == nil then
background = false background = false
end end
_class_0.__parent.__init(self, parent) _class_0.__parent.__init(self, pop, parent)
self.w = 20 self.w = 20
self.h = 20 self.h = 20
self.background = background self.background = background

View File

@ -206,7 +206,8 @@ do
} }
_base_0.__index = _base_0 _base_0.__index = _base_0
_class_0 = setmetatable({ _class_0 = setmetatable({
__init = function(self, parent) __init = function(self, pop, 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, parent, text, color) __init = function(self, pop, parent, text, color)
if text == nil then if text == nil then
text = "" text = ""
end end
@ -118,7 +118,10 @@ do
255 255
} }
end 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.font = graphics.newFont(14)
self:setText(text) self:setText(text)
self.color = color self.color = color

View File

@ -10,7 +10,7 @@ local element = require(tostring(path) .. "/element")
local box = require(tostring(path) .. "/box") local box = require(tostring(path) .. "/box")
local text = require(tostring(path) .. "/text") local text = require(tostring(path) .. "/text")
local left = 1 local left = 1
local move_event = true local mousemoved_event = true
do do
local major, minor, revision = love.getVersion() local major, minor, revision = love.getVersion()
if (major == 0) and (minor == 10) and ((revision == 0) or (revision == 1)) then 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 if (major == 0) and (minor == 9) then
left = "l" left = "l"
if revision == 1 then if revision == 1 then
move_event = false mousemoved_event = false
end end
else else
print("elements/window: unrecognized LÖVE version: " .. tostring(major) .. "." .. tostring(minor) .. "." .. tostring(revision)) print("elements/window: unrecognized LÖVE version: " .. tostring(major) .. "." .. tostring(minor) .. "." .. tostring(revision))
@ -111,7 +111,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, parent, title, tBackground, tColor, wBackground) __init = function(self, pop, parent, title, tBackground, tColor, wBackground)
if title == nil then if title == nil then
title = "window" title = "window"
end end
@ -139,8 +139,10 @@ do
255 255
} }
end 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) self.head = box(self, tBackground)
print(self, title, tColor)
self.title = text(self, title, tColor) self.title = text(self, title, tColor)
self.window = box(self, wBackground) self.window = box(self, wBackground)
local height = self.title:getHeight() local height = self.title:getHeight()
@ -152,6 +154,56 @@ do
self.title, self.title,
self.window 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, end,
__base = _base_0, __base = _base_0,
__name = "window", __name = "window",

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](parent, ...) element = pop.elements[element](pop, parent, ...)
insert(parent.child, element) insert(parent.child, element)
elseif parent == false then elseif parent == false then
element = pop.elements[element](false, ...) element = pop.elements[element](pop, false, ...)
else else
element = pop.elements[element](pop.screen, parent, ...) element = pop.elements[element](pop, pop.screen, parent, ...)
insert(pop.screen.child, element) insert(pop.screen.child, element)
end end
return element return element
@ -140,12 +140,12 @@ pop.mousepressed = function(x, y, button, element)
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!")
pop.focused = element pop.focused = element
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])
if handled then if handled then
pop.focused = element.child[i]
break break
end end
end end

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: (parent, background=false) => new: (pop, parent, background=false) =>
super parent super pop, parent
@w = 20 @w = 20
@h = 20 @h = 20

View File

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

View File

@ -12,8 +12,12 @@ class text extends element
else else
return pop.create("text", parent, ...) return pop.create("text", parent, ...)
new: (parent, text="", color={255,255,255,255}) => new: (pop, parent, text="", color={255,255,255,255}) =>
super parent print("---===---")
print(@, pop, parent, text, color)
print("---===---")
super pop, parent
@font = graphics.newFont 14 @font = graphics.newFont 14
@setText text @setText text

View File

@ -8,7 +8,7 @@ text = require "#{path}/text"
-- version compatibility -- version compatibility
left = 1 -- what is the left mouse button? 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 do
major, minor, revision = love.getVersion! major, minor, revision = love.getVersion!
@ -17,16 +17,18 @@ do
if (major == 0) and (minor == 9) if (major == 0) and (minor == 9)
left = "l" left = "l"
if revision == 1 if revision == 1
move_event = false mousemoved_event = false
else else
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)"
class window extends element class window extends element
new: (parent, title="window", tBackground={25, 180, 230, 255}, tColor={255, 255, 255, 255}, wBackground={200, 200, 210, 255}) => new: (pop, parent, title="window", tBackground={25, 180, 230, 255}, tColor={255, 255, 255, 255}, wBackground={200, 200, 210, 255}) =>
super parent print (parent == pop.screen), (title == "Window")
super pop, parent
@head = box @, tBackground -- title box at top @head = box @, tBackground -- title box at top
print @, title, tColor
@title = text @, title, tColor -- text at top @title = text @, title, tColor -- text at top
@window = box @, wBackground -- main window area @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 --@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 --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: => debugDraw: =>
graphics.setLineWidth 0.5 graphics.setLineWidth 0.5
graphics.setColor 0, 0, 0, 100 graphics.setColor 0, 0, 0, 100

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](parent, ...) element = pop.elements[element](pop, parent, ...)
insert parent.child, element insert parent.child, element
elseif parent == false elseif parent == false
element = pop.elements[element](false, ...) element = pop.elements[element](pop, false, ...)
else else
element = pop.elements[element](pop.screen, parent, ...) element = pop.elements[element](pop, pop.screen, parent, ...)
insert pop.screen.child, element insert pop.screen.child, element
return element return element
@ -114,12 +114,13 @@ pop.mousepressed = (x, y, button, element) ->
if element.mousepressed if element.mousepressed
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!"
pop.focused = element pop.focused = element
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