diff options
Diffstat (limited to 'chickadee/render/font.scm')
-rw-r--r-- | chickadee/render/font.scm | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/chickadee/render/font.scm b/chickadee/render/font.scm index bac5056..4bb44ce 100644 --- a/chickadee/render/font.scm +++ b/chickadee/render/font.scm @@ -44,6 +44,7 @@ font-line-height font-bold? font-italic? + draw-text* draw-text)) (define-record-type <font-char> @@ -252,7 +253,7 @@ extension must be either .xml or .fnt." (x-advance (attr node 'xadvance string->number)) (page (or (attr node 'page string->number) 0)) (region (make-texture-region (hash-ref pages page) - x y width height)) + (make-rect x y width height))) (char (make-font-char id region (vec2 x-offset y-offset) @@ -295,38 +296,48 @@ extension must be either .xml or .fnt." (define (font-ref font char) (hashv-ref (font-chars font) char)) -(define %default-offset (vec2 0.0 0.0)) - -(define draw-text +(define draw-text* (let ((cursor (vec2 0.0 0.0)) - (char-pos (vec2 0.0 0.0))) - (lambda* (font text position #:key - (rotation 0) - (scale 1.0) - matrix - (offset %default-offset) - (blend-mode 'alpha)) - "Draw the string TEXT with the first character starting at -POSITION using FONT." + (rect (make-rect 0.0 0.0 0.0 0.0))) + (lambda* (font text matrix #:key (blend-mode 'alpha)) ;; TODO: Respect kerning. (define (render-char c) (let* ((char (font-ref font c)) + (texture (font-char-texture-region char)) (dimensions (font-char-dimensions char)) (offset (font-char-offset 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 - #:offset offset - #:scale scale - #:rotation rotation - #:matrix matrix - #:blend-mode blend-mode) + (set-rect-x! rect (+ (vec2-x cursor) (vec2-x offset))) + (set-rect-y! rect (+ (vec2-y cursor) (vec2-y offset))) + (set-rect-width! rect (vec2-x dimensions)) + (set-rect-height! rect (vec2-y dimensions)) + (draw-sprite* texture rect matrix #:blend-mode blend-mode) ;; Move forward to where the next character needs to be drawn. (set-vec2-x! cursor (+ (vec2-x cursor) (vec2-x (font-char-advance char)))))) - (vec2-copy! position cursor) ; initialize position - (with-batched-sprites - (string-for-each render-char text))))) + (set-vec2-x! cursor 0.0) + (set-vec2-y! cursor 0.0) + (string-for-each render-char text)))) + +(define %default-scale (vec2 1.0 1.0)) +(define %null-vec (vec2 0.0 0.0)) + +(define draw-text + (let ((matrix (make-null-matrix4))) + (lambda* (font + text + position + #:key + (origin %null-vec2) + (rotation 0) + (scale %default-scale) + (blend-mode 'alpha)) + "Draw the string TEXT with the first character starting at +POSITION using FONT." + (matrix4-2d-transform! matrix + #:origin origin + #:position position + #:rotation rotation + #:scale scale) + (draw-text* font text matrix #:blend-mode blend-mode)))) |