summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <davet@gnu.org>2019-05-08 17:43:53 -0400
committerDavid Thompson <davet@gnu.org>2019-05-08 17:43:53 -0400
commitf316a93fc3813c4c04042485de12ab90985e6da8 (patch)
treed1008a3efde186e9d68fa636365c66e07e9136f1
parent116cdfdee1aa562eac0e8d326a792cbe6067af12 (diff)
render: font: Respect newline character when rendering.
* chickadee/render/font.scm (draw-text*): Advance to the next line on screen when \n is encountered.
-rw-r--r--chickadee/render/font.scm34
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))))