diff options
Diffstat (limited to 'chickadee')
-rw-r--r-- | chickadee/render/font.scm | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/chickadee/render/font.scm b/chickadee/render/font.scm index 55b282c..aace909 100644 --- a/chickadee/render/font.scm +++ b/chickadee/render/font.scm @@ -314,21 +314,25 @@ extension must be either .xml or .fnt." (start 0) (end (string-length text))) ;; TODO: Respect kerning. (define (render-char c) - ;; TODO: What if "?" isn't in the font? - (let* ((char (or (font-ref font c) (font-ref font #\?))) - (texture (font-char-texture-region char)) - (dimensions (font-char-dimensions char)) - (offset (font-char-offset char))) - (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)))))) + (if (eqv? c #\newline) + (begin + (set-vec2-x! cursor 0.0) + (set-vec2-y! cursor (- (vec2-y cursor) (font-line-height font)))) + ;; TODO: What if "?" isn't in the font? + (let* ((char (or (font-ref font c) (font-ref font #\?))) + (texture (font-char-texture-region char)) + (dimensions (font-char-dimensions char)) + (offset (font-char-offset char))) + (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))))))) (set-vec2! cursor 0.0 0.0) (string-for-each render-char text start end)))) |