From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Gemini Lasswell Newsgroups: gmane.emacs.bugs Subject: bug#24658: 26.0.50; gamegrid on HiDPI displays (feature request) Date: Mon, 16 Oct 2017 10:52:02 -0700 Message-ID: <87tvyzm14t.fsf@runbox.com> References: <877f9gw7op.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1508177544 20177 195.159.176.226 (16 Oct 2017 18:12:24 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 16 Oct 2017 18:12:24 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.60 (gnu/linux) Cc: 24658@debbugs.gnu.org To: Tamas Papp Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Oct 16 20:12:20 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e49s3-0003oD-Ml for geb-bug-gnu-emacs@m.gmane.org; Mon, 16 Oct 2017 20:12:11 +0200 Original-Received: from localhost ([::1]:34547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e49sB-0007nD-65 for geb-bug-gnu-emacs@m.gmane.org; Mon, 16 Oct 2017 14:12:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33411) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e49Za-00080C-Cu for bug-gnu-emacs@gnu.org; Mon, 16 Oct 2017 13:53:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e49ZW-0005c1-9Y for bug-gnu-emacs@gnu.org; Mon, 16 Oct 2017 13:53:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:35510) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e49ZW-0005bt-04 for bug-gnu-emacs@gnu.org; Mon, 16 Oct 2017 13:53:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1e49ZV-0007Rz-Oi for bug-gnu-emacs@gnu.org; Mon, 16 Oct 2017 13:53:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Gemini Lasswell Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 16 Oct 2017 17:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24658 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 24658-submit@debbugs.gnu.org id=B24658.150817634928594 (code B ref 24658); Mon, 16 Oct 2017 17:53:01 +0000 Original-Received: (at 24658) by debbugs.gnu.org; 16 Oct 2017 17:52:29 +0000 Original-Received: from localhost ([127.0.0.1]:44191 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e49Yz-0007R7-1S for submit@debbugs.gnu.org; Mon, 16 Oct 2017 13:52:29 -0400 Original-Received: from aibo.runbox.com ([91.220.196.211]:35318) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e49Yw-0007Qz-Ao for 24658@debbugs.gnu.org; Mon, 16 Oct 2017 13:52:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=runbox.com; s=rbselector1; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From; bh=/RgRq8hsiFoGUFVBoiVYlp/vOpazbSvGHuVLsGEn72s=; b=O2m0fAf/ZH8Ve1dZ4aCtJI4TSm GPq+ZMN2hckJLwIFY+l2deP1RLHKiOYBklEn3dRoQ+a/moS9pp6ntZrkYm36UGDOlCnmokK3FX4td juMaLJoaWgdG68YiWwBAbCwZm55YJZYF5V5Hai7zNzNB+dvAhYIEm4gUtwDKMAIaKD5Ij95nJCsO0 HNMyxgg+l8U4t7OFBpU+BZE+EKOvS9OdXxiwZyAp7s4/sq7k64RZuMiWIEjLCR3LmTf01LJXXbEob aev/MFinIUYwEK8r8OOjPiuBBr2LW2+l3hwpGM1cIQ48TBJSzP/CtpfRsgXh3rOmndz+SWinuGzqm 3afbCeCA==; Original-Received: from [10.9.9.210] (helo=mailfront10.runbox.com) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1e49Yv-0004Ps-Ii; Mon, 16 Oct 2017 19:52:25 +0200 Original-Received: from c-24-22-244-161.hsd1.wa.comcast.net ([24.22.244.161] helo=chinook) by mailfront10.runbox.com with esmtpsa (uid:179284 ) (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) id 1e49Ya-000473-Oy; Mon, 16 Oct 2017 19:52:05 +0200 In-Reply-To: <877f9gw7op.fsf@gmail.com> (Tamas Papp's message of "Mon, 10 Oct 2016 17:21:58 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:138544 Archived-At: --=-=-= Content-Type: text/plain Tamas Papp writes: > Games that use gamegrid (snake, tetris, pong) are hard to see on > high-resolution laptop display (eg 3200x1800) --- it looks like the cell > size is hardcoded as 16. Here's a patch which makes gamegrid change its grid size based on display dimensions. Its target is an on-screen size of 7mm, which works well on the various displays I have. Let me know how it looks on yours. Changing gamegrid-glyph-height-mm before starting one of the games will let you experiment. Emacs Developers, Should I include a NEWS entry about the effect on Tetris/Snake/Pong instead of or in addition to the one about gamegrid-glyph-height? And is this patch appropriate for release or master at this point? --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=0001-Make-Snake-Tetris-and-Pong-adjust-to-display-DPI.patch >From 1a8876bac69627bc1bb8fb9498100b8dc283723a Mon Sep 17 00:00:00 2001 From: Gemini Lasswell Date: Mon, 16 Oct 2017 08:30:51 -0700 Subject: [PATCH] Make Snake, Tetris and Pong adjust to display DPI Replace gamegrid's constant 16x16 glyph with a generated one based on display dimensions (bug#24658). * lisp/play/gamegrid.el (gamegrid-glyph-height-mm): New variable. (gamegrid-glyph-height): Deleted. (gamegrid-xpm, gamegrid-xbm): Constants replaced with functions. (gamegrid-colorize-glyph): Use new functions instead of constants. (gamegrid-calculate-glyph-size, gamegrid-insert-xbm-bits): New functions. --- etc/NEWS | 7 ++ lisp/play/gamegrid.el | 178 ++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 150 insertions(+), 35 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 2b2aa7c0f0..c7a9522d1f 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1403,6 +1403,13 @@ them through 'format' first. Even that is discouraged: for ElDoc support, you should set 'eldoc-documentation-function' instead of calling 'eldoc-message' directly. +--- +** The constant 'gamegrid-glyph-height' has been deleted. Gamegrid +now calculates its glyph height based on display dimensions. Use +'gamegrid-calculate-glyph-height' to get the glyph height in pixels. +Before calling it, you may set 'gamegrid-glyph-height-mm' to the +desired on-screen glyph height in millimeters. + * Lisp Changes in Emacs 26.1 diff --git a/lisp/play/gamegrid.el b/lisp/play/gamegrid.el index 6214e07506..641ef7f246 100644 --- a/lisp/play/gamegrid.el +++ b/lisp/play/gamegrid.el @@ -86,49 +86,157 @@ gamegrid-grid-x-face (defvar gamegrid-mono-x-face nil) (defvar gamegrid-mono-tty-face nil) -;; ;;;;;;;;;;;;; constants ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defconst gamegrid-glyph-height 16) - -(defconst gamegrid-xpm "\ +(defvar gamegrid-glyph-height-mm 7.0 + "Desired glyph height in mm.") + +;; ;;;;;;;;;;;;; glyph generation ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defun gamegrid-calculate-glyph-size () + "Calculate appropriate glyph size in pixels based on display resolution. +Return a multiple of 8 no less than 16." + (if (and (display-pixel-height) (display-mm-height)) + (let* ((y-pitch (/ (display-pixel-height) (float (display-mm-height)))) + (pixels (* y-pitch gamegrid-glyph-height-mm)) + (rounded (* (floor (/ (+ pixels 4) 8)) 8))) + (max 16 rounded)) + 16)) + +;; Example of glyph in XPM format: +;; +;; /* XPM */ +;; static char *noname[] = { +;; /* width height ncolors chars_per_pixel */ +;; \"16 16 3 1\", +;; /* colors */ +;; \"+ s col1\", +;; \". s col2\", +;; \"- s col3\", +;; /* pixels */ +;; \"---------------+\", +;; \"--------------++\", +;; \"--............++\", +;; \"--............++\", +;; \"--............++\", +;; \"--............++\", +;; \"--............++\", +;; \"--............++\", +;; \"--............++\", +;; \"--............++\", +;; \"--............++\", +;; \"--............++\", +;; \"--............++\", +;; \"--............++\", +;; \"-+++++++++++++++\", +;; \"++++++++++++++++\" +;; }; + +(defun gamegrid-xpm () + "Generate the XPM format image used for each square." + (let* ((glyph-pixel-count (gamegrid-calculate-glyph-size)) + (border-pixel-count (/ glyph-pixel-count 8)) + (center-pixel-count (- glyph-pixel-count (* border-pixel-count 2)))) + (with-temp-buffer + (insert (format "\ /* XPM */ static char *noname[] = { /* width height ncolors chars_per_pixel */ -\"16 16 3 1\", +\"%s %s 3 1\", /* colors */ \"+ s col1\", \". s col2\", \"- s col3\", /* pixels */ -\"---------------+\", -\"--------------++\", -\"--............++\", -\"--............++\", -\"--............++\", -\"--............++\", -\"--............++\", -\"--............++\", -\"--............++\", -\"--............++\", -\"--............++\", -\"--............++\", -\"--............++\", -\"--............++\", -\"-+++++++++++++++\", -\"++++++++++++++++\" -}; -" - "XPM format image used for each square") - -(defvar gamegrid-xbm "\ +" glyph-pixel-count glyph-pixel-count)) + + (dotimes (row border-pixel-count) + (let ((edge-pixel-count (+ row 1))) + (insert "\"") + (dotimes (_ (- glyph-pixel-count edge-pixel-count)) (insert "-")) + (dotimes (_ edge-pixel-count) (insert "+")) + (insert "\",\n"))) + + (let ((middle (format "\"%s%s%s\",\n" + (make-string border-pixel-count ?-) + (make-string center-pixel-count ?.) + (make-string border-pixel-count ?+)))) + (dotimes (_ center-pixel-count) (insert middle))) + + (dotimes (row border-pixel-count) + (let ((edge-pixel-count (- border-pixel-count row 1))) + (insert "\"") + (dotimes (_ edge-pixel-count) (insert "-")) + (dotimes (_ (- glyph-pixel-count edge-pixel-count)) (insert "+")) + (insert "\"") + (if (/= row (1- border-pixel-count)) + (insert ",\n") + (insert "\n};\n")))) + (buffer-string)))) + +;; Example of glyph in XBM format: +;; +;; /* gamegrid XBM */ +;; #define gamegrid_width 16 +;; #define gamegrid_height 16 +;; static unsigned char gamegrid_bits[] = { +;; 0xff, 0xff, 0xff, 0x7f, 0xff, 0x3f, 0xaf, 0x0a, 0x57, 0x15, 0xaf, 0x0a, +;; 0x57, 0x15, 0xaf, 0x0a, 0x57, 0x15, 0xaf, 0x0a, 0x57, 0x15, 0xaf, 0x0a, +;; 0x57, 0x15, 0x07, 0x00, 0x03, 0x00, 0x01, 0x00 }; + +(defun gamegrid-xbm () + "Generate XBM format image used for each square." + (let* ((glyph-pixel-count (gamegrid-calculate-glyph-size)) + (border-pixel-count (1- (/ glyph-pixel-count 4))) + (center-pixel-count (- glyph-pixel-count (* 2 border-pixel-count)))) + (with-temp-buffer + (insert (format "\ /* gamegrid XBM */ -#define gamegrid_width 16 -#define gamegrid_height 16 +#define gamegrid_width %s +#define gamegrid_height %s static unsigned char gamegrid_bits[] = { - 0xff, 0xff, 0xff, 0x7f, 0xff, 0x3f, 0xaf, 0x0a, 0x57, 0x15, 0xaf, 0x0a, - 0x57, 0x15, 0xaf, 0x0a, 0x57, 0x15, 0xaf, 0x0a, 0x57, 0x15, 0xaf, 0x0a, - 0x57, 0x15, 0x07, 0x00, 0x03, 0x00, 0x01, 0x00 };" - "XBM format image used for each square.") +" glyph-pixel-count glyph-pixel-count)) + (dotimes (row border-pixel-count) + (gamegrid-insert-xbm-bits + (concat (make-string (- glyph-pixel-count row) ?1) + (make-string row ?0))) + (insert ", \n")) + + (let* ((left-border (make-string border-pixel-count ?1)) + (right-border (make-string border-pixel-count ?0)) + (even-line (apply 'concat + (append (list left-border) + (make-list (/ center-pixel-count 2) "10") + (list right-border)))) + (odd-line (apply 'concat + (append (list left-border) + (make-list (/ center-pixel-count 2) "01") + (list right-border))))) + (dotimes (row center-pixel-count) + (gamegrid-insert-xbm-bits (if (eq (logand row 1) 1) odd-line even-line)) + (insert ", \n"))) + + (dotimes (row border-pixel-count) + (let ((edge-pixel-count (- border-pixel-count row))) + (gamegrid-insert-xbm-bits + (concat (make-string edge-pixel-count ?1) + (make-string (- glyph-pixel-count edge-pixel-count) ?0)))) + (if (/= row (1- border-pixel-count)) + (insert ", \n") + (insert " };\n"))) + (buffer-string)))) + +(defun gamegrid-insert-xbm-bits (str) + "Convert binary to hex and insert in current buffer. +STR should be a string composed of 1s and 0s and be a multiple of +8 in length. Divide it into 8 bit bytes, reverse the order of +each, convert them to hex and insert them in comma separated C +format." + (let ((byte-count (/ (length str) 8))) + (dotimes (i byte-count) + (let* ((byte (reverse (substring str (* i 8) (+ (* i 8) 8)))) + (value (string-to-number byte 2))) + (insert (format "0x%02x" value)) + (unless (= i (1- byte-count)) + (insert ", ")))))) ;; ;;;;;;;;;;;;;;;; miscellaneous functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -228,13 +336,13 @@ gamegrid-make-face gamegrid-mono-tty-face)))) (defun gamegrid-colorize-glyph (color) - (find-image `((:type xpm :data ,gamegrid-xpm + (find-image `((:type xpm :data ,(gamegrid-xpm) :ascent center :color-symbols (("col1" . ,(gamegrid-color color 0.6)) ("col2" . ,(gamegrid-color color 0.8)) ("col3" . ,(gamegrid-color color 1.0)))) - (:type xbm :data ,gamegrid-xbm + (:type xbm :data ,(gamegrid-xbm) :ascent center :foreground ,(gamegrid-color color 1.0) :background ,(gamegrid-color color 0.5))))) -- 2.14.2 --=-=-=--