From e5e9f0621e3d39e585ec362fa22a5022eba38c08 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 14 Apr 2021 21:12:59 -0400 Subject: node-2d: Add <9-patch> class. --- starling/node-2d.scm | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/starling/node-2d.scm b/starling/node-2d.scm index f439ebe..1af8a2a 100644 --- a/starling/node-2d.scm +++ b/starling/node-2d.scm @@ -26,6 +26,8 @@ #:use-module (chickadee math matrix) #:use-module (chickadee math rect) #:use-module (chickadee math vector) + #:use-module (chickadee graphics 9-patch) + #:use-module (chickadee graphics blend) #:use-module (chickadee graphics color) #:use-module (chickadee graphics engine) #:use-module (chickadee graphics font) @@ -111,6 +113,12 @@ start-time change-animation + + top-margin + bottom-margin + left-margin + right-margin + batch @@ -675,6 +683,53 @@ (set! (current-animation sprite) name) (set! (start-time sprite) (elapsed-time))) + +;;; +;;; 9-Patch +;;; + +(define-class <9-patch> () + (texture #:accessor texture #:init-keyword #:texture #:asset? #t) + (left-margin #:accessor left-margin #:init-keyword #:left) + (right-margin #:accessor right-margin #:init-keyword #:right) + (bottom-margin #:accessor bottom-margin #:init-keyword #:bottom) + (top-margin #:accessor top-margin #:init-keyword #:top) + (mode #:accessor mode #:init-keyword #:mode #:init-value 'stretch) + (blend-mode #:accessor blend-mode #:init-keyword #:blend-mode + #:init-value blend:alpha) + (tint #:accessor tint #:init-keyword #:tint #:init-value white) + (render-rect #:getter render-rect #:init-form (make-rect 0.0 0.0 0.0 0.0))) + +(define-method (initialize (9-patch <9-patch>) initargs) + (let ((default-margin (get-keyword #:margin initargs 0.0))) + (slot-set! 9-patch 'left-margin default-margin) + (slot-set! 9-patch 'right-margin default-margin) + (slot-set! 9-patch 'bottom-margin default-margin) + (slot-set! 9-patch 'top-margin default-margin)) + (next-method) + (set-rect-width! (render-rect 9-patch) (width 9-patch)) + (set-rect-height! (render-rect 9-patch) (height 9-patch))) + +(define-method (on-change (9-patch <9-patch>) slot-name old new) + (case slot-name + ((width) + (set-rect-width! (render-rect 9-patch) width)) + ((height) + (set-rect-height! (render-rect 9-patch) height))) + (next-method)) + +(define-method (render (9-patch <9-patch>) alpha) + (draw-9-patch* (texture 9-patch) + (render-rect 9-patch) + (world-matrix 9-patch) + #:top-margin (top-margin 9-patch) + #:bottom-margin (bottom-margin 9-patch) + #:left-margin (left-margin 9-patch) + #:right-margin (right-margin 9-patch) + #:mode (mode 9-patch) + #:blend-mode (blend-mode 9-patch) + #:tint (tint 9-patch))) + ;;; ;;; Sprite Batch -- cgit v1.2.3