diff options
| -rw-r--r-- | chess-display.el | 47 | ||||
| -rw-r--r-- | chess-images.el | 26 | ||||
| -rw-r--r-- | chess.texi | 28 |
3 files changed, 66 insertions, 35 deletions
diff --git a/chess-display.el b/chess-display.el index 7c9aac6..b62d6ba 100644 --- a/chess-display.el +++ b/chess-display.el @@ -47,6 +47,7 @@ ;; User interface ;; +(defvar chess-display-session) (defvar chess-display-game) (defvar chess-display-search-function) (defvar chess-display-variation) @@ -58,6 +59,7 @@ (defvar chess-display-highlight-function nil) (defvar chess-display-mode-line "") +(make-variable-buffer-local 'chess-display-session) (make-variable-buffer-local 'chess-display-game) (make-variable-buffer-local 'chess-display-search-function) (make-variable-buffer-local 'chess-display-variation) @@ -70,28 +72,37 @@ (make-variable-buffer-local 'chess-display-mode-line) (defmacro chess-with-current-buffer (buffer &rest body) - `(if buffer - (with-current-buffer buffer - ,@body) - ,@body)) + `(let ((buf ,buffer)) + (if buf + (with-current-buffer buf + ,@body) + ,@body))) -(defun chess-display-create (style perspective &optional search-func) +(defun chess-display-create (style perspective &optional session search-func) "Create a chess display, for displaying chess objects." (let ((draw (intern-soft (concat (symbol-name style) "-draw"))) - (highlight (intern-soft (concat (symbol-name style) "-highlight")))) + (highlight (intern-soft (concat (symbol-name style) "-highlight"))) + (initialize (intern-soft (concat (symbol-name style) "-initialize")))) (with-current-buffer (generate-new-buffer "*Chessboard*") (setq cursor-type nil + chess-display-session session chess-display-draw-function draw chess-display-highlight-function highlight chess-display-perspective perspective chess-display-search-function search-func) (chess-display-mode) + (funcall initialize) + (if session + (let ((game (chess-session-data session 'current-game))) + (if game + (chess-display-set-game nil game)))) (current-buffer)))) (defsubst chess-display-destroy (display) "Destroy a chess display object, killing all of its buffers." - (if (buffer-live-p display) - (kill-buffer display))) + (let ((buf (or display (current-buffer)))) + (if (buffer-live-p buf) + (kill-buffer buf)))) (defsubst chess-display-perspective (display) (chess-with-current-buffer display @@ -236,9 +247,7 @@ change that position object, the display can be updated by calling `chess-display-update'." (chess-with-current-buffer display (if chess-display-draw-function - (funcall chess-display-draw-function - (chess-display-position nil) - chess-display-perspective)) + (funcall chess-display-draw-function)) (chess-display-set-modeline))) (defun chess-display-move (display start &optional target) @@ -256,7 +265,7 @@ If only START is given, it must be in algebraic move notation." start target)))) (cond ((chess-display-active-p) - (chess-session-event chess-current-session 'move ply)) + (chess-session-event chess-display-session 'move ply)) (chess-display-game ;; jww (2002-03-28): This should beget a variation, or alter ;; the game, just as SCID allows @@ -279,11 +288,11 @@ are displaying with doesn't support that mode. `selected' is a mode that is supported by most displays, and is the default mode." (chess-with-current-buffer display (if (chess-display-active-p) - (chess-session-event chess-current-session 'highlight + (chess-session-event chess-display-session 'highlight index (or mode 'selected)) (if chess-display-highlight-function (funcall chess-display-highlight-function index - (or mode 'selected))))) + (or mode 'selected)))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; @@ -408,7 +417,7 @@ The game must be part of an active session (i.e., not just reviewing a game object), and the board must represent the current position in that game (i.e., not editing the position, or reviewing an earlier position within the game)." - (and chess-current-session + (and chess-display-session chess-display-game (= (chess-display index nil) (chess-game-index chess-display-game)) @@ -453,7 +462,7 @@ position within the game)." "Quit the current game." (interactive) (if (chess-display-active-p) - (chess-session-event chess-current-session 'shutdown) + (chess-session-event chess-display-session 'shutdown) (chess-display-destroy nil))) (defun chess-display-manual-move (move) @@ -537,8 +546,8 @@ to the end or beginning." (defun chess-display-send-board () "Send the current board configuration to the user." (interactive) - (if chess-current-session - (chess-session-event chess-current-session 'setup + (if chess-display-session + (chess-session-event chess-display-session 'setup (chess-game-create (chess-display-position nil)))) (setq cursor-type nil chess-display-edit-mode nil)) @@ -665,7 +674,7 @@ Clicking once on a piece selects it; then click on the target location." (let ((last-sel chess-display-last-selected)) ;; if they select the same square again, just deselect it (if (/= (point) (car last-sel)) - (chess-display-move (cadr last-sel) coord) + (chess-display-move nil (cadr last-sel) coord) ;; put the board back to rights (chess-display-update nil)) (setq chess-display-last-selected nil)) diff --git a/chess-images.el b/chess-images.el index 44baabd..f9e3efc 100644 --- a/chess-images.el +++ b/chess-images.el @@ -145,21 +145,17 @@ jww (2001-06-23): This is still not fully implemented." "This display module presents a standard chessboard using images." (if (not (eq event 'initialize)) (apply 'chess-display session buffer event args) - (with-current-buffer - (chess-display session buffer event - 'chess-images-draw 'chess-images-highlight) + (chess-display session buffer event 'chess-images))) - (let ((map (current-local-map))) - (define-key map [?^] 'chess-images-increase-size) - (define-key map [?V] 'chess-images-decrease-size) - (define-key map [?D] 'chess-images-set-directory)) +(defun chess-images-initialize () + (let ((map (current-local-map))) + (define-key map [?^] 'chess-images-increase-size) + (define-key map [?V] 'chess-images-decrease-size) + (define-key map [?D] 'chess-images-set-directory)) - (setq chess-images-size - (chess-images-best-size (- (display-pixel-height) 20) - (- (display-pixel-width) 20)) - chess-images-cache nil) - - (current-buffer)))) + (setq chess-images-cache nil + chess-images-size (chess-images-best-size (- (display-pixel-height) 20) + (- (display-pixel-width) 20)))) (defun chess-images-popup-board () (let* ((size (float (+ (* (or chess-images-border-width 0) 8) @@ -181,11 +177,11 @@ jww (2001-06-23): This is still not fully implemented." max-char-height)))) (defun chess-images-draw () - "Draw the given chess BOARD." + "Draw the current chess display position." (if (null (get-buffer-window (current-buffer) t)) (chess-images-popup-board)) (let* ((inhibit-redisplay t) - (board chess-display-position) + (board (chess-display-position nil)) (inverted (null chess-display-perspective)) (rank (if inverted 7 0)) (file (if inverted 7 0)) @@ -426,16 +426,42 @@ functions given so far. In order to present them in a meaningful fashion to a human reader, it is necessary to create and use a display object. -@defun chess-display-create style perspective +@defun chess-display-create style perspective &optional session search-func +Create a display, using the given @var{style}. The initial +@var{perspective}---non-nil for white, nil for black---determines the +orientation, which can be inverted by the user afterward. + +If @var{session} is given, the display is linked to that +@var{session}, and any moves made on the board that pertain to the +current game's final position, will be transmitted to the +@var{session}. If there is no @var{session}, then moves are made +directly to the game itself. Thus, use @var{session} when you want to +play, and don't when you want to review/edit games. + +@var{search-func} can be a function which is used to search out legal +chess moves when editing position, plies and variations. Since game +object already know the search function to use for that game, this +argument is ignored when a game object is being manipulated. The +default value is @code{chess-standard-search-position}. + +The return value is a display object, which must be passed to all of +the other functions in the section. It is the buffer containing the +chessboard. @end defun @defun chess-display-destroy display +Destroy the given @var{display} object, freeing all memory used by it. @end defun @defun chess-display-set-perspective display perspective +Change the perspective on @var{display} to @var{perspective}, which +must be non-nil for a board from white's perspective, and nil for a +board from black's perspective. @end defun @defun chess-display-search-function display +Return the search function being used by the @var{display} to validate +moves. @end defun @defun chess-display-search-position display position target piece |
