summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2022-12-14 21:58:03 -0500
committerDavid Thompson <dthompson2@worcester.edu>2022-12-14 21:58:03 -0500
commit57cde916fb7b0794dd44382b0526336c654afddd (patch)
tree2470e93993fc1adfb9e1d15f61e3b24e13183e0f
parenta041ba88379729537cf1042d57a6c8bcfc269e5c (diff)
node-2d: Add centering within parent procedures.
-rw-r--r--catbird/node-2d.scm20
1 files changed, 20 insertions, 0 deletions
diff --git a/catbird/node-2d.scm b/catbird/node-2d.scm
index 0a1f683..05393fa 100644
--- a/catbird/node-2d.scm
+++ b/catbird/node-2d.scm
@@ -56,8 +56,11 @@
align-right
align-top
center
+ center-in-parent
center-horizontal
+ center-horizontal-in-parent
center-vertical
+ center-vertical-in-parent
default-height
default-width
expire-local-matrix
@@ -726,6 +729,23 @@ A."
(center-horizontal a b)
(center-vertical a b))
+(define (center-horizontal-in-parent node)
+ "Center x position of NODE within its parent."
+ (set! (position-x node)
+ (+ (/ (- (width (parent node)) (local-width node)) 2.0)
+ (- (local-origin-x node) (local-x node)))))
+
+(define (center-vertical-in-parent node)
+ "Center y position of NODE within its parent."
+ (set! (position-y node)
+ (+ (/ (- (height (parent node)) (local-height node)) 2.0)
+ (- (local-origin-y node) (local-y node)))))
+
+(define (center-in-parent node)
+ "Center NODE within its parent."
+ (center-horizontal-in-parent node)
+ (center-vertical-in-parent node))
+
;;;
;;; Sprite