src cleanup, fix #9

This commit is contained in:
Paul Liverman III 2016-04-16 23:43:15 -07:00
parent e4e39449d8
commit 99ad9698aa
5 changed files with 20 additions and 20 deletions

View File

@ -57,4 +57,4 @@ class box extends element
if type(@background) == "table"
return unpack @background
else
error "This box doesn't have a color." --might be a bad idea
error "Box \"#{@}\" doesn't have a color." --might be a bad idea

View File

@ -42,7 +42,7 @@ class element
addChild: (child) =>
-- make sure we don't duplicate references
if child.parent
child.parent\removeChild(child)
child.parent\removeChild child
insert @child, child
child.parent = @
@ -104,7 +104,6 @@ class element
y = oldY
for i = 1, #@child
unless @child[i].excludeMovement
@child[i]\move x - oldX, y - oldY
return @

View File

@ -5,7 +5,7 @@ path = sub ..., 1, len(...) - len "/box"
element = require "#{path}/element"
class text extends element
-- this should be completely unneccessary, but I'm keeping it just in case
-- this should be completely unneccessary, but I'm keeping it just in case (and moreso to remember how to do this)
@wrap = (pop) ->
return (parent, ...) ->
if type(parent) == "string"

View File

@ -1,4 +1,5 @@
import graphics from love
import insert, remove from table
import sub, len from string
path = sub ..., 1, len(...) - len "/window"
@ -28,11 +29,6 @@ class window extends element
load: (pop) ->
pop_ref = pop
--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
@ -52,15 +48,12 @@ class window extends element
@head, @title, @window
}
--@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) =>
if @selected
-- for some reason, y and dx are actually dx and dy...what the fuck? (note: in version 0.10.0)
-- for some reason, y and dx are actually dx and dy...what the fuck? (note: in version 0.10.0 AND 0.10.1)
@parent\move y, dx --dx, dy
return true
return false
@ -110,11 +103,18 @@ class window extends element
return @
addChild: (child) =>
@window.child[#@window.child+1] = child
child.parent = @window
@window\addChild child
return @
-- pass through to window, but return us if window returns itself
removeChild: (child) =>
result = @window\removeChild child
if result == @window
return @
else
return result
getChildren: =>
return @window.child

View File

@ -68,17 +68,20 @@ pop.load = ->
print "extension loaded: \"#{name}\""
-- main window (called screen because there will be a window element class)
-- main window (called screen because there is a window element class)
pop.screen = pop.create("element", false)\setSize(graphics.getWidth!, graphics.getHeight!)
print "created \"pop.screen\""
-- creates an element with specified parent (parent can be false or non-existent)
pop.create = (element, parent=pop.screen, ...) ->
-- if valid parent element (includes default of pop.screen when no parent has been passed)
if inheritsFromElement parent
element = pop.elements[element](parent, ...)
insert parent.child, element
-- if explicitly no parent
elseif parent == false
element = pop.elements[element](false, ...)
-- else we use pop.screen, and "parent" is actually first argument
else
element = pop.elements[element](pop.screen, parent, ...)
insert pop.screen.child, element
@ -86,7 +89,6 @@ pop.create = (element, parent=pop.screen, ...) ->
return element
pop.update = (dt, element=pop.screen) ->
--pop.screen\update dt
unless element.excludeUpdate
if element.update
element\update dt
@ -94,7 +96,6 @@ pop.update = (dt, element=pop.screen) ->
pop.update dt, element.child[i]
pop.draw = (element=pop.screen) ->
--pop.screen\draw!
unless element.excludeDraw
if element.draw
element\draw!