Fix the Bubbles game on TTY frames

* lisp/play/bubbles.el (bubbles--col-offset)
(bubbles--row-offset): Doc fixes.
(bubbles--compute-offsets): Conflate the GUI and TTY code into
a single common version.  Set the offsets to simple numbers,
not to lists.
(bubbles--initialize, bubbles--show-scores): Wrap offset
values in a list, so that they are interpreted as pixel
values, not as units of character width.  This fixes the game
on TTY frames.  (Bug#32744)
This commit is contained in:
Eli Zaretskii 2018-09-17 17:34:31 +03:00
parent 3bbf21b913
commit c71cfb79c3

View file

@ -250,10 +250,10 @@ Available modes are `shift-default' and `shift-always'."
"Indicate whether images have been created successfully.") "Indicate whether images have been created successfully.")
(defvar bubbles--col-offset 0 (defvar bubbles--col-offset 0
"Horizontal offset for centering the bubbles grid.") "Horizontal offset for centering the bubbles grid, in pixels.")
(defvar bubbles--row-offset 0 (defvar bubbles--row-offset 0
"Vertical offset for centering the bubbles grid.") "Vertical offset for centering the bubbles grid, in pixels.")
(defvar bubbles--save-data nil (defvar bubbles--save-data nil
"List containing bubbles save data (SCORE BUFFERCONTENTS).") "List containing bubbles save data (SCORE BUFFERCONTENTS).")
@ -960,33 +960,26 @@ columns on its right towards the left.
(defun bubbles--compute-offsets () (defun bubbles--compute-offsets ()
"Update horizontal and vertical offsets for centering the bubbles grid. "Update horizontal and vertical offsets for centering the bubbles grid.
Set `bubbles--col-offset' and `bubbles--row-offset'." Set `bubbles--col-offset' and `bubbles--row-offset'."
(cond ((and (display-images-p) (let* ((use-images-p (and (display-images-p)
bubbles--images-ok bubbles--images-ok
(not (eq bubbles-graphics-theme 'ascii)) (not (eq bubbles-graphics-theme 'ascii))))
(fboundp 'window-inside-pixel-edges)) (bubbles--image-size
;; compute offset in units of pixels (if use-images-p (car (image-size (car bubbles--images) t)) 1))
(let ((bubbles--image-size ;; In GUI mode, leave thin margins around the images.
(car (image-size (car bubbles--images) t)))) (image-hor-size
(setq bubbles--col-offset (if use-images-p (+ bubbles--image-size 2) bubbles--image-size))
(list (image-vert-size
(max 0 (/ (- (nth 2 (window-inside-pixel-edges)) (if use-images-p (1+ bubbles--image-size) bubbles--image-size)))
(nth 0 (window-inside-pixel-edges)) (setq bubbles--col-offset
(* ( + bubbles--image-size 2) ;; margin (max 0 (/ (- (nth 2 (window-body-pixel-edges))
(bubbles--grid-width))) 2)))) (nth 0 (window-body-pixel-edges))
(setq bubbles--row-offset (* image-hor-size (bubbles--grid-width)))
(list 2)))
(max 0 (/ (- (nth 3 (window-inside-pixel-edges)) (setq bubbles--row-offset
(nth 1 (window-inside-pixel-edges)) (max 0 (/ (- (nth 3 (window-body-pixel-edges))
(* (+ bubbles--image-size 1) ;; margin (nth 1 (window-body-pixel-edges))
(bubbles--grid-height))) 2)))))) (* image-vert-size (bubbles--grid-height)))
(t 2)))))
;; compute offset in units of chars
(setq bubbles--col-offset
(max 0 (/ (- (window-width)
(bubbles--grid-width)) 2)))
(setq bubbles--row-offset
(max 0 (/ (- (window-height)
(bubbles--grid-height) 2) 2))))))
(defun bubbles--remove-overlays () (defun bubbles--remove-overlays ()
"Remove all overlays." "Remove all overlays."
@ -1007,7 +1000,8 @@ Set `bubbles--col-offset' and `bubbles--row-offset'."
(insert " ") (insert " ")
(put-text-property (point-min) (point) (put-text-property (point-min) (point)
'display 'display
(cons 'space (list :height bubbles--row-offset))) (cons 'space (list :height
(list bubbles--row-offset))))
(insert "\n") (insert "\n")
(let ((max-char (length (bubbles--colors)))) (let ((max-char (length (bubbles--colors))))
(dotimes (i (bubbles--grid-height)) (dotimes (i (bubbles--grid-height))
@ -1015,7 +1009,8 @@ Set `bubbles--col-offset' and `bubbles--row-offset'."
(insert " ") (insert " ")
(put-text-property p (point) (put-text-property p (point)
'display 'display
(cons 'space (list :width bubbles--col-offset)))) (cons 'space (list :width
(list bubbles--col-offset)))))
(dotimes (j (bubbles--grid-width)) (dotimes (j (bubbles--grid-width))
(let* ((index (random max-char)) (let* ((index (random max-char))
(char (nth index bubbles-chars))) (char (nth index bubbles-chars)))
@ -1025,7 +1020,8 @@ Set `bubbles--col-offset' and `bubbles--row-offset'."
(insert "\n ") (insert "\n ")
(put-text-property (1- (point)) (point) (put-text-property (1- (point)) (point)
'display 'display
(cons 'space (list :width bubbles--col-offset)))) (cons 'space (list :width
(list bubbles--col-offset)))))
(put-text-property (point-min) (point-max) 'pointer 'arrow)) (put-text-property (point-min) (point-max) 'pointer 'arrow))
(bubbles-mode) (bubbles-mode)
(bubbles--reset-score) (bubbles--reset-score)
@ -1177,7 +1173,7 @@ Use optional parameter POS instead of point if given."
(insert " ") (insert " ")
(put-text-property (1- (point)) (point) (put-text-property (1- (point)) (point)
'display 'display
(cons 'space (list :width bubbles--col-offset))) (cons 'space (list :width (list bubbles--col-offset))))
(insert (format "Score: %4d" bubbles--score)) (insert (format "Score: %4d" bubbles--score))
(put-text-property pos (point) 'status t)))) (put-text-property pos (point) 'status t))))
@ -1197,7 +1193,7 @@ Use optional parameter POS instead of point if given."
(insert "\n ") (insert "\n ")
(put-text-property (1- (point)) (point) (put-text-property (1- (point)) (point)
'display 'display
(cons 'space (list :width bubbles--col-offset))) (cons 'space (list :width (list bubbles--col-offset))))
(insert "Game Over!")) (insert "Game Over!"))
;; save score ;; save score
(gamegrid-add-score (format "bubbles-%s-%d-%d-%d-scores" (gamegrid-add-score (format "bubbles-%s-%d-%d-%d-scores"