diff options
author | David Thompson <dthompson2@worcester.edu> | 2022-12-27 19:28:50 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2022-12-27 19:28:50 -0500 |
commit | 6d9c61b18a8b3f46959e1d57746c9f2512c955a4 (patch) | |
tree | 83386d6726834a44b898ec7d263d485e1bc420e6 | |
parent | 9a2690d9dfe91604f67f2de09d4f3b316f7db6f4 (diff) |
graphics: 9-patch: Fix rendering of texture regions.
-rw-r--r-- | chickadee/graphics/9-patch.scm | 4 | ||||
-rw-r--r-- | examples/9-patch.scm | 14 | ||||
-rw-r--r-- | examples/images/dialog-box.png | bin | 407 -> 8050 bytes |
3 files changed, 13 insertions, 5 deletions
diff --git a/chickadee/graphics/9-patch.scm b/chickadee/graphics/9-patch.scm index 833fa42..faf5ef9 100644 --- a/chickadee/graphics/9-patch.scm +++ b/chickadee/graphics/9-patch.scm @@ -85,9 +85,9 @@ uniform int mode; float patch(float d, float m0, float m1, float length, float texLength) { if(d <= m0) { // inside the left/bottom margin. - return d; + return d * texLength; } else if(d >= length - m1) { // inside the right/top margin. - return texLength - (length - d); + return texLength - ((length - d) * texLength); } else if(mode == 0) { // in the middle, stretch mode. return mix(m0, texLength - m1, (d - m0) / (length - m0 - m1)); } else { // in the middle, tile mode. diff --git a/examples/9-patch.scm b/examples/9-patch.scm index debc69d..518ef89 100644 --- a/examples/9-patch.scm +++ b/examples/9-patch.scm @@ -6,12 +6,20 @@ (chickadee graphics texture)) (define image #f) +(define region1 #f) +(define region2 #f) +(define area1 (make-rect 192.0 192.0 256.0 96.0)) +(define area2 (make-rect 192.0 50.0 256.0 96.0)) +(define text-position (vec2 204.0 266.0)) (define (load) - (set! image (load-image "images/dialog-box.png"))) + (set! image (load-image "images/dialog-box.png")) + (set! region1 (make-texture-region image (make-rect 0.0 0.0 78.0 39.0))) + (set! region2 (make-texture-region image (make-rect 78.0 0.0 41.0 18.0)))) (define (draw alpha) - (draw-9-patch image (make-rect 192.0 192.0 256.0 96.0) #:margin 4.0) - (draw-text "I am error." (vec2 200.0 266.0))) + (draw-9-patch region1 area1 #:margin 7.0) + (draw-9-patch region2 area2 #:margin 4.0) + (draw-text "This is the 9-patch test." text-position)) (run-game #:load load #:draw draw) diff --git a/examples/images/dialog-box.png b/examples/images/dialog-box.png Binary files differindex a3b3329..c5bf71e 100644 --- a/examples/images/dialog-box.png +++ b/examples/images/dialog-box.png |