From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Oliver Scholz Newsgroups: gmane.emacs.devel Subject: Re: gamegrid.el and some games Date: Sat, 14 Sep 2002 01:11:31 +0200 Organization: Olymp Sender: emacs-devel-admin@gnu.org Message-ID: References: <87n0ql94mz.fsf@pot.cnuce.cnr.it> NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: main.gmane.org 1031952959 32281 127.0.0.1 (13 Sep 2002 21:35:59 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 13 Sep 2002 21:35:59 +0000 (UTC) Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17py6W-0008ON-00 for ; Fri, 13 Sep 2002 23:35:56 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 17pyiZ-0000p8-00 for ; Sat, 14 Sep 2002 00:15:15 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17py6e-000552-00; Fri, 13 Sep 2002 17:36:04 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 17py4T-00053A-00 for emacs-devel@gnu.org; Fri, 13 Sep 2002 17:33:49 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 17py4R-00052o-00 for emacs-devel@gnu.org; Fri, 13 Sep 2002 17:33:49 -0400 Original-Received: from main.gmane.org ([80.91.224.249]) by monty-python.gnu.org with esmtp (Exim 4.10) id 17py4Q-00052h-00 for emacs-devel@gnu.org; Fri, 13 Sep 2002 17:33:46 -0400 Original-Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 17py4B-0008IJ-00 for ; Fri, 13 Sep 2002 23:33:31 +0200 Original-To: emacs-devel@gnu.org X-Injected-Via-Gmane: http://gmane.org/ Original-Received: from news by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 17py4B-0008IA-00 for ; Fri, 13 Sep 2002 23:33:31 +0200 Original-Path: hermes!nobody Original-Lines: 323 Original-NNTP-Posting-Host: dialin-145-254-208-180.arcor-ip.net Original-X-Trace: main.gmane.org 1031952811 31868 145.254.208.180 (13 Sep 2002 21:33:31 GMT) Original-X-Complaints-To: usenet@main.gmane.org Original-NNTP-Posting-Date: Fri, 13 Sep 2002 21:33:31 +0000 (UTC) X-Operating-System: Linux from Scratch X-Attribution: os X-Face: "HgH2sgK|bfH$;PiOJI6|qUCf.ve<51_Od(%ynHr?=>znn#~#oS>",F%B8&\vus),2AsPYb -n>PgddtGEn}s7kH?7kH{P_~vu?]OvVN^qD(L)>G^gDCl(U9n{:d>'DkilN!_K"eNzjrtI4Ya6;Td% IZGMbJ{lawG+'J>QXPZD&TwWU@^~A}f^zAb[Ru;CT(UA]c& User-Agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2 (i686-pc-linux-gnu) Cancel-Lock: sha1:y8JoGuBk01Zetz12s5/32GPbGt4= Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:7890 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:7890 --=-=-= Francesco Potorti` writes: [...] > I have send a patch some time ago, which enables XPM (and PBM) for > gamegrid. (BTW what happend to this patch?) > > Would you send it to me? O.K. Attached. The diff is against the version of gamegrid.el that comes with Emacs 21.2. AFAICS there are some changes in the current CVS. Could this cause problems? I am not familiar with diff & patch. > I was just trying to do that. *hehehe* I was quicker. > I guess gamegrid is mainly supposed to provide simple grids, > i.e. colored squares. > > Yes, after some study I arrived to the same conclusion, so I further > reduced my patch to pong.el, tetris.el, snake.el before installing it. > > The option to use characters is -- I guess -- > intended only as a fallback on ttys without color. OTOH: it allows to > utilize arbitrary XPM images > > Yes, for example pong could use a real ball. Oh, that's easy: (defvar pong-ball-glyph "/* XPM */ static char * ball_xpm[] = { \"16 16 4 1\", \" c Black\", \"+ c Red4\", \"- c Red1\", \". c Red\", \" ------ \", \" ---------- \", \" ----....--++ \", \" ---........+++ \", \" --..........++ \", \"---..........+++\", \"--............++\", \"--............++\", \"--............++\", \"--............++\", \"---..........+++\", \" --..........++ \", \" ---........+++ \", \" -+++....++++ \", \" ++++++++++ \", \" ++++++ \"};") (defvar pong-ball-options `(((glyph [xpm :data ,pong-ball-glyph]) (t ?\*)) ((color-x color-x) (mono-x grid-x) (color-tty color-tty)) (((glyph color-x) [1 0 0]) (color-tty pong-ball-color)))) This reveals, however, a problem with my patch: As I said, I use `display-images-p' and then `find-image' to get either XPM or PBM; the latter AFAIU is supposed to be always available if `display-images-p' returns t. This is o.k. for all games that come with Emacs. But it could lead to unexpected results for packages like sokoban.el or for pong if you add the image above: if an Emacs is compiled without support for XPM, there is no PBM as a fall-back. -- Oliver --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=gamegrid.diff --- /usr/local/share/emacs/21.2/lisp/play/gamegrid.el Tue May 7 23:18:49 2002 +++ gamegrid.el Mon Jul 22 00:46:33 2002 @@ -42,6 +42,10 @@ (defvar gamegrid-font "-*-courier-medium-r-*-*-*-140-100-75-*-*-iso8859-*" "Name of the font used in X mode.") +(defvar gamegrid-face nil + "Indicates the face to use as a default.") +(make-variable-buffer-local 'gamegrid-face) + (defvar gamegrid-display-options nil) (defvar gamegrid-buffer-width 0) @@ -115,6 +119,16 @@ " "XPM format image used for each square") +(defvar gamegrid-xbm "\ +/* 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 };" + "XBM format image used for each square.") + ;; ;;;;;;;;;;;;;;;; miscellaneous functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defsubst gamegrid-characterp (arg) @@ -145,7 +159,7 @@ (if gamegrid-font (condition-case nil (set-face-font face gamegrid-font) - ('error nil)))) + (error nil)))) (defun gamegrid-setup-face (face color) (set-face-foreground face color) @@ -153,23 +167,23 @@ (gamegrid-set-font face) (condition-case nil (set-face-background-pixmap face [nothing]);; XEmacs - ('error nil)) + (error nil)) (condition-case nil (set-face-background-pixmap face nil);; Emacs - ('error nil))) + (error nil))) (defun gamegrid-make-mono-tty-face () (let ((face (make-face 'gamegrid-mono-tty-face))) (condition-case nil (set-face-property face 'reverse t) - ('error nil)) + (error nil)) face)) (defun gamegrid-make-color-tty-face (color) - (let* ((color-str (symbol-value color)) - (name (intern (format "gamegrid-color-tty-face-%s" color-str))) + (let* (;(color-str (symbol-value color)) + (name (intern (format "gamegrid-color-tty-face-%s" color))) (face (make-face name))) - (gamegrid-setup-face face color-str) + (gamegrid-setup-face face color) face)) (defun gamegrid-make-grid-x-face () @@ -215,13 +229,16 @@ gamegrid-mono-tty-face)))) (defun gamegrid-colorize-glyph (color) - (make-glyph - (vector - 'xpm - :data gamegrid-xpm - :color-symbols (list (cons "col1" (gamegrid-color color 0.6)) - (cons "col2" (gamegrid-color color 0.8)) - (cons "col3" (gamegrid-color color 1.0)))))) + (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 + :ascent center + :foreground ,(gamegrid-color color 1.0) + :background ,(gamegrid-color color 0.5))))) (defun gamegrid-match-spec (spec) (let ((locale (car spec)) @@ -245,38 +262,35 @@ (vector data)) ((eq data 'colorize) (gamegrid-colorize-glyph color)) + ((listp data) + (find-image data)) ;untested! ((vectorp data) - (make-glyph data))))) + (gamegrid-make-image-from-vector data))))) -(defun gamegrid-color-display-p () - (if (fboundp 'device-class) - (eq (device-class (selected-device)) 'color) - (eq (cdr-safe (assq 'display-type (frame-parameters))) 'color))) +(defun gamegrid-make-image-from-vector (vect) + "Convert an XEmacs style \"glyph\" to an image-spec." + (let ((l (list 'image :type))) + (dotimes (n (length vect)) + (setf l (nconc l (list (aref vect n))))) + (nconc l (list :ascent 'center)))) (defun gamegrid-display-type () - (let ((window-system-p - (or (and (fboundp 'console-on-window-system-p) - (console-on-window-system-p)) - (and (fboundp 'display-color-p) - (display-color-p)) - window-system))) (cond ((and gamegrid-use-glyphs - window-system-p - (featurep 'xpm)) + (display-images-p)) 'glyph) ((and gamegrid-use-color - window-system-p - (gamegrid-color-display-p)) + (display-graphic-p) + (display-color-p)) 'color-x) - (window-system-p + ((display-graphic-p) 'mono-x) ((and gamegrid-use-color - (gamegrid-color-display-p)) + (display-color-p)) 'color-tty) - ((fboundp 'set-face-property) + ((display-multi-font-p) ;??? 'mono-tty) (t - 'emacs-tty)))) + 'emacs-tty))) (defun gamegrid-set-display-table () (if (fboundp 'specifierp) @@ -287,26 +301,21 @@ 'remove-locale) (setq buffer-display-table gamegrid-display-table))) -(defun gamegrid-hide-cursor () - (if (fboundp 'specifierp) - (set-specifier text-cursor-visible-p nil (current-buffer)))) - (defun gamegrid-setup-default-font () - (cond ((eq gamegrid-display-mode 'glyph) - (let* ((font-spec (face-property 'default 'font)) - (name (font-name font-spec)) - (max-height nil)) - (loop for c from 0 to 255 do - (let ((glyph (aref gamegrid-display-table c))) - (cond ((glyphp glyph) - (let ((height (glyph-height glyph))) - (if (or (null max-height) - (< max-height height)) - (setq max-height height))))))) - (if max-height - (while (and (> (font-height font-spec) max-height) - (setq name (x-find-smaller-font name))) - (add-spec-to-specifier font-spec name (current-buffer)))))))) + (setq gamegrid-face + (copy-face 'default + (intern (concat "gamegrid-face-" (buffer-name))))) + (when (eq gamegrid-display-mode 'glyph) + (let ((max-height nil)) + (loop for c from 0 to 255 do + (let ((glyph (aref gamegrid-display-table c))) + (when (and (listp glyph) (eq (car glyph) 'image)) + (let ((height (cdr (image-size glyph)))) + (if (or (null max-height) + (< max-height height)) + (setq max-height height)))))) + (when (and max-height (< max-height 1)) + (set-face-attribute gamegrid-face nil :height max-height))))) (defun gamegrid-initialize-display () (setq gamegrid-display-mode (gamegrid-display-type)) @@ -320,11 +329,13 @@ (aset gamegrid-display-table c glyph))) (gamegrid-setup-default-font) (gamegrid-set-display-table) - (gamegrid-hide-cursor)) + (setq cursor-type nil)) (defun gamegrid-set-face (c) - (unless (eq gamegrid-display-mode 'glyph) + (if (eq gamegrid-display-mode 'glyph) + (add-text-properties (1- (point)) (point) + (list 'display (list (aref gamegrid-display-table c)))) (put-text-property (1- (point)) (point) 'face @@ -351,14 +362,18 @@ (defun gamegrid-init-buffer (width height blank) (setq gamegrid-buffer-width width gamegrid-buffer-height height) - (let ((line (concat - (make-string width blank) - "\n")) + (let ((line (concat (make-string width blank) "\n")) (buffer-read-only nil)) (erase-buffer) (setq gamegrid-buffer-start (point)) (dotimes (i height) - (insert-string line)) + (insert line)) + ;; Adjust the height of the default face to the height of the + ;; images. Unlike XEmacs, Emacs doesn't allow to make the default + ;; face buffer-local; so we do this with an overlay. + (when (eq gamegrid-display-mode 'glyph) + (overlay-put (make-overlay (point-min) (point-max)) + 'face gamegrid-face)) (goto-char (point-min)))) (defun gamegrid-init (options) --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit -- 28 Fructidor an 210 de la Révolution Liberté, Egalité, Fraternité! --=-=-=--