mirror of
https://github.com/TangentFoxy/Pop.Box.git
synced 2024-12-15 12:44:20 +00:00
src cleanup, fix #9
This commit is contained in:
parent
e4e39449d8
commit
99ad9698aa
@ -57,4 +57,4 @@ class box extends element
|
|||||||
if type(@background) == "table"
|
if type(@background) == "table"
|
||||||
return unpack @background
|
return unpack @background
|
||||||
else
|
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
|
||||||
|
@ -42,7 +42,7 @@ class element
|
|||||||
addChild: (child) =>
|
addChild: (child) =>
|
||||||
-- make sure we don't duplicate references
|
-- make sure we don't duplicate references
|
||||||
if child.parent
|
if child.parent
|
||||||
child.parent\removeChild(child)
|
child.parent\removeChild child
|
||||||
|
|
||||||
insert @child, child
|
insert @child, child
|
||||||
child.parent = @
|
child.parent = @
|
||||||
@ -104,7 +104,6 @@ class element
|
|||||||
y = oldY
|
y = oldY
|
||||||
|
|
||||||
for i = 1, #@child
|
for i = 1, #@child
|
||||||
unless @child[i].excludeMovement
|
|
||||||
@child[i]\move x - oldX, y - oldY
|
@child[i]\move x - oldX, y - oldY
|
||||||
|
|
||||||
return @
|
return @
|
||||||
|
@ -5,7 +5,7 @@ path = sub ..., 1, len(...) - len "/box"
|
|||||||
element = require "#{path}/element"
|
element = require "#{path}/element"
|
||||||
|
|
||||||
class text extends 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) ->
|
@wrap = (pop) ->
|
||||||
return (parent, ...) ->
|
return (parent, ...) ->
|
||||||
if type(parent) == "string"
|
if type(parent) == "string"
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import graphics from love
|
import graphics from love
|
||||||
|
import insert, remove from table
|
||||||
import sub, len from string
|
import sub, len from string
|
||||||
|
|
||||||
path = sub ..., 1, len(...) - len "/window"
|
path = sub ..., 1, len(...) - len "/window"
|
||||||
@ -28,11 +29,6 @@ class window extends element
|
|||||||
load: (pop) ->
|
load: (pop) ->
|
||||||
pop_ref = 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}) =>
|
new: (parent, title="window", tBackground={25, 180, 230, 255}, tColor={255, 255, 255, 255}, wBackground={200, 200, 210, 255}) =>
|
||||||
super parent
|
super parent
|
||||||
|
|
||||||
@ -52,15 +48,12 @@ class window extends element
|
|||||||
@head, @title, @window
|
@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
|
@head.selected = false -- whether or not the window title (and thus, the window) has been selected
|
||||||
|
|
||||||
if mousemoved_event
|
if mousemoved_event
|
||||||
@head.mousemoved = (x, y, dx, dy) =>
|
@head.mousemoved = (x, y, dx, dy) =>
|
||||||
if @selected
|
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
|
@parent\move y, dx --dx, dy
|
||||||
return true
|
return true
|
||||||
return false
|
return false
|
||||||
@ -110,11 +103,18 @@ class window extends element
|
|||||||
return @
|
return @
|
||||||
|
|
||||||
addChild: (child) =>
|
addChild: (child) =>
|
||||||
@window.child[#@window.child+1] = child
|
@window\addChild child
|
||||||
child.parent = @window
|
|
||||||
|
|
||||||
return @
|
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: =>
|
getChildren: =>
|
||||||
return @window.child
|
return @window.child
|
||||||
|
|
||||||
|
@ -68,17 +68,20 @@ pop.load = ->
|
|||||||
|
|
||||||
print "extension loaded: \"#{name}\""
|
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!)
|
pop.screen = pop.create("element", false)\setSize(graphics.getWidth!, graphics.getHeight!)
|
||||||
print "created \"pop.screen\""
|
print "created \"pop.screen\""
|
||||||
|
|
||||||
-- 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 valid parent element (includes default of pop.screen when no parent has been passed)
|
||||||
if inheritsFromElement parent
|
if inheritsFromElement parent
|
||||||
element = pop.elements[element](parent, ...)
|
element = pop.elements[element](parent, ...)
|
||||||
insert parent.child, element
|
insert parent.child, element
|
||||||
|
-- if explicitly no parent
|
||||||
elseif parent == false
|
elseif parent == false
|
||||||
element = pop.elements[element](false, ...)
|
element = pop.elements[element](false, ...)
|
||||||
|
-- else we use pop.screen, and "parent" is actually first argument
|
||||||
else
|
else
|
||||||
element = pop.elements[element](pop.screen, parent, ...)
|
element = pop.elements[element](pop.screen, parent, ...)
|
||||||
insert pop.screen.child, element
|
insert pop.screen.child, element
|
||||||
@ -86,7 +89,6 @@ pop.create = (element, parent=pop.screen, ...) ->
|
|||||||
return element
|
return element
|
||||||
|
|
||||||
pop.update = (dt, element=pop.screen) ->
|
pop.update = (dt, element=pop.screen) ->
|
||||||
--pop.screen\update dt
|
|
||||||
unless element.excludeUpdate
|
unless element.excludeUpdate
|
||||||
if element.update
|
if element.update
|
||||||
element\update dt
|
element\update dt
|
||||||
@ -94,7 +96,6 @@ pop.update = (dt, element=pop.screen) ->
|
|||||||
pop.update dt, element.child[i]
|
pop.update dt, element.child[i]
|
||||||
|
|
||||||
pop.draw = (element=pop.screen) ->
|
pop.draw = (element=pop.screen) ->
|
||||||
--pop.screen\draw!
|
|
||||||
unless element.excludeDraw
|
unless element.excludeDraw
|
||||||
if element.draw
|
if element.draw
|
||||||
element\draw!
|
element\draw!
|
||||||
|
Loading…
Reference in New Issue
Block a user