all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Oliver Scholz <alkibiades@gmx.de>
Subject: Re: gamegrid.el and some games
Date: Mon, 16 Sep 2002 13:58:38 +0200	[thread overview]
Message-ID: <m3vg56i1sh.fsf@ID-87814.user.dfncis.de> (raw)
In-Reply-To: E17qOZG-0000Q8-00@fencepost.gnu.org

[-- Attachment #1: Type: text/plain, Size: 2173 bytes --]

Richard Stallman <rms@gnu.org> writes:

> Your patch is large enough we need legal papers to use it.

I think this is already done. I sent papers for past and future
changes to Emacs some time ago and already got a confirmation from the
FSF's office.

> I will tell you more in another message.  We also need change log
> entries in order to install it.  Could you write those?

Is this o.K?

	* gamegrid.el (gamegrid-face): new variable to emulate a
	buffer-local default face.
	(gamegrid-xbm): new variable; XBM image as a replacement for
	`gamegrid-xpm' on Emacsen compiled without XPM-support.
	(gamegrid-make-color-tty-face): Accept a string (= the colour) as
	well as a symbol (= a variable holding the colour-string) as
	argument.
	(gamegrid-colorize-glyph): Replace XEmacs-code for the generation
	of images through Emacs-code.
	(gamegrid-match-spec): Call `gamegrid-make-image-from-vector' to
	convert XEmacs-type image descriptors.
	(gamegrid-color-display-p): Removed. (Use `display-colors-p'
	instead.)
	(gamegrid-make-image-from-vector): New function. Convert XEmacs'
	image descriptors.
	(gamegrid-display-type): Use Emacs' standard `display-.*-p'
	functions to check for display capabilities. Fix the recognition
	of image-support in Emacs 21 by this way.
	(gamegrid-hide-cursor): Removed.
	(gamegrid-setup-default-font): Ported the code from XEmacs to
	Emacs: create a new face and assign the variable `gamegrid-face'
	to it. Make sure that the face is not higher than the smallest
	image used by the game.
	(gamegrid-initialize-display): Use `(setq cursor-type nil)'
	instead of `gamegrid-hide-cursor'.
	(gamegrid-set-face): If `gamegrid-display-mode' is 'glyph, put an
	image in the buffer, instead of applying a face. [This is because
	Emacs display-tables are not as capable as the display-tables in
	XEmacs. Maybe this function should be renamed to reflect the
	change?]
	(gamegrid-init-buffer): Use `insert' instead of
	`insert-string'. If `gamegrid-display-mode' is 'glyph, put the
	face held by `gamegrid-face' in an overlay over the whole buffer
	to emulate a buffer-local default-face.


I attached the latest version of my patch.

    -- Oliver


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: gamegrid.diff --]
[-- Type: text/x-patch, Size: 7268 bytes --]

--- /usr/local/share/emacs/21.2/lisp/play/gamegrid.el	Tue May  7 23:18:49 2002
+++ gamegrid.el	Mon Sep 16 13:14:22 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,20 +167,20 @@
   (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))
+  (let* ((color-str (if (stringp color) color (symbol-value color)))
 	 (name (intern (format "gamegrid-color-tty-face-%s" color-str)))
 	 (face (make-face name)))
     (gamegrid-setup-face face color-str)
@@ -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)

[-- Attachment #3: Type: text/plain, Size: 72 bytes --]


-- 
30 Fructidor an 210 de la Révolution
Liberté, Egalité, Fraternité!

  reply	other threads:[~2002-09-16 11:58 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-13 10:55 gamegrid.el and some games Francesco Potorti`
     [not found] ` <87sn0eglkp.fsf@bundalo.shootybangbang.com>
2002-09-13 13:09   ` Francesco Potorti`
2002-09-14 17:35     ` Richard Stallman
2002-09-13 14:16 ` Oliver Scholz
2002-09-13 17:32   ` Francesco Potorti`
2002-09-13 23:11     ` Oliver Scholz
2002-09-14  1:03       ` Alex Schroeder
2002-09-15  1:50         ` Richard Stallman
2002-09-16 12:11           ` Oliver Scholz
2002-09-19 15:22             ` Luke A. Olbrish
2002-09-20  3:44               ` Richard Stallman
2002-09-15  1:51       ` Richard Stallman
2002-09-16 11:58         ` Oliver Scholz [this message]
2002-09-16 19:27           ` Richard Stallman
2002-09-16 12:01         ` Oliver Scholz
2002-09-16 19:27           ` Richard Stallman
2002-09-16 23:13             ` alkibiades
2002-09-17 15:53               ` Richard Stallman
2002-09-17 16:12                 ` Gerd Moellmann
2002-09-18 15:04                 ` Oliver Scholz
2002-09-18 16:03                   ` Oliver Scholz
2002-09-19 11:45                   ` Eli Zaretskii
2002-09-19 15:17                   ` Richard Stallman
2002-09-20  0:26                     ` Oliver Scholz
2002-09-20  9:40                       ` Miles Bader
2002-09-20 12:01                         ` Oliver Scholz
2002-09-20 10:12                       ` Francesco Potorti`
2002-09-20  1:18                     ` Miles Bader
2002-09-20  9:20                       ` rms
2002-09-20 11:41                         ` Oliver Scholz
2002-09-20  6:54                     ` Gerd Moellmann
2002-09-14 17:35 ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3vg56i1sh.fsf@ID-87814.user.dfncis.de \
    --to=alkibiades@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.