Avoiding string-append for drawing menu
This commit is contained in:
parent
a42d5c5656
commit
8627f06ebd
1 changed files with 19 additions and 14 deletions
33
game.scm
33
game.scm
|
@ -753,7 +753,9 @@
|
|||
(1+ menu:max-items)
|
||||
num-items)))
|
||||
(r-start (- -2 padding-y))
|
||||
(r-end (- (+ r-start height) padding-y)))
|
||||
(r-end (- (+ r-start height) padding-y))
|
||||
(gutter-x (- (vec2-x center) (* tile-width (1- (floor (/ width 2))))))
|
||||
(text-x (+ tile-width gutter-x)))
|
||||
(let row ((r r-start)
|
||||
(y (- (vec2-y center) (* tile-height (floor (/ height 2))))))
|
||||
;; Draw menu background
|
||||
|
@ -766,21 +768,24 @@
|
|||
(set-stroke-color! context "blue")
|
||||
(stroke-rect context x y w h)))
|
||||
;; Draw menu text
|
||||
(set-text-align! context "center")
|
||||
(set-font! context "normal 16px monogram")
|
||||
(set-fill-color! context "#fff")
|
||||
(let ((r-index (- (+ r (* (current-menu-page) menu:max-items)) (current-menu-page))))
|
||||
(if (= r r-start)
|
||||
(fill-text context (menu-name (current-menu)) (vec2-x center) (+ y text-offset-y))
|
||||
(if (and (>= r -1) (< r-index num-items) (< r r-end))
|
||||
(let* ((item (if (= r -1)
|
||||
(if (= (current-menu-page) 0)
|
||||
"Back" "...")
|
||||
(if (and (= r (1- r-end)) (< r-index (1- num-items)))
|
||||
"..."
|
||||
(menu-item-name (vector-ref (menu-items (current-menu)) r-index)))))
|
||||
(text (string-append (if (= r-index (current-menu-index)) "▸ " " ") item)))
|
||||
(fill-text context text (vec2-x center) (+ y text-offset-y))))))
|
||||
(when (= r r-start)
|
||||
(set-text-align! context "center")
|
||||
(fill-text context (menu-name (current-menu)) (vec2-x center) (+ y text-offset-y)))
|
||||
(let* ((r-index (- (+ r (* (current-menu-page) menu:max-items)) (current-menu-page))))
|
||||
(set-text-align! context "left")
|
||||
(if (= r-index (current-menu-index))
|
||||
(fill-text context "▸" gutter-x (+ y text-offset-y)))
|
||||
(if (and (>= r -1) (< r-index num-items) (< r r-end))
|
||||
(fill-text context
|
||||
(if (= r -1)
|
||||
(if (= (current-menu-page) 0) "Back" "...")
|
||||
(if (and (= r (1- r-end)) (< r-index (1- num-items)))
|
||||
"..."
|
||||
(menu-item-name (vector-ref (menu-items (current-menu))
|
||||
r-index))))
|
||||
text-x (+ y text-offset-y))))
|
||||
;; Draw next row
|
||||
(set! r (1+ r))
|
||||
(if (< r (+ r-start height))
|
||||
|
|
Loading…
Add table
Reference in a new issue