From 57cde916fb7b0794dd44382b0526336c654afddd Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 14 Dec 2022 21:58:03 -0500 Subject: node-2d: Add centering within parent procedures. --- catbird/node-2d.scm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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 -- cgit v1.2.3