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