summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chickadee/render/font.scm33
1 files changed, 13 insertions, 20 deletions
diff --git a/chickadee/render/font.scm b/chickadee/render/font.scm
index fab1977..c2c1bea 100644
--- a/chickadee/render/font.scm
+++ b/chickadee/render/font.scm
@@ -44,11 +44,10 @@
draw-text))
(define-record-type <font-char>
- (make-font-char id texture region offset dimensions advance)
+ (make-font-char id texture-region offset dimensions advance)
font-char?
(id font-char-id)
- (texture font-char-texture)
- (region font-char-region)
+ (texture-region font-char-texture-region)
(offset font-char-offset)
(dimensions font-char-dimensions)
(advance font-char-advance))
@@ -112,12 +111,9 @@
(attr node 'yoffset string->number)))
(x-advance (attr node 'xadvance string->number))
(page (or (attr node 'page string->number) 0))
- (region (make-rect (x->s x)
- (y->t y)
- (x->s width)
- (y->t height)))
+ (region (make-texture-region (hash-ref pages page)
+ x y width height))
(char (make-font-char id
- (hash-ref pages page)
region
(vec2 x-offset y-offset)
(vec2 width height)
@@ -161,8 +157,8 @@
(hashv-ref (font-chars font) char))
(define draw-text
- (let ((p (vec2 0.0 0.0))
- (rect (make-rect 0.0 0.0 0.0 0.0)))
+ (let ((cursor (vec2 0.0 0.0))
+ (char-pos (vec2 0.0 0.0)))
(lambda* (font text position #:key scale rotation (blend-mode 'alpha))
"Draw the string TEXT with the first character starting at
POSITION using FONT."
@@ -171,21 +167,18 @@ POSITION using FONT."
(let* ((char (font-ref font c))
(dimensions (font-char-dimensions char))
(offset (font-char-offset char)))
- (set-rect-x! rect (+ (vec2-x p) (vec2-x offset)))
- (set-rect-y! rect (+ (vec2-y p) (vec2-y offset)))
- (set-rect-width! rect (vec2-x dimensions))
- (set-rect-height! rect (vec2-y dimensions))
- (draw-sprite (font-char-texture char)
- rect
- #:texcoords (font-char-region char)
+ (set-vec2-x! char-pos (+ (vec2-x cursor) (vec2-x offset)))
+ (set-vec2-y! char-pos (+ (vec2-y cursor) (vec2-y offset)))
+ (draw-sprite (font-char-texture-region char)
+ char-pos
#:scale scale
#:rotation rotation
#:blend-mode blend-mode)
;; Move forward to where the next character needs to be drawn.
- (set-vec2-x! p
- (+ (vec2-x p)
+ (set-vec2-x! cursor
+ (+ (vec2-x cursor)
(vec2-x
(font-char-advance char))))))
- (vec2-copy! position p) ; initialize position
+ (vec2-copy! position cursor) ; initialize position
(with-batched-sprites
(string-for-each render-char text)))))