diff options
| author | John Wiegley <johnw@newartisans.com> | 2002-04-16 23:41:13 +0000 |
|---|---|---|
| committer | John Wiegley <johnw@newartisans.com> | 2002-04-16 23:41:13 +0000 |
| commit | 83513cbc2750ed373c1ab04c17ebd07776ceead7 (patch) | |
| tree | dbf4109ea60e6e55031b90976c7a40ef070aea57 /chess-ics1.el | |
| parent | bc2e50417174e3d96489951eef50d4250bca1843 (diff) | |
Lots of painting improvements for displays, to improve efficiency.
Diffstat (limited to 'chess-ics1.el')
| -rw-r--r-- | chess-ics1.el | 58 |
1 files changed, 32 insertions, 26 deletions
diff --git a/chess-ics1.el b/chess-ics1.el index e372f30..067a67a 100644 --- a/chess-ics1.el +++ b/chess-ics1.el @@ -39,14 +39,35 @@ (defun chess-ics1-handler (event &rest args) (cond ((eq event 'initialize) t) + ((eq event 'popup) (if chess-display-popup (funcall chess-ics1-popup-function))) + ((eq event 'draw) (apply 'chess-ics1-draw args)) + + ((eq event 'draw-square) + (apply 'chess-ics1-draw-square args)) + ((eq event 'highlight) (apply 'chess-ics1-highlight args)))) +(defsubst chess-ics1-piece-text (piece) + (let ((p (char-to-string piece))) + (add-text-properties 0 1 (list 'face (if (> piece ?a) + 'chess-ics1-black-face + 'chess-ics1-white-face)) p) + p)) + +(defsubst chess-ics1-draw-square (pos piece index) + "Draw a piece image at point on an already drawn display." + (save-excursion + (goto-char pos) + (forward-char) + (delete-char 1) + (insert (chess-ics1-piece-text piece)))) + (defun chess-ics1-draw (position perspective) "Draw the given POSITION from PERSPECTIVE's point of view. PERSPECTIVE is t for white or nil for black." @@ -69,13 +90,7 @@ PERSPECTIVE is t for white or nil for black." (insert (format " %d " (1+ (- 7 rank))))) (insert "| ") (setq begin (1- (point))) - (let ((p (char-to-string piece))) - (add-text-properties - 0 1 (list 'face (if (> piece ?a) - 'chess-ics1-black-face - 'chess-ics1-white-face)) p) - (insert p)) - (insert ? ) + (insert (chess-ics1-piece-text piece) ? ) (add-text-properties begin (point) (list 'chess-coord (chess-rf-to-index rank file)))) @@ -91,25 +106,16 @@ PERSPECTIVE is t for white or nil for black." (goto-char pos))) (defun chess-ics1-highlight (index &optional mode) - (if (null (get-buffer-window (current-buffer) t)) - (pop-to-buffer (current-buffer))) - (let ((inverted (not (chess-display-perspective nil))) - beg end) - (save-excursion - (goto-char (point-min)) - (let ((rank (chess-index-rank index)) - (file (chess-index-file index))) - (goto-line (+ 3 (* 2 (if inverted (- 7 rank) rank)))) - (forward-char (+ 8 (* 4 (if inverted (- 7 file) file))))) - (skip-chars-backward "^|") - (setq beg (point)) - (skip-chars-forward "^|") - (put-text-property beg (point) 'face - (cond - ((eq mode :selected) - 'chess-ics1-highlight-face) - (t - (chess-display-get-face mode))))))) + (let ((pos (chess-display-index-pos nil index))) + (put-text-property pos (save-excursion + (goto-char pos) + (skip-chars-forward "^|") + (point)) + 'face (cond + ((eq mode :selected) + 'chess-ics1-highlight-face) + (t + (chess-display-get-face mode)))))) (defun chess-debug-position (&optional position) "This is a debugging function, and not meant from general use." |
