diff options
| author | Eli Zaretskii | 2018-09-17 17:34:31 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2018-09-17 17:34:31 +0300 |
| commit | c71cfb79c3e9cfcd1189be5ac9fa12333a995565 (patch) | |
| tree | 90f4d93bb14d2e8206f1b97fd6aa219f436c0811 | |
| parent | 3bbf21b9139e203d7254a9434c88bd38238ed57e (diff) | |
| download | emacs-c71cfb79c3e9cfcd1189be5ac9fa12333a995565.tar.gz emacs-c71cfb79c3e9cfcd1189be5ac9fa12333a995565.zip | |
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)
| -rw-r--r-- | lisp/play/bubbles.el | 64 |
1 files changed, 30 insertions, 34 deletions
diff --git a/lisp/play/bubbles.el b/lisp/play/bubbles.el index e30838dfca4..ee2135b9bbe 100644 --- a/lisp/play/bubbles.el +++ b/lisp/play/bubbles.el | |||
| @@ -250,10 +250,10 @@ Available modes are `shift-default' and `shift-always'." | |||
| 250 | "Indicate whether images have been created successfully.") | 250 | "Indicate whether images have been created successfully.") |
| 251 | 251 | ||
| 252 | (defvar bubbles--col-offset 0 | 252 | (defvar bubbles--col-offset 0 |
| 253 | "Horizontal offset for centering the bubbles grid.") | 253 | "Horizontal offset for centering the bubbles grid, in pixels.") |
| 254 | 254 | ||
| 255 | (defvar bubbles--row-offset 0 | 255 | (defvar bubbles--row-offset 0 |
| 256 | "Vertical offset for centering the bubbles grid.") | 256 | "Vertical offset for centering the bubbles grid, in pixels.") |
| 257 | 257 | ||
| 258 | (defvar bubbles--save-data nil | 258 | (defvar bubbles--save-data nil |
| 259 | "List containing bubbles save data (SCORE BUFFERCONTENTS).") | 259 | "List containing bubbles save data (SCORE BUFFERCONTENTS).") |
| @@ -960,33 +960,26 @@ columns on its right towards the left. | |||
| 960 | (defun bubbles--compute-offsets () | 960 | (defun bubbles--compute-offsets () |
| 961 | "Update horizontal and vertical offsets for centering the bubbles grid. | 961 | "Update horizontal and vertical offsets for centering the bubbles grid. |
| 962 | Set `bubbles--col-offset' and `bubbles--row-offset'." | 962 | Set `bubbles--col-offset' and `bubbles--row-offset'." |
| 963 | (cond ((and (display-images-p) | 963 | (let* ((use-images-p (and (display-images-p) |
| 964 | bubbles--images-ok | 964 | bubbles--images-ok |
| 965 | (not (eq bubbles-graphics-theme 'ascii)) | 965 | (not (eq bubbles-graphics-theme 'ascii)))) |
| 966 | (fboundp 'window-inside-pixel-edges)) | 966 | (bubbles--image-size |
| 967 | ;; compute offset in units of pixels | 967 | (if use-images-p (car (image-size (car bubbles--images) t)) 1)) |
| 968 | (let ((bubbles--image-size | 968 | ;; In GUI mode, leave thin margins around the images. |
| 969 | (car (image-size (car bubbles--images) t)))) | 969 | (image-hor-size |
| 970 | (setq bubbles--col-offset | 970 | (if use-images-p (+ bubbles--image-size 2) bubbles--image-size)) |
| 971 | (list | 971 | (image-vert-size |
| 972 | (max 0 (/ (- (nth 2 (window-inside-pixel-edges)) | 972 | (if use-images-p (1+ bubbles--image-size) bubbles--image-size))) |
| 973 | (nth 0 (window-inside-pixel-edges)) | 973 | (setq bubbles--col-offset |
| 974 | (* ( + bubbles--image-size 2) ;; margin | 974 | (max 0 (/ (- (nth 2 (window-body-pixel-edges)) |
| 975 | (bubbles--grid-width))) 2)))) | 975 | (nth 0 (window-body-pixel-edges)) |
| 976 | (setq bubbles--row-offset | 976 | (* image-hor-size (bubbles--grid-width))) |
| 977 | (list | 977 | 2))) |
| 978 | (max 0 (/ (- (nth 3 (window-inside-pixel-edges)) | 978 | (setq bubbles--row-offset |
| 979 | (nth 1 (window-inside-pixel-edges)) | 979 | (max 0 (/ (- (nth 3 (window-body-pixel-edges)) |
| 980 | (* (+ bubbles--image-size 1) ;; margin | 980 | (nth 1 (window-body-pixel-edges)) |
| 981 | (bubbles--grid-height))) 2)))))) | 981 | (* image-vert-size (bubbles--grid-height))) |
| 982 | (t | 982 | 2))))) |
| 983 | ;; compute offset in units of chars | ||
| 984 | (setq bubbles--col-offset | ||
| 985 | (max 0 (/ (- (window-width) | ||
| 986 | (bubbles--grid-width)) 2))) | ||
| 987 | (setq bubbles--row-offset | ||
| 988 | (max 0 (/ (- (window-height) | ||
| 989 | (bubbles--grid-height) 2) 2)))))) | ||
| 990 | 983 | ||
| 991 | (defun bubbles--remove-overlays () | 984 | (defun bubbles--remove-overlays () |
| 992 | "Remove all overlays." | 985 | "Remove all overlays." |
| @@ -1007,7 +1000,8 @@ Set `bubbles--col-offset' and `bubbles--row-offset'." | |||
| 1007 | (insert " ") | 1000 | (insert " ") |
| 1008 | (put-text-property (point-min) (point) | 1001 | (put-text-property (point-min) (point) |
| 1009 | 'display | 1002 | 'display |
| 1010 | (cons 'space (list :height bubbles--row-offset))) | 1003 | (cons 'space (list :height |
| 1004 | (list bubbles--row-offset)))) | ||
| 1011 | (insert "\n") | 1005 | (insert "\n") |
| 1012 | (let ((max-char (length (bubbles--colors)))) | 1006 | (let ((max-char (length (bubbles--colors)))) |
| 1013 | (dotimes (i (bubbles--grid-height)) | 1007 | (dotimes (i (bubbles--grid-height)) |
| @@ -1015,7 +1009,8 @@ Set `bubbles--col-offset' and `bubbles--row-offset'." | |||
| 1015 | (insert " ") | 1009 | (insert " ") |
| 1016 | (put-text-property p (point) | 1010 | (put-text-property p (point) |
| 1017 | 'display | 1011 | 'display |
| 1018 | (cons 'space (list :width bubbles--col-offset)))) | 1012 | (cons 'space (list :width |
| 1013 | (list bubbles--col-offset))))) | ||
| 1019 | (dotimes (j (bubbles--grid-width)) | 1014 | (dotimes (j (bubbles--grid-width)) |
| 1020 | (let* ((index (random max-char)) | 1015 | (let* ((index (random max-char)) |
| 1021 | (char (nth index bubbles-chars))) | 1016 | (char (nth index bubbles-chars))) |
| @@ -1025,7 +1020,8 @@ Set `bubbles--col-offset' and `bubbles--row-offset'." | |||
| 1025 | (insert "\n ") | 1020 | (insert "\n ") |
| 1026 | (put-text-property (1- (point)) (point) | 1021 | (put-text-property (1- (point)) (point) |
| 1027 | 'display | 1022 | 'display |
| 1028 | (cons 'space (list :width bubbles--col-offset)))) | 1023 | (cons 'space (list :width |
| 1024 | (list bubbles--col-offset))))) | ||
| 1029 | (put-text-property (point-min) (point-max) 'pointer 'arrow)) | 1025 | (put-text-property (point-min) (point-max) 'pointer 'arrow)) |
| 1030 | (bubbles-mode) | 1026 | (bubbles-mode) |
| 1031 | (bubbles--reset-score) | 1027 | (bubbles--reset-score) |
| @@ -1177,7 +1173,7 @@ Use optional parameter POS instead of point if given." | |||
| 1177 | (insert " ") | 1173 | (insert " ") |
| 1178 | (put-text-property (1- (point)) (point) | 1174 | (put-text-property (1- (point)) (point) |
| 1179 | 'display | 1175 | 'display |
| 1180 | (cons 'space (list :width bubbles--col-offset))) | 1176 | (cons 'space (list :width (list bubbles--col-offset)))) |
| 1181 | (insert (format "Score: %4d" bubbles--score)) | 1177 | (insert (format "Score: %4d" bubbles--score)) |
| 1182 | (put-text-property pos (point) 'status t)))) | 1178 | (put-text-property pos (point) 'status t)))) |
| 1183 | 1179 | ||
| @@ -1197,7 +1193,7 @@ Use optional parameter POS instead of point if given." | |||
| 1197 | (insert "\n ") | 1193 | (insert "\n ") |
| 1198 | (put-text-property (1- (point)) (point) | 1194 | (put-text-property (1- (point)) (point) |
| 1199 | 'display | 1195 | 'display |
| 1200 | (cons 'space (list :width bubbles--col-offset))) | 1196 | (cons 'space (list :width (list bubbles--col-offset)))) |
| 1201 | (insert "Game Over!")) | 1197 | (insert "Game Over!")) |
| 1202 | ;; save score | 1198 | ;; save score |
| 1203 | (gamegrid-add-score (format "bubbles-%s-%d-%d-%d-scores" | 1199 | (gamegrid-add-score (format "bubbles-%s-%d-%d-%d-scores" |