]> code.delx.au - gnu-emacs-elpa/blobdiff - chess-plain.el
Added var chess-plain-spacing (default 0) to be able to widen the board.
[gnu-emacs-elpa] / chess-plain.el
index 6b70e6355947734f10928e21c8a4f1f9bc28215b..efa41f65b426efcfb53db1f503796235d9097da3 100644 (file)
@@ -10,7 +10,7 @@
 
 (defgroup chess-plain nil
   "A minimal, customizable ASCII display."
-  :group 'chess-ascii)
+  :group 'chess-display)
 
 (defcustom chess-plain-draw-border nil
   "*Non-nil if a border should be drawn (using `chess-plain-border-chars')."
 (defcustom chess-plain-border-chars '(?+ ?- ?+ ?| ?| ?+ ?- ?+)
   "*Characters used to draw borders."
   :group 'chess-plain
-  :type '(list character character character character
-              character character character character))
+  :type '(list (character :tag "Upper left corner")
+              (character :tag "Upper border")
+              (character :tag "Upper right corner")
+              (character :tag "Left border")
+              (character :tag "Right border")
+              (character :tag "Lower left corner")
+              (character :tag "Lowwer border")
+              (character :tag "Lower right corner")))
 
 (defcustom chess-plain-black-square-char ?.
   "*Character used to indicate black squares."
@@ -61,22 +67,43 @@ modify `chess-plain-piece-chars' to avoid real confusion.)"
   :type '(choice (const 'color) (const 'square-color)))
         ;; fails somehow
 
-(defun chess-plain-draw ()
+(defcustom chess-plain-spacing 0
+  "*Number of spaces between pieces."
+  :group 'chess-plain
+  :type 'integer)
+
+(defcustom chess-plain-popup-function 'chess-display-popup-in-window
+  "The function used to popup a chess-plain display."
+  :type 'function
+  :group 'chess-plain)
+
+;;; Code:
+
+(defun chess-plain-handler (event &rest args)
+  (cond
+   ((eq event 'initialize) t)
+   ((eq event 'popup)
+    (if chess-display-popup
+       (funcall chess-plain-popup-function)))
+   ((eq event 'draw)
+    (apply 'chess-plain-draw args))
+   ((eq event 'highlight)
+    (apply 'chess-plain-highlight args))))
+
+(defun chess-plain-draw (position perspective)
   "Draw the given POSITION from PERSPECTIVE's point of view.
 PERSPECTIVE is t for white or nil for black."
-  (if (null (get-buffer-window (current-buffer) t))
-      (pop-to-buffer (current-buffer)))
   (let ((inhibit-redisplay t)
        (pos (point)))
     (erase-buffer)
-    (let* ((position (chess-display-position nil))
-          (inverted (not (chess-display-perspective nil)))
+    (let* ((inverted (not perspective))
           (rank (if inverted 7 0))
           (file (if inverted 7 0))
           beg)
       (if chess-plain-draw-border
          (insert ?  (nth 0 chess-plain-border-chars)
-                 (make-string 8 (nth 1 chess-plain-border-chars))
+                 (make-string (+ 8 (* 7 chess-plain-spacing))
+                              (nth 1 chess-plain-border-chars))
                  (nth 2 chess-plain-border-chars) ?\n))
       (while (if inverted (>= rank 0) (< rank 8))
        (if chess-plain-draw-border
@@ -101,7 +128,9 @@ PERSPECTIVE is t for white or nil for black."
                         (t pchar)))))
            (add-text-properties begin (point)
                                 (list 'chess-coord
-                                      (chess-rf-to-index rank file))))
+                                      (chess-rf-to-index rank file)))
+           (when (if inverted (>= file 1) (< file 7))
+             (insert (make-string chess-plain-spacing ? ))))
          (setq file (if inverted (1- file) (1+ file))))
        (if chess-plain-draw-border
            (insert (nth 4 chess-plain-border-chars)))
@@ -110,15 +139,14 @@ PERSPECTIVE is t for white or nil for black."
              rank (if inverted (1- rank) (1+ rank))))
       (if chess-plain-draw-border
          (insert ?  (nth 5 chess-plain-border-chars)
-                 (make-string 8 (nth 6 chess-plain-border-chars))
+                 (make-string (+ 8 (* 7 chess-plain-spacing)) 
+                              (nth 6 chess-plain-border-chars))
                  (nth 7 chess-plain-border-chars) ?\n
                  ? ?  (if (not inverted) "abcdefgh" "hgfedcba")))
       (set-buffer-modified-p nil)
       (goto-char pos))))
 
 (defun chess-plain-highlight (index &optional mode)
-  (if (null (get-buffer-window (current-buffer) t))
-      (pop-to-buffer (current-buffer)))
   (let ((inverted (not (chess-display-perspective nil))))
     (save-excursion
       (beginning-of-line)
@@ -134,7 +162,11 @@ PERSPECTIVE is t for white or nil for black."
                          (1+ file)
                        file)))
       (put-text-property (point) (1+ (point)) 'face
-                        'chess-display-highlight-face))))
+                        (cond
+                         ((eq mode :selected)
+                          'chess-plain-highlight-face)
+                         (t
+                          (chess-display-get-face mode)))))))
 
 (provide 'chess-plain)