summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2021-04-14 21:12:59 -0400
committerDavid Thompson <dthompson2@worcester.edu>2021-04-14 21:13:30 -0400
commite5e9f0621e3d39e585ec362fa22a5022eba38c08 (patch)
tree7a32ee34032377bb7e5aaa27f06dda7d4d448b9c
parentb9eed31f9812f3190c9a14386afeb8ab59643447 (diff)
node-2d: Add <9-patch> class.
-rw-r--r--starling/node-2d.scm55
1 files changed, 55 insertions, 0 deletions
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
+ <nine-patch>
+ top-margin
+ bottom-margin
+ left-margin
+ right-margin
+
<sprite-batch>
batch
@@ -677,6 +685,53 @@
;;;
+;;; 9-Patch
+;;;
+
+(define-class <9-patch> (<node-2d>)
+ (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
;;;