summaryrefslogtreecommitdiff
path: root/starling/node.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@vistahigherlearning.com>2019-07-11 18:31:35 -0400
committerDavid Thompson <dthompson@vistahigherlearning.com>2019-07-11 18:31:35 -0400
commit4a9357d489352102570a6a2d7afb3bf096105195 (patch)
tree25ca33749b4fbbad71340cfb69f08242af234bfb /starling/node.scm
parenta6d8b4e287f0ac32d72feab10c2bf452d65fac32 (diff)
node: Add on-attach and on-detach methods.
Diffstat (limited to 'starling/node.scm')
-rw-r--r--starling/node.scm17
1 files changed, 15 insertions, 2 deletions
diff --git a/starling/node.scm b/starling/node.scm
index 07fef48..920a9bd 100644
--- a/starling/node.scm
+++ b/starling/node.scm
@@ -1,5 +1,5 @@
;;; Starling Game Engine
-;;; Copyright © 2018 David Thompson <davet@gnu.org>
+;;; Copyright © 2018, 2019 David Thompson <davet@gnu.org>
;;;
;;; This program is free software: you can redistribute it and/or
;;; modify it under the terms of the GNU General Public License as
@@ -50,6 +50,8 @@
render-tree
child-ref
&
+ on-attach
+ on-detach
attach-to
detach
run-script
@@ -205,6 +207,12 @@ represented as a ratio in the range [0, 1]."
((_ parent child-name . rest)
(& (child-ref parent 'child-name) . rest))))
+(define-method (on-attach (parent <node>) (child <node>))
+ #t)
+
+(define-method (on-detach (parent <node>) (child <node>))
+ #t)
+
(define-method (attach-to (new-parent <node>) . new-children)
"Attach NEW-CHILDREN to NEW-PARENT."
;; Validate all children first. The whole operation will fail if
@@ -230,6 +238,10 @@ represented as a ratio in the range [0, 1]."
;; must also be active.
(when (active? new-parent)
(activate child)))
+ new-children)
+ ;; Notify parent of attach event.
+ (for-each (lambda (child)
+ (on-attach new-parent child))
new-children))
(define-method (detach (node <node>))
@@ -242,7 +254,8 @@ represented as a ratio in the range [0, 1]."
;; Detaching deactives the node and all of its children.
(when (active? node)
(deactivate node))
- (set! (parent node) #f)))
+ (set! (parent node) #f)
+ (on-detach p node)))
(define-method (detach . nodes)
"Detach all NODES from their respective parents."