Add emacs-xtra.
[emacs.git] / lisp / textmodes / artist.el
blob9535d39b1d1e8dd987388e6966186956cfe91fb1
1 ;;; artist.el --- draw ascii graphics with your mouse
3 ;; Copyright (C) 2000, 2001, 2004 Free Software Foundation, Inc.
5 ;; Author: Tomas Abrahamsson <tab@lysator.liu.se>
6 ;; Maintainer: Tomas Abrahamsson <tab@lysator.liu.se>
7 ;; Keywords: mouse
8 ;; Version: 1.2.4
9 ;; Release-date: 25-Oct-2001
10 ;; Location: http://www.lysator.liu.se/~tab/artist/
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
29 ;;; Commentary:
31 ;; What is artist?
32 ;; ---------------
34 ;; Artist is an Emacs lisp package that allows you to draw lines,
35 ;; rectangles and ellipses by using your mouse and/or keyboard. The
36 ;; shapes are made up with the ascii characters |, -, / and \.
38 ;; Features are:
40 ;; * Intersecting: When a `|' intersects with a `-', a `+' is
41 ;; drawn, like this: | \ /
42 ;; --+-- X
43 ;; | / \
45 ;; * Rubber-banding: When drawing lines you can interactively see the
46 ;; result while holding the mouse button down and moving the mouse. If
47 ;; your machine is not fast enough (a 386 is a bit to slow, but a
48 ;; pentium is well enough), you can turn this feature off. You will
49 ;; then see 1's and 2's which mark the 1st and 2nd endpoint of the line
50 ;; you are drawing.
52 ;; * Drawing operations: The following drawing operations are implemented:
54 ;; lines straight-lines
55 ;; rectangles squares
56 ;; poly-lines straight poly-lines
57 ;; ellipses circles
58 ;; text (see-thru) text (overwrite)
59 ;; spray-can setting size for spraying
60 ;; vaporize line vaporize lines
61 ;; erase characters erase rectangles
63 ;; Straight lines are lines that go horizontally, vertically or
64 ;; diagonally. Plain lines go in any direction. The operations in
65 ;; the right column are accessed by holding down the shift key while
66 ;; drawing.
68 ;; It is possible to vaporize (erase) entire lines and connected lines
69 ;; (rectangles for example) as long as the lines being vaporized are
70 ;; straight and connected at their endpoints. Vaporizing is inspired
71 ;; by the drawrect package by Jari Aalto <jari.aalto@poboxes.com>.
73 ;; * Flood-filling: You can fill any area with a certain character by
74 ;; flood-filling.
76 ;; * Cut copy and paste: You can cut, copy and paste rectangular
77 ;; regions. Artist also interfaces with the rect package (this can be
78 ;; turned off if it causes you any trouble) so anything you cut in
79 ;; artist can be yanked with C-x r y and vice versa.
81 ;; * Drawing with keys: Everything you can do with the mouse, you can
82 ;; also do without the mouse.
84 ;; * Arrows: After having drawn a (straight) line or a (straight)
85 ;; poly-line, you can set arrows on the line-ends by typing < or >.
87 ;; * Aspect-ratio: You can set the variable artist-aspect-ratio to
88 ;; reflect the height-width ratio for the font you are using. Squares
89 ;; and circles are then drawn square/round. Note, that once your
90 ;; ascii-file is shown with font with a different height-width ratio,
91 ;; the squares won't be square and the circles won't be round.
93 ;; * Picture mode compatibility: Artist is picture mode compatible (this
94 ;; can be turned off).
96 ;; See the documentation for the function artist-mode for a detailed
97 ;; description on how to use artist.
100 ;; What about adding my own drawing modes?
101 ;; ---------------------------------------
103 ;; See the short guide at the end of this file.
104 ;; If you add a new drawing mode, send it to me, and I would gladly
105 ;; include in the next release!
108 ;;; Installation:
110 ;; To use artist, put this in your .emacs:
112 ;; (autoload 'artist-mode "artist" "Enter artist-mode" t)
115 ;;; Requirements:
117 ;; Artist requires Emacs 19.28 or higher.
119 ;; Artist requires the `rect' package (which comes with Emacs) to be
120 ;; loadable, unless the variable `artist-interface-with-rect' is set
121 ;; to nil.
123 ;; Artist also requires the Picture mode (which also comes with Emacs)
124 ;; to be loadable, unless the variable `artist-picture-compatibility'
125 ;; is set to nil.
127 ;;; Known bugs:
129 ;; The shifted operations are not available when drawing with the mouse
130 ;; in Emacs 19.29 and 19.30.
132 ;; It is not possible to change between shifted and unshifted operation
133 ;; while drawing with the mouse. (See the comment in the function
134 ;; artist-shift-has-changed for further details.)
137 ;;; ChangeLog:
139 ;; 1.2.4 25-Oct-2001
140 ;; Bugfix: Some operations (the edit menu) got hidden
141 ;; Bugfix: The first arrow for poly-lines was always pointing
142 ;; to the right
143 ;; Changed: Updated with changes made for Emacs 21.1
145 ;; 1.2.3 20-Nov-2000
146 ;; Bugfix: Autoload cookie corrected
148 ;; 1.2.2 19-Nov-2000
149 ;; Changed: More documentation fixes.
150 ;; Bugfix: The arrow characters (`artist-arrows'), which
151 ;; got wrong in 1.1, are now corrected.
153 ;; 1.2.1 15-Nov-2000
154 ;; New: Documentation fixes.
155 ;; Bugfix: Sets next-line-add-newlines to t while in artist-mode.
156 ;; Drawing with keys was confusing without this fix, if
157 ;; next-line-add-newlines was set to nil.
158 ;; Thanks to Tatsuo Furukawa <tatsuo@kobe.hp.com> for this.
160 ;; 1.2 22-Oct-2000
161 ;; New: Updated to work with Emacs 21
163 ;; 1.1 15-Aug-2000
164 ;; Bugfix: Cursor follows mouse pointer more closely.
165 ;; New: Works with Emacs 20.x
166 ;; New: Variables are customizable
168 ;; 1.1-beta1 21-Apr-1998
169 ;; New: Spray-can (Utterly useless, I believe, but it was fun
170 ;; to implement :-) after an idea by Karl-Johan Karlsson
171 ;; <kj@lysator.liu.se>.
172 ;; New: Freehand drawing (with pen).
173 ;; New: Vaporizing lines.
174 ;; New: Text-rendering using figlet.
175 ;; New: Picture mode compatibility.
176 ;; Changed: All Artist keys now uses the prefix C-c C-a not to conflict
177 ;; with Picture mode.
178 ;; Bugfix: No longer leaves traces of lines when rubberbanding
179 ;; if the buffer auto-scrolls.
180 ;; Bugfix: Infinite loop sometimes when rubberbanding was turned
181 ;; off.
183 ;; 1.0 01-Mar-1998
184 ;; First official release.
186 ;;; Code:
188 ;; Variables
190 (defconst artist-version "1.2.4")
191 (defconst artist-maintainer-address "tab@lysator.liu.se")
194 (eval-and-compile
195 (condition-case ()
196 (require 'custom)
197 (error nil))
198 (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
199 nil ;; We've got what we needed
200 ;; We have the old custom-library, hack around it!
201 (defmacro defgroup (&rest args)
202 nil)
203 (defmacro defface (var values doc &rest args)
204 `(make-face ,var))
205 (defmacro defcustom (var value doc &rest args)
206 `(defvar ,var ,value ,doc))))
208 ;; User options
209 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
211 (defgroup artist nil
212 "Customization of the Artist mode."
213 :group 'mouse)
215 (defgroup artist-text nil
216 "Customization of the text rendering."
217 :group 'artist)
219 (defcustom artist-rubber-banding t
220 "Interactively do rubber-banding when non-nil."
221 :group 'artist
222 :type 'boolean)
224 (defcustom artist-first-char ?1
225 "Character to set at first point when not rubber-banding."
226 :group 'artist
227 :type 'character)
229 (defcustom artist-second-char ?2
230 "Character to set at second point when not rubber-banding."
231 :group 'artist
232 :type 'character)
234 (defcustom artist-interface-with-rect t
235 "Whether to interface with the rect package or not.
237 Interfacing to the rect package means that the Copy and Paste operations
238 will use the rectangle buffer when accessing the copied area. This means
239 that you can insert a rectangle which is copied using the artist package
240 and vice versa.
242 If this causes any problem for you (for example, if the implementation of
243 the rectangle package changes), you can set this variable to nil, and the
244 artist package will use its own copy buffer."
245 :group 'artist
246 :type 'boolean)
248 (defvar artist-arrows [ ?> nil ?v ?L ?< nil ?^ nil ]
249 ;; This is a defvar, not a defcustom, since the custom
250 ;; package shows vectors of characters as a vector of integers,
251 ;; which is confusing
252 "A vector of characters to use as arrows.
254 The vector is 8 elements long and contains a character for each
255 direction, or nil if there is no suitable character to use for arrow
256 in that direction.
258 The directions are as follows:
260 5 6 7
261 \\ | /
262 4 - * - 0
263 / | \\
264 3 2 1")
266 (defcustom artist-aspect-ratio 1
267 "Defines the character height-to-width aspect ratio.
268 This is used when drawing squares and circles. If the height of the"
269 :group 'artist
270 :type 'number)
272 (defcustom artist-trim-line-endings t
273 "Whether or not to remove white-space at end of lines.
275 If non-nil, line-endings are trimmed (that is, extraneous white-space
276 at the end of the line is removed) when the shape is drawn."
277 :group 'artist
278 :type 'boolean)
281 (defcustom artist-flood-fill-right-border 'window-width
282 "Right edge definition, used when flood-filling.
284 When flood-filling, if the area is not closed off to the right, then
285 flood-filling will fill no more to the right than specified by this
286 variable. This limit is called the fill-border."
287 :group 'artist
288 :type '(choice (const :tag "limited to window" window-width)
289 (const :tag "limited to value of `fill-column'" fill-column)))
291 (defcustom artist-flood-fill-show-incrementally t
292 "Whether or not to incrementally update display when flood-filling.
294 If non-nil, incrementally update display when flood-filling.
295 If set to non-nil, this currently implies discarding any input events
296 during the flood-fill."
297 :group 'artist
298 :type 'boolean)
301 (defcustom artist-ellipse-right-char ?\)
302 "Character to use at the rightmost position when drawing narrow ellipses.
304 In this figure, it is the right parenthesis (the ``)'' character):
305 -----
307 -----"
308 :group 'artist
309 :type 'character)
312 (defcustom artist-ellipse-left-char ?\(
313 "Character to use at the leftmost position when drawing narrow ellipses.
315 In this figure, it is the left parenthesis (the ``('' character):
316 -----
318 -----"
319 :group 'artist
320 :type 'character)
322 (defcustom artist-picture-compatibility t
323 "Whether or not picture mode compatibility is on."
324 :group 'artist
325 :type 'boolean)
330 (defcustom artist-vaporize-fuzziness 1
331 "How to vaporize lines that are cut off.
333 Accept this many characters cutting off a line and still treat
334 it as one line.
335 Example:
336 If `artist-vaporize-fuzziness' is 2, then those will be recognized as
337 lines from A to B (provided you start vaporizing them at the ``*''):
339 A----*------/-----------B
341 A----*----/\\------------B
342 / \\
344 but this one won't, since it is cut off by more than 2 characters:
345 \\/ /
346 A----*----/\\/----------B
347 / /\\
348 (in fact, only the left part (between the A and the leftmost ``/''
349 crossing the line) will be vaporized)"
350 :group 'artist
351 :type 'integer)
354 (defvar artist-pointer-shape (if (eq window-system 'x) x-pointer-crosshair nil)
355 "*If in X Windows, use this pointer shape while drawing with the mouse.")
358 (defcustom artist-text-renderer 'artist-figlet
359 "Function for doing text rendering."
360 :group 'artist-text
361 :type 'symbol)
364 (defcustom artist-figlet-program "figlet"
365 "Program to run for `figlet'."
366 :group 'artist-text
367 :type 'string)
370 (defcustom artist-figlet-default-font "standard"
371 "Default font for `figlet'."
372 :group 'artist-text
373 :type 'string)
376 (defcustom artist-figlet-list-fonts-command
377 ;; list files ending with *.flf in any directory printed by the
378 ;; ``figlet -I2'' command. I think this will not produce more than
379 ;; one directory, but it never hurts to be on the safe side...
380 "for dir in `figlet -I2`; do cd $dir; ls *.flf; done"
381 "Command to run to get list of available fonts."
382 :group 'artist-text
383 :type 'string)
386 (defcustom artist-spray-interval 0.2
387 "Number of seconds between repeated spraying."
388 :group 'artist
389 :type 'number)
392 (defcustom artist-spray-radius 4
393 "Size of the area for spraying."
394 :group 'artist
395 :type 'integer)
398 (defvar artist-spray-chars '(?\ ?. ?- ?+ ?m ?% ?* ?#)
399 ;; This is a defvar, not a defcustom, since the custom
400 ;; package shows lists of characters as a lists of integers,
401 ;; which is confusing
402 "*Characters (``color'') to use when spraying.
403 They should be ordered
404 from the ``lightest'' to the ``heaviest'' since spraying replaces a
405 light character with the next heavier one.")
408 (defvar artist-spray-new-char ?.
409 "*Initial character to use when spraying.
410 This character is used if spraying upon a character that is
411 not in `artist-spray-chars'. The character defined by this variable
412 should be in `artist-spray-chars', or spraying will behave
413 strangely.")
416 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
417 ;; End of user options
420 ;; Internal variables
422 (defvar artist-mode nil
423 "Non-nil to enable `artist-mode' and nil to disable.")
424 (make-variable-buffer-local 'artist-mode)
426 (defvar artist-mode-name " Artist"
427 "Name of artist mode beginning with a space (appears in the mode-line).")
429 (defvar artist-curr-go 'pen-char
430 "Current selected graphics operation.")
431 (make-variable-buffer-local 'artist-curr-go)
433 (defvar artist-line-char-set nil
434 "Boolean to tell whether user has set some char to use when drawing lines.")
435 (make-variable-buffer-local 'artist-line-char-set)
437 (defvar artist-line-char nil
438 "Char to use when drawing lines.")
439 (make-variable-buffer-local 'artist-line-char)
441 (defvar artist-fill-char-set nil
442 "Boolean to tell whether user has set some char to use when filling.")
443 (make-variable-buffer-local 'artist-fill-char-set)
445 (defvar artist-fill-char nil
446 "Char to use when filling.")
447 (make-variable-buffer-local 'artist-fill-char)
449 (defvar artist-erase-char ?\s
450 "Char to use when erasing.")
451 (make-variable-buffer-local 'artist-erase-char)
453 (defvar artist-default-fill-char ?.
454 "Char to use when a fill-char is required but none is set.")
455 (make-variable-buffer-local 'artist-default-fill-char)
457 ; This variable is not buffer local
458 (defvar artist-copy-buffer nil
459 "Copy buffer.")
461 (defvar artist-draw-region-min-y 0
462 "Line-number for top-most visited line for draw operation.")
463 (make-variable-buffer-local 'artist-draw-region-min-y)
465 (defvar artist-draw-region-max-y 0
466 "Line-number for bottom-most visited line for draw operation.")
467 (make-variable-buffer-local 'artist-draw-region-max-y)
469 (defvar artist-borderless-shapes nil
470 "When non-nil, draw shapes without border.
471 The fill char is used instead, if it is set.")
472 (make-variable-buffer-local 'artist-borderless-shapes)
475 (eval-when-compile
476 ;; Make rect available at compile-time
477 (require 'rect) ; for interfacing with rect
478 (require 'reporter) ; the bug-reporting tool
479 (require 'picture)) ; picture mode compatibility
481 (if artist-interface-with-rect
482 (require 'rect))
484 (require 'reporter)
486 (if artist-picture-compatibility
487 (require 'picture))
490 (defvar artist-mode-map
491 (let ((map (make-sparse-keymap)))
492 (setq artist-mode-map (make-sparse-keymap))
493 (define-key map [down-mouse-1] 'artist-down-mouse-1)
494 (define-key map [S-down-mouse-1] 'artist-down-mouse-1)
495 (define-key map [down-mouse-2] 'artist-mouse-choose-operation)
496 (define-key map [S-down-mouse-2] 'artist-mouse-choose-operation)
497 (define-key map [down-mouse-3] 'artist-down-mouse-3)
498 (define-key map [S-down-mouse-3] 'artist-down-mouse-3)
499 (define-key map "\r" 'artist-key-set-point) ; return
500 (define-key map [up] 'artist-previous-line)
501 (define-key map "\C-p" 'artist-previous-line)
502 (define-key map [down] 'artist-next-line)
503 (define-key map "\C-n" 'artist-next-line)
504 (define-key map [left] 'artist-backward-char)
505 (define-key map "\C-b" 'artist-backward-char)
506 (define-key map [right] 'artist-forward-char)
507 (define-key map "\C-f" 'artist-forward-char)
508 (define-key map "<" 'artist-toggle-first-arrow)
509 (define-key map ">" 'artist-toggle-second-arrow)
510 (define-key map "\C-c\C-a\C-e" 'artist-select-erase-char)
511 (define-key map "\C-c\C-a\C-f" 'artist-select-fill-char)
512 (define-key map "\C-c\C-a\C-l" 'artist-select-line-char)
513 (define-key map "\C-c\C-a\C-o" 'artist-select-operation)
514 (define-key map "\C-c\C-a\C-r" 'artist-toggle-rubber-banding)
515 (define-key map "\C-c\C-a\C-t" 'artist-toggle-trim-line-endings)
516 (define-key map "\C-c\C-a\C-s" 'artist-toggle-borderless-shapes)
517 (define-key map "\C-c\C-c" 'artist-mode-off)
518 (define-key map "\C-c\C-al" 'artist-select-op-line)
519 (define-key map "\C-c\C-aL" 'artist-select-op-straight-line)
520 (define-key map "\C-c\C-ar" 'artist-select-op-rectangle)
521 (define-key map "\C-c\C-aR" 'artist-select-op-square)
522 (define-key map "\C-c\C-as" 'artist-select-op-square)
523 (define-key map "\C-c\C-ap" 'artist-select-op-poly-line)
524 (define-key map "\C-c\C-aP" 'artist-select-op-straight-poly-line)
525 (define-key map "\C-c\C-ae" 'artist-select-op-ellipse)
526 (define-key map "\C-c\C-ac" 'artist-select-op-circle)
527 (define-key map "\C-c\C-at" 'artist-select-op-text-see-thru)
528 (define-key map "\C-c\C-aT" 'artist-select-op-text-overwrite)
529 (define-key map "\C-c\C-aS" 'artist-select-op-spray-can)
530 (define-key map "\C-c\C-az" 'artist-select-op-spray-set-size)
531 (define-key map "\C-c\C-a\C-d" 'artist-select-op-erase-char)
532 (define-key map "\C-c\C-aE" 'artist-select-op-erase-rectangle)
533 (define-key map "\C-c\C-av" 'artist-select-op-vaporize-line)
534 (define-key map "\C-c\C-aV" 'artist-select-op-vaporize-lines)
535 (define-key map "\C-c\C-a\C-k" 'artist-select-op-cut-rectangle)
536 (define-key map "\C-c\C-a\M-w" 'artist-select-op-copy-rectangle)
537 (define-key map "\C-c\C-a\C-y" 'artist-select-op-paste)
538 (define-key map "\C-c\C-af" 'artist-select-op-flood-fill)
539 (define-key map "\C-c\C-a\C-b" 'artist-submit-bug-report)
540 map)
541 "Keymap for `artist-minor-mode'.")
543 (defvar artist-replacement-table (make-vector 256 0)
544 "Replacement table for `artist-replace-char'.")
548 ;;; The table of graphic operations
550 (defvar artist-mt
551 ;; Implementation note: Maybe this should be done using a structure
552 ;; in the cl package?
555 (menu
556 ("Drawing"
557 ((function-call
558 ( "Undo" do-undo undo))
560 (separator )
561 (graphics-operation
562 ("Pen" (("Pen" pen-char "pen-c"
563 artist-no-arrows nil
564 nil nil nil
565 artist-do-continously
566 artist-pen
567 (nil))
568 ("Pen Line" pen-line "pen-l"
569 artist-arrows artist-pen-set-arrow-points
570 artist-pen-reset-last-xy nil nil
571 artist-do-continously
572 artist-pen-line
573 (nil)))))
575 (graphics-operation
576 ("Line" (("line" line "line"
577 artist-arrows artist-set-arrow-points-for-2points
578 nil nil nil
580 artist-draw-line
581 (artist-undraw-line
582 artist-nil nil))
583 ("straight line" s-line "sline"
584 artist-arrows artist-set-arrow-points-for-2points
585 nil nil nil
587 artist-draw-sline
588 (artist-undraw-sline
589 artist-nil nil)))))
591 (graphics-operation
592 ("Rectangle" (("rectangle" rect "rect"
593 artist-no-arrows nil
594 nil nil nil
596 artist-draw-rect
597 (artist-undraw-rect
598 artist-t-if-fill-char-set artist-fill-rect))
599 ("square" square "square"
600 artist-no-arrows nil
601 nil nil nil
603 artist-draw-square
604 (artist-undraw-square
605 artist-t-if-fill-char-set artist-fill-square)))))
607 (graphics-operation
608 ("Poly-line" (("poly-line" polyline "poly"
609 artist-arrows artist-set-arrow-points-for-poly
610 nil nil nil
611 artist-do-poly
612 artist-draw-line
613 (artist-undraw-line
614 artist-nil nil))
615 ("straight poly-line" spolyline "s-poly"
616 artist-arrows artist-set-arrow-points-for-poly
617 nil nil nil
618 artist-do-poly
619 artist-draw-sline
620 (artist-undraw-sline
621 artist-nil nil)))))
623 (graphics-operation
624 ("Ellipse" (("ellipse" ellipse "ellipse"
625 artist-no-arrows nil
626 nil nil nil
628 artist-draw-ellipse
629 (artist-undraw-ellipse
630 artist-t-if-fill-char-set artist-fill-ellipse))
631 ("circle" circle "circle"
632 artist-no-arrows nil
633 nil nil nil
635 artist-draw-circle
636 (artist-undraw-circle
637 artist-t-if-fill-char-set artist-fill-circle)))))
639 (graphics-operation
640 ("Text" (("text see-thru" text-thru "text-thru"
641 artist-no-arrows nil
642 nil nil nil
644 artist-text-see-thru
645 nil)
646 ("text overwrite" text-ovwrt "text-ovwrt"
647 artist-no-arrows nil
648 nil nil nil
650 artist-text-overwrite
651 nil))))
653 (graphics-operation
654 ("Spray-can" (("spray-can" spray-can "spray-can"
655 artist-no-arrows nil
656 nil nil nil
657 artist-do-continously
658 artist-spray
659 (artist-spray-get-interval))
660 ("spray set size" spray-get-size "spray-size"
661 artist-no-arrows nil
662 nil artist-spray-clear-circle artist-spray-set-radius
664 artist-draw-circle
665 (artist-undraw-circle
666 artist-nil nil)))))
668 (graphics-operation
669 ("Erase" (("erase char" erase-char "erase-c"
670 artist-no-arrows nil
671 nil nil nil
672 artist-do-continously
673 artist-erase-char
674 (nil))
675 ("erase rectangle" erase-rect "erase-r"
676 artist-no-arrows nil
677 nil nil nil
679 artist-draw-rect
680 (artist-undraw-rect
681 artist-t artist-erase-rect)))))
683 (graphics-operation
684 ("Vaporize" (("vaporize line" vaporize-line "vaporize-1"
685 artist-no-arrows nil
686 nil nil nil
688 artist-vaporize-line
689 nil)
690 ("vaporize lines" vaporize-lines "vaporize-n"
691 artist-no-arrows nil
692 nil nil nil
694 artist-vaporize-lines
695 nil)))))))
697 (menu
698 ("Edit"
699 ((graphics-operation
700 ("Cut" (("cut rectangle" cut-r "cut-r"
701 artist-no-arrows nil
702 nil nil nil
704 artist-draw-rect
705 (artist-undraw-rect
706 artist-t artist-cut-rect)
707 ("cut square" cut-s "cut-s"
708 artist-no-arrows nil
709 nil nil nil
711 artist-draw-square
712 (artist-undraw-square
713 artist-t artist-cut-square))))))
715 (graphics-operation
716 ("Copy" (("copy rectangle" copy-r "copy-r"
717 artist-no-arrows nil
718 nil nil nil
720 artist-draw-rect
721 (artist-undraw-rect
722 artist-t artist-copy-rect)
723 ("copy square" copy-s "copy-s"
724 artist-no-arrows nil
725 nil nil nil
727 artist-draw-square
728 (artist-undraw-square
729 artist-t artist-copy-square))))))
731 (graphics-operation
732 ("Paste" (("paste" paste "paste"
733 artist-no-arrows nil
734 nil nil nil
736 artist-paste
737 nil)
738 ("paste" paste "paste"
739 artist-no-arrows nil
740 nil nil nil
742 artist-paste
743 nil))))
745 (graphics-operation
746 ("Flood-fill" (("flood-fill" flood-fill "flood"
747 artist-no-arrows nil
748 nil nil nil
750 artist-flood-fill
751 nil)
752 ("flood-fill" flood-fill "flood"
753 artist-no-arrows nil
754 nil nil nil
756 artist-flood-fill
757 nil)))))))
759 (menu
760 ("Settings"
761 ((function-call
762 ("Set Fill" set-fill artist-select-fill-char))
764 (function-call
765 ("Set Line" set-line artist-select-line-char))
767 (function-call
768 ("Set Erase" set-erase artist-select-erase-char))
770 (function-call
771 ("Rubber-banding" rubber-band artist-toggle-rubber-banding))
773 (function-call
774 ("Trimming" trimming artist-toggle-trim-line-endings))
776 (function-call
777 ("Borders" borders artist-toggle-borderless-shapes))
779 (function-call
780 ("Spray-chars" spray-chars artist-select-spray-chars)))))
782 ) ;; end of list
784 "Master Table for `artist-mode'.
785 This table is primarily a table over the different graphics operations
786 available in artist mode, but it also holds layout information for the
787 popup menu.
789 The master table is a list of table elements. The elements of this table
790 have the layout
792 (TAG INFO-PART)
794 There are three kinds of TAG:
796 `menu' -- a sub-menu
797 `separator' -- produce a separator in the popup menu
798 `function-call' -- call a function
799 `graphics-operation' -- a graphics operation
801 The layout of the INFO-PART for `menu' is
803 (TITLE ((TAG-1 INFO-PART-1) (TAG-2 INFO-PART-2) ...))
805 TITLE is the title of the submenu; this is followed by a list of
806 menu items, each on the general form (TAG INFO-PART).
809 The layout of the INFO-PART for `separator' is empty and not used.
812 This is the layout of the INFO-PART for `function-call':
814 (KEYWORD SYMBOL FN)
816 KEYWORD is a string naming the operation, and appears in the popup menu.
817 SYMBOL is the symbol for the operations.
818 FN is the function performing the operation. This function
819 is called with no arguments. Its return value is ignored.
822 The layout of the INFO-PART for `graphics-operation' is
824 (TITLE (UNSHIFTED SHIFTED))
826 TITLE is the title that appears in the popup menu. UNSHIFTED
827 and SHIFTED specify for unshifted and shifted operation. Both
828 have the form
830 (KEYWORD KEY-SYMBOL MODE-LINE ARROW-PRED ARROW-SET-FN
831 INIT-FN PREP-FILL-FN EXIT-FN DRAW-HOW DRAW-FN EXTRA-DRAW-INFO)
833 KEYWORD is a string specifying the name of the shape to draw.
834 This is used when selecting drawing operation.
835 KEY-SYMBOL is the key which is used when looking up members
836 through the functions `artist-go-get-MEMBER-from-symbol'
837 and `artist-fc-get-MEMBER-from-symbol'.
838 MODE-LINE is a string that appears in the mode-line when drawing
839 the shape.
840 ARROW-PRED is a function that is called to find out if the shape
841 can have arrows. The function is called with no arguments and
842 must return nil or t.
843 ARROW-SET-FN is a function that is called to set arrow end-points.
844 Arguments and return values for this funcion are described below.
845 INIT-FN is, if non-nil, a function that is called when the first
846 point of the shape is set. Arguments and return values for
847 this funcion are described below.
848 PREP-FILL-FN is, if non-nil, a function that is called after
849 the last point is set, but before the filling is done.
850 Arguments and return values for this funcion are described below.
851 EXIT-FN is, if non-nil, a function that is called after filling
852 is done. Arguments and return values for this funcion are
853 described below.
854 DRAW-HOW defines the kind of shape. The kinds of shapes are:
855 `artist-do-continously' -- Do drawing operation continously,
856 as long as the mouse button is held down.
857 `artist-do-poly' -- Do drawing operation many times.
858 1 -- Do drawing operation only once.
859 2 -- The drawing operation requires two points.
860 DRAW-FN is the function to call for drawing. Arguments and
861 return values for this funcion are described below.
862 EXTRA-DRAW-INFO the layout of this depends on the value of DRAW-HOW:
863 If DRAW-HOW is `artist-do-continously':
865 (INTERVAL-FN)
867 INTERVAL-FN is, if non-nil, a function to call for getting
868 an interval between repeated calls to the DRAW-FN.
869 This function is called with no arguments and must
870 return a number, the interval in seconds.
871 If nil, calls to DRAW-FN are done only when the mouse
872 or cursor is moved.
874 If DRAW-HOW is either `artist-do-poly' or 2:
876 (UNDRAW-FN FILL-PRED FILL-FN)
878 UNDRAW-FN is a function to call for undrawing the shape.
879 Arguments and return values for this funcion are
880 described below.
881 FILL-PRED is a function that is called to find out if the shape
882 can have arrows. The function must take no arguments and
883 return nil or t.
884 FILL-FN is a function to call for filling the shape.
885 Arguments and return values for this funcion are
886 described below.
888 If DRAW-HOW is 1:
892 Note! All symbols and keywords (both in the `funcion-call' INFO-PART
893 as well as in the `graphics-operation' INFO-PART) must be unique.
895 The following table describe function arguments and return value
896 for different functions and DRAW-HOWs.
898 If DRAW-HOW is either `artist-do-continously' or 1:
900 INIT-FN X Y ==> ignored
901 PREP-FILL-FN X Y ==> ignored
902 EXIT-FN X Y ==> ignored
903 ARROW-SET-FN X Y ==> ignored
904 DRAW-FN X Y ==> ignored
906 If DRAW-HOW is 2:
908 INIT-FN X1 Y1 ==> ignored
909 PREP-FILL-FN X1 Y1 X2 Y2 ==> ignored
910 EXIT-FN X1 Y1 X2 Y2 ==> ignored
911 ARROW-SET-FN X1 Y1 X2 Y2 ==> ignored
912 DRAW-FN X1 Y1 X2 Y2 ==> (ENDPOINT-1 ENDPOINT-2 SHAPE)
913 UNDRAW-FN (ENDPOINT-1 ENDPOINT-2 SHAPE) ==> ignored
914 FILL-FN (ENDPOINT-1 ENDPOINT-2 SHAPE) X1 Y1 X2 Y2 ==> ignored
916 ENDPOINT-1 and ENDPOINT-2 are endpoints which are created with
917 `artist-make-endpoint'
918 SHAPE is an opaque structure, created by the DRAW-FN and intented
919 to be used only by the UNDRAW-FN.
921 If DRAW-HOW is `artist-do-poly':
923 INIT-FN X1 Y1
924 PREP-FILL-FN POINT-LIST
925 ARROW-SET-FN POINT-LIST
926 EXIT-FN POINT-LIST
927 DRAW-FN X-LAST Y-LAST X-NEW Y-NEW ==> (ENDPOINT-1 ENDPOINT-2 SHAPE)
928 UNDRAW-FN (ENDPOINT-1 ENDPOINT-2 SHAPE)
929 FILL-FN POINT-LIST
931 ENDPOINT-1 and ENDPOINT-2 are endpoints which are created with
932 `artist-make-endpoint'.
933 SHAPE is an opaque structure, created by the DRAW-FN and intented
934 to be used only by the UNDRAW-FN.
935 POINT-LIST is a list of vectors [X Y].")
939 ;; Accessors for the master table
942 (defun artist-mt-get-tag (element)
943 "Retrieve the tag component from the master table ELEMENT."
944 (elt element 0))
946 (defun artist-mt-get-info-part (element)
947 "Retrieve the info part component from the master table ELEMENT."
948 (elt element 1))
950 ;; For the 'graphics-operation info-parts
952 (defsubst artist-go-get-desc (info-part)
953 "Retrieve the description component from a graphics operation INFO-PART."
954 (elt info-part 0))
956 (defsubst artist-go-get-unshifted (info-part)
957 "Retrieve the unshifted info from a graphics operation INFO-PART."
958 (elt (elt info-part 1) 0))
960 (defsubst artist-go-get-shifted (info-part)
961 "Retrieve the shifted info from a graphics operation INFO-PART."
962 (elt (elt info-part 1) 1))
964 (defsubst artist-go-get-keyword (info-variant-part)
965 "Retrieve the keyword component from an INFO-VARIANT-PART.
966 An INFO-VARIANT-PART is the shifted or unshifted info from a info-part."
967 (elt info-variant-part 0))
969 (defsubst artist-go-get-symbol (info-variant-part)
970 "Retrieve the symbol component from an INFO-VARIANT-PART.
971 An INFO-VARIANT-PART is the shifted or unshifted info from a info-part."
972 (elt info-variant-part 1))
974 (defsubst artist-go-get-mode-line (info-variant-part)
975 "Retrieve the mode line component from an INFO-VARIANT-PART.
976 An INFO-VARIANT-PART is the shifted or unshifted info from a info-part."
977 (elt info-variant-part 2))
979 (defsubst artist-go-get-arrow-pred (info-variant-part)
980 "Retrieve the arrow predicate component from an INFO-VARIANT-PART.
981 An INFO-VARIANT-PART is the shifted or unshifted info from a info-part."
982 (elt info-variant-part 3))
984 (defsubst artist-go-get-arrow-set-fn (info-variant-part)
985 "Retrieve the arrow set component from an INFO-VARIANT-PART.
986 An INFO-VARIANT-PART is the shifted or unshifted info from a info-part."
987 (elt info-variant-part 4))
989 (defsubst artist-go-get-init-fn (info-variant-part)
990 "Retrieve the init function component from an INFO-VARIANT-PART.
991 An INFO-VARIANT-PART is the shifted or unshifted info from a info-part."
992 (elt info-variant-part 5))
994 (defsubst artist-go-get-prep-fill-fn (info-variant-part)
995 "Retrieve the fill preparation function component from an INFO-VARIANT-PART.
996 An INFO-VARIANT-PART is the shifted or unshifted info from a info-part."
997 (elt info-variant-part 6))
999 (defsubst artist-go-get-exit-fn (info-variant-part)
1000 "Retrieve the exit component from an INFO-VARIANT-PART.
1001 An INFO-VARIANT-PART is the shifted or unshifted info from a info-part."
1002 (elt info-variant-part 7))
1004 (defsubst artist-go-get-draw-how (info-variant-part)
1005 "Retrieve the draw how component from an INFO-VARIANT-PART.
1006 An INFO-VARIANT-PART is the shifted or unshifted info from a info-part."
1007 (elt info-variant-part 8))
1009 (defsubst artist-go-get-draw-fn (info-variant-part)
1010 "Retrieve the draw function component from an INFO-VARIANT-PART.
1011 An INFO-VARIANT-PART is the shifted or unshifted info from a info-part."
1012 (elt info-variant-part 9))
1014 (defsubst artist-go-get-undraw-fn (info-variant-part)
1015 "Retrieve the undraw function component from an INFO-VARIANT-PART.
1016 An INFO-VARIANT-PART is the shifted or unshifted info from a info-part.
1017 This interval function component is available only if the `draw-how'
1018 component is other than `artist-do-continously' or 1."
1019 (elt (elt info-variant-part 10) 0))
1021 (defsubst artist-go-get-interval-fn (info-variant-part)
1022 "Retrieve the interval function component from an INFO-VARIANT-PART.
1023 An INFO-VARIANT-PART is the shifted or unshifted info from a info-part.
1024 This interval function component is available only if the `draw-how'
1025 component is `artist-do-continously'."
1026 (elt (elt info-variant-part 10) 0))
1028 (defsubst artist-go-get-fill-pred (info-variant-part)
1029 "Retrieve the fill predicate component from an INFO-VARIANT-PART.
1030 An INFO-VARIANT-PART is the shifted or unshifted info from a info-part.
1031 This interval function component is available only if the `draw-how'
1032 component is other than `artist-do-continously' or 1."
1033 (elt (elt info-variant-part 10) 1))
1035 (defsubst artist-go-get-fill-fn (info-variant-part)
1036 "Retrieve the fill function component from an INFO-VARIANT-PART.
1037 An INFO-VARIANT-PART is the shifted or unshifted info from a info-part.
1038 This interval function component is available only if the `draw-how'
1039 component is other than `artist-do-continously' or 1."
1040 (elt (elt info-variant-part 10) 2))
1042 ;; For the 'function-call info-parts
1044 (defsubst artist-fc-get-keyword (info-part)
1045 "Retrieve the keyword component from a graphics operation INFO-PART."
1046 (elt info-part 0))
1048 (defsubst artist-fc-get-symbol (info-part)
1049 "Retrieve the symbol component from a graphics operation INFO-PART."
1050 (elt info-part 1))
1052 (defsubst artist-fc-get-fn (info-part)
1053 "Retrieve the function component from a graphics operation INFO-PART."
1054 (elt info-part 2))
1056 ;; For the 'menu info-parts
1058 (defsubst artist-mn-get-title (info-part)
1059 "Retrieve the title component from a graphics operation INFO-PART."
1060 (elt info-part 0))
1062 (defsubst artist-mn-get-items (info-part)
1063 "Retrieve the items component from a graphics operation INFO-PART."
1064 (elt info-part 1))
1066 ;;; ---------------------------------
1067 ;;; The artist-mode
1068 ;;; ---------------------------------
1070 ;;;###autoload
1071 (defun artist-mode (&optional state)
1072 "Toggle artist mode. With arg, turn artist mode on if arg is positive.
1073 Artist lets you draw lines, squares, rectangles and poly-lines, ellipses
1074 and circles with your mouse and/or keyboard.
1076 How to quit artist mode
1078 Type \\[artist-mode-off] to quit artist-mode.
1081 How to submit a bug report
1083 Type \\[artist-submit-bug-report] to submit a bug report.
1086 Drawing with the mouse:
1088 mouse-2
1089 shift mouse-2 Pops up a menu where you can select what to draw with
1090 mouse-1, and where you can do some settings (described
1091 below).
1093 mouse-1
1094 shift mouse-1 Draws lines, rectangles or poly-lines, erases, cuts, copies
1095 or pastes:
1097 Operation Not shifted Shifted
1098 --------------------------------------------------------------
1099 Pen fill-char at point line from last point
1100 to new point
1101 --------------------------------------------------------------
1102 Line Line in any direction Straight line
1103 --------------------------------------------------------------
1104 Rectangle Rectangle Square
1105 --------------------------------------------------------------
1106 Poly-line Poly-line in any dir Straight poly-lines
1107 --------------------------------------------------------------
1108 Ellipses Ellipses Circles
1109 --------------------------------------------------------------
1110 Text Text (see thru) Text (overwrite)
1111 --------------------------------------------------------------
1112 Spray-can Spray-can Set size for spray
1113 --------------------------------------------------------------
1114 Erase Erase character Erase rectangle
1115 --------------------------------------------------------------
1116 Vaporize Erase single line Erase connected
1117 lines
1118 --------------------------------------------------------------
1119 Cut Cut rectangle Cut square
1120 --------------------------------------------------------------
1121 Copy Copy rectangle Copy square
1122 --------------------------------------------------------------
1123 Paste Paste Paste
1124 --------------------------------------------------------------
1125 Flood-fill Flood-fill Flood-fill
1126 --------------------------------------------------------------
1128 * Straight lines can only go horizontally, vertically
1129 or diagonally.
1131 * Poly-lines are drawn while holding mouse-1 down. When you
1132 release the button, the point is set. If you want a segment
1133 to be straight, hold down shift before pressing the
1134 mouse-1 button. Click mouse-2 or mouse-3 to stop drawing
1135 poly-lines.
1137 * See thru for text means that text already in the buffer
1138 will be visible through blanks in the text rendered, while
1139 overwrite means the opposite.
1141 * Vaporizing connected lines only vaporizes lines whose
1142 _endpoints_ are connected. See also the variable
1143 `artist-vaporize-fuzziness'.
1145 * Cut copies, then clears the rectangle/square.
1147 * When drawing lines or poly-lines, you can set arrows.
1148 See below under ``Arrows'' for more info.
1150 * The mode line shows the currently selected drawing operation.
1151 In addition, if it has an asterisk (*) at the end, you
1152 are currently drawing something.
1154 * Be patient when flood-filling -- large areas take quite
1155 some time to fill.
1158 mouse-3 Erases character under pointer
1159 shift mouse-3 Erases rectangle
1162 Settings
1164 Set fill Sets the character used when filling rectangles/squares
1166 Set line Sets the character used when drawing lines
1168 Erase char Sets the character used when erasing
1170 Rubber-banding Toggles rubber-banding
1172 Trimming Toggles trimming of line-endings (that is: when the shape
1173 is drawn, extraneous white-space at end of lines is removed)
1175 Borders Toggles the drawing of line borders around filled shapes.
1178 Drawing with keys
1180 \\[artist-key-set-point] Does one of the following:
1181 For lines/rectangles/squares: sets the first/second endpoint
1182 For poly-lines: sets a point (use C-u \\[artist-key-set-point] to set last point)
1183 When erase characters: toggles erasing
1184 When cutting/copying: Sets first/last endpoint of rect/square
1185 When pasting: Pastes
1187 \\[artist-select-operation] Selects what to draw
1189 Move around with \\[artist-next-line], \\[artist-previous-line], \\[artist-forward-char] and \\[artist-backward-char].
1191 \\[artist-select-fill-char] Sets the charater to use when filling
1192 \\[artist-select-line-char] Sets the charater to use when drawing
1193 \\[artist-select-erase-char] Sets the charater to use when erasing
1194 \\[artist-toggle-rubber-banding] Toggles rubber-banding
1195 \\[artist-toggle-trim-line-endings] Toggles trimming of line-endings
1196 \\[artist-toggle-borderless-shapes] Toggles borders on drawn shapes
1199 Arrows
1201 \\[artist-toggle-first-arrow] Sets/unsets an arrow at the beginning
1202 of the line/poly-line
1204 \\[artist-toggle-second-arrow] Sets/unsets an arrow at the end
1205 of the line/poly-line
1208 Selecting operation
1210 There are some keys for quickly selecting drawing operations:
1212 \\[artist-select-op-line] Selects drawing lines
1213 \\[artist-select-op-straight-line] Selects drawing straight lines
1214 \\[artist-select-op-rectangle] Selects drawing rectangles
1215 \\[artist-select-op-square] Selects drawing squares
1216 \\[artist-select-op-poly-line] Selects drawing poly-lines
1217 \\[artist-select-op-straight-poly-line] Selects drawing straight poly-lines
1218 \\[artist-select-op-ellipse] Selects drawing ellipses
1219 \\[artist-select-op-circle] Selects drawing circles
1220 \\[artist-select-op-text-see-thru] Selects rendering text (see thru)
1221 \\[artist-select-op-text-overwrite] Selects rendering text (overwrite)
1222 \\[artist-select-op-spray-can] Spray with spray-can
1223 \\[artist-select-op-spray-set-size] Set size for the spray-can
1224 \\[artist-select-op-erase-char] Selects erasing characters
1225 \\[artist-select-op-erase-rectangle] Selects erasing rectangles
1226 \\[artist-select-op-vaporize-line] Selects vaporizing single lines
1227 \\[artist-select-op-vaporize-lines] Selects vaporizing connected lines
1228 \\[artist-select-op-cut-rectangle] Selects cutting rectangles
1229 \\[artist-select-op-copy-rectangle] Selects copying rectangles
1230 \\[artist-select-op-paste] Selects pasting
1231 \\[artist-select-op-flood-fill] Selects flood-filling
1234 Variables
1236 This is a brief overview of the different varaibles. For more info,
1237 see the documentation for the variables (type \\[describe-variable] <variable> RET).
1239 artist-rubber-banding Interactively do rubber-banding or not
1240 artist-first-char What to set at first/second point...
1241 artist-second-char ...when not rubber-banding
1242 artist-interface-with-rect If cut/copy/paste should interface with rect
1243 artist-arrows The arrows to use when drawing arrows
1244 artist-aspect-ratio Character height-to-width for squares
1245 artist-trim-line-endings Trimming of line endings
1246 artist-flood-fill-right-border Right border when flood-filling
1247 artist-flood-fill-show-incrementally Update display while filling
1248 artist-pointer-shape Pointer shape to use while drawing
1249 artist-ellipse-left-char Character to use for narrow ellipses
1250 artist-ellipse-right-char Character to use for narrow ellipses
1251 artist-borderless-shapes If shapes should have borders
1252 artist-picture-compatibility Whether or not to be picture mode compatible
1253 artist-vaporize-fuzziness Tolerance when recognizing lines
1254 artist-spray-interval Seconds between repeated sprayings
1255 artist-spray-radius Size of the spray-area
1256 artist-spray-chars The spray-``color''
1257 artist-spray-new-chars Initial spray-``color''
1259 Hooks
1261 When entering artist-mode, the hook `artist-mode-init-hook' is called.
1262 When quitting artist-mode, the hook `artist-mode-exit-hook' is called.
1265 Keymap summary
1267 \\{artist-mode-map}"
1268 (interactive)
1269 (if (setq artist-mode
1270 (if (null state) (not artist-mode)
1271 (> (prefix-numeric-value state) 0)))
1272 (artist-mode-init)
1273 (artist-mode-exit)))
1275 ;; insert our minor mode string
1276 (or (assq 'artist-mode minor-mode-alist)
1277 (setq minor-mode-alist
1278 (cons '(artist-mode artist-mode-name)
1279 minor-mode-alist)))
1281 ;; insert our minor mode keymap
1282 (or (assq 'artist-mode minor-mode-map-alist)
1283 (setq minor-mode-map-alist
1284 (cons (cons 'artist-mode artist-mode-map)
1285 minor-mode-map-alist)))
1289 (eval-when-compile
1290 ;; Variables that are made local in artist-mode-init
1291 (defvar artist-key-is-drawing nil)
1292 (defvar artist-key-endpoint1 nil)
1293 (defvar artist-key-poly-point-list nil)
1294 (defvar artist-key-shape nil)
1295 (defvar artist-key-draw-how nil)
1296 (defvar artist-popup-menu-table nil)
1297 (defvar artist-key-compl-table nil)
1298 (defvar artist-rb-save-data nil)
1299 (defvar artist-arrow-point-1 nil)
1300 (defvar artist-arrow-point-2 nil))
1303 ;; Init and exit
1304 (defun artist-mode-init ()
1305 "Init Artist mode. This will call the hook `artist-mode-init-hook'."
1306 (let ((i 0))
1307 (while (< i 256)
1308 (aset artist-replacement-table i i)
1309 (setq i (1+ i))))
1310 (aset artist-replacement-table ?\n ?\ )
1311 (aset artist-replacement-table ?\t ?\ )
1312 (aset artist-replacement-table 0 ?\ )
1313 (make-local-variable 'artist-key-is-drawing)
1314 (make-local-variable 'artist-key-endpoint1)
1315 (make-local-variable 'artist-key-poly-point-list)
1316 (make-local-variable 'artist-key-shape)
1317 (make-local-variable 'artist-key-draw-how)
1318 (make-local-variable 'artist-popup-menu-table)
1319 (make-local-variable 'artist-key-compl-table)
1320 (make-local-variable 'artist-rb-save-data)
1321 (make-local-variable 'artist-arrow-point-1)
1322 (make-local-variable 'artist-arrow-point-2)
1323 (setq artist-key-is-drawing nil)
1324 (setq artist-key-endpoint1 nil)
1325 (setq artist-key-poly-point-list nil)
1326 (setq artist-key-shape nil)
1327 (setq artist-popup-menu-table (artist-compute-popup-menu-table artist-mt))
1328 (setq artist-key-compl-table (artist-compute-key-compl-table artist-mt))
1329 (setq artist-rb-save-data (make-vector 7 0))
1330 (setq artist-arrow-point-1 nil)
1331 (setq artist-arrow-point-2 nil)
1332 (make-local-variable 'next-line-add-newlines)
1333 (setq next-line-add-newlines t)
1334 (setq artist-key-draw-how
1335 (artist-go-get-draw-how-from-symbol artist-curr-go))
1336 (if (and artist-picture-compatibility (not (eq major-mode 'picture-mode)))
1337 (progn
1338 (picture-mode)
1339 (message "")))
1340 (run-hooks 'artist-mode-init-hook)
1341 (artist-mode-line-show-curr-operation artist-key-is-drawing))
1343 (defun artist-mode-exit ()
1344 "Exit Artist mode. This will call the hook `artist-mode-exit-hook'."
1345 (if (and artist-picture-compatibility (eq major-mode 'picture-mode))
1346 (picture-mode-exit))
1347 (kill-local-variable 'next-line-add-newlines)
1348 (run-hooks 'artist-mode-exit-hook))
1350 (defun artist-mode-off ()
1351 "Turn Artist mode off."
1352 (interactive)
1353 (artist-mode -1)
1354 (force-mode-line-update))
1357 ;; General routines
1360 (defun artist-update-display ()
1361 "Repaint the display."
1362 (sit-for 0))
1364 (defun artist-mode-line-show-curr-operation (is-drawing)
1365 "Show current operation in mode-line. If IS-DRAWING, show that."
1366 (let ((mtext (concat artist-mode-name "/"
1367 (artist-go-get-mode-line-from-symbol artist-curr-go)
1368 (if is-drawing "/*" ""))))
1369 (setcdr (assq 'artist-mode minor-mode-alist) (list mtext)))
1370 (force-mode-line-update))
1373 (defun artist-t-if-fill-char-set ()
1374 "Return the value of the variable `artist-fill-char-set'."
1375 artist-fill-char-set)
1377 (defun artist-t ()
1378 "Always return t."
1381 (defun artist-nil ()
1382 "Always return nil."
1383 nil)
1385 (defun artist-arrows ()
1386 "Say yes to arrows!"
1389 (defun artist-no-arrows ()
1390 "Say no to arrows!"
1391 nil)
1394 ;; Auxiliary init-routines
1398 ; Computing the table for the x-popup-menu from the master table
1401 (defun artist-compute-popup-menu-table (menu-table)
1402 "Create a menu from from MENU-TABLE data.
1403 The returned value is suitable for the `x-popup-menu' function."
1404 (cons "Artist menu"
1405 (artist-compute-popup-menu-table-sub menu-table)))
1407 (defun artist-compute-popup-menu-table-sub (menu-table)
1408 "Compute operation table suitable for `x-popup-menu' from MENU-TABLE."
1409 (mapcar
1410 (lambda (element)
1411 (let ((element-tag (artist-mt-get-tag element)))
1412 (cond ((eq element-tag 'graphics-operation)
1413 (let* ((info-part (artist-mt-get-info-part element))
1414 (descr (artist-go-get-desc info-part))
1415 (unshifted (artist-go-get-unshifted info-part))
1416 (symbol (artist-go-get-symbol unshifted)))
1417 (list descr symbol)))
1419 ((eq element-tag 'function-call)
1420 (let* ((info-part (artist-mt-get-info-part element))
1421 (keyword (artist-fc-get-keyword info-part))
1422 (symbol (artist-fc-get-symbol info-part)))
1423 (list keyword symbol)))
1425 ((eq element-tag 'separator)
1426 '("" ""))
1428 ((eq element-tag 'menu)
1429 (let* ((info-part (artist-mt-get-info-part element))
1430 (title (artist-mn-get-title info-part))
1431 (items (artist-mn-get-items info-part)))
1432 (cons title (artist-compute-popup-menu-table-sub items))))
1435 (error "Internal error: unknown element-tag: \"%s\""
1436 element-tag)))))
1437 menu-table))
1440 ; Computing the completion table from the master table
1443 (defun artist-compute-key-compl-table (menu-table)
1444 "Compute completion table from MENU-TABLE, suitable for `completing-read'."
1445 (apply
1446 'nconc
1447 (artist-remove-nulls
1448 (mapcar
1449 (lambda (element)
1450 (let ((element-tag (artist-mt-get-tag element)))
1451 (cond ((eq element-tag 'graphics-operation)
1452 (let* ((info-part (artist-mt-get-info-part element))
1453 (unshifted (artist-go-get-unshifted info-part))
1454 (shifted (artist-go-get-shifted info-part))
1455 (unshifted-kwd (artist-go-get-keyword unshifted))
1456 (shifted-kwd (artist-go-get-keyword shifted)))
1457 (list (list unshifted-kwd) (list shifted-kwd))))
1458 ((eq element-tag 'menu)
1459 (let* ((info-part (artist-mt-get-info-part element))
1460 (items (artist-mn-get-items info-part)))
1461 (artist-compute-key-compl-table items)))
1463 nil))))
1464 menu-table))))
1468 ; Retrieving a symbol (graphics operation or function-call) from a keyword
1471 (defun artist-mt-get-symbol-from-keyword (kwd)
1472 "Search master table for keyword KWD and return its symbol."
1473 (artist-mt-get-symbol-from-keyword-sub artist-mt kwd))
1475 (defun artist-mt-get-symbol-from-keyword-sub (table kwd)
1476 "Search TABLE for keyword KWD and return its symbol."
1477 (catch 'found
1478 (mapcar
1479 (lambda (element)
1480 (let ((element-tag (artist-mt-get-tag element)))
1481 (cond ((eq element-tag 'graphics-operation)
1482 (let* ((info-part (artist-mt-get-info-part element))
1483 (unshifted (artist-go-get-unshifted info-part))
1484 (shifted (artist-go-get-shifted info-part))
1485 (unshifted-kwd (artist-go-get-keyword unshifted))
1486 (shifted-kwd (artist-go-get-keyword shifted))
1487 (unshifted-sym (artist-go-get-symbol unshifted))
1488 (shifted-sym (artist-go-get-symbol shifted)))
1489 (if (string-equal kwd unshifted-kwd)
1490 (throw 'found unshifted-sym))
1491 (if (string-equal kwd shifted-kwd)
1492 (throw 'found shifted-sym))))
1494 ((eq element-tag 'function-call)
1495 (let* ((info-part (artist-mt-get-info-part element))
1496 (keyword (artist-fc-get-keyword info-part))
1497 (symbol (artist-fc-get-symbol info-part)))
1498 (if (string-equal kwd keyword)
1499 (throw 'found symbol))))
1500 ((eq element-tag 'menu)
1501 (let* ((info-part (artist-mt-get-info-part element))
1502 (items (artist-mn-get-items info-part))
1503 (answer (artist-mt-get-symbol-from-keyword-sub
1504 items kwd)))
1505 (if answer (throw 'found answer))))
1507 nil))))
1508 table)
1509 nil))
1513 ; Retrieving info from a graphics operation symbol
1516 (defun artist-go-retrieve-from-symbol (symbol retrieve-fn)
1517 "Search the master table for a graphics operation SYMBOL.
1518 Calls RETRIEVE-FN to retrieve information from that symbol's
1519 info-variant-part."
1520 (artist-go-retrieve-from-symbol-sub artist-mt symbol retrieve-fn))
1522 (defun artist-go-retrieve-from-symbol-sub (table symbol retrieve-fn)
1523 "Search the TABLE for a graphics operation SYMBOL.
1524 Calls RETRIEVE-FN to retrieve information from that symbol's
1525 info-variant-part."
1526 (catch 'found
1527 (mapcar
1528 (lambda (element)
1529 (let ((element-tag (artist-mt-get-tag element)))
1530 (cond ((eq element-tag 'graphics-operation)
1531 (let* ((info-part (artist-mt-get-info-part element))
1532 (unshifted (artist-go-get-unshifted info-part))
1533 (shifted (artist-go-get-shifted info-part))
1534 (unshifted-sym (artist-go-get-symbol unshifted))
1535 (shifted-sym (artist-go-get-symbol shifted))
1536 (variant-part (cond
1537 ((eq unshifted-sym symbol) unshifted)
1538 ((eq shifted-sym symbol) shifted)
1539 (t nil))))
1540 (if variant-part ; if found do:
1541 (throw 'found (funcall retrieve-fn variant-part)))))
1543 ((eq element-tag 'menu)
1544 (let* ((info-part (artist-mt-get-info-part element))
1545 (items (artist-mn-get-items info-part))
1546 (answer (artist-go-retrieve-from-symbol-sub
1547 items symbol retrieve-fn)))
1548 (if answer (throw 'found answer)))))))
1550 table)
1551 nil))
1553 (defun artist-go-get-keyword-from-symbol (symbol)
1554 "Search the master table, get keyword from a graphics operation SYMBOL."
1555 (artist-go-retrieve-from-symbol symbol 'artist-go-get-keyword))
1557 (defun artist-go-get-mode-line-from-symbol (symbol)
1558 "Search the master table, get mode-line from a graphics operation SYMBOL."
1559 (artist-go-retrieve-from-symbol symbol 'artist-go-get-mode-line))
1561 (defun artist-go-get-arrow-pred-from-symbol (symbol)
1562 "Search the master table, get arrow-pred from a graphics operation SYMBOL."
1563 (artist-go-retrieve-from-symbol symbol 'artist-go-get-arrow-pred))
1565 (defun artist-go-get-arrow-set-fn-from-symbol (symbol)
1566 "Search the master table, get arrow-set-fn from a graphics operation SYMBOL."
1567 (artist-go-retrieve-from-symbol symbol 'artist-go-get-arrow-set-fn))
1569 (defun artist-go-get-init-fn-from-symbol (symbol)
1570 "Search the master table, get init-fn from a graphics operation SYMBOL."
1571 (artist-go-retrieve-from-symbol symbol 'artist-go-get-init-fn))
1573 (defun artist-go-get-prep-fill-fn-from-symbol (symbol)
1574 "Search the master table, get prep-fill-fn from a graphics operation SYMBOL."
1575 (artist-go-retrieve-from-symbol symbol 'artist-go-get-prep-fill-fn))
1577 (defun artist-go-get-exit-fn-from-symbol (symbol)
1578 "Search the master table, get exit-fn from a graphics operation SYMBOL."
1579 (artist-go-retrieve-from-symbol symbol 'artist-go-get-exit-fn))
1581 (defun artist-go-get-draw-fn-from-symbol (symbol)
1582 "Search the master table, get draw-fn from a graphics operation SYMBOL."
1583 (artist-go-retrieve-from-symbol symbol 'artist-go-get-draw-fn))
1585 (defun artist-go-get-draw-how-from-symbol (symbol)
1586 "Search the master table, get draw-how from a graphics operation SYMBOL."
1587 (artist-go-retrieve-from-symbol symbol 'artist-go-get-draw-how))
1589 (defun artist-go-get-undraw-fn-from-symbol (symbol)
1590 "Search the master table, get undraw-fn from a graphics operation SYMBOL."
1591 (artist-go-retrieve-from-symbol symbol 'artist-go-get-undraw-fn))
1593 (defun artist-go-get-interval-fn-from-symbol (symbol)
1594 "Search the master table, get interval-fn from a graphics operation SYMBOL."
1595 (artist-go-retrieve-from-symbol symbol 'artist-go-get-interval-fn))
1597 (defun artist-go-get-fill-pred-from-symbol (symbol)
1598 "Search the master table, get fill-pred from a graphics operation SYMBOL."
1599 (artist-go-retrieve-from-symbol symbol 'artist-go-get-fill-pred))
1601 (defun artist-go-get-fill-fn-from-symbol (symbol)
1602 "Search the master table, get fill-fn from a graphics operation SYMBOL."
1603 (artist-go-retrieve-from-symbol symbol 'artist-go-get-fill-fn))
1605 (defun artist-go-get-symbol-shift (symbol is-shifted)
1606 "Search for (shifted or unshifted) graphics operation SYMBOL.
1607 If IS-SHIFTED is non-nil, return the shifted symbol,
1608 otherwise the shifted symbol."
1609 (artist-go-get-symbol-shift-sub artist-mt symbol is-shifted))
1611 (defun artist-go-get-symbol-shift-sub (table symbol is-shifted)
1612 "Search TABLE for (shifted or unshifted) graphics SYMBOL.
1613 If IS-SHIFTED is non-nil, return the shifted symbol,
1614 otherwise the shifted symbol."
1615 (catch 'found
1616 (mapcar
1617 (lambda (element)
1618 (let ((element-tag (artist-mt-get-tag element)))
1619 (cond ((eq element-tag 'graphics-operation)
1620 (let* ((info-part (artist-mt-get-info-part element))
1621 (unshift-variant (artist-go-get-unshifted info-part))
1622 (shift-variant (artist-go-get-shifted info-part))
1623 (unshift-sym (artist-go-get-symbol unshift-variant))
1624 (shift-sym (artist-go-get-symbol shift-variant)))
1625 (if (or (eq symbol unshift-sym) (eq symbol shift-sym))
1626 (throw 'found (if is-shifted shift-sym unshift-sym)))))
1628 ((eq element-tag 'menu)
1629 (let* ((info-part (artist-mt-get-info-part element))
1630 (items (artist-mn-get-items info-part))
1631 (answer (artist-go-get-symbol-shift-sub
1632 items symbol is-shifted)))
1633 (if answer (throw 'found answer)))))))
1635 table)
1636 nil))
1639 ; Retrieving info from a function-call symbol
1642 (defun artist-fc-retrieve-from-symbol (symbol retrieve-fn)
1643 "Search the master table for a function call SYMBOL.
1644 Calls RETRIEVE-FN to retrieve information from that symbol's
1645 info-variant-part."
1646 (artist-fc-retrieve-from-symbol-sub artist-mt symbol retrieve-fn))
1648 (defun artist-fc-retrieve-from-symbol-sub (table symbol retrieve-fn)
1649 "Search TABLE for a function-call SYMBOL.
1650 Calls RETRIEVE-FN to retrieve information from that symbol's
1651 info-variant-part."
1652 (catch 'found
1653 (mapcar
1654 (lambda (element)
1655 (let ((element-tag (artist-mt-get-tag element)))
1656 (cond ((eq element-tag 'function-call)
1657 (let* ((info-part (artist-mt-get-info-part element))
1658 (fc-symbol (artist-fc-get-symbol info-part)))
1659 (if (eq fc-symbol symbol)
1660 (throw 'found (funcall retrieve-fn info-part)))))
1662 ((eq element-tag 'menu)
1663 (let* ((info-part (artist-mt-get-info-part element))
1664 (items (artist-mn-get-items info-part))
1665 (answer (artist-fc-retrieve-from-symbol-sub
1666 items symbol retrieve-fn)))
1667 (if answer (throw 'found answer)))))))
1669 table)
1670 nil))
1672 (defun artist-fc-get-fn-from-symbol (symbol)
1673 "Search the master table to get function from a function call SYMBOL."
1674 (artist-fc-retrieve-from-symbol symbol 'artist-fc-get-fn))
1678 ;; Utilities
1681 ;; Macro that won't funcall the function if it is nil.
1683 (defmacro artist-funcall (fn &rest args)
1684 "Call function FN with ARGS iff FN is not nil."
1685 (list 'if fn (cons 'funcall (cons fn args))))
1687 (defvar artist-butlast-fn 'artist-butlast
1688 "The butlast function.")
1690 (if (fboundp 'butlast)
1691 (setq artist-butlast-fn 'butlast)
1692 (setq artist-butlast-fn 'artist-butlast))
1694 (defun artist-butlast (l)
1695 "Return the list L with all elements but the last."
1696 (cond ((null l) nil)
1697 ((null (cdr l)) nil)
1698 (t (cons (car l) (artist-butlast (cdr l))))))
1701 (defun artist-last (l &optional n)
1702 "Return the last link in the list L.
1703 With optional argument N, returns Nth-to-last link (default 1)."
1704 (nth (- (length l) (or n 1)) l))
1706 (defun artist-remove-nulls (l)
1707 "Remove nils in list L."
1708 (remq nil l))
1710 (defun artist-uniq (l)
1711 "Remove consecutive duplicates in list L. Comparison is done with `equal'."
1712 (cond ((null l) nil)
1713 ((null (cdr l)) l) ; only one element in list
1714 ((equal (car l) (car (cdr l))) (artist-uniq (cdr l))) ; first 2 equal
1715 (t (cons (car l) (artist-uniq (cdr l)))))) ; first 2 are different
1717 (defmacro artist-push (x stack)
1718 "Push element X to a STACK."
1719 (list 'setq stack (list 'cons x stack)))
1721 (defmacro artist-pop (stack)
1722 "Pop an element from a STACK."
1723 (list 'prog1
1724 (list 'car stack)
1725 (list 'setq stack (list 'cdr stack))))
1727 (defun artist-string-split (str r)
1728 "Split string STR at occurrences of regexp R, returning a list of strings."
1729 (let ((res nil)
1730 (start 0)
1731 (match-pos 0))
1732 (while (setq match-pos (string-match r str start))
1733 (setq res (cons (copy-sequence (substring str start match-pos)) res))
1734 (setq start (match-end 0)))
1735 (if (null res)
1736 (list str)
1737 (if (< (match-end 0) (- (length str) 1))
1738 (setq res (cons (substring str (match-end 0) (length str)) res)))
1739 (reverse res))))
1741 (defun artist-string-to-file (str file-name)
1742 "Write string STR to file FILE-NAME."
1743 (write-region str 'end-is-ignored file-name nil 'no-message))
1745 (defun artist-file-to-string (file-name)
1746 "Read from file FILE-NAME into a string."
1747 (save-excursion
1748 (let ((tmp-buffer (get-buffer-create (concat "*artist-" file-name "*"))))
1749 (set-buffer tmp-buffer)
1750 (goto-char (point-min))
1751 (insert-file-contents file-name nil nil nil t)
1752 (let ((str (copy-sequence (buffer-substring (point-min)
1753 (point-max)))))
1754 (kill-buffer tmp-buffer)
1755 str))))
1757 (defun artist-clear-buffer (buf)
1758 "Clear contents of buffer BUF."
1759 (save-excursion
1760 (set-buffer buf)
1761 (goto-char (point-min))
1762 (delete-char (- (point-max) (point-min)) nil)))
1765 (defun artist-system (program stdin &optional program-args)
1766 "Run PROGRAM synchronously with the contents of string STDIN to stdin.
1767 Optional args PROGRAM-ARGS are arguments to PROGRAM.
1768 Return a list (RETURN-CODE STDOUT STDERR)."
1769 (save-excursion
1770 (let* ((tmp-stdin-file-name (if stdin
1771 (make-temp-file
1772 (concat (file-name-as-directory
1773 (or (getenv "TMPDIR") "/tmp"))
1774 "artist-stdin."))
1775 nil))
1776 (tmp-stdout-buffer (get-buffer-create
1777 (concat "*artist-" program "*")))
1778 (tmp-stderr-file-name (make-temp-file
1779 (concat (file-name-as-directory
1780 (or (getenv "TMPDIR") "/tmp"))
1781 "artist-stdout.")))
1782 (binary-process-input nil) ; for msdos
1783 (binary-process-output nil))
1785 ;; Prepare stdin
1786 (if stdin (artist-string-to-file stdin tmp-stdin-file-name))
1788 ;; Clear the buffer
1789 (artist-clear-buffer tmp-stdout-buffer)
1791 ;; Start the program
1792 (unwind-protect
1793 (let ((res (if program-args
1794 (apply 'call-process
1795 program
1796 tmp-stdin-file-name
1797 (list tmp-stdout-buffer
1798 tmp-stderr-file-name)
1800 (if (stringp program-args)
1801 (list program-args)
1802 program-args))
1803 (apply 'call-process
1804 program
1805 tmp-stdin-file-name
1806 (list tmp-stdout-buffer
1807 tmp-stderr-file-name)
1808 nil))))
1810 ;; the return value
1811 (list res
1812 (save-excursion
1813 (set-buffer tmp-stdout-buffer)
1814 (copy-sequence (buffer-substring (point-min)
1815 (point-max))))
1816 (artist-file-to-string tmp-stderr-file-name)))
1818 ;; Unwind: remove temporary files and buffers
1819 (if (and stdin (file-exists-p tmp-stdin-file-name))
1820 (delete-file tmp-stdin-file-name))
1821 (if (file-exists-p tmp-stderr-file-name)
1822 (delete-file tmp-stderr-file-name))
1823 (if (memq tmp-stdout-buffer (buffer-list))
1824 (kill-buffer tmp-stdout-buffer))))))
1826 ;; Routines that deal with the buffer
1828 ;; artist-current-line get line number (top of buffer is 0)
1830 ;; artist-move-to-xy move to (x,y) (0,0) is beg-of-buffer
1832 ;; artist-get-char-at-xy get char in at (x,y)
1834 ;; artist-replace-char overwrite (replace) char at point
1835 ;; artist-replace-chars overwrite (replace) chars at point
1838 (defsubst artist-current-column ()
1839 "Return point's current column."
1840 (current-column))
1842 (defsubst artist-current-line ()
1843 "Return point's current line, buffer-relative. Top of buffer is 0."
1844 (+ (count-lines 1 (point))
1845 (if (= (current-column) 0) 1 0)
1846 -1))
1848 (defsubst artist-move-to-xy (x y)
1849 "Move to column X, at row Y from the top of buffer. Top line is 0."
1851 ;; Q: Why do we do forward-line twice?
1852 ;; A: The documentation for forward-line says
1854 ;; "... Returns the count of lines left to move. ... With
1855 ;; positive N, a non-empty line at the end counts as one
1856 ;; line successfully moved (for the return value)."
1858 ;; This means that if we are trying to move forward past the end
1859 ;; of the buffer, and that last line happened to be longer than
1860 ;; the current column, then we end up at the end of that last
1861 ;; line, and forward-line returns one less than we actually
1862 ;; wanted to move.
1864 ;; Example: In the figure below, the `X' is the very last
1865 ;; character in the buffer ("a non-empty line at the
1866 ;; end"). Suppose point is at at P. Then (forward-line 1)
1867 ;; returns 0 and puts point after the `X'.
1869 ;; --------top of buffer--------
1871 ;; P X
1872 ;; -------bottom of buffer------
1874 ;; But, if we are at the end of buffer when trying to move
1875 ;; forward, then forward-line will return the (for us) correct
1876 ;; value, which is good, because we will come to the end of the
1877 ;; buffer by the first forward-line. The second forward-line
1878 ;; will then get us where we really wanted to go.
1880 ;; If we are not moving past the end of the buffer, then the
1881 ;; second forward-line will return 0.
1883 ;; Q: What happens if we are moving upwards?
1884 ;; A: That will work good. insert-char won't insert a negative
1885 ;; number of chars, and forward-line will fail silently if we are
1886 ;; moving past the beginning of the buffer.
1888 (forward-line (- y (artist-current-line)))
1889 (insert-char ?\n (forward-line (- y (artist-current-line))))
1890 (move-to-column (max x 0) t)
1891 (let ((curr-y (artist-current-line)))
1892 (setq artist-draw-region-min-y (min curr-y artist-draw-region-min-y))
1893 (setq artist-draw-region-max-y (max curr-y artist-draw-region-max-y))))
1895 (defsubst artist-get-char-at-xy (x y)
1896 "Return the character found at column X, row Y.
1897 Also updates the variables `artist-draw-min-y' and `artist-draw-max-y'."
1898 (artist-move-to-xy x y)
1899 (let ((curr-y (artist-current-line)))
1900 (setq artist-draw-region-min-y (min curr-y artist-draw-region-min-y))
1901 (setq artist-draw-region-max-y (max curr-y artist-draw-region-max-y)))
1902 (following-char))
1905 (defun artist-get-char-at-xy-conv (x y)
1906 "Retrieve the character at X, Y, converting tabs and new-lines to spaces."
1907 (save-excursion
1908 (aref artist-replacement-table (artist-get-char-at-xy x y))))
1911 (defun artist-replace-char (new-char)
1912 "Replace the character at point with NEW-CHAR."
1913 ;; Check that the variable exists first. The doc says it was added in 19.23.
1914 (if (and (and (boundp 'emacs-major-version) (= emacs-major-version 20))
1915 (and (boundp 'emacs-minor-version) (<= emacs-minor-version 3)))
1916 ;; This is a bug workaround for Emacs 20, versions up to 20.3:
1917 ;; The self-insert-command doesn't care about the overwrite-mode,
1918 ;; so the insertion is done in the same way as in picture mode.
1919 ;; This seems to be a little bit slower.
1920 (progn
1921 (artist-move-to-xy (1+ (artist-current-column))
1922 (artist-current-line))
1923 (delete-char -1)
1924 (insert (aref artist-replacement-table new-char)))
1925 ;; In emacs-19, the self-insert-command works better and faster
1926 (let ((overwrite-mode 'overwrite-mode-textual)
1927 (fill-column 32765) ; Large :-)
1928 (blink-matching-paren nil))
1929 (setq last-command-event (aref artist-replacement-table new-char))
1930 (self-insert-command 1))))
1932 (defun artist-replace-chars (new-char count)
1933 "Replace characters at point with NEW-CHAR. COUNT chars are replaced."
1934 ;; Check that the variable exists first. The doc says it was added in 19.23.
1935 (if (and (and (boundp 'emacs-major-version) (= emacs-major-version 20))
1936 (and (boundp 'emacs-minor-version) (<= emacs-minor-version 3)))
1937 ;; This is a bug workaround for Emacs 20, versions up to 20.3:
1938 ;; The self-insert-command doesn't care about the overwrite-mode,
1939 ;; so the insertion is done in the same way as in picture mode.
1940 ;; This seems to be a little bit slower.
1941 (let* ((replaced-c (aref artist-replacement-table new-char))
1942 (replaced-s (make-string count replaced-c)))
1943 (artist-move-to-xy (+ (artist-current-column) count)
1944 (artist-current-line))
1945 (delete-char (- count))
1946 (insert replaced-s))
1947 ;; In emacs-19, the self-insert-command works better
1948 (let ((overwrite-mode 'overwrite-mode-textual)
1949 (fill-column 32765) ; Large :-)
1950 (blink-matching-paren nil))
1951 (setq last-command-event (aref artist-replacement-table new-char))
1952 (self-insert-command count))))
1954 (defsubst artist-replace-string (string &optional see-thru)
1955 "Replace contents at point with STRING.
1956 With optional argument SEE-THRU, set to non-nil, text in the buffer
1957 ``shines thru'' blanks in the STRING."
1958 (let ((char-list (append string nil)) ; convert the string to a list
1959 (overwrite-mode 'overwrite-mode-textual)
1960 (fill-column 32765) ; Large :-)
1961 (blink-matching-paren nil))
1962 (while char-list
1963 (let ((c (car char-list)))
1964 (if (and see-thru (= (aref artist-replacement-table c) ?\ ))
1965 (artist-move-to-xy (1+ (artist-current-column))
1966 (artist-current-line))
1967 (artist-replace-char c)))
1968 (setq char-list (cdr char-list)))))
1971 ;; Routines for setting and unsetting points
1972 ;; Used when not rubber-banding
1974 (defun artist-no-rb-unset-point1 ()
1975 "Unsets point 1 when not rubber-banding."
1976 (let ((x-now (artist-current-column))
1977 (y-now (artist-current-line))
1978 (x (aref artist-rb-save-data 0))
1979 (y (aref artist-rb-save-data 1)))
1980 (artist-move-to-xy x y)
1981 (artist-replace-char (aref artist-rb-save-data 2))
1982 (artist-move-to-xy x-now y-now)))
1984 (defun artist-no-rb-set-point1 (x y)
1985 "Set point 1 at X, Y when not rubber-banding."
1986 (let ((x-now (artist-current-column))
1987 (y-now (artist-current-line)))
1988 (aset artist-rb-save-data 0 x)
1989 (aset artist-rb-save-data 1 y)
1990 (aset artist-rb-save-data 2 (artist-get-char-at-xy x y))
1991 (artist-move-to-xy x y)
1992 (artist-replace-char artist-first-char)
1993 (artist-move-to-xy x-now y-now)
1994 (aset artist-rb-save-data 6 0)))
1996 (defun artist-no-rb-unset-point2 ()
1997 "This function unsets point 2 when not rubber-banding."
1998 (if (= (aref artist-rb-save-data 6) 1)
1999 (let ((x-now (artist-current-column))
2000 (y-now (artist-current-line))
2001 (x (aref artist-rb-save-data 3))
2002 (y (aref artist-rb-save-data 4)))
2003 (artist-move-to-xy x y)
2004 (artist-replace-char (aref artist-rb-save-data 5))
2005 (artist-move-to-xy x-now y-now))))
2007 (defun artist-no-rb-set-point2 (x y)
2008 "Set point 2 at X, Y when not rubber-banding."
2009 (let ((x-now (artist-current-column))
2010 (y-now (artist-current-line)))
2011 (aset artist-rb-save-data 3 x)
2012 (aset artist-rb-save-data 4 y)
2013 (aset artist-rb-save-data 5 (artist-get-char-at-xy x y))
2014 (artist-move-to-xy x y)
2015 (artist-replace-char artist-second-char)
2016 (artist-move-to-xy x-now y-now)
2017 (aset artist-rb-save-data 6 1)))
2019 (defun artist-no-rb-unset-points ()
2020 "This function unsets point 1 and 2 when not rubber-banding."
2021 (artist-no-rb-unset-point1)
2022 (artist-no-rb-unset-point2))
2025 ;; artist-intersection-char
2027 ;; Note: If changing this, see the notes for artist-unintersection-char
2028 ;; and artist-vaporize-lines
2030 (defun artist-intersection-char (new-c old-c)
2031 "Calculates intersection character when drawing a NEW-C on top of an OLD-C.
2032 Return character according to this scheme:
2034 OLD-C NEW-C return
2035 - | +
2036 | - +
2037 + | +
2038 + - +
2039 \\ / X
2040 / \\ X
2041 X / X
2042 X \\ X
2043 other combinations NEW-C"
2045 (cond ((and (= old-c ?- ) (= new-c ?| )) ?+ )
2046 ((and (= old-c ?| ) (= new-c ?- )) ?+ )
2047 ((and (= old-c ?+ ) (= new-c ?- )) ?+ )
2048 ((and (= old-c ?+ ) (= new-c ?| )) ?+ )
2049 ((and (= old-c ?\\ ) (= new-c ?/ )) ?X )
2050 ((and (= old-c ?/ ) (= new-c ?\\ )) ?X )
2051 ((and (= old-c ?X ) (= new-c ?/ )) ?X )
2052 ((and (= old-c ?X ) (= new-c ?\\ )) ?X )
2053 (t new-c)))
2055 ;; artist-unintersection-char
2057 ;; Note: If changing this, see the note for artist-vaporize-lines
2059 (defun artist-unintersection-char (line-c buffer-c)
2060 "Restore character to before intersection when removing LINE-C from BUFFER-C.
2061 Return character according to this scheme:
2063 LINE-C BUFFER-C return
2064 - + |
2065 | + -
2066 \\ X /
2067 / X \\
2068 other combinations `artist-erase-char'."
2070 (cond ((and (= line-c ?- ) (= buffer-c ?+ )) ?| )
2071 ((and (= line-c ?| ) (= buffer-c ?+ )) ?- )
2072 ((and (= line-c ?\\ ) (= buffer-c ?X )) ?/ )
2073 ((and (= line-c ?/ ) (= buffer-c ?X )) ?\\ )
2074 ((= line-c buffer-c) artist-erase-char)
2075 (t buffer-c)))
2078 ;; Computing the line-char to use
2079 ;; for use with borderless shapes
2081 (defsubst artist-compute-line-char ()
2082 "Compute which character to use for lines, if any.
2083 Return value is either nil for the default characters that make up lines, or
2084 a character chosen depending on the variables `artist-borderless-shapes',
2085 `artist-fill-char-set', `artist-fill-char' and
2086 `artist-line-char-set' and `artist-line-char'."
2087 (if (and artist-borderless-shapes artist-fill-char-set)
2088 artist-fill-char
2089 (if artist-line-char-set
2090 artist-line-char
2091 nil)))
2094 ;; Things for drawing horizontal, vertical and diagonal (straight) lines.
2096 ;; A line here is a vector:
2097 ;; [ start-x start-y length direction saved-char-1 saved-char-2 ... ]
2098 ;; directions start with 0 at the x-axis and counts anti clockwise.
2100 (defvar artist-direction-info
2101 ;; x y char
2102 [ [ 1 0 ?- ] ; direction 0
2103 [ 1 1 ?\\ ] ; direction 1
2104 [ 0 1 ?| ] ; direction 2
2105 [ -1 1 ?/ ] ; direction 3
2106 [ -1 0 ?- ] ; direction 4
2107 [ -1 -1 ?\\ ] ; direction 5
2108 [ 0 -1 ?| ] ; direction 6
2109 [ 1 -1 ?/ ] ] ; direction 7
2110 "Table used for stepping x and y coordinates in a specific direction.
2111 This table is also used for determining which char to use for that direction.")
2113 (defsubst artist-direction-step-x (direction)
2114 "Return the x-step for DIRECTION from the `artist-direction-info' table."
2115 (aref (aref artist-direction-info direction) 0))
2117 (defsubst artist-direction-step-y (direction)
2118 "Return the y-step for DIRECTION from the `artist-direction-info' table."
2119 (aref (aref artist-direction-info direction) 1))
2121 (defun artist-direction-char (direction)
2122 "Return the character for DIRECTION from the `artist-direction-info' table."
2123 (aref (aref artist-direction-info direction) 2))
2125 ;; artist-find-direction
2129 (defun artist-find-direction (x1 y1 x2 y2)
2130 "Find the direction from point X1,Y1 to X2,Y2.
2131 Returns a DIRECTION, a number 0--7, coded as follows:
2133 5 6 7
2134 \\ | /
2135 4 - * - 0
2136 / | \\
2137 3 2 1"
2138 (let ((delta-x (- x2 x1))
2139 (delta-y (- y2 y1)))
2140 (cond ((>= delta-x (* 2 (abs delta-y))) 0)
2141 ((>= delta-y (* 2 (abs delta-x))) 2)
2142 ((>= (- delta-x) (* 2 (abs delta-y))) 4)
2143 ((>= (- delta-y) (* 2 (abs delta-x))) 6)
2144 ((and (>= delta-x 0) (>= delta-y 0)) 1)
2145 ((and (<= delta-x 0) (>= delta-y 0)) 3)
2146 ((and (<= delta-x 0) (<= delta-y 0)) 5)
2147 ((and (>= delta-x 0) (<= delta-y 0)) 7))))
2149 (defun artist-straight-calculate-length (direction x1 y1 x2 y2)
2150 "Calculate length for a straight line in DIRECTION from X1,Y1 to X2,Y2."
2151 (cond ((or (= direction 7)
2152 (= direction 0)
2153 (= direction 1)) (1+ (- x2 x1)))
2154 ((or (= direction 3)
2155 (= direction 4)
2156 (= direction 5)) (1+ (- x1 x2)))
2157 (t (1+ (abs (- y2 y1))))))
2159 (defun artist-sline (x1 y1 x2 y2)
2160 "Create a straight line from X1,Y1 to X2,Y2."
2161 (let* ((direction (artist-find-direction x1 y1 x2 y2))
2162 (length (artist-straight-calculate-length direction x1 y1 x2 y2))
2163 (line (make-vector (+ length 4) x1)))
2164 ;; not needed:
2165 ;; (aset line 0 x1)
2166 ;; because we set all elements to x1
2167 (aset line 1 y1)
2168 (aset line 2 length)
2169 (aset line 3 direction)
2170 line))
2172 (defun artist-save-chars-under-sline (line)
2173 "Save characters under a LINE."
2174 (let ((x (aref line 0))
2175 (y (aref line 1))
2176 (length (+ (aref line 2) 4))
2177 (direction (aref line 3))
2178 (i 4))
2179 (while (< i length)
2180 (aset line i (artist-get-char-at-xy x y))
2181 (setq x (+ x (artist-direction-step-x direction)))
2182 (setq y (+ y (artist-direction-step-y direction)))
2183 (setq i (1+ i))))
2184 line)
2188 ;; Things for drawing lines in all directions.
2189 ;; The line drawing engine is the eight-point alrogithm.
2191 ;; A line is here a list of (x y saved-char new-char)s.
2193 (defvar artist-octant-info
2194 ;; Initial Step in Step in
2195 ;; coeffs x and y x and y
2196 ;; for if q >= 0 if g < 0
2197 ;; dfdx,dfdy
2198 [ [ 2 1 1 0 1 1 ] ; 1st octant
2199 [ 1 2 1 1 0 1 ] ; 2nd octant
2200 [ -1 2 0 1 -1 1 ] ; 3rd octant
2201 [ -2 1 -1 1 -1 0 ] ; 4th octant
2202 [ -2 -1 -1 0 -1 -1 ] ; 5th octant
2203 [ -1 -2 -1 -1 0 -1 ] ; 6th octant
2204 [ 1 -2 0 -1 1 -1 ] ; 7th octant
2205 [ 2 -1 1 -1 1 0 ] ] ; 8th octant
2206 "Table used by line drawing algorithm (eight point).")
2208 ;; Primitives for the artist-octant-info.
2209 ;; Decrease octant by 1 since elt counts from 0 and octant counts from 1.
2211 (defsubst artist-get-dfdx-init-coeff (octant)
2212 "Retrieve dfdx component for OCTANT."
2213 (aref (aref artist-octant-info (- octant 1)) 0))
2215 (defsubst artist-get-dfdy-init-coeff (octant)
2216 "Retrieve dfdy component for OCTANT."
2217 (aref (aref artist-octant-info (- octant 1)) 1))
2219 (defsubst artist-get-x-step-q>=0 (octant)
2220 "Retrieve x-step component for OCTANT when q >= 0."
2221 (aref (aref artist-octant-info (- octant 1)) 2))
2223 (defsubst artist-get-y-step-q>=0 (octant)
2224 "Retrieve y-step component for OCTANT when q >= 0."
2225 (aref (aref artist-octant-info (- octant 1)) 3))
2227 (defsubst artist-get-x-step-q<0 (octant)
2228 "Retrieve x-step component for OCTANT for q < 0."
2229 (aref (aref artist-octant-info (- octant 1)) 4))
2231 (defsubst artist-get-y-step-q<0 (octant)
2232 "Retrieve y-step component for OCTANT for q < 0."
2233 (aref (aref artist-octant-info (- octant 1)) 5))
2236 ;; Find octant from x1 y1 x2 y2 coordinates.
2238 (defun artist-find-octant (x1 y1 x2 y2)
2239 "Find octant for a line from X1,Y1 to X2,Y2.
2240 Octant are numbered 1--8, anti-clockwise as:
2242 \\3|2/
2243 4\\|/1
2244 ---+---
2245 5/|\\8
2246 /6|7\\"
2248 (if (<= x1 x2) ; quadrant 1 or 4
2249 (if (<= y1 y2) ; quadrant 1, octant 1 or 2
2250 (if (>= (- x2 x1) (- y2 y1))
2253 (if (>= (- x2 x1) (- (- y2 y1))) ; quadrant 4, octant 7 or 8
2256 (if (<= y1 y2) ; quadrant 2 or 3
2257 (if (>= (- (- x2 x1)) (- y2 y1)) ; quadrant 2, octant 3 or 4
2260 (if (>= (- (- x2 x1)) (- (- y2 y1))) ; quadrant 3, octant 5 or 6
2262 6))))
2264 ;; Some inline funtions for creating, setting and reading
2265 ;; members of a coordinate
2267 (defsubst artist-new-coord (x y &optional new-char)
2268 "Create a new coordinate at X,Y for use in a line.
2269 Optional argument NEW-CHAR can be used for setting the new-char component
2270 in the coord."
2271 (let ((coord (make-vector 4 x)))
2272 (aset coord 1 y)
2273 (aset coord 3 new-char)
2274 coord))
2276 (defsubst artist-coord-get-x (coord)
2277 "Retrieve the x component of a COORD."
2278 (aref coord 0))
2280 (defsubst artist-coord-get-y (coord)
2281 "Retrieve the y component of a COORD."
2282 (aref coord 1))
2284 (defsubst artist-coord-set-x (coord new-x)
2285 "Set the x component of a COORD to NEW-X."
2286 (aset coord 0 new-x)
2287 coord)
2289 (defsubst artist-coord-set-y (coord new-y)
2290 "Set the y component of a COORD to NEW-Y."
2291 (aset coord 1 new-y)
2292 coord)
2294 (defsubst artist-coord-get-saved-char (coord)
2295 "Retrieve the saved char component of a COORD."
2296 (aref coord 2))
2298 (defsubst artist-coord-get-new-char (coord)
2299 "Retrieve the new char component of a COORD."
2300 (aref coord 3))
2302 (defsubst artist-coord-add-saved-char (coord saved-char)
2303 "Set the saved char component of a COORD to SAVED-CHAR."
2304 (aset coord 2 saved-char)
2305 coord)
2307 (defsubst artist-coord-add-new-char (coord new-char)
2308 "Set the new char component of a COORD to NEW-CHAR."
2309 (aset coord 3 new-char)
2310 coord)
2312 (defsubst artist-coord-set-new-char (coord new-char)
2313 "Set the new char component of a COORD to NEW-CHAR."
2314 (aset coord 3 new-char)
2315 coord)
2318 ;; Pretend we are plotting a pixel. Instead we just list it
2320 (defmacro artist-put-pixel (point-list x y)
2321 "In POINT-LIST, store a ``pixel'' at coord X,Y."
2322 (list 'setq point-list
2323 (list 'append point-list (list 'list (list 'artist-new-coord x y)))))
2325 ;; Calculate list of points using eight point algorithm
2326 ;; return a list of coords
2328 (defun artist-eight-point (x1 y1 x2 y2)
2329 "Run the eight-point algorithm to get a list of coords from X1,Y1 to X2,Y2."
2330 (let* ((point-list nil)
2331 (octant (artist-find-octant x1 y1 x2 y2))
2332 (dfdx-coeff (artist-get-dfdx-init-coeff octant))
2333 (dfdy-coeff (artist-get-dfdy-init-coeff octant))
2334 (x-step-q>=0 (artist-get-x-step-q>=0 octant))
2335 (y-step-q>=0 (artist-get-y-step-q>=0 octant))
2336 (x-step-q<0 (artist-get-x-step-q<0 octant))
2337 (y-step-q<0 (artist-get-y-step-q<0 octant))
2338 (dfdx (- (- y2 y1)))
2339 (dfdy (- x2 x1))
2340 (x x1)
2341 (y y1)
2342 (f 0)
2343 (q (+ (* 2 f)
2344 (* dfdx-coeff dfdx)
2345 (* dfdy-coeff dfdy))))
2346 (artist-put-pixel point-list x y)
2347 (while (or (not (eq x x2)) (not (eq y y2)))
2348 (if (>= q 0)
2349 (progn
2350 (setq x (+ x x-step-q>=0))
2351 (setq y (+ y y-step-q>=0))
2352 (setq f (+ f (* x-step-q>=0 dfdx) (* y-step-q>=0 dfdy))))
2353 (progn
2354 (setq x (+ x x-step-q<0))
2355 (setq y (+ y y-step-q<0))
2356 (setq f (+ f (* x-step-q<0 dfdx) (* y-step-q<0 dfdy)))))
2357 (setq q (+ (* 2 f) (* dfdx-coeff dfdx) (* dfdy-coeff dfdy)))
2358 (artist-put-pixel point-list x y))
2359 point-list))
2361 ;; artist-save-chars-under-point-list
2362 ;; Remebers the chars that were there before we did draw the line.
2363 ;; Returns point-list.
2365 (defun artist-save-chars-under-point-list (point-list)
2366 "Save characters originally under POINT-LIST."
2367 (mapcar
2368 (lambda (coord)
2369 (artist-coord-add-saved-char
2370 coord
2371 (artist-get-char-at-xy (artist-coord-get-x coord)
2372 (artist-coord-get-y coord))))
2373 point-list))
2375 ;; artist-calculate-new-char, artist-calculate-new-chars
2376 ;; Calculates which char to insert depending on direction of point-list.
2378 ;; Depending on new-coord's position relative to last-coord one of the
2379 ;; following chars are returned: \ | / - o, as indicated by this:
2381 ;; \ | /
2382 ;; - o -
2383 ;; / | \
2385 ;; artist-calculate-new-char works on one coordinate, returns char.
2386 ;; artist-calculate-new-chars works on a point-list, returns point-list.
2388 (defun artist-calculate-new-char (last-coord new-coord)
2389 "Return a line-char to use when moving from LAST-COORD to NEW-COORD."
2390 (let ((last-x (artist-coord-get-x last-coord))
2391 (last-y (artist-coord-get-y last-coord))
2392 (new-x (artist-coord-get-x new-coord))
2393 (new-y (artist-coord-get-y new-coord)))
2394 (cond ((> new-x last-x) (cond ((< new-y last-y) ?/ )
2395 ((> new-y last-y) ?\\ )
2396 (t ?- )))
2397 ((< new-x last-x) (cond ((< new-y last-y) ?\\ )
2398 ((> new-y last-y) ?/ )
2399 (t ?- )))
2400 ((eq new-y last-y) ?o)
2401 (t ?| ))))
2403 (defun artist-calculate-new-chars (point-list)
2404 "Return a list of coords with line-chars calculated. Input: POINT-LIST."
2405 (if (null (cdr point-list))
2406 (list (artist-coord-add-new-char (car point-list) ?o ))
2407 (let ((last-coord (car point-list)))
2408 (cons (artist-coord-add-new-char
2409 (car point-list)
2410 (artist-calculate-new-char (car (cdr point-list))
2411 (car point-list)))
2412 (mapcar
2413 (lambda (this-coord)
2414 (prog1
2415 (artist-coord-add-new-char
2416 this-coord
2417 (artist-calculate-new-char last-coord this-coord))
2418 (setq last-coord this-coord)))
2419 (cdr point-list))))))
2421 ;; artist-modify-new-chars
2422 ;; Replaces some characters with some other characters.
2424 ;; artist-modify-new-chars works on a point-list, returns point-list.
2426 (defun artist-modify-new-chars (point-list)
2427 "Replace intersecting characters in POINT-LIST.
2428 This function returns a point-list."
2429 (mapcar
2430 (lambda (coord)
2431 (let* ((new-c (artist-coord-get-new-char coord))
2432 (saved-c (artist-coord-get-saved-char coord))
2433 (modified-c (artist-intersection-char new-c saved-c)))
2434 (artist-coord-set-new-char coord modified-c)))
2435 point-list))
2439 ;; functions for accessing endoints and elements in object requiring
2440 ;; 2 endpoints
2443 (defun artist-make-endpoint (x y)
2444 "Create an endpoint at X, Y."
2445 (let ((new-endpoint (make-vector 2 x)))
2446 (aset new-endpoint 1 y)
2447 new-endpoint))
2449 (defun artist-endpoint-get-x (endpoint)
2450 "Retrieve the x component of an ENDPOINT."
2451 (aref endpoint 0))
2453 (defun artist-endpoint-get-y (endpoint)
2454 "Retrieve the y component of an ENDPOINT."
2455 (aref endpoint 1))
2457 (defun artist-make-2point-object (endpoint1 endpoint2 shapeinfo)
2458 "Create a 2-point object of ENDPOINT1, ENDPOINT2 and SHAPEINFO."
2459 (list endpoint1 endpoint2 shapeinfo))
2461 (defun artist-2point-get-endpoint1 (obj)
2462 "Retrieve the first endpoint of a 2-point object OBJ."
2463 (elt obj 0))
2465 (defun artist-2point-get-endpoint2 (obj)
2466 "Retrieve the second endpoint of a 2-point object OBJ."
2467 (elt obj 1))
2469 (defun artist-2point-get-shapeinfo (obj)
2470 "Retrieve the shapeinfo component of a 2-point object OBJ."
2471 (elt obj 2))
2475 ;; Drawing and undrawing lines (any direction)
2478 (defun artist-draw-line (x1 y1 x2 y2)
2479 "Draws a line from X1, Y1 to X2, Y2.
2481 Output is a line, which is a list (END-POINT-1 END-POINT-2 SHAPE-INFO).
2483 END-POINT-1 and END-POINT-2 are two-element vectors on the form [X Y].
2484 SHAPE-INFO is a list of vectors [X Y SAVED-CHAR NEW-CHAR]."
2485 (let ((endpoint1 (artist-make-endpoint x1 y1))
2486 (endpoint2 (artist-make-endpoint x2 y2)))
2487 (artist-make-2point-object
2488 endpoint1
2489 endpoint2
2490 (mapcar
2491 (lambda (coord)
2492 (artist-move-to-xy (artist-coord-get-x coord)
2493 (artist-coord-get-y coord))
2494 (if artist-line-char-set
2495 (artist-replace-char artist-line-char)
2496 (artist-replace-char (artist-coord-get-new-char coord)))
2497 coord)
2498 (artist-modify-new-chars
2499 (artist-calculate-new-chars
2500 (artist-save-chars-under-point-list
2501 (artist-eight-point x1 y1 x2 y2))))))))
2503 (defun artist-undraw-line (line)
2504 "Undraws LINE."
2505 (mapcar
2506 (lambda (coord)
2507 (artist-move-to-xy (artist-coord-get-x coord)
2508 (artist-coord-get-y coord))
2509 (artist-replace-char (artist-coord-get-saved-char coord))
2510 coord)
2511 (artist-2point-get-shapeinfo line)))
2514 ;; Drawing and undrawing straight lines
2517 (defun artist-draw-sline (x1 y1 x2 y2)
2518 "Draw a strait line from X1, Y1 to X2, Y2.
2519 Straight lines are vertical, horizontal or diagonal lines.
2520 They are faster to draw and most often they are what you need
2521 when drawing a simple image.
2523 Output is a straight line, which is a list on the form
2524 \(END-POINT-1 END-POINT-2 SHAPE-INFO).
2526 END-POINT-1 and END-POINT-2 are two-element vectors on the form [X Y].
2527 SHAPE-INFO is a vector [START-X START-Y LENGTH-OF-LINE DIRECTION
2528 ORIGINAL-CHAR-1 ORIGINAL-CHAR-2 ... ]."
2529 (let* ((line (artist-save-chars-under-sline (artist-sline x1 y1 x2 y2)))
2530 (x (aref line 0))
2531 (y (aref line 1))
2532 (length (+ (aref line 2) 4))
2533 (direction (aref line 3))
2534 (line-char (artist-direction-char direction))
2535 (i 4)
2536 (endpoint1 (artist-make-endpoint x y))
2537 (endpoint2 nil))
2538 (while (< i length)
2539 (artist-move-to-xy x y)
2540 (if artist-line-char-set
2541 (artist-replace-char artist-line-char)
2542 (artist-replace-char (artist-intersection-char
2543 line-char
2544 (aref line i))))
2545 (if (not (< (1+ i) length))
2546 ;; This is the last element. Set the second endpoint
2547 (setq endpoint2 (artist-make-endpoint x y)))
2548 (setq x (+ x (artist-direction-step-x direction)))
2549 (setq y (+ y (artist-direction-step-y direction)))
2550 (setq i (1+ i)))
2551 (artist-make-2point-object endpoint1 endpoint2 line)))
2554 (defun artist-undraw-sline (line)
2555 "Undraw a straight line LINE."
2556 (if line
2557 (let* ((shape-info (artist-2point-get-shapeinfo line))
2558 (x (aref shape-info 0))
2559 (y (aref shape-info 1))
2560 (length (+ (aref shape-info 2) 4))
2561 (direction (aref shape-info 3))
2562 (i 4))
2563 (while (< i length)
2564 (artist-move-to-xy x y)
2565 (artist-replace-char (aref shape-info i))
2566 (setq x (+ x (artist-direction-step-x direction)))
2567 (setq y (+ y (artist-direction-step-y direction)))
2568 (setq i (1+ i))))))
2572 ;; Drawing and undrawing rectangles and squares
2575 (defun artist-draw-rect (x1 y1 x2 y2)
2576 "Draws a rectangle with corners at X1, Y1 and X2, Y2.
2578 Output is a rectangle, which is a list on the form
2579 \(END-POINT-1 END-POINT-2 SHAPE-INFO).
2581 END-POINT-1 and END-POINT-2 are two-element vectors on the form [X Y].
2582 SHAPE-INFO is a list of four straight lines."
2583 (let* ((artist-line-char (artist-compute-line-char))
2584 (artist-line-char-set artist-line-char)
2585 (line1 (artist-draw-sline x1 y1 x2 y1))
2586 (line2 (artist-draw-sline x2 y1 x2 y2))
2587 (line3 (artist-draw-sline x2 y2 x1 y2))
2588 (line4 (artist-draw-sline x1 y2 x1 y1))
2589 (endpoint1 (artist-make-endpoint x1 y1))
2590 (endpoint2 (artist-make-endpoint x2 y2)))
2591 (artist-make-2point-object endpoint1
2592 endpoint2
2593 (list line1 line2 line3 line4))))
2595 (defun artist-undraw-rect (rectangle)
2596 "Undraws RECTANGLE."
2597 (if rectangle
2598 (let ((shape-info (artist-2point-get-shapeinfo rectangle)))
2599 (artist-undraw-sline (elt shape-info 3))
2600 (artist-undraw-sline (elt shape-info 2))
2601 (artist-undraw-sline (elt shape-info 1))
2602 (artist-undraw-sline (elt shape-info 0)))))
2605 (defun artist-rect-corners-squarify (x1 y1 x2 y2)
2606 "Compute square corners from rectangle corners at X1, Y1 and X2, Y2.
2607 The square's first corner will be X1, Y1. The position of the second corner
2608 depends on which of X2 and Y2 is most far away from X1, Y1."
2609 (let* ((delta-x (- x2 x1))
2610 (delta-y (- y2 y1))
2611 (delta-x-sign (if (< delta-x 0) -1 1))
2612 (delta-y-sign (if (< delta-y 0) -1 1))
2613 (new-x2) ; set below
2614 (new-y2)) ; set below
2616 ;; Check which of x2 and y2 is most distant
2617 ;; take care to the aspect ratio
2618 (if (> (abs delta-x) (abs delta-y))
2620 ;; *** x2 more distant than y2 (with care taken to aspect ratio)
2621 (progn
2622 (setq new-x2 x2)
2623 (setq new-y2 (+ y1 (round (/ (* (abs delta-x) delta-y-sign)
2624 artist-aspect-ratio)))))
2626 ;; *** y2 more distant than x2 (with care taken to aspect ratio)
2627 (progn
2628 (setq new-x2 (round (+ x1 (* (* (abs delta-y) delta-x-sign)
2629 artist-aspect-ratio))))
2630 (setq new-y2 y2)))
2632 ;; Return this
2633 (list x1 y1 new-x2 new-y2)))
2636 (defun artist-draw-square (x1 y1 x2 y2)
2637 "Draw a square with corners at X1, Y1 and X2, Y2.
2639 Output is a square, which is a list on the form
2640 \(END-POINT-1 END-POINT-2 SHAPE-INFO).
2642 END-POINT-1 and END-POINT-2 are two-element vectors on the form [X Y].
2643 SHAPE-INFO is a list of four straight lines."
2644 (let* ((artist-line-char (artist-compute-line-char))
2645 (artist-line-char-set artist-line-char)
2646 (square-corners (artist-rect-corners-squarify x1 y1 x2 y2))
2647 (new-x1 (elt square-corners 0))
2648 (new-y1 (elt square-corners 1))
2649 (new-x2 (elt square-corners 2))
2650 (new-y2 (elt square-corners 3))
2651 (endpoint1 (artist-make-endpoint new-x1 new-y1))
2652 (endpoint2 (artist-make-endpoint new-x2 new-y2))
2653 (line1 (artist-draw-sline new-x1 new-y1 new-x2 new-y1))
2654 (line2 (artist-draw-sline new-x2 new-y1 new-x2 new-y2))
2655 (line3 (artist-draw-sline new-x2 new-y2 new-x1 new-y2))
2656 (line4 (artist-draw-sline new-x1 new-y2 new-x1 new-y1)))
2657 (artist-make-2point-object endpoint1
2658 endpoint2
2659 (list line1 line2 line3 line4))))
2661 (defun artist-undraw-square (square)
2662 "Undraws SQUARE."
2663 (if square
2664 (let ((shape-info (artist-2point-get-shapeinfo square)))
2665 (artist-undraw-sline (elt shape-info 3))
2666 (artist-undraw-sline (elt shape-info 2))
2667 (artist-undraw-sline (elt shape-info 1))
2668 (artist-undraw-sline (elt shape-info 0)))))
2671 ;; Filling rectangles and squares
2674 (defun artist-fill-rect (rect x1 y1 x2 y2)
2675 "Fill rectangle RECT from X1,Y1 to X2,Y2."
2676 (let ((x (1+ (min x1 x2)))
2677 (y (1+ (min y1 y2)))
2678 (x-max (max x1 x2))
2679 (y-max (max y1 y2)))
2680 (let ((w (- x-max x)))
2681 (while (< y y-max)
2682 (artist-move-to-xy x y)
2683 (artist-replace-chars artist-fill-char w)
2684 (setq y (1+ y))))))
2686 (defun artist-fill-square (square x1 y1 x2 y2)
2687 "Fills a SQUARE from X1,Y1 to X2,Y2."
2688 (let* ((square-corners (artist-rect-corners-squarify x1 y1 x2 y2))
2689 (new-x1 (elt square-corners 0))
2690 (new-y1 (elt square-corners 1))
2691 (new-x2 (elt square-corners 2))
2692 (new-y2 (elt square-corners 3))
2693 (x (1+ (min new-x1 new-x2)))
2694 (y (1+ (min new-y1 new-y2)))
2695 (x-max (max new-x1 new-x2))
2696 (y-max (max new-y1 new-y2))
2697 (w (- x-max x)))
2698 (while (< y y-max)
2699 (artist-move-to-xy x y)
2700 (artist-replace-chars artist-fill-char w)
2701 (setq y (1+ y)))))
2705 ;; Pen drawing
2708 (defun artist-pen (x1 y1)
2709 "Draws a character at X1, Y1.
2710 The character is replaced with the character in `artist-fill-char'."
2711 (artist-move-to-xy x1 y1)
2712 (artist-replace-char (if artist-line-char-set
2713 artist-line-char
2714 (if artist-fill-char-set
2715 artist-fill-char
2716 artist-default-fill-char))))
2719 (defun artist-pen-line (x1 y1)
2720 "Draws a line from last pen position to X1, Y1.
2721 The character is replaced with the character in `artist-fill-char'.
2722 This will store all points in `artist-key-poly-point-list' in reversed
2723 order (I assume it is faster to cons to the beginning of the list than
2724 to append to the end of the list, when doing free-hand drawing)."
2725 (let ((artist-line-char (if artist-line-char-set
2726 artist-line-char
2727 (if artist-fill-char-set
2728 artist-fill-char
2729 artist-default-fill-char))))
2731 ;; Draw line from last point to this
2732 (let ((x-last (car (car artist-key-poly-point-list)))
2733 (y-last (cdr (car artist-key-poly-point-list))))
2734 (artist-move-to-xy x-last y-last)
2735 (artist-replace-char artist-line-char)
2736 (artist-draw-line x-last y-last x1 y1))
2738 ;; Update the point-list
2739 (setq artist-key-poly-point-list
2740 (cons (cons x1 y1) artist-key-poly-point-list))))
2742 (defun artist-pen-reset-last-xy (x1 y1)
2743 "Reset the last x and y points to X1, Y1 when doing pen-drawing."
2744 (artist-clear-arrow-points)
2745 (setq artist-key-poly-point-list (list (cons x1 y1))))
2748 (defun artist-pen-set-arrow-points (x1 y1)
2749 "Set arrow points for pen drawing using X1, Y1.
2750 Also, the `artist-key-poly-point-list' is reversed."
2752 (setq artist-key-poly-point-list
2753 (artist-uniq artist-key-poly-point-list))
2755 (if (>= (length artist-key-poly-point-list) 2)
2757 ;; Only set arrow-points if the point-list has two or more entries
2758 (let ((xn (car (car artist-key-poly-point-list)))
2759 (yn (cdr (car artist-key-poly-point-list)))
2760 (xn-1 (car (car (cdr artist-key-poly-point-list))))
2761 (yn-1 (cdr (car (cdr artist-key-poly-point-list))))
2762 (dirn)) ; direction for point n
2763 (setq artist-key-poly-point-list (reverse artist-key-poly-point-list))
2764 (let ((x0 (car (car artist-key-poly-point-list)))
2765 (y0 (cdr (car artist-key-poly-point-list)))
2766 (x1 (car (car (cdr artist-key-poly-point-list))))
2767 (y1 (cdr (car (cdr artist-key-poly-point-list))))
2768 (dir0)) ; direction for point 0
2769 (setq dir0 (artist-find-direction x1 y1 x0 y0))
2770 (setq dirn (artist-find-direction xn-1 yn-1 xn yn))
2771 (setq artist-arrow-point-1 (artist-make-arrow-point x0 y0 dir0))
2772 (setq artist-arrow-point-2 (artist-make-arrow-point xn yn dirn))))))
2776 ;; Text rendering
2778 (defun artist-figlet-run (text font extra-args)
2779 "Run figlet rendering TEXT using FONT.
2780 EXTRA-ARGS for figlet, for the command line, may be specified."
2781 (let* ((figlet-args (cond ((and font extra-args)
2782 (cons (concat "-f" font)
2783 (artist-string-split extra-args "[ \t]+")))
2784 (font (concat "-f" font))
2785 (extra-args
2786 (artist-string-split extra-args "[ \t]+"))
2787 (t nil)))
2788 (figlet-output (artist-system artist-figlet-program text figlet-args))
2789 (exit-code (elt figlet-output 0))
2790 (stdout (elt figlet-output 1))
2791 (stderr (elt figlet-output 2)))
2792 (if (not (= exit-code 0))
2793 (error "Failed to render font: %s (%d)" stderr exit-code))
2794 stdout))
2796 (defun artist-figlet-get-font-list ()
2797 "Read fonts in with the shell command.
2798 Returns a list of strings."
2799 (let* ((cmd-interpreter "/bin/sh")
2800 (ls-cmd artist-figlet-list-fonts-command)
2801 (result (artist-system cmd-interpreter ls-cmd nil))
2802 (exit-code (elt result 0))
2803 (stdout (elt result 1))
2804 (stderr (elt result 2)))
2805 (if (not (= exit-code 0))
2806 (error "Failed to read available fonts: %s (%d)" stderr exit-code))
2807 (artist-string-split stdout ".flf\n")))
2809 (defun artist-figlet-choose-font ()
2810 "Read any extra arguments for figlet."
2811 (interactive)
2812 (let* ((avail-fonts (artist-figlet-get-font-list))
2813 (font (completing-read (concat "Select font: (default "
2814 artist-figlet-default-font
2815 ") ")
2816 (mapcar
2817 (lambda (font) (cons font font))
2818 avail-fonts))))
2819 (if (string= font "") artist-figlet-default-font font)))
2821 (defun artist-figlet-get-extra-args ()
2822 "Read any extra arguments for figlet."
2823 (let ((extra-args (read-input "Extra args to figlet: ")))
2824 (if (string= extra-args "")
2826 extra-args)))
2828 (defun artist-figlet (text)
2829 "Render TEXT using figlet."
2830 (let* ((figlet-font (artist-figlet-choose-font))
2831 (figlet-extra-args (artist-figlet-get-extra-args)))
2832 (artist-figlet-run text figlet-font figlet-extra-args)))
2835 (defun artist-text-insert-common (x y text see-thru)
2836 "At position X, Y, insert text TEXT.
2837 If SEE-THRU is non-nil, then blanks in TEXT does not replace text
2838 in the buffer."
2839 (let* ((string-list (artist-string-split text "\n"))
2840 (i 0)
2841 (len (length string-list)))
2842 (while (< i len)
2843 (artist-move-to-xy x (+ y i))
2844 (artist-replace-string (car string-list) see-thru)
2845 (setq string-list (cdr string-list))
2846 (setq i (1+ i)))))
2848 (defun artist-text-insert-see-thru (x y text)
2849 "At position X, Y, insert text TEXT.
2850 Let text already in buffer shine thru the TEXT inserted."
2851 (artist-text-insert-common x y text t))
2853 (defun artist-text-insert-overwrite (x y text)
2854 "At position X, Y, insert text TEXT.
2855 Let blanks in TEXT overwrite any text already in the buffer."
2856 (artist-text-insert-common x y text nil))
2858 (defun artist-text-see-thru (x y)
2859 "Prompt for text to render, render it at X,Y.
2860 This is done by calling the function specified by `artist-text-renderer',
2861 which must return a list of strings, to be inserted in the buffer.
2863 Text already in the buffer ``shines thru'' blanks in the rendered text."
2864 (let* ((input-text (read-input "Type text to render: "))
2865 (rendered-text (artist-funcall artist-text-renderer input-text)))
2866 (artist-text-insert-see-thru x y rendered-text)))
2869 (defun artist-text-overwrite (x y)
2870 "Prompt for text to render, render it at X,Y.
2871 This is done by calling the function specified by `artist-text-renderer',
2872 which must return a list of strings, to be inserted in the buffer.
2874 Blanks in the rendered text overwrites any text in the buffer."
2875 (let* ((input-text (read-input "Type text to render: "))
2876 (rendered-text (artist-funcall artist-text-renderer input-text)))
2877 (artist-text-insert-overwrite x y rendered-text)))
2880 ;; Spraying
2883 (defun artist-spray-get-interval ()
2884 "Retrieves the interval for repeated spray."
2885 artist-spray-interval)
2887 (defun artist-spray-random-points (n radius)
2888 "Generate N random points within a radius of RADIUS.
2889 Returns a list of points. Each point is on the form (X1 . Y1)."
2890 (let ((points))
2891 (while (> n 0)
2892 (let* ((angle (* (random 359) (/ pi 180)))
2893 (dist (random radius))
2894 (point (cons (round (* dist (cos angle)))
2895 (round (* dist (sin angle))))))
2896 (setq points (cons point points)))
2897 (setq n (- n 1)))
2898 points))
2900 (defun artist-spray (x1 y1)
2901 "Spray at X1, Y1."
2902 (let* ((num-points (* artist-spray-radius artist-spray-radius))
2903 (spray-points (artist-spray-random-points num-points
2904 artist-spray-radius)))
2905 (while spray-points
2906 ;; Replace one spray point
2907 (let* ((point (car spray-points))
2908 (x (+ x1 (car point)))
2909 (y (+ y1 (cdr point)))
2910 (buf-c (artist-get-char-at-xy-conv x y))
2911 (this-c (memq buf-c artist-spray-chars))
2912 (next-c (cond ((null this-c) artist-spray-new-char)
2913 ((null (cdr this-c)) (car this-c))
2914 (t (car (cdr this-c))))))
2915 (artist-move-to-xy x y)
2916 (artist-replace-char next-c))
2918 ;; Step to next spray point
2919 (setq spray-points (cdr spray-points)))))
2921 (defun artist-spray-clear-circle (circle x1 y1 x2 y2)
2922 "Clears circle CIRCLE at X1, Y1 through X2, Y2."
2923 (artist-undraw-circle circle))
2925 (defun artist-spray-set-radius (circle x1 y1 x2 y2)
2926 "Set spray radius from CIRCLE at X1, Y1 through X2, Y2."
2927 (let ((dx (- x2 x1))
2928 (dy (- y2 y1)))
2929 (setq artist-spray-radius (round (sqrt (+ (* dx dx) (* dy dy)))))
2930 (if (= 0 artist-spray-radius)
2931 (setq artist-spray-radius 1))))
2934 ;; Erasing
2937 (defun artist-erase-char (x1 y1)
2938 "Erases a character at X1, Y1.
2939 The character is replaced with the character in `artist-erase-char'."
2940 (artist-move-to-xy x1 y1)
2941 (artist-replace-char artist-erase-char))
2943 (defun artist-erase-rect (rect x1 y1 x2 y2)
2944 "Erase rectangle RECT from X1, Y1, X2, Y2."
2945 (let ((artist-line-char-set t)
2946 (artist-fill-char-set t)
2947 (artist-line-char artist-erase-char)
2948 (artist-fill-char artist-erase-char))
2949 (artist-draw-rect x1 y1 x2 y2)
2950 (artist-fill-rect rect x1 y1 x2 y2)))
2954 ;; Vaporizing (erasing) line and lines
2958 (defun artist-vap-find-endpoint (x1 y1 step-x step-y accept-set reject-set)
2959 "Find one endpoint for line through X1, Y1.
2960 The endpoint is searched for in the direction defined by STEP-X, STEP-Y,
2961 accepting characters in the list ACCEPT-SET, stopping immediately
2962 when finding characters in the list REJECT-SET. Fuzziness, that is
2963 the number of consecutive characters not in ACCEPT-SET to allow as
2964 part of the line, is determined by the variable `artist-vaporize-fuzziness'.
2965 An endpoint is a cons pair, (ENDPOINT-X . ENDPOINT-Y)."
2966 (let ((x x1)
2967 (y y1)
2968 (x-last x1)
2969 (y-last y1)
2970 (done nil))
2971 (while (not done)
2972 (let ((c (artist-get-char-at-xy-conv x y)))
2973 (cond ((memq c reject-set)
2974 (setq done t))
2976 ;; We found a character we are accepting as part of the line.
2977 ;; Update position
2978 ((memq c accept-set)
2979 (setq x-last x
2980 y-last y
2981 x (+ x step-x)
2982 y (+ y step-y))
2983 (if (or (< x 0) (< y 0)) ;stop at the edge
2984 (setq done t)))
2986 ;; We found a character we are not accepting as part of
2987 ;; the line Search `artist-vaporize-fuzziness'
2988 ;; characters away from this position in the same
2989 ;; direction to see if there are any characters in the
2990 ;; accept-set. If not, we have found the endpoint.
2992 (let ((fuzziness artist-vaporize-fuzziness)
2993 (x-tmp x)
2994 (y-tmp y))
2996 ;; while we have more fuzziness left and we have not
2997 ;; found a character accepted as a line, move
2998 ;; forward!
2999 (while (and (> fuzziness 0) (not (memq c accept-set)))
3000 (setq x-tmp (+ x-tmp step-x))
3001 (setq y-tmp (+ y-tmp step-y))
3002 (setq c (artist-get-char-at-xy-conv x-tmp y-tmp))
3003 (setq fuzziness (- fuzziness 1)))
3004 (if (memq c accept-set)
3006 ;; The line continues on the other side of the
3007 ;; not-accepted character.
3008 (setq x x-tmp
3009 y y-tmp)
3011 ;; Else: We couldn't find any line on the other side.
3012 ;; That means we are done searching for the endpoint.
3013 (setq done t)))))))
3014 (cons x-last y-last)))
3017 (defun artist-vap-find-endpoints-horiz (x y)
3018 "Find endpoints for a horizontal line through X, Y.
3019 An endpoint is a cons pair, (ENDPOINT-X . ENDPOINT-Y)."
3020 (list (artist-vap-find-endpoint x y 1 0 '(?- ?+) '(? ))
3021 (artist-vap-find-endpoint x y -1 0 '(?- ?+) '(? ))))
3023 (defun artist-vap-find-endpoints-vert (x y)
3024 "Find endpoints for a vertical line through X, Y.
3025 An endpoint is a cons pair, (ENDPOINT-X . ENDPOINT-Y)."
3026 (list (artist-vap-find-endpoint x y 0 1 '(?| ?+) '(? ))
3027 (artist-vap-find-endpoint x y 0 -1 '(?| ?+) '(? ))))
3029 (defun artist-vap-find-endpoints-swne (x y)
3030 "Find endpoints for a diagonal line (made by /'s) through X, Y.
3031 An endpoint is a cons pair, (ENDPOINT-X . ENDPOINT-Y)."
3032 (list (artist-vap-find-endpoint x y 1 -1 '(?/ ?X) '(? ))
3033 (artist-vap-find-endpoint x y -1 1 '(?/ ?X) '(? ))))
3035 (defun artist-vap-find-endpoints-nwse (x y)
3036 "Find endpoints for a diagonal line (made by \\'s) through X, Y.
3037 An endpoint is a cons pair, (ENDPOINT-X . ENDPOINT-Y)."
3038 (list (artist-vap-find-endpoint x y 1 1 '(?\\ ?X) '(? ))
3039 (artist-vap-find-endpoint x y -1 -1 '(?\\ ?X) '(? ))))
3042 (defun artist-vap-find-endpoints (x y)
3043 "Given a point X1, Y1, return a list of endpoints of lines through X, Y.
3044 An endpoint is a cons pair, (ENDPOINT-X . ENDPOINT-Y)."
3045 (if artist-line-char-set
3047 (let ((c (artist-get-char-at-xy-conv x y)))
3048 (cond ((eq c ?-) (artist-vap-find-endpoints-horiz x y))
3049 ((eq c ?|) (artist-vap-find-endpoints-vert x y))
3050 ((eq c ?/) (artist-vap-find-endpoints-swne x y))
3051 ((eq c ?\\) (artist-vap-find-endpoints-nwse x y))
3052 ((eq c ?+) (append (artist-vap-find-endpoints-horiz x y)
3053 (artist-vap-find-endpoints-vert x y)))
3054 ((eq c ?X) (append (artist-vap-find-endpoints-swne x y)
3055 (artist-vap-find-endpoints-nwse x y)))
3057 ;; We don't know how to find directions when we are on
3058 ;; another character
3059 (t nil)))))
3062 (defun artist-vap-group-in-pairs (l)
3063 "Group elements in list L in pairs."
3064 (cond ((null l) nil)
3065 ((null (cdr l)) l) ; unevent number of elements in list
3066 (t (append (list (list (car l) (car (cdr l))))
3067 (artist-vap-group-in-pairs (cdr (cdr l)))))))
3069 (defun artist-vaporize-by-endpoints (endpoint1 endpoint2)
3070 "Given ENDPOINT1 and ENDPOINT2, vaporize the line between them.
3071 An endpoint is a pair (X . Y)."
3072 (let* ((x1 (car endpoint1))
3073 (y1 (cdr endpoint1))
3074 (x2 (car endpoint2))
3075 (y2 (cdr endpoint2))
3076 (dir (artist-find-direction x1 y1 x2 y2))
3077 (x-step (aref [1 1 0 -1 -1 -1 0 1] dir))
3078 (y-step (aref [0 1 1 1 0 -1 -1 -1] dir))
3079 (line-c (aref [?- ?\\ ?| ?/ ?- ?\\ ?| ?/] dir))
3080 (line-len (elt (list (abs (- x2 x1))
3081 (abs (- x2 x1))
3082 (abs (- y2 y1))
3083 (abs (- y2 y1))
3084 (abs (- x1 x2))
3085 (abs (- x1 x2))
3086 (abs (- y1 y2))
3087 (abs (- y1 y2)))
3088 dir))
3089 (x x1)
3090 (y y1))
3091 (while (>= line-len 0)
3092 (let* ((buffer-c (artist-get-char-at-xy-conv x y))
3093 (new-c (artist-unintersection-char line-c buffer-c)))
3094 (artist-move-to-xy x y)
3095 (artist-replace-char new-c))
3096 (setq x (+ x x-step)
3097 y (+ y y-step)
3098 line-len (- line-len 1)))))
3101 (defun artist-vaporize-line (x1 y1)
3102 "Vaporize (erase) the straight line through X1, Y1.
3103 Do this by replacing the characters that forms the line with
3104 `artist-erase-char'. Output is a list of endpoints for lines
3105 through X1, Y1. An endpoint is a cons pair, (ENDPOINT-X . ENDPOINT-Y)."
3106 (let ((endpoints (artist-vap-find-endpoints x1 y1)))
3107 (mapcar
3108 (lambda (endpoints)
3109 (let ((ep1 (car endpoints))
3110 (ep2 (car (cdr endpoints))))
3111 (artist-vaporize-by-endpoints ep1 ep2)))
3112 (artist-vap-group-in-pairs endpoints))
3113 endpoints))
3116 ;; Implementation note: This depends on artist-vaporize-line doing
3117 ;; unintersections of intersecting lines.
3119 ;; Example:
3120 ;; Suppose the buffer looks like this and that we start vaporizing
3121 ;; lines at (3,0) (at the ``*'').
3123 ;; 0123456
3124 ;; 0+--*--+
3125 ;; 1| |
3126 ;; 2| |
3127 ;; 3+-----+
3129 ;; We will then push (0,0) and (6,0) on the stack, and vaporize the
3130 ;; topmost horizontal line:
3132 ;; 0123456
3133 ;; 0| |
3134 ;; 1| |
3135 ;; 2| |
3136 ;; 3+-----+
3138 ;; We will then pop (0,0) and remove the left-most vertival line while
3139 ;; pushing the lower left corner (0,3) on the stack, and so on until
3140 ;; the entire rectangle is vaporized.
3142 ;; Now, What if the `+' in the upper left and upper right corners,
3143 ;; had not been changed to `|' but to spaces instead? We would
3144 ;; have failed when popping (0,0) and vaporizing that line because
3145 ;; we wouldn't find any line at (0,0):
3147 ;; 0123456
3148 ;; 0
3149 ;; 1| |
3150 ;; 2| |
3151 ;; 3+-----+
3153 ;; That's why we depend on artist-vaporize-line doing unintersecting
3154 ;; of crossing lines. There are alternative ways to handle this
3155 ;; if it becomes too much a trouble.
3157 (defun artist-vaporize-lines (x1 y1)
3158 "Vaporize lines reachable from point X1, Y1."
3159 (let ((ep-stack nil))
3160 (mapcar
3161 (lambda (ep) (artist-push ep ep-stack))
3162 (artist-vap-find-endpoints x1 y1))
3163 (while (not (null ep-stack))
3164 (let* ((vaporize-point (artist-pop ep-stack))
3165 (new-endpoints (artist-vaporize-line (car vaporize-point)
3166 (cdr vaporize-point))))
3167 (mapcar
3168 (lambda (endpoint) (artist-push endpoint ep-stack))
3169 new-endpoints)))))
3173 ;; Circles and ellipses
3175 (defun artist-ellipse-generate-quadrant (x-radius y-radius)
3176 "Create a point-list for first quadrant.
3177 Points go from (X-RADIUS, 0) to (0, Y-RADIUS).
3178 Quadrant is generated around origo."
3179 (let* ((rx2 (* x-radius x-radius))
3180 (ry2 (* y-radius y-radius))
3181 (2rx2 (* 2 rx2))
3182 (2ry2 (* 2 ry2))
3184 (x 0)
3185 (y y-radius)
3186 (px 0)
3187 (py (* 2rx2 y))
3188 (point-list nil))
3189 (artist-put-pixel point-list x y)
3190 (setq p (round (+ ry2 (- (* rx2 y-radius)) (* 0.25 rx2))))
3191 (while (< px py)
3192 (setq x (1+ x)
3193 px (+ px 2ry2))
3194 (if (< p 0)
3195 (setq p (+ p ry2 px))
3196 (setq y (- y 1)
3197 py (- py 2rx2)
3198 p (+ p ry2 px (- py))))
3199 (artist-put-pixel point-list x y))
3200 (setq p (round (+ (* ry2 (+ x 0.5) (+ x 0.5))
3201 (* rx2 (- y 1) (- y 1))
3202 (- (* rx2 ry2)))))
3203 (while (> y 0)
3204 (setq y (- y 1)
3205 py (- py 2rx2))
3206 (if (> p 0)
3207 (setq p (+ p rx2 (- py)))
3208 (setq x (1+ x)
3209 px (+ px 2ry2)
3210 p (+ p rx2 (- py) px)))
3211 (artist-put-pixel point-list x y))
3212 point-list))
3214 (defsubst artist-new-fill-item (x y width)
3215 "Create a new item at X, Y, with WIDTH.
3216 This is for use in fill-info in ellipses and circles."
3217 (let ((new-item (make-vector 3 x)))
3218 (aset new-item 1 y)
3219 (aset new-item 2 width)
3220 new-item))
3222 (defsubst artist-fill-item-get-x (fill-item)
3223 "Retrieve the x component of a FILL-ITEM."
3224 (aref fill-item 0))
3226 (defsubst artist-fill-item-set-x (fill-item new-x)
3227 "Set the x component of a FILL-ITEM to NEW-X."
3228 (aset fill-item 0 new-x)
3229 fill-item)
3231 (defsubst artist-fill-item-get-y (fill-item)
3232 "Retrieve the y component of a FILL-ITEM."
3233 (aref fill-item 1))
3235 (defsubst artist-fill-item-set-y (fill-item new-y)
3236 "Set the y component of a FILL-ITEM to NEW-Y."
3237 (aset fill-item 1 new-y)
3238 fill-item)
3240 (defsubst artist-fill-item-get-width (fill-item)
3241 "Retrieve the width component of a FILL-ITEM."
3242 (aref fill-item 2))
3244 (defsubst artist-fill-item-set-width (fill-item new-width)
3245 "Set the width component of a FILL-ITEM to NEW-WIDTH."
3246 (aset fill-item 2 new-width)
3247 fill-item)
3250 (defun artist-ellipse-point-list-add-center (x-center y-center point-list)
3251 "Add offsets X-CENTER and Y-CENTER to coordinates in POINT-LIST."
3252 (mapcar
3253 (lambda (p)
3254 (artist-coord-set-x p (+ x-center (artist-coord-get-x p)))
3255 (artist-coord-set-y p (+ y-center (artist-coord-get-y p))))
3256 point-list))
3259 (defun artist-ellipse-fill-info-add-center (x-center y-center fill-info)
3260 "Add offsets X-CENTER and Y-CENTER to fill-items in FILL-INFO."
3261 (mapcar
3262 (lambda (p)
3263 (artist-fill-item-set-x p (+ x-center (artist-fill-item-get-x p)))
3264 (artist-fill-item-set-y p (+ y-center (artist-fill-item-get-y p))))
3265 fill-info))
3267 (defun artist-ellipse-remove-0-fills (fill-info)
3268 "Remove fill-infos from FILL-INFO that fills a zero-width field."
3269 (cond ((null fill-info)
3270 nil)
3271 ((= 0 (artist-fill-item-get-width (car fill-info)))
3272 (artist-ellipse-remove-0-fills (cdr fill-info)))
3274 (append (list (car fill-info))
3275 (artist-ellipse-remove-0-fills (cdr fill-info))))))
3278 (defun artist-ellipse-compute-fill-info (point-list)
3279 "Compute fill info for ellipse around 0,0 from POINT-LIST.
3280 The POINT-LIST is expected to cover the first quadrant."
3281 (let ((first-half nil)
3282 (both-halves nil)
3283 (last-y nil))
3285 ;; Create first half (the lower one (since y grows downwards)) from
3286 ;; the first quadrant.
3287 (mapcar
3288 (lambda (coord)
3289 (let* ((x (artist-coord-get-x coord))
3290 (y (artist-coord-get-y coord))
3291 (width (max (- (* 2 x) 1) 0))
3292 (left-edge (- x width)))
3293 (if (or (null last-y) (not (= y last-y)))
3294 ;; This was either the first time,
3295 ;; or it was the first time on a new line
3296 (setq first-half
3297 (append first-half
3298 ;; Fill info item starts at left-edge on line y
3299 (list (artist-new-fill-item left-edge y width)))))
3300 (setq last-y y)))
3301 point-list)
3303 ;; Create the other half by mirroring the first half.
3304 (setq both-halves
3305 (append first-half
3306 (mapcar
3307 (lambda (i)
3308 (artist-new-fill-item (artist-fill-item-get-x i)
3309 (- (artist-fill-item-get-y i))
3310 (artist-fill-item-get-width i)))
3311 ;; The cdr below is so we don't include fill-info for
3312 ;;; the middle line twice
3313 (cdr (reverse first-half)))))
3314 (artist-ellipse-remove-0-fills both-halves)))
3317 (defun artist-ellipse-mirror-quadrant (point-list)
3318 "Mirror a POINT-LIST describing first quadrant to create a complete ellipse."
3319 (let ((right-half nil)
3320 (left-half nil))
3322 ;; First, if last char in that quadrant is `/', then replace it with `)'
3323 ;; This way we avoids things
3324 ;; --------- ---------
3325 ;; / \ / \
3326 ;; that look like: \ / instead we get: ( )
3327 ;; \ / \ /
3328 ;; --------- ---------
3329 (let ((last-coord (artist-last point-list)))
3330 (if (= (artist-coord-get-new-char last-coord) ?/)
3331 (artist-coord-set-new-char last-coord artist-ellipse-right-char)))
3333 ;; Create the other part of the right half by mirroring the first part
3334 (setq right-half
3335 (append
3336 point-list
3337 (mapcar
3338 (lambda (coord)
3339 (let ((c (artist-coord-get-new-char coord)))
3340 (artist-new-coord (artist-coord-get-x coord)
3341 (- (artist-coord-get-y coord))
3342 (cond ((= c ?/) ?\\)
3343 ((= c ?\\) ?/)
3344 (t c)))))
3345 ;; The cdr below is so we don't draw the middle right char twice
3346 (cdr (reverse point-list)))))
3348 ;; Create the left half by mirroring the right half.
3349 (setq left-half
3350 (mapcar
3351 (lambda (coord)
3352 (let ((c (artist-coord-get-new-char coord)))
3353 (artist-new-coord (- (artist-coord-get-x coord))
3354 (artist-coord-get-y coord)
3355 (cond ((= c ?/) ?\\)
3356 ((= c ?\\) ?/)
3357 ((= c artist-ellipse-right-char)
3358 artist-ellipse-left-char)
3359 (t c)))))
3360 ;; The cdr and butlast below is so we don't draw the middle top
3361 ;; and middle bottom char twice.
3362 (funcall artist-butlast-fn (cdr (reverse right-half)))))
3363 (append right-half left-half)))
3366 (defun artist-draw-ellipse-general (x1 y1 x-radius y-radius)
3367 "Draw an ellipse with center at X1, Y1 and X-RADIUS and Y-RADIUS.
3369 Output is an ellipse, which is a list (END-POINT-1 END-POINT-2 SHAPE-INFO).
3371 END-POINT-1 and END-POINT-2 are two-element vectors on the form [X Y].
3372 SHAPE-INFO is a two-element vector on the form [POINT-LIST FILL-INFO].
3374 POINT-LIST is a list of vectors on the form [X Y SAVED-CHAR NEW-CHAR].
3375 FILL-INFO is a list of vectors on the form [X Y ELLIPSE-WIDTH-ON-THIS-LINE].
3377 Ellipses with zero Y-RADIUS are not drawn correctly."
3378 (let* ((point-list (artist-ellipse-generate-quadrant x-radius y-radius))
3379 (fill-info (artist-ellipse-compute-fill-info point-list))
3380 (shape-info (make-vector 2 0)))
3382 (setq point-list (artist-calculate-new-chars point-list))
3383 (setq point-list (artist-ellipse-mirror-quadrant point-list))
3384 (setq point-list (artist-ellipse-point-list-add-center x1 y1 point-list))
3385 (setq fill-info (artist-ellipse-fill-info-add-center x1 y1 fill-info))
3387 ;; Draw the ellipse
3388 (setq point-list
3389 (mapcar
3390 (lambda (coord)
3391 (artist-move-to-xy (artist-coord-get-x coord)
3392 (artist-coord-get-y coord))
3393 (if artist-line-char-set
3394 (artist-replace-char artist-line-char)
3395 (artist-replace-char (artist-coord-get-new-char coord)))
3396 coord)
3397 (artist-modify-new-chars
3398 (artist-save-chars-under-point-list point-list))))
3400 (aset shape-info 0 point-list)
3401 (aset shape-info 1 fill-info)
3402 (artist-make-2point-object (artist-make-endpoint x1 y1)
3403 (artist-make-endpoint x-radius y-radius)
3404 shape-info)))
3406 (defun artist-draw-ellipse-with-0-height (x1 y1 x-radius y-radius)
3407 "Draw an ellipse with center at X1, Y1 and X-RADIUS and Y-RADIUS.
3409 Output is an ellipse, which is a list (END-POINT-1 END-POINT-2 SHAPE-INFO).
3411 END-POINT-1 and END-POINT-2 are two-element vectors on the form [X Y].
3412 SHAPE-INFO is a two-element vector on the form [POINT-LIST FILL-INFO].
3414 POINT-LIST is a list of vectors on the form [X Y SAVED-CHAR NEW-CHAR].
3415 FILL-INFO is a list of vectors on the form [X Y ELLIPSE-WIDTH-ON-THIS-LINE].
3417 The Y-RADIUS must be 0, but the X-RADIUS must not be 0."
3418 (let ((point-list nil)
3419 (width (max (- (abs (* 2 x-radius)) 1)))
3420 (left-edge (1+ (- x1 (abs x-radius))))
3421 (line-char (if artist-line-char-set artist-line-char ?-))
3422 (i 0)
3423 (point-list nil)
3424 (fill-info nil)
3425 (shape-info (make-vector 2 0)))
3426 (while (< i width)
3427 (let* ((line-x (+ left-edge i))
3428 (line-y y1)
3429 (new-coord (artist-new-coord line-x line-y)))
3430 (artist-coord-add-saved-char new-coord
3431 (artist-get-char-at-xy line-x line-y))
3432 (artist-move-to-xy line-x line-y)
3433 (artist-replace-char line-char)
3434 (setq point-list (append point-list (list new-coord)))
3435 (setq i (1+ i))))
3436 (aset shape-info 0 point-list)
3437 (aset shape-info 1 fill-info)
3438 (artist-make-2point-object (artist-make-endpoint x1 y1)
3439 (artist-make-endpoint x-radius y-radius)
3440 shape-info)))
3442 (defun artist-draw-ellipse (x1 y1 x2 y2)
3443 "Draw an ellipse with center at X1, Y1 and point X2,Y2.
3445 Output is an ellipse, which is a list (END-POINT-1 END-POINT-2 SHAPE-INFO).
3447 END-POINT-1 and END-POINT-2 are two-element vectors on the form [X Y].
3448 SHAPE-INFO is a two-element vector on the form [POINT-LIST FILL-INFO].
3450 POINT-LIST is a list of vectors on the form [X Y SAVED-CHAR NEW-CHAR].
3451 FILL-INFO is a list of vectors on the form [X Y ELLIPSE-WIDTH-ON-THIS-LINE]."
3452 (let* ((artist-line-char (artist-compute-line-char))
3453 (artist-line-char-set artist-line-char)
3454 (width (abs (- x2 x1)))
3455 (height (abs (- y2 y1)))
3457 ;; When we draw our ellipse, we want it to go through the cursor
3458 ;; position, but since x1,y1, x2,y2 marks the corners of one
3459 ;; of the quadrants, we have to enlarge the ellipse a bit.
3460 ;; Ok, so then why by sqrt(2)?
3461 ;; It comes from the equation for the ellipse (where a is the
3462 ;; x-radius and b is the y-radius):
3463 ;; f(x,y) = x^2 / a^2 + y^2 / b^2 - 1 = 0
3464 ;; and the fact that we want the enlarged ellipse to have the
3465 ;; same proportions as the smaller square, therefore we have:
3466 ;; a/b = x/y
3467 ;; Solving this yields a-in-larger-ellipse = a-in-smaller * sqrt(2)
3468 (x-radius (round (* width (sqrt 2))))
3469 (y-radius (round (* height (sqrt 2))))
3470 (x x1)
3471 (y y1))
3472 (if (and (= y1 y2) (not (= x1 x2)))
3473 (artist-draw-ellipse-with-0-height x y x-radius y-radius)
3474 (artist-draw-ellipse-general x y x-radius y-radius))))
3477 (defun artist-undraw-ellipse (ellipse)
3478 "Undraw ELLIPSE."
3479 (if ellipse
3480 (let ((point-list (aref (artist-2point-get-shapeinfo ellipse) 0)))
3481 (mapcar
3482 (lambda (coord)
3483 (artist-move-to-xy (artist-coord-get-x coord)
3484 (artist-coord-get-y coord))
3485 (artist-replace-char (artist-coord-get-saved-char coord))
3486 coord)
3487 point-list))))
3490 (defun artist-draw-circle (x1 y1 x2 y2)
3491 "Draw a circle with center at X1, Y1 and point X2,Y2.
3493 Output is an ellipse, which is a list (END-POINT-1 END-POINT-2 SHAPE-INFO).
3495 END-POINT-1 and END-POINT-2 are two-element vectors on the form [X Y].
3496 SHAPE-INFO is a two-element vector on the form [POINT-LIST FILL-INFO].
3498 POINT-LIST is a list of vectors on the form [X Y SAVED-CHAR NEW-CHAR].
3499 FILL-INFO is a list of vectors on the form [X Y ELLIPSE-WIDTH-ON-THIS-LINE]."
3500 (let* ((artist-line-char (artist-compute-line-char))
3501 (artist-line-char-set artist-line-char)
3502 (width (abs (- x2 x1)))
3503 (height (abs (- y2 y1)))
3504 ;; When drawing our circle, we want it to through the cursor
3505 ;; just as when drawing the ellispe, but we have to take
3506 ;; care for the aspect-ratio.
3507 ;; The equation for the ellipse (where a is the x-radius and
3508 ;; b is the y-radius):
3509 ;; f(x,y) = x^2 / a^2 + y^2 / b^2 - 1 = 0
3510 ;; together with the relationship
3511 ;; a = aspect-ratio * b
3512 ;; gives
3513 ;; a = sqrt( x^2 + (aspect-ratio * y)^2 ) and
3514 ;; b = a / aspect-ratio
3515 (x-radius (round (sqrt (+ (* width width)
3516 (* (* artist-aspect-ratio height)
3517 (* artist-aspect-ratio height))))))
3518 (y-radius (round (/ x-radius artist-aspect-ratio))))
3519 (artist-draw-ellipse-general x1 y1 x-radius y-radius)))
3521 (defalias 'artist-undraw-circle 'artist-undraw-ellipse)
3525 ; Filling ellipses
3527 (defun artist-fill-ellipse (ellipse x y x-radius y-radius)
3528 "Fill an ELLIPSE centered at X,Y with radius X-RADIUS and Y-RADIUS."
3529 (let ((fill-info (aref (artist-2point-get-shapeinfo ellipse) 1)))
3530 (mapcar
3531 (lambda (fill-item)
3532 (artist-move-to-xy (artist-fill-item-get-x fill-item)
3533 (artist-fill-item-get-y fill-item))
3534 (artist-replace-chars artist-fill-char
3535 (artist-fill-item-get-width fill-item))
3536 fill-item)
3537 fill-info)))
3539 (defalias 'artist-fill-circle 'artist-fill-ellipse)
3543 ;; Cutting, copying and pasting rectangles and squares
3544 ;; (filling functions)
3547 (defun artist-cut-rect (rect x1 y1 x2 y2)
3548 "Copy rectangle RECT drawn from X1, Y1 to X2, Y2, then clear it."
3549 (artist-undraw-rect rect)
3550 (artist-copy-generic x1 y1 x2 y2)
3551 (artist-erase-rect rect x1 y1 x2 y2))
3553 (defun artist-cut-square (square x1 y1 x2 y2)
3554 "Copy a SQUARE drawn from X1, Y1 to X2, Y2 (made square), then clears it."
3555 (artist-undraw-square square)
3556 (let* ((square-corners (artist-rect-corners-squarify x1 y1 x2 y2))
3557 (new-x1 (elt square-corners 0))
3558 (new-y1 (elt square-corners 1))
3559 (new-x2 (elt square-corners 2))
3560 (new-y2 (elt square-corners 3)))
3561 (artist-copy-generic new-x1 new-y1 new-x2 new-y2)
3562 (artist-erase-rect square new-x1 new-y1 new-x2 new-y2)))
3565 (defun artist-get-buffer-contents-at-xy (x y width)
3566 "Retrieve contents from the buffer at X, Y. WIDTH characters are returned."
3567 (artist-move-to-xy x y)
3568 (let ((here (point))
3569 (there (save-excursion (artist-move-to-xy (+ x width) y) (point))))
3570 (untabify here there)
3571 (setq there (save-excursion (artist-move-to-xy (+ x width) y) (point)))
3572 (buffer-substring here there)))
3575 (defun artist-copy-generic (x1 y1 x2 y2)
3576 "Copy a rectangular area with corners at X1, Y1 and X2, Y2.
3577 Output is a copy buffer, a list of strings, representing the
3578 original contents of that area in the buffer."
3579 (let* ((x (min x1 x2))
3580 (y (min y1 y2))
3581 (x-max (max x1 x2))
3582 (y-max (max y1 y2))
3583 (w (+ (- x-max x) 1))
3584 (l nil))
3585 (while (<= y y-max)
3586 (setq l (cons (artist-get-buffer-contents-at-xy x y w) l))
3587 (setq y (1+ y)))
3588 (if artist-interface-with-rect
3589 (setq killed-rectangle (reverse l))
3590 (setq artist-copy-buffer (reverse l)))))
3593 (defun artist-copy-rect (rect x1 y1 x2 y2)
3594 "Copy rectangle RECT drawn from X1, Y1 to X2, Y2."
3595 (artist-undraw-rect rect)
3596 (artist-copy-generic x1 y1 x2 y2))
3598 (defun artist-copy-square (square x1 y1 x2 y2)
3599 "Copies a SQUARE drawn from X1, Y1 to X2, Y2 (but made square)."
3600 (artist-undraw-square square)
3601 (let* ((square-corners (artist-rect-corners-squarify x1 y1 x2 y2))
3602 (new-x1 (elt square-corners 0))
3603 (new-y1 (elt square-corners 1))
3604 (new-x2 (elt square-corners 2))
3605 (new-y2 (elt square-corners 3)))
3606 (artist-copy-generic new-x1 new-y1 new-x2 new-y2)))
3608 (defun artist-paste (x y)
3609 "Pastes the contents of the copy-buffer at X,Y."
3610 (let ((copy-buf (if artist-interface-with-rect
3611 killed-rectangle
3612 artist-copy-buffer)))
3613 (if (not (null copy-buf))
3614 (while (not (null copy-buf))
3615 (artist-move-to-xy x y)
3616 (artist-replace-string (car copy-buf))
3617 (setq copy-buf (cdr copy-buf))
3618 (setq y (1+ y)))
3619 (message "Nothing to paste"))))
3623 ;; Flood filling
3625 (defun artist-ff-too-far-right (x)
3626 "Determine if the position X is too far to the right."
3627 (cond ((numberp artist-flood-fill-right-border)
3628 (> x artist-flood-fill-right-border))
3629 ((eq artist-flood-fill-right-border 'window-width)
3630 (> x (- (window-width) 2)))
3631 ((eq artist-flood-fill-right-border 'fill-column)
3632 (> x fill-column))
3633 (t (error "Invalid value for `artist-flood-fill-right-border'"))))
3635 (defun artist-ff-get-rightmost-from-xy (x y)
3636 "Find the rightmost position in this run, starting at X, Y."
3637 (save-excursion
3638 (let ((char-at-xy (artist-get-char-at-xy-conv x y))
3639 (last-x x))
3640 (setq x (1+ x))
3641 (while (and (not (artist-ff-too-far-right x))
3642 (= char-at-xy (artist-get-char-at-xy-conv x y)))
3643 (setq last-x x)
3644 (setq x (1+ x)))
3645 last-x)))
3647 (defun artist-ff-is-topmost-line (x y)
3648 "Determine whether the position X,Y is on the topmost line or not."
3649 (= y 0))
3651 (defun artist-ff-is-bottommost-line (x y)
3652 "Determine whether the position X,Y is on the bottommost line or not."
3653 (save-excursion
3654 (goto-char (point-max))
3655 (beginning-of-line)
3656 (let ((last-line (artist-current-line)))
3657 (if (= (point) (point-max))
3659 ;; Last line is empty, don't paint on it, report previous line
3660 ;; as last line
3661 (>= y (- last-line 1))
3662 (>= y last-line)))))
3664 (defun artist-flood-fill (x1 y1)
3665 "Flood-fill starting at X1, Y1. Fill with the char in `artist-fill-char'."
3666 (let ((stack nil)
3667 (input-queue nil)
3668 ;; We are flood-filling the area that has this character.
3669 (c (artist-get-char-at-xy-conv x1 y1))
3670 (artist-fill-char (if artist-fill-char-set
3671 artist-fill-char
3672 artist-default-fill-char)))
3674 ;; Fill only if the fill-char is not the same as the character whose
3675 ;; area we are about to fill, or, in other words, don't fill if we
3676 ;; needn't.
3677 (if (not (= c artist-fill-char))
3678 (artist-push (artist-new-coord x1 y1) stack))
3680 (while (not (null stack))
3681 (let* ((coord (artist-pop stack))
3682 (x (artist-coord-get-x coord))
3683 (y (artist-coord-get-y coord))
3685 ;; Here we keep track of the leftmost and rightmost position
3686 ;; for this run
3687 (x-leftmost 0)
3688 (x-rightmost 0)
3689 (last-x 0)
3691 ;; Remember if line above and below are accessible
3692 ;; Lines below the last one, and prior to the first-one
3693 ;; are not accessible.
3694 (lines-above nil)
3695 (lines-below nil)
3697 ;; Remember char for position on line above and below, so we
3698 ;; can find the rightmost positions on the runs.
3699 (last-c-above -1)
3700 (last-c-below -1))
3702 (setq x-rightmost (artist-ff-get-rightmost-from-xy x y))
3703 (setq lines-above (not (artist-ff-is-topmost-line x y)))
3704 (setq lines-below (not (artist-ff-is-bottommost-line x y)))
3705 (setq last-x x-rightmost)
3706 (setq x x-rightmost)
3708 ;; Search line above, push rightmost positions of runs for that line
3709 (while (and (>= x 0) (= c (artist-get-char-at-xy-conv x y)))
3710 (if lines-above
3711 (let ((c-above (artist-get-char-at-xy-conv x (- y 1))))
3712 (if (and (= c-above c) (/= c-above last-c-above))
3713 (artist-push (artist-new-coord x (- y 1)) stack))
3714 (setq last-c-above c-above)))
3715 (setq last-x x)
3716 (setq x (- x 1)))
3718 ;; Remember the left-most position on this run
3719 (setq x-leftmost last-x)
3721 ;; Search line below, push rightmost positions of runs for that line
3722 (setq x x-rightmost)
3723 (while (>= x x-leftmost)
3724 (if lines-below
3725 (let ((c-below (artist-get-char-at-xy-conv x (1+ y))))
3726 (if (and (= c-below c) (/= c-below last-c-below))
3727 (artist-push (artist-new-coord x (1+ y)) stack))
3728 (setq last-c-below c-below)))
3729 (setq x (- x 1)))
3731 (artist-move-to-xy x-leftmost y)
3732 (artist-replace-chars artist-fill-char (1+ (- x-rightmost x-leftmost)))
3734 ;; If we are to show incrementally, we have to remove any pending
3735 ;; input from the input queue, because processing of pending input
3736 ;; always has priority over display updates (although this input
3737 ;; won't be processed until we are done). Later on we will queue
3738 ;; the input on the input queue again.
3739 (if artist-flood-fill-show-incrementally
3740 (progn
3741 (if (input-pending-p)
3742 (discard-input))
3743 (artist-update-display)))))))
3746 ;; Accessors to arrow-points
3749 (defun artist-make-arrow-point (x y direction &optional state)
3750 "Create an arrow point at X, Y for a line in direction DIRECTION.
3751 Optional argument STATE can be used to set state (default is nil)."
3752 (save-excursion
3753 (let* ((arrow-point (make-vector 4 0))
3754 (arrow-marker (make-marker)))
3755 (artist-move-to-xy x y)
3756 (set-marker arrow-marker (point))
3757 (aset arrow-point 0 arrow-marker)
3758 (aset arrow-point 1 (artist-get-char-at-xy x y))
3759 (aset arrow-point 2 direction)
3760 (aset arrow-point 3 state)
3761 arrow-point)))
3763 (defsubst artist-arrow-point-get-marker (arrow-point)
3764 "Retrieve the marker component of an ARROW-POINT."
3765 (aref arrow-point 0))
3767 (defsubst artist-arrow-point-get-orig-char (arrow-point)
3768 "Retrieve the orig char component of an ARROW-POINT."
3769 (aref arrow-point 1))
3771 (defsubst artist-arrow-point-get-direction (arrow-point)
3772 "Retrieve the direction component of an ARROW-POINT."
3773 (aref arrow-point 2))
3775 (defsubst artist-arrow-point-get-state (arrow-point)
3776 "Retrieve the state component of an ARROW-POINT."
3777 (aref arrow-point 3))
3779 (defsubst artist-arrow-point-set-state (arrow-point new-state)
3780 "Set the state component of an ARROW-POINT to NEW-STATE."
3781 (aset arrow-point 3 new-state))
3784 (defun artist-clear-arrow-points ()
3785 "Clear current endpoints."
3786 (setq artist-arrow-point-1 nil)
3787 (setq artist-arrow-point-2 nil))
3789 (defun artist-set-arrow-points-for-poly (point-list)
3790 "Generic function for setting arrow-points for poly-shapes from POINT-LIST."
3791 (let* ((ep1 (elt point-list 0))
3792 (ep2 (elt point-list 1))
3793 (x1 (artist-endpoint-get-x ep1))
3794 (y1 (artist-endpoint-get-y ep1))
3795 (x2 (artist-endpoint-get-x ep2))
3796 (y2 (artist-endpoint-get-y ep2))
3797 (dir1 (artist-find-direction x2 y2 x1 y1))
3798 (epn (artist-last point-list))
3799 (epn-1 (artist-last point-list 2))
3800 (xn (artist-endpoint-get-x epn))
3801 (yn (artist-endpoint-get-y epn))
3802 (xn-1 (artist-endpoint-get-x epn-1))
3803 (yn-1 (artist-endpoint-get-y epn-1))
3804 (dirn (artist-find-direction xn-1 yn-1 xn yn)))
3805 (setq artist-arrow-point-1 (artist-make-arrow-point x1 y1 dir1))
3806 (setq artist-arrow-point-2 (artist-make-arrow-point xn yn dirn))))
3809 (defun artist-set-arrow-points-for-2points (shape x1 y1 x2 y2)
3810 "Generic function for setting arrow-points for 2-point shapes.
3811 The 2-point shape SHAPE is drawn from X1, Y1 to X2, Y2."
3812 (let* ((endpoint1 (artist-2point-get-endpoint1 shape))
3813 (endpoint2 (artist-2point-get-endpoint2 shape))
3814 (x1 (artist-endpoint-get-x endpoint1))
3815 (y1 (artist-endpoint-get-y endpoint1))
3816 (x2 (artist-endpoint-get-x endpoint2))
3817 (y2 (artist-endpoint-get-y endpoint2)))
3818 (setq artist-arrow-point-1
3819 (artist-make-arrow-point x1 y1
3820 (artist-find-direction x2 y2 x1 y1)))
3821 (setq artist-arrow-point-2
3822 (artist-make-arrow-point x2 y2
3823 (artist-find-direction x1 y1 x2 y2)))))
3827 ;; Common routine for drawing/undrawing shapes based
3828 ;; on the draw-how
3831 (defun artist-key-undraw-continously (x y)
3832 "Undraw current continous shape with point at X, Y."
3833 ;; No undraw-info for continous shapes
3834 nil)
3836 (defun artist-key-undraw-poly (x y)
3837 "Undraw current poly shape with point at X, Y."
3838 (let ((undraw-fn (artist-go-get-undraw-fn-from-symbol artist-curr-go))
3839 (x1 (artist-endpoint-get-x artist-key-endpoint1))
3840 (y1 (artist-endpoint-get-y artist-key-endpoint1)))
3841 (artist-funcall undraw-fn artist-key-shape)))
3843 (defun artist-key-undraw-1point (x y)
3844 "Undraw current 1-point shape at X, Y."
3845 ;; No undraw-info for 1-point shapes
3846 nil)
3848 (defun artist-key-undraw-2points (x y)
3849 "Undraw current 2-point shape at X, Y."
3850 (let ((undraw-fn (artist-go-get-undraw-fn-from-symbol artist-curr-go))
3851 (x1 (artist-endpoint-get-x artist-key-endpoint1))
3852 (y1 (artist-endpoint-get-y artist-key-endpoint1)))
3853 (artist-funcall undraw-fn artist-key-shape)))
3855 (defun artist-key-undraw-common ()
3856 "Common routine undrawing current shape."
3857 (let ((draw-how (artist-go-get-draw-how-from-symbol artist-curr-go))
3858 (col (artist-current-column))
3859 (row (artist-current-line)))
3861 ;; Depending on what we are currently drawing, call other routines
3862 ;; that knows how to do the job
3864 (cond ((eq draw-how 'artist-do-continously)
3865 (artist-key-undraw-continously col row))
3866 ((eq draw-how 'artist-do-poly)
3867 (artist-key-undraw-poly col row))
3868 ((and (numberp draw-how) (= draw-how 1))
3869 (artist-key-undraw-1point col row))
3870 ((and (numberp draw-how) (= draw-how 2))
3871 (artist-key-undraw-2points col row))
3872 (t (message "Undrawing \"%s\"s is not yet implemented" draw-how)))
3874 ;; Now restore the old position
3876 (artist-move-to-xy col row)))
3880 ;; Implementation note: This really should honor the interval-fn entry
3881 ;; in the master table, `artist-mt', which would mean leaving a timer
3882 ;; that calls `draw-fn' every now and then. That timer would then have
3883 ;; to be cancelled and reinstalled whenever the user moves the cursor.
3884 ;; This could be done, but what if the user suddenly switches to another
3885 ;; drawing mode, or even kills the buffer! In the mouse case, it is much
3886 ;; simpler: when at the end of `artist-mouse-draw-continously', the
3887 ;; user has released the button, so the timer will always be cancelled
3888 ;; at that point.
3889 (defun artist-key-draw-continously (x y)
3890 "Draws current continous shape at X,Y."
3891 (let ((draw-fn (artist-go-get-draw-fn-from-symbol artist-curr-go)))
3892 (setq artist-key-shape (artist-funcall draw-fn x y))))
3894 (defun artist-key-draw-poly (x y)
3895 "Draws current poly-point shape with nth point at X,Y."
3896 (let ((draw-fn (artist-go-get-draw-fn-from-symbol artist-curr-go))
3897 (x1 (artist-endpoint-get-x artist-key-endpoint1))
3898 (y1 (artist-endpoint-get-y artist-key-endpoint1)))
3899 (setq artist-key-shape (artist-funcall draw-fn x1 y1 x y))))
3901 (defun artist-key-draw-1point (x y)
3902 "Draws current 1-point shape at X,Y."
3903 (let ((draw-fn (artist-go-get-draw-fn-from-symbol artist-curr-go)))
3904 (setq artist-key-shape (artist-funcall draw-fn x y))))
3907 (defun artist-key-draw-2points (x y)
3908 "Draws current 2-point shape at X,Y."
3909 (let ((draw-fn (artist-go-get-draw-fn-from-symbol artist-curr-go))
3910 (x1 (artist-endpoint-get-x artist-key-endpoint1))
3911 (y1 (artist-endpoint-get-y artist-key-endpoint1)))
3912 (setq artist-key-shape (artist-funcall draw-fn x1 y1 x y))))
3914 (defun artist-key-draw-common ()
3915 "Common routine for drawing current shape."
3916 (let ((draw-how (artist-go-get-draw-how-from-symbol artist-curr-go))
3917 (col (artist-current-column))
3918 (row (artist-current-line)))
3920 ;; Depending on what we are currently drawing, call other routines
3921 ;; that knows how to do the job
3923 (cond ((eq draw-how 'artist-do-continously)
3924 (artist-key-draw-continously col row))
3925 ((eq draw-how 'artist-do-poly)
3926 (artist-key-draw-poly col row))
3927 ((and (numberp draw-how) (= draw-how 1))
3928 (artist-key-draw-1point col row))
3929 ((and (numberp draw-how) (= draw-how 2))
3930 (artist-key-draw-2points col row))
3931 (t (message "Drawing \"%s\"s is not yet implemented" draw-how)))
3933 ;; Now restore the old position
3935 (artist-move-to-xy col row)))
3940 ;; Functions related to trimming line-endings
3941 ;; The region between the topmost and bottommost visited line is
3942 ;; called a draw-region.
3945 (defun artist-draw-region-reset ()
3946 "Reset the current draw-region."
3947 (setq artist-draw-region-max-y 0)
3948 (setq artist-draw-region-min-y 1000000))
3950 (defun artist-draw-region-trim-line-endings (min-y max-y)
3951 "Trim lines in current draw-region from MIN-Y to MAX-Y.
3952 Trimming here means removing white space at end of a line."
3953 ;; Safetyc check: switch min-y and max-y if if max-y is smaller
3954 (if (< max-y min-y)
3955 (let ((tmp min-y))
3956 (setq min-y max-y)
3957 (setq max-y tmp)))
3958 (save-excursion
3959 (let ((curr-y min-y))
3960 (while (<= curr-y max-y)
3961 (artist-move-to-xy 0 curr-y)
3962 (end-of-line)
3963 (delete-horizontal-space)
3964 (setq curr-y (1+ curr-y))))))
3967 ;; Drawing shapes by using keys
3970 (defun artist-key-do-continously-continously (x y)
3971 "Update current continous shape at X,Y."
3972 (let ((draw-fn (artist-go-get-draw-fn-from-symbol artist-curr-go)))
3973 (artist-funcall draw-fn x y)))
3976 (defun artist-key-do-continously-poly (x y)
3977 "Update current poly-point shape with nth point at X,Y."
3978 (let ((draw-fn (artist-go-get-draw-fn-from-symbol artist-curr-go))
3979 (undraw-fn (artist-go-get-undraw-fn-from-symbol artist-curr-go))
3980 (x1 (artist-endpoint-get-x artist-key-endpoint1))
3981 (y1 (artist-endpoint-get-y artist-key-endpoint1))
3982 (x2 x)
3983 (y2 y))
3984 ;; If not rubber-banding, then move the 2
3985 ;; Otherwise re-draw the shape to the new position
3987 (if (not artist-rubber-banding)
3988 (progn
3989 (artist-no-rb-unset-point2)
3990 (artist-no-rb-set-point2 x y))
3991 (progn
3992 (artist-funcall undraw-fn artist-key-shape)
3993 (setq artist-key-shape (artist-funcall draw-fn x1 y1 x2 y2))))))
3996 (defun artist-key-do-continously-1point (x y)
3997 "Update current 1-point shape at X,Y."
3998 ;; Nothing to do continously for operations
3999 ;; where we have only one input point
4000 nil)
4002 (defun artist-key-do-continously-2points (x y)
4003 "Update current 2-point shape with 2nd point at X,Y."
4004 (let ((draw-fn (artist-go-get-draw-fn-from-symbol artist-curr-go))
4005 (undraw-fn (artist-go-get-undraw-fn-from-symbol artist-curr-go))
4006 (x1 (artist-endpoint-get-x artist-key-endpoint1))
4007 (y1 (artist-endpoint-get-y artist-key-endpoint1))
4008 (x2 x)
4009 (y2 y))
4010 ;; If not rubber-banding, then move the 2
4011 ;; Otherwise re-draw the shape to the new position
4013 (if (not artist-rubber-banding)
4014 (progn
4015 (artist-no-rb-unset-point2)
4016 (artist-no-rb-set-point2 x y))
4017 (progn
4018 (artist-funcall undraw-fn artist-key-shape)
4019 (setq artist-key-shape (artist-funcall draw-fn x1 y1 x2 y2))))))
4022 (defun artist-key-do-continously-common ()
4023 "Common routine for updating current shape."
4024 (let ((draw-how (artist-go-get-draw-how-from-symbol artist-curr-go))
4025 (col (artist-current-column))
4026 (row (artist-current-line)))
4028 ;; Depending on what we are currently drawing, call other routines
4029 ;; that knows how to do the job
4031 (cond ((eq draw-how 'artist-do-continously)
4032 (artist-key-do-continously-continously col row))
4033 ((eq draw-how 'artist-do-poly)
4034 (artist-key-do-continously-poly col row))
4035 ((and (numberp draw-how) (= draw-how 1))
4036 (artist-key-do-continously-1point col row))
4037 ((and (numberp draw-how) (= draw-how 2))
4038 (artist-key-do-continously-2points col row))
4039 (t (message "Drawing \"%s\"s is not yet implemented" draw-how)))
4041 ;; Now restore the old position
4043 (artist-move-to-xy col row)))
4046 (defun artist-key-set-point-continously (x y)
4047 "Set point for current continous shape at X,Y."
4048 ;; Maybe set arrow-points for continous shapes
4049 (let ((arrow-pred (artist-go-get-arrow-pred-from-symbol artist-curr-go))
4050 (arrow-set-fn (artist-go-get-arrow-set-fn-from-symbol artist-curr-go))
4051 (init-fn (artist-go-get-init-fn-from-symbol artist-curr-go))
4052 (prep-fill-fn (artist-go-get-prep-fill-fn-from-symbol artist-curr-go))
4053 (exit-fn (artist-go-get-exit-fn-from-symbol artist-curr-go)))
4055 (if (not artist-key-is-drawing)
4056 ;; *** We are about to begin drawing
4057 (progn
4058 (artist-funcall init-fn x y))
4060 ;; *** We are about to stop drawing
4061 (progn
4063 (artist-funcall prep-fill-fn x y)
4064 (if (artist-funcall arrow-pred)
4065 (artist-funcall arrow-set-fn x y)
4066 (artist-clear-arrow-points))
4067 (artist-funcall exit-fn x y))))
4069 ;; Toggle the is-drawing flag
4070 (setq artist-key-is-drawing (not artist-key-is-drawing)))
4074 (defun artist-key-set-point-poly (x y &optional this-is-last-point)
4075 "Set point for current poly-point shape at X,Y.
4076 If optional argument THIS-IS-LAST-POINT is non-nil, this point is the last."
4077 (let ((draw-fn (artist-go-get-draw-fn-from-symbol artist-curr-go))
4078 (init-fn (artist-go-get-init-fn-from-symbol artist-curr-go))
4079 (prep-fill-fn (artist-go-get-prep-fill-fn-from-symbol artist-curr-go))
4080 (exit-fn (artist-go-get-exit-fn-from-symbol artist-curr-go))
4081 (fill-pred (artist-go-get-fill-pred-from-symbol artist-curr-go))
4082 (fill-fn (artist-go-get-fill-fn-from-symbol artist-curr-go))
4083 (arrow-pred (artist-go-get-arrow-pred-from-symbol artist-curr-go))
4084 (arrow-set-fn (artist-go-get-arrow-set-fn-from-symbol artist-curr-go)))
4086 (if (not artist-key-is-drawing)
4088 ;; *** We were not drawing ==> set first point
4089 (progn
4091 (artist-funcall init-fn x y)
4093 ;; If not rubber-banding, set first point.
4094 ;; Otherwise, draw the shape from x,y to x,y
4095 (if (not artist-rubber-banding)
4096 (artist-no-rb-set-point1 x y)
4097 (setq artist-key-shape (artist-funcall draw-fn x y x y)))
4099 ;; Set first endpoint
4100 (setq artist-key-endpoint1 (artist-make-endpoint x y))
4102 ;; Set point-list to contain start point
4103 (setq artist-key-poly-point-list (list (artist-make-endpoint x y)))
4105 ;; Since we are not ready, set the arrow-points to nil
4106 (artist-clear-arrow-points)
4108 ;; Change state to drawing
4109 (setq artist-key-is-drawing t)
4111 ;; Feedback
4112 (message (substitute-command-keys
4113 (concat "First point set. "
4114 "Set next with \\[artist-key-set-point], "
4115 "set last with C-u \\[artist-key-set-point]"))))
4118 ;; *** We were drawing ==> we are about to set nth point
4119 ;; (last point if the argument this-is-last-point is non-nil)
4121 (let ((x1 (artist-endpoint-get-x artist-key-endpoint1))
4122 (y1 (artist-endpoint-get-y artist-key-endpoint1))
4123 (x2 x)
4124 (y2 y))
4126 ;; If not rubber-banding, undraw the 1's and 2's, then
4127 ;; draw the shape (if we were rubber-banding, then the
4128 ;; shape is already drawn in artist-key-do-continously-2points.)
4130 (if (not artist-rubber-banding)
4131 (progn
4132 (artist-no-rb-unset-points)
4133 (setq artist-key-shape (artist-funcall draw-fn x1 y1 x2 y2))))
4135 ;; Set x2 and y2 from shape's second point
4136 ;; (which might be different from the mouse's second point,
4137 ;; if, for example, we are drawing a straight line)
4139 (if (not (null artist-key-shape))
4140 (let ((endpoint2 (artist-2point-get-endpoint2 artist-key-shape)))
4141 (setq x2 (artist-endpoint-get-x endpoint2))
4142 (setq y2 (artist-endpoint-get-y endpoint2))))
4144 ;; Add the endpoint to the list of poly-points
4145 (setq artist-key-poly-point-list
4146 (append artist-key-poly-point-list
4147 (list (artist-make-endpoint x2 y2))))
4149 ;; Now do handle the case when this is the last point,
4150 ;; and the case when this point isn't the last
4152 (if (not this-is-last-point)
4153 ;; ** This is not the last point
4154 (progn
4155 ;; Start drawing a new 2-point-shape from last endpoint.
4157 ;; First set the start-point
4158 (setq x1 x2)
4159 (setq y1 y2)
4160 (setq artist-key-endpoint1 (artist-make-endpoint x1 y1))
4162 ;; If we are not rubber-banding, then place the '1
4163 ;; Otherwise, draw the shape from x1,y1 to x1,y1
4164 (if (not artist-rubber-banding)
4165 (artist-no-rb-set-point1 x1 y1)
4166 (setq artist-key-shape (artist-funcall draw-fn x1 y1 x1 y1)))
4168 ;; Feedback
4169 (message "Point set"))
4171 ;; ** This is the last point
4172 (progn
4174 (artist-funcall prep-fill-fn artist-key-poly-point-list)
4176 ;; Maybe fill
4177 (if (artist-funcall fill-pred)
4178 (artist-funcall fill-fn artist-key-shape
4179 artist-key-poly-point-list))
4181 ;; Set the arrow-points
4182 (if (artist-funcall arrow-pred)
4183 (artist-funcall arrow-set-fn artist-key-poly-point-list)
4184 (artist-clear-arrow-points))
4186 (artist-funcall exit-fn artist-key-poly-point-list)
4188 ;; Change state to not drawing
4189 (setq artist-key-shape nil)
4190 (setq artist-key-endpoint1 nil)
4191 (setq artist-key-is-drawing nil)))))))
4194 (defun artist-key-set-point-1point (x y)
4195 "Set point for current 1-point shape at X,Y."
4196 (let ((draw-fn (artist-go-get-draw-fn-from-symbol artist-curr-go))
4197 (init-fn (artist-go-get-init-fn-from-symbol artist-curr-go))
4198 (prep-fill-fn (artist-go-get-prep-fill-fn-from-symbol artist-curr-go))
4199 (exit-fn (artist-go-get-exit-fn-from-symbol artist-curr-go))
4200 (draw-fn (artist-go-get-draw-fn-from-symbol artist-curr-go))
4201 (arrow-pred (artist-go-get-arrow-pred-from-symbol artist-curr-go))
4202 (arrow-set-fn (artist-go-get-arrow-set-fn-from-symbol artist-curr-go)))
4203 (artist-funcall init-fn x y)
4204 (artist-funcall draw-fn x y)
4205 (artist-funcall prep-fill-fn x y)
4206 (if (artist-funcall arrow-pred)
4207 (artist-funcall arrow-set-fn x y)
4208 (artist-clear-arrow-points))
4209 (artist-funcall exit-fn x y))
4210 (setq artist-key-shape nil)
4211 (setq artist-key-is-drawing nil))
4214 (defun artist-key-set-point-2points (x y)
4215 "Set first or second point in current 2-point shape at X,Y."
4216 (let ((draw-fn (artist-go-get-draw-fn-from-symbol artist-curr-go))
4217 (init-fn (artist-go-get-init-fn-from-symbol artist-curr-go))
4218 (prep-fill-fn (artist-go-get-prep-fill-fn-from-symbol artist-curr-go))
4219 (exit-fn (artist-go-get-exit-fn-from-symbol artist-curr-go))
4220 (fill-pred (artist-go-get-fill-pred-from-symbol artist-curr-go))
4221 (fill-fn (artist-go-get-fill-fn-from-symbol artist-curr-go))
4222 (arrow-pred (artist-go-get-arrow-pred-from-symbol artist-curr-go))
4223 (arrow-set-fn (artist-go-get-arrow-set-fn-from-symbol artist-curr-go)))
4224 (if (not artist-key-is-drawing)
4226 ;; *** We were not drawing ==> set first point
4227 (progn
4229 (artist-funcall init-fn x y)
4231 ;; If not rubber-banding, set first point.
4232 ;; Otherwise, draw the shape from x,y to x,y
4233 (if (not artist-rubber-banding)
4234 (artist-no-rb-set-point1 x y)
4235 (setq artist-key-shape (artist-funcall draw-fn x y x y)))
4237 ;; Set first endpoint
4238 (setq artist-key-endpoint1 (artist-make-endpoint x y))
4240 ;; Since we are not ready, clear the arrow-points
4241 (artist-clear-arrow-points)
4243 ;; Change state to drawing
4244 (setq artist-key-is-drawing t))
4246 ;; *** We were drawing ==> we are about to set 2nd point
4247 ;; and end the drawing operation
4249 (let ((x1 (artist-endpoint-get-x artist-key-endpoint1))
4250 (y1 (artist-endpoint-get-y artist-key-endpoint1))
4251 (x2 x)
4252 (y2 y))
4254 ;; If not rubber-banding, undraw the 1's and 2's, then
4255 ;; draw the shape (if we were rubber-banding, then the
4256 ;; shape is already drawn in artist-key-do-continously-2points.)
4258 (if (not artist-rubber-banding)
4259 (progn
4260 (artist-no-rb-unset-points)
4261 (setq artist-key-shape (artist-funcall draw-fn x1 y1 x2 y2))))
4263 (artist-funcall prep-fill-fn artist-key-shape x1 y1 x2 y2)
4265 ;; Maybe fill
4267 (if (artist-funcall fill-pred)
4268 (artist-funcall fill-fn artist-key-shape x1 y1 x2 y2))
4270 ;; Maybe set the arrow-points
4272 (if (artist-funcall arrow-pred)
4273 (artist-funcall arrow-set-fn artist-key-shape x1 y1 x2 y2)
4274 (artist-clear-arrow-points))
4276 (artist-funcall exit-fn artist-key-shape x1 y1 x2 y2)
4278 ;; Change state to not drawing
4279 (setq artist-key-is-drawing nil)))))
4282 (defun artist-key-set-point-common (arg)
4283 "Common routine for setting point in current shape.
4284 With non-nil ARG, set the last point."
4285 (let ((draw-how (artist-go-get-draw-how-from-symbol artist-curr-go))
4286 (col (artist-current-column))
4287 (row (artist-current-line))
4288 (was-drawing artist-key-is-drawing))
4290 ;; First, if we are about to draw, then reset the draw-region
4291 (if (not artist-key-is-drawing)
4292 (artist-draw-region-reset))
4294 ;; Depending on what we are currently drawing, call other routines
4295 ;; that knows how to do the job
4297 (cond ((eq draw-how 'artist-do-continously)
4298 (artist-key-set-point-continously col row)
4299 ;; Do this now, otherwise nothing will happen until we move.
4300 (artist-key-do-continously-continously col row))
4301 ((eq draw-how 'artist-do-poly)
4302 (artist-key-set-point-poly col row arg))
4303 ((and (numberp draw-how) (= draw-how 1))
4304 (artist-key-set-point-1point col row))
4305 ((and (numberp draw-how) (= draw-how 2))
4306 (artist-key-set-point-2points col row))
4307 (t (message "Drawing \"%s\"s is not yet implemented" draw-how)))
4309 ;; Maybe trim line endings
4310 (if (and artist-trim-line-endings
4311 was-drawing
4312 (not artist-key-is-drawing))
4313 (artist-draw-region-trim-line-endings artist-draw-region-min-y
4314 artist-draw-region-max-y))
4316 ;; Now restore the old position
4318 (artist-move-to-xy col row)
4319 (artist-mode-line-show-curr-operation artist-key-is-drawing)))
4322 ;; Key navigation
4325 (defun artist-previous-line (&optional n)
4326 "Move cursor up optional N lines (default is 1), updating current shape.
4327 If N is negative, move cursor down."
4328 (interactive "p")
4329 (let ((col (artist-current-column)))
4330 (if (not artist-key-is-drawing)
4331 (progn
4332 (previous-line n)
4333 (move-to-column col t))
4334 (previous-line n)
4335 (move-to-column col t)
4336 (artist-key-do-continously-common))))
4339 (defun artist-next-line (&optional n)
4340 "Move cursor down optional N lines (default is 1), updating current shape.
4341 If N is negative, move cursor up."
4342 (interactive "p")
4343 (let ((col (artist-current-column)))
4344 (if (not artist-key-is-drawing)
4345 (progn
4346 (next-line n)
4347 (move-to-column col t))
4348 (next-line n)
4349 (move-to-column col t)
4350 (artist-key-do-continously-common))))
4352 (defun artist-backward-char (&optional n)
4353 "Move cursor backward optional N chars (default is 1), updating curr shape.
4354 If N is negative, move forward."
4355 (interactive "p")
4356 (if (> n 0)
4357 (artist-forward-char (- n))
4358 (artist-forward-char n)))
4360 (defun artist-forward-char (&optional n)
4361 "Move cursor forward optional N chars (default is 1), updating curr shape.
4362 If N is negative, move backward."
4363 (interactive "p")
4364 (let* ((step-x (if (>= n 0) 1 -1))
4365 (distance (abs n))
4366 (curr-col (artist-current-column))
4367 (new-col (max 0 (+ curr-col (* distance step-x)))))
4368 (if (not artist-key-is-drawing)
4369 (move-to-column new-col t)
4370 (move-to-column new-col t)
4371 (artist-key-do-continously-common))))
4374 (defun artist-key-set-point (&optional arg)
4375 "Set a point for the current shape. With optional ARG, set the last point."
4376 (interactive "P")
4377 (artist-key-set-point-common arg))
4380 (defun artist-select-fill-char (c)
4381 "Set current fill character to be C."
4382 (interactive "cType fill char (type RET to turn off): ")
4383 (cond ((eq c ?\r) (setq artist-fill-char-set nil)
4384 (message "Fill cancelled"))
4385 (t (setq artist-fill-char-set t)
4386 (setq artist-fill-char c)
4387 (message "Fill set to \"%c\"" c))))
4390 (defun artist-select-line-char (c)
4391 "Set current line character to be C."
4392 (interactive "cType line char (type RET to turn off): ")
4393 (cond ((eq c ?\r) (setq artist-line-char-set nil)
4394 (message "Normal lines"))
4395 (t (setq artist-line-char-set t)
4396 (setq artist-line-char c)
4397 (message "Line drawn with \"%c\"" c)))
4398 (if artist-key-is-drawing
4399 (artist-key-do-continously-common)))
4402 (defun artist-select-erase-char (c)
4403 "Set current erase character to be C."
4404 (interactive "cType char to use when erasing (type RET for normal): ")
4405 (cond ((eq c ?\r) (setq artist-erase-char ?\ )
4406 (message "Normal erasing"))
4407 (t (setq artist-erase-char c)
4408 (message "Erasing with \"%c\"" c)))
4409 (if artist-key-is-drawing
4410 (artist-key-do-continously-common)))
4412 (defun artist-charlist-to-string (char-list)
4413 "Convert a list of characters, CHAR-LIST, to a string."
4414 (let ((result ""))
4415 (while (not (null char-list))
4416 (setq result (concat result (char-to-string (car char-list))))
4417 (setq char-list (cdr char-list)))
4418 result))
4420 (defun artist-string-to-charlist (str)
4421 "Convert a string, STR, to list of characters."
4422 (append str nil))
4424 (defun artist-select-spray-chars (chars initial-char)
4425 "Set current spray characters to be CHARS, starting with INITIAL-CHAR."
4426 ;; This huge unreadable `interactive'-clause does the following
4427 ;; 1. Asks for a string of spray-characters
4428 ;; 2. Asks for the initial character (default is the first),
4429 ;; and loops if the answer is not a char within the string in 1.
4430 (interactive
4431 (let* ((str (read-string "Select spray-can characters, lightest first: "
4432 (artist-charlist-to-string artist-spray-chars)))
4433 (char-list (artist-string-to-charlist str))
4434 (initial (let* ((err-msg "")
4435 (ok nil)
4436 (first-char-as-str (char-to-string (car char-list)))
4437 (first-s) (first-c))
4438 (while (not ok)
4439 (setq first-s
4440 (read-string
4441 (format (concat "%sSelect initial-character, "
4442 "one of \"%s\" (%s): ")
4443 err-msg str first-char-as-str)))
4444 (if (equal first-s "")
4445 (setq first-s first-char-as-str))
4446 (setq first-c (car (artist-string-to-charlist first-s)))
4447 (setq ok (not (null (member first-c char-list))))
4448 (if (not ok)
4449 (setq err-msg (format
4450 "Not in spray-chars: \"%s\". "
4451 (char-to-string first-c)))))
4452 first-c)))
4453 (list char-list initial)))
4454 (setq artist-spray-chars chars)
4455 (setq artist-spray-new-char initial-char)
4456 (message "Spray-chars set to \"%s\", initial: \"%s\""
4457 (artist-charlist-to-string chars) (char-to-string initial-char)))
4460 (defun artist-select-operation (op-str)
4461 "Select drawing operation OP-STR."
4462 (interactive (list (completing-read "Select operation: "
4463 artist-key-compl-table)))
4464 (let* ((op-symbol (artist-mt-get-symbol-from-keyword op-str))
4465 (draw-how (if op-symbol
4466 (artist-go-get-draw-how-from-symbol op-symbol)
4467 nil)))
4468 ;; First check that the string was valid
4469 (if (null op-symbol)
4470 (error "Unknown drawing method: %s" op-str))
4472 ;; Second, check that we are not about to switch to a different
4473 ;; kind of shape (do that only if we are drawing with keys;
4474 ;; otherwise this function cannot get called).
4475 (if (and artist-key-is-drawing
4476 (not (equal artist-key-draw-how draw-how)))
4477 (error "Cannot switch to a different kind of shape while drawing"))
4479 ;; If we were drawing, undraw the shape
4480 (if (and artist-key-is-drawing
4481 artist-rubber-banding)
4482 (artist-key-undraw-common))
4484 ;; Set the current operation and draw-how
4485 (setq artist-curr-go op-symbol)
4486 (setq artist-key-draw-how draw-how)
4488 ;; If we were drawing, redraw the shape (but don't if shape
4489 ;; is drawn by setting only one point)
4490 (if (and artist-key-is-drawing
4491 artist-rubber-banding
4492 (not (eq artist-key-draw-how 1)))
4493 (artist-key-draw-common)))
4495 ;; Feedback
4496 (artist-mode-line-show-curr-operation artist-key-is-drawing))
4499 (defun artist-toggle-rubber-banding (&optional state)
4500 "Toggle rubber-banding.
4501 If optional argument STATE is positive, turn rubber-banding on."
4502 (interactive)
4503 (if artist-key-is-drawing
4504 (error "Cannot toggle rubber-banding while drawing"))
4505 (if (setq artist-rubber-banding
4506 (if (null state) (not artist-rubber-banding)
4507 (> (prefix-numeric-value state) 0)))
4508 (message "Rubber-banding is now on")
4509 (message "Rubber-banding is now off")))
4512 (defun artist-toggle-trim-line-endings (&optional state)
4513 "Toggle trimming of line-endings.
4514 If optional argument STATE is positive, turn trimming on."
4515 (interactive)
4516 (if (setq artist-trim-line-endings
4517 (if (null state) (not artist-trim-line-endings)
4518 (> (prefix-numeric-value state) 0)))
4519 (message "Trimming is now on")
4520 (message "Trimming is now off")))
4523 (defun artist-toggle-borderless-shapes (&optional state)
4524 "Toggle borders of shapes.
4525 If optional argument STATE is positive, turn borders on."
4526 (interactive)
4527 (if (setq artist-borderless-shapes
4528 (if (null state) (not artist-borderless-shapes)
4529 (> (prefix-numeric-value state) 0)))
4530 (message "Borders are now off")
4531 (message "Borders are now on")))
4534 (defun artist-toggle-first-arrow ()
4535 "Toggle first arrow for shape, if possible."
4536 (interactive)
4537 (save-excursion
4538 (if (not (null artist-arrow-point-1))
4539 (let* ((arrow-point artist-arrow-point-1)
4540 (arrow-state (artist-arrow-point-get-state arrow-point))
4541 (arrow-marker (artist-arrow-point-get-marker arrow-point))
4542 (direction (artist-arrow-point-get-direction arrow-point))
4543 (orig-char (artist-arrow-point-get-orig-char arrow-point))
4544 (arrow-char (aref artist-arrows direction))
4545 (new-state (not arrow-state)))
4547 (goto-char (marker-position arrow-marker))
4549 (if new-state
4550 (if arrow-char
4551 (artist-replace-char arrow-char))
4552 (artist-replace-char orig-char))
4554 (artist-arrow-point-set-state artist-arrow-point-1 new-state)))))
4556 (defun artist-toggle-second-arrow ()
4557 "Toggle second arrow for shape, if possible."
4558 (interactive)
4559 (save-excursion
4560 (if (not (null artist-arrow-point-2))
4561 (let* ((arrow-point artist-arrow-point-2)
4562 (arrow-state (artist-arrow-point-get-state arrow-point))
4563 (arrow-marker (artist-arrow-point-get-marker arrow-point))
4564 (direction (artist-arrow-point-get-direction arrow-point))
4565 (orig-char (artist-arrow-point-get-orig-char arrow-point))
4566 (arrow-char (aref artist-arrows direction))
4567 (new-state (not arrow-state)))
4569 (goto-char (marker-position arrow-marker))
4571 (if new-state
4572 (if arrow-char
4573 (artist-replace-char arrow-char))
4574 (artist-replace-char orig-char))
4576 (artist-arrow-point-set-state artist-arrow-point-2 new-state)))))
4579 (defun artist-select-op-line ()
4580 "Select drawing lines."
4581 (interactive)
4582 (artist-select-operation "line"))
4584 (defun artist-select-op-straight-line ()
4585 "Select drawing straight lines."
4586 (interactive)
4587 (artist-select-operation "straight line"))
4589 (defun artist-select-op-rectangle ()
4590 "Select drawing rectangles."
4591 (interactive)
4592 (artist-select-operation "rectangle"))
4594 (defun artist-select-op-square ()
4595 "Select drawing squares."
4596 (interactive)
4597 (artist-select-operation "square"))
4599 (defun artist-select-op-poly-line ()
4600 "Select drawing poly-lines."
4601 (interactive)
4602 (artist-select-operation "poly-line"))
4604 (defun artist-select-op-straight-poly-line ()
4605 "Select drawing straight poly-lines."
4606 (interactive)
4607 (artist-select-operation "straight poly-line"))
4609 (defun artist-select-op-ellipse ()
4610 "Select drawing ellipses."
4611 (interactive)
4612 (artist-select-operation "ellipse"))
4614 (defun artist-select-op-circle ()
4615 "Select drawing circles."
4616 (interactive)
4617 (artist-select-operation "circle"))
4619 (defun artist-select-op-text-see-thru ()
4620 "Select rendering text (see thru)."
4621 (interactive)
4622 (artist-select-operation "text see-thru"))
4624 (defun artist-select-op-text-overwrite ()
4625 "Select rendering text (overwrite)."
4626 (interactive)
4627 (artist-select-operation "text overwrite"))
4629 (defun artist-select-op-spray-can ()
4630 "Select spraying."
4631 (interactive)
4632 (artist-select-operation "spray-can"))
4634 (defun artist-select-op-spray-set-size ()
4635 "Select setting size for spraying."
4636 (interactive)
4637 (artist-select-operation "spray set size"))
4639 (defun artist-select-op-erase-char ()
4640 "Select erasing characters."
4641 (interactive)
4642 (artist-select-operation "erase char"))
4644 (defun artist-select-op-erase-rectangle ()
4645 "Select erasing rectangles."
4646 (interactive)
4647 (artist-select-operation "erase rectangle"))
4649 (defun artist-select-op-vaporize-line ()
4650 "Select vaporizing single lines."
4651 (interactive)
4652 (artist-select-operation "vaporize line"))
4654 (defun artist-select-op-vaporize-lines ()
4655 "Select vaporizing connected lines."
4656 (interactive)
4657 (artist-select-operation "vaporize lines"))
4659 (defun artist-select-op-cut-rectangle ()
4660 "Select cutting rectangles."
4661 (interactive)
4662 (artist-select-operation "cut rectangle"))
4664 (defun artist-select-op-cut-square ()
4665 "Select cutting squares."
4666 (interactive)
4667 (artist-select-operation "cut square"))
4669 (defun artist-select-op-copy-rectangle ()
4670 "Select copying rectangles."
4671 (interactive)
4672 (artist-select-operation "copy rectangle"))
4674 (defun artist-select-op-copy-square ()
4675 "Select copying squares."
4676 (interactive)
4677 (artist-select-operation "cut square"))
4679 (defun artist-select-op-paste ()
4680 "Select pasting."
4681 (interactive)
4682 (artist-select-operation "paste"))
4684 (defun artist-select-op-flood-fill ()
4685 "Select flood-filling."
4686 (interactive)
4687 (artist-select-operation "flood-fill"))
4690 ;; Drawing lines by using mouse
4691 ;; Mouse button actions
4694 (defun artist-update-pointer-shape ()
4695 "Perform the update of the X Windows pointer shape."
4696 (set-mouse-color nil))
4698 (defun artist-set-pointer-shape (new-pointer-shape)
4699 "Set the shape of the X Windows pointer to NEW-POINTER-SHAPE."
4700 (setq x-pointer-shape new-pointer-shape)
4701 (artist-update-pointer-shape))
4703 (defsubst artist-event-is-shifted (ev)
4704 "Check whether the shift-key is pressed in event EV."
4705 (memq 'shift (event-modifiers ev)))
4707 (defun artist-do-nothing ()
4708 "Function that does nothing."
4709 (interactive))
4711 (defun artist-down-mouse-1 (ev)
4712 "Perform drawing action for event EV."
4713 (interactive "@e")
4714 (let* ((real (artist-go-get-symbol-shift
4715 artist-curr-go (artist-event-is-shifted ev)))
4716 (draw-how (artist-go-get-draw-how-from-symbol real))
4717 ;; Remember original values for draw-region-min-y and max-y
4718 ;; in case we are interrupting a key-draw operation.
4719 (orig-draw-region-min-y artist-draw-region-min-y)
4720 (orig-draw-region-max-y artist-draw-region-max-y)
4721 (orig-pointer-shape (if (eq window-system 'x) x-pointer-shape nil))
4722 (echo-keystrokes 10000) ; a lot of seconds
4723 ;; Remember original binding for the button-up event to this
4724 ;; button-down event.
4725 (key (let* ((basic (event-basic-type ev))
4726 (unshifted basic)
4727 (shifted (make-symbol (concat "S-" (symbol-name basic)))))
4728 (if (artist-event-is-shifted ev)
4729 (make-vector 1 shifted)
4730 (make-vector 1 unshifted))))
4731 (orig-button-up-binding (lookup-key (current-global-map) key)))
4733 (unwind-protect
4734 (progn
4735 (if (eq window-system 'x)
4736 (artist-set-pointer-shape artist-pointer-shape))
4738 ;; Redefine the button-up binding temporarily (the original
4739 ;; binding is restored in the unwind-forms below). This is to
4740 ;; avoid the phenomenon outlined in this scenario:
4742 ;; 1. A routine which reads something from the mini-buffer (such
4743 ;; as the text renderer) is called from below.
4744 ;; 2. Meanwhile, the users releases the mouse button.
4745 ;; 3. As a (funny :-) coincidence, the binding for the
4746 ;; button-up event is often mouse-set-point, so Emacs
4747 ;; sets the point to where the button was released, which is
4748 ;; in the buffer where the user wants to place the text.
4749 ;; 4. The user types C-x o (or uses the mouse once again)
4750 ;; until he reaches the mini-buffer which is still prompting
4751 ;; for some text to render.
4753 ;; To do this foolproof, all local and minor-mode maps should
4754 ;; be searched and temporarily changed as well, since they
4755 ;; too might have some binding for the button-up event,
4756 ;; but I hope dealing with the global map will suffice.
4757 (define-key (current-global-map) key 'artist-do-nothing)
4759 (artist-draw-region-reset)
4761 (artist-mode-line-show-curr-operation t)
4763 (cond ((eq draw-how 'artist-do-continously)
4764 (artist-mouse-draw-continously ev))
4765 ((eq draw-how 'artist-do-poly)
4766 (artist-mouse-draw-poly ev))
4767 ((and (numberp draw-how) (= draw-how 1))
4768 (artist-mouse-draw-1point ev))
4769 ((and (numberp draw-how) (= draw-how 2))
4770 (artist-mouse-draw-2points ev))
4771 (t (message "Drawing \"%s\"s is not yet implemented"
4772 draw-how)))
4774 (if artist-trim-line-endings
4775 (artist-draw-region-trim-line-endings artist-draw-region-min-y
4776 artist-draw-region-max-y))
4777 (setq artist-draw-region-min-y orig-draw-region-min-y)
4778 (setq artist-draw-region-max-y orig-draw-region-max-y))
4780 ; This is protected
4781 (if (eq window-system 'x)
4782 (artist-set-pointer-shape orig-pointer-shape))
4784 (if orig-button-up-binding
4785 (define-key (current-global-map) key orig-button-up-binding))
4787 (artist-mode-line-show-curr-operation artist-key-is-drawing))))
4790 (defun artist-mouse-choose-operation (ev op)
4791 "Choose operation for event EV and operation OP."
4792 (interactive
4793 (progn
4794 (select-window (posn-window (event-start last-input-event)))
4795 (list last-input-event
4796 (x-popup-menu last-nonmenu-event artist-popup-menu-table))))
4798 (let ((draw-fn (artist-go-get-draw-fn-from-symbol (car op)))
4799 (set-fn (artist-fc-get-fn-from-symbol (car op))))
4800 (cond
4802 ;; *** It was a draw-function
4803 ((not (listp draw-fn))
4804 (let* ((unshifted (artist-go-get-symbol-shift (car op) nil))
4805 (shifted (artist-go-get-symbol-shift (car op) t))
4806 (shift-state (artist-event-is-shifted ev))
4807 (selected-op (if shift-state shifted unshifted))
4808 (keyword (artist-go-get-keyword-from-symbol selected-op)))
4809 (artist-select-operation keyword)))
4811 ;; *** It was a set/unset function
4812 ((not (listp set-fn))
4813 (call-interactively set-fn)))))
4816 (defun artist-down-mouse-3 (ev)
4817 "Erase character or rectangle, depending on event EV."
4818 (interactive "@e")
4819 (let ((artist-curr-go 'erase-char))
4820 (artist-down-mouse-1 ev))
4821 ;; Restore mode-line
4822 (artist-mode-line-show-curr-operation artist-key-is-drawing))
4826 ;; Mouse routines
4829 (defsubst artist-shift-has-changed (shift-state ev)
4830 "From the last SHIFT-STATE and EV, determine if the shift-state has changed."
4831 ;; This one simply doesn't work.
4833 ;; There seems to be no way to tell whether the user has pressed shift
4834 ;; while dragging the cursor around when we are in a track-mouse
4835 ;; form. Calling (event-modifiers ev) yields nil :-( Neither is the
4836 ;; (event-basic-type ev) of any help (it is simply `mouse-movement').
4838 ;; So this doesn't work:
4839 ;; (cond ((and shift-state (not (artist-event-is-shifted ev))) t)
4840 ;; ((and (not shift-state) (artist-event-is-shifted ev)) t)
4841 ;; (t nil))
4842 nil)
4844 (defun artist-coord-win-to-buf (coord)
4845 "Convert a window-relative coordinate COORD to a buffer-relative coordinate."
4846 (let ((window-x (car coord))
4847 (window-y (cdr coord))
4848 (window-start-x (window-hscroll))
4849 (window-start-y (save-excursion (goto-char (window-start))
4850 (artist-current-line))))
4851 (cons (+ window-x window-start-x)
4852 (+ window-y window-start-y))))
4855 (defun artist-mouse-draw-continously (ev)
4856 "Generic function for shapes that requires 1 point as input.
4857 Operation is done continously while the mouse button is hold down.
4858 The event, EV, is the mouse event."
4859 (let* ((unshifted (artist-go-get-symbol-shift artist-curr-go nil))
4860 (shifted (artist-go-get-symbol-shift artist-curr-go t))
4861 (shift-state (artist-event-is-shifted ev))
4862 (op (if shift-state shifted unshifted))
4863 (draw-how (artist-go-get-draw-how-from-symbol op))
4864 (init-fn (artist-go-get-init-fn-from-symbol op))
4865 (prep-fill-fn (artist-go-get-prep-fill-fn-from-symbol op))
4866 (exit-fn (artist-go-get-exit-fn-from-symbol op))
4867 (draw-fn (artist-go-get-draw-fn-from-symbol op))
4868 (interval-fn (artist-go-get-interval-fn-from-symbol op))
4869 (interval (artist-funcall interval-fn))
4870 (arrow-pred (artist-go-get-arrow-pred-from-symbol op))
4871 (arrow-set-fn (artist-go-get-arrow-set-fn-from-symbol op))
4872 (ev-start (event-start ev))
4873 (initial-win (posn-window ev-start))
4874 (ev-start-pos (artist-coord-win-to-buf (posn-col-row ev-start)))
4875 (x1 (car ev-start-pos))
4876 (y1 (cdr ev-start-pos))
4877 (shape)
4878 (timer))
4879 (select-window (posn-window ev-start))
4880 (artist-funcall init-fn x1 y1)
4881 (if (not artist-rubber-banding)
4882 (artist-no-rb-set-point1 x1 y1))
4883 (track-mouse
4884 (while (or (mouse-movement-p ev)
4885 (member 'down (event-modifiers ev)))
4886 (setq ev-start-pos (artist-coord-win-to-buf
4887 (posn-col-row (event-start ev))))
4888 (setq x1 (car ev-start-pos))
4889 (setq y1 (cdr ev-start-pos))
4891 ;; Cancel previous timer
4892 (if timer
4893 (cancel-timer timer))
4895 (if (not (eq initial-win (posn-window (event-start ev))))
4896 ;; If we moved outside the window, do nothing
4899 ;; Still in same window:
4901 ;; Check if user presses or releases shift key
4902 (if (artist-shift-has-changed shift-state ev)
4904 ;; First check that the draw-how is the same as we
4905 ;; already have. Otherwise, ignore the changed shift-state.
4906 (if (not (eq draw-how
4907 (artist-go-get-draw-how-from-symbol
4908 (if (not shift-state) shifted unshifted))))
4909 (message "Cannot switch to shifted operation")
4911 ;; progn is "implicit" since this is the else-part
4912 (setq shift-state (not shift-state))
4913 (setq op (if shift-state shifted unshifted))
4914 (setq draw-how (artist-go-get-draw-how-from-symbol op))
4915 (setq draw-fn (artist-go-get-draw-fn-from-symbol op))))
4917 ;; Draw the new shape
4918 (setq shape (artist-funcall draw-fn x1 y1))
4919 (artist-move-to-xy x1 y1)
4921 ;; Start the timer to call `draw-fn' repeatedly every
4922 ;; `interval' second
4923 (if (and interval draw-fn)
4924 (setq timer (run-at-time interval interval draw-fn x1 y1))))
4926 ;; Read next event
4927 (setq ev (read-event))))
4929 ;; Cancel any timers
4930 (if timer
4931 (cancel-timer timer))
4933 (artist-funcall prep-fill-fn x1 y1)
4935 (if (artist-funcall arrow-pred)
4936 (artist-funcall arrow-set-fn x1 y1)
4937 (artist-clear-arrow-points))
4939 (artist-funcall exit-fn x1 y1)
4940 (artist-move-to-xy x1 y1)))
4944 (defun artist-mouse-draw-poly (ev)
4945 "Generic function for shapes requiring several points as input.
4946 The event, EV, is the mouse event."
4947 (interactive "@e")
4948 (message "Mouse-1: set new point, mouse-2: set last point")
4949 (let* ((unshifted (artist-go-get-symbol-shift artist-curr-go nil))
4950 (shifted (artist-go-get-symbol-shift artist-curr-go t))
4951 (shift-state (artist-event-is-shifted ev))
4952 (op (if shift-state shifted unshifted))
4953 (draw-how (artist-go-get-draw-how-from-symbol op))
4954 (init-fn (artist-go-get-init-fn-from-symbol op))
4955 (prep-fill-fn (artist-go-get-prep-fill-fn-from-symbol op))
4956 (exit-fn (artist-go-get-exit-fn-from-symbol op))
4957 (draw-fn (artist-go-get-draw-fn-from-symbol op))
4958 (undraw-fn (artist-go-get-undraw-fn-from-symbol op))
4959 (fill-pred (artist-go-get-fill-pred-from-symbol op))
4960 (fill-fn (artist-go-get-fill-fn-from-symbol op))
4961 (arrow-pred (artist-go-get-arrow-pred-from-symbol op))
4962 (arrow-set-fn (artist-go-get-arrow-set-fn-from-symbol op))
4963 (ev-start (event-start ev))
4964 (initial-win (posn-window ev-start))
4965 (ev-start-pos (artist-coord-win-to-buf (posn-col-row ev-start)))
4966 (x1-last (car ev-start-pos))
4967 (y1-last (cdr ev-start-pos))
4968 (x2 x1-last)
4969 (y2 y1-last)
4970 (is-down t)
4971 (shape nil)
4972 (point-list nil)
4973 (done nil))
4974 (select-window (posn-window ev-start))
4975 (artist-funcall init-fn x1-last y1-last)
4976 (if (not artist-rubber-banding)
4977 (artist-no-rb-set-point1 x1-last y1-last))
4978 (track-mouse
4979 (while (not done)
4980 ;; decide what to do
4981 (cond
4983 ;; *** Mouse button is released.
4984 ((and is-down
4985 (or (member 'click (event-modifiers ev))
4986 (member 'drag (event-modifiers ev))))
4987 ;; First, if not rubber-banding, draw the line.
4989 (if (not artist-rubber-banding)
4990 (progn
4991 (artist-no-rb-unset-points)
4992 (setq shape (artist-funcall draw-fn x1-last y1-last x2 y2))))
4994 ;; Set the second point to the shape's second point
4995 ;; (which might be different from the mouse's second point,
4996 ;; if, for example, we are drawing a straight line)
4998 (if (not (null shape))
4999 (let ((endpoint2 (artist-2point-get-endpoint2 shape)))
5000 (setq x1-last (artist-endpoint-get-x endpoint2))
5001 (setq y1-last (artist-endpoint-get-y endpoint2))))
5002 (setq point-list (cons (artist-make-endpoint x1-last y1-last)
5003 point-list))
5004 (setq shape nil)
5005 (setq is-down nil))
5007 ;; *** Mouse button 2 or 3 down
5008 ((and (member 'down (event-modifiers ev))
5009 (or (equal (event-basic-type ev) 'mouse-2)
5010 (equal (event-basic-type ev) 'mouse-3)))
5011 ;; Ignore
5012 nil)
5014 ;; *** Mouse button 2 or 3 released
5015 ((and (or (member 'click (event-modifiers ev))
5016 (member 'drag (event-modifiers ev)))
5017 (or (equal (event-basic-type ev) 'mouse-2)
5018 (equal (event-basic-type ev) 'mouse-3)))
5020 ;; This means the end of our poly-line drawing-session.
5022 (setq done t))
5024 ;; *** Mouse button 1 went down
5025 ((and (not is-down)
5026 (member 'down (event-modifiers ev))
5027 (equal (event-basic-type ev) 'mouse-1))
5028 ;; Check whether the (possibly new, that depends on if shift
5029 ;; has been pressed or released) symbol has the same draw-how
5030 ;; information as the previous had. If it hasn't, we can't
5031 ;; proceed.
5033 (if (not (eq draw-how
5034 (artist-go-get-draw-how-from-symbol
5035 (if (not shift-state) shifted unshifted))))
5036 (message "Cannot switch operation")
5037 (progn
5038 ;; Decide operation
5040 (setq unshifted
5041 (artist-go-get-symbol-shift artist-curr-go nil)
5042 shifted
5043 (artist-go-get-symbol-shift artist-curr-go t)
5044 shift-state (artist-event-is-shifted ev)
5045 op (if shift-state shifted unshifted)
5046 draw-how (artist-go-get-draw-how-from-symbol op)
5047 draw-fn (artist-go-get-draw-fn-from-symbol op)
5048 undraw-fn (artist-go-get-undraw-fn-from-symbol op)
5049 fill-pred (artist-go-get-fill-pred-from-symbol op)
5050 fill-fn (artist-go-get-fill-fn-from-symbol op))
5052 ;; Draw shape from last place to this place
5054 ;; set x2 and y2
5056 (setq ev-start-pos (artist-coord-win-to-buf
5057 (posn-col-row (event-start ev))))
5058 (setq x2 (car ev-start-pos))
5059 (setq y2 (cdr ev-start-pos))
5061 ;; Draw the new shape (if not rubber-banding, place both marks)
5063 (if artist-rubber-banding
5064 (setq shape (artist-funcall draw-fn x1-last y1-last x2 y2))
5065 (progn
5066 (artist-no-rb-set-point1 x1-last y1-last)
5067 (artist-no-rb-set-point2 x2 y2)))
5069 ;; Show new operation in mode-line
5070 (let ((artist-curr-go op))
5071 (artist-mode-line-show-curr-operation t))))
5073 (setq is-down t))
5076 ;; *** Mouse moved, button is down and we are still in orig window
5077 ((and (mouse-movement-p ev)
5078 is-down
5079 (eq initial-win (posn-window (event-start ev))))
5080 ;; Draw shape from last place to this place
5082 ;; set x2 and y2
5083 (setq ev-start-pos (artist-coord-win-to-buf
5084 (posn-col-row (event-start ev))))
5085 (setq x2 (car ev-start-pos))
5086 (setq y2 (cdr ev-start-pos))
5088 ;; First undraw last shape
5089 ;; (unset last point if not rubberbanding)
5091 (artist-funcall undraw-fn shape)
5093 ;; Draw the new shape (if not rubberbanding, set 2nd mark)
5095 (if artist-rubber-banding
5096 (setq shape (artist-funcall draw-fn x1-last y1-last x2 y2))
5097 (progn
5098 (artist-no-rb-unset-point2)
5099 (artist-no-rb-set-point2 x2 y2)))
5100 ;; Move cursor
5101 (artist-move-to-xy x2 y2))
5103 ;; *** Mouse moved, button is down but we are NOT in orig window
5104 ((and (mouse-movement-p ev)
5105 is-down
5106 (not (eq initial-win (posn-window (event-start ev)))))
5107 ;; Ignore
5108 nil)
5111 ;; *** Moving mouse while mouse button is not down
5112 ((and (mouse-movement-p ev) (not is-down))
5113 ;; don't do anything.
5114 nil)
5117 ;; *** Mouse button 1 went down, first time
5118 ((and is-down
5119 (member 'down (event-modifiers ev))
5120 (equal (event-basic-type ev) 'mouse-1))
5121 ;; don't do anything
5122 nil)
5125 ;; *** Another event
5127 ;; End drawing
5129 (setq done t)))
5131 ;; Read next event (only if we should not stop)
5132 (if (not done)
5133 (setq ev (read-event)))))
5135 ;; Reverse point-list (last points are cond'ed first)
5136 (setq point-list (reverse point-list))
5138 (artist-funcall prep-fill-fn point-list)
5140 ;; Maybe fill
5141 (if (artist-funcall fill-pred)
5142 (artist-funcall fill-fn point-list))
5144 ;; Maybe set arrow points
5145 (if (and point-list (artist-funcall arrow-pred))
5146 (artist-funcall arrow-set-fn point-list)
5147 (artist-clear-arrow-points))
5149 (artist-funcall exit-fn point-list)
5150 (artist-move-to-xy x2 y2)))
5153 (defun artist-mouse-draw-1point (ev)
5154 "Generic function for shapes requiring only 1 point as input.
5155 Operation is done once. The event, EV, is the mouse event."
5156 (interactive "@e")
5157 (let* ((unshifted (artist-go-get-symbol-shift artist-curr-go nil))
5158 (shifted (artist-go-get-symbol-shift artist-curr-go t))
5159 (shift-state (artist-event-is-shifted ev))
5160 (op (if shift-state shifted unshifted))
5161 (draw-how (artist-go-get-draw-how-from-symbol op))
5162 (init-fn (artist-go-get-init-fn-from-symbol op))
5163 (prep-fill-fn (artist-go-get-prep-fill-fn-from-symbol op))
5164 (exit-fn (artist-go-get-exit-fn-from-symbol op))
5165 (draw-fn (artist-go-get-draw-fn-from-symbol op))
5166 (arrow-pred (artist-go-get-arrow-pred-from-symbol op))
5167 (arrow-set-fn (artist-go-get-arrow-set-fn-from-symbol op))
5168 (ev-start (event-start ev))
5169 (ev-start-pos (artist-coord-win-to-buf (posn-col-row ev-start)))
5170 (x1 (car ev-start-pos))
5171 (y1 (cdr ev-start-pos)))
5172 (select-window (posn-window ev-start))
5173 (artist-funcall init-fn x1 y1)
5174 (artist-funcall draw-fn x1 y1)
5175 (artist-funcall prep-fill-fn x1 y1)
5176 (if (artist-funcall arrow-pred)
5177 (artist-funcall arrow-set-fn x1 y1)
5178 (artist-clear-arrow-points))
5179 (artist-funcall exit-fn x1 y1)
5180 (artist-move-to-xy x1 y1)))
5183 (defun artist-mouse-draw-2points (ev)
5184 "Generic function for shapes requiring 2 points as input.
5185 The event, EV, is the mouse event."
5186 (interactive "@e")
5187 (let* ((unshifted (artist-go-get-symbol-shift artist-curr-go nil))
5188 (shifted (artist-go-get-symbol-shift artist-curr-go t))
5189 (shift-state (artist-event-is-shifted ev))
5190 (op (if shift-state shifted unshifted))
5191 (draw-how (artist-go-get-draw-how-from-symbol op))
5192 (init-fn (artist-go-get-init-fn-from-symbol op))
5193 (prep-fill-fn (artist-go-get-prep-fill-fn-from-symbol op))
5194 (exit-fn (artist-go-get-exit-fn-from-symbol op))
5195 (draw-fn (artist-go-get-draw-fn-from-symbol op))
5196 (undraw-fn (artist-go-get-undraw-fn-from-symbol op))
5197 (fill-pred (artist-go-get-fill-pred-from-symbol op))
5198 (fill-fn (artist-go-get-fill-fn-from-symbol op))
5199 (arrow-pred (artist-go-get-arrow-pred-from-symbol op))
5200 (arrow-set-fn (artist-go-get-arrow-set-fn-from-symbol op))
5201 (ev-start (event-start ev))
5202 (initial-win (posn-window ev-start))
5203 (ev-start-pos (artist-coord-win-to-buf (posn-col-row ev-start)))
5204 (x1 (car ev-start-pos))
5205 (y1 (cdr ev-start-pos))
5206 (x2)
5207 (y2)
5208 (shape))
5209 (select-window (posn-window ev-start))
5210 (artist-funcall init-fn x1 y1)
5211 (if (not artist-rubber-banding)
5212 (artist-no-rb-set-point1 x1 y1))
5213 (track-mouse
5214 (while (or (mouse-movement-p ev)
5215 (member 'down (event-modifiers ev)))
5216 (setq ev-start-pos (artist-coord-win-to-buf
5217 (posn-col-row (event-start ev))))
5218 (setq x2 (car ev-start-pos))
5219 (setq y2 (cdr ev-start-pos))
5221 (if (not (eq initial-win (posn-window (event-start ev))))
5222 ;; If we moved outside the window, do nothing
5225 ;; Still in same window:
5227 ;; First undraw last shape (unset last point if not rubberbanding)
5228 (if artist-rubber-banding
5229 (artist-funcall undraw-fn shape)
5230 (artist-no-rb-unset-point2))
5232 ;; Check if user presses or releases shift key
5233 (if (artist-shift-has-changed shift-state ev)
5235 ;; First check that the draw-how is the same as we
5236 ;; already have. Otherwise, ignore the changed shift-state.
5237 (if (not (eq draw-how
5238 (artist-go-get-draw-how-from-symbol
5239 (if (not shift-state) shifted unshifted))))
5240 (message "Cannot switch to shifted operation")
5242 (message "Switching")
5243 ;; progn is "implicit" since this is the else-part
5244 (setq shift-state (not shift-state))
5245 (setq op (if shift-state shifted unshifted))
5246 (setq draw-how (artist-go-get-draw-how-from-symbol op))
5247 (setq draw-fn (artist-go-get-draw-fn-from-symbol op))
5248 (setq undraw-fn (artist-go-get-undraw-fn-from-symbol op))
5249 (setq fill-pred (artist-go-get-fill-pred-from-symbol op))
5250 (setq fill-fn (artist-go-get-fill-fn-from-symbol op))))
5252 ;; Draw the new shape
5253 (if artist-rubber-banding
5254 (setq shape (artist-funcall draw-fn x1 y1 x2 y2))
5255 (artist-no-rb-set-point2 x2 y2))
5256 ;; Move cursor
5257 (artist-move-to-xy x2 y2))
5260 ;; Read next event
5261 (setq ev (read-event))))
5263 ;; If we are not rubber-banding (that is, we were moving around the `2')
5264 ;; draw the shape
5265 (if (not artist-rubber-banding)
5266 (progn
5267 (artist-no-rb-unset-points)
5268 (setq shape (artist-funcall draw-fn x1 y1 x2 y2))))
5270 (artist-funcall prep-fill-fn shape x1 y1 x2 y2)
5272 ;; Maybe fill
5273 (if (artist-funcall fill-pred)
5274 (artist-funcall fill-fn shape x1 y1 x2 y2))
5276 ;; Maybe set arrow-points
5277 (if (artist-funcall arrow-pred)
5278 (artist-funcall arrow-set-fn shape x1 y1 x2 y2)
5279 (artist-clear-arrow-points))
5281 (artist-funcall exit-fn shape x1 y1 x2 y2)
5282 (artist-move-to-xy x2 y2)))
5286 ;; Bug-report-submitting
5288 (defun artist-submit-bug-report ()
5289 "Submit via mail a bug report on Artist."
5290 (interactive)
5291 (require 'reporter)
5292 (if (y-or-n-p "Do you want to submit a bug report on Artist? ")
5293 (let ((to artist-maintainer-address)
5294 (vars '(window-system
5295 window-system-version
5297 artist-rubber-banding
5298 artist-interface-with-rect
5299 artist-aspect-ratio
5300 ;; Now the internal ones
5301 artist-curr-go
5302 artist-key-poly-point-list
5303 artist-key-shape
5304 artist-key-draw-how
5305 artist-arrow-point-1
5306 artist-arrow-point-2)))
5307 ;; Remove those variables from vars that are not bound
5308 (mapcar
5309 (function
5310 (lambda (x)
5311 (if (not (and (boundp x) (symbol-value x)))
5312 (setq vars (delq x vars))))) vars)
5313 (reporter-submit-bug-report
5314 artist-maintainer-address
5315 (concat "artist.el " artist-version)
5316 vars
5317 nil nil
5318 (concat "Hello Tomas,\n\n"
5319 "I have a nice bug report on Artist for you! Here it is:")))))
5323 ;; Now provide this minor mode
5326 (provide 'artist)
5329 ;;; About adding drawing modes
5330 ;;; --------------------------
5332 ;; If you are going to add a new drawing mode, read the following
5333 ;; sketchy outlines to get started a bit easier.
5335 ;; 1. If your new drawing mode falls into one of the following
5336 ;; categories, goto point 2, otherwise goto point 3.
5338 ;; - Modes where the shapes are drawn continously, as long as
5339 ;; the mouse button is held down (continous modes).
5340 ;; Example: the erase-char mode, the pen and pen-line modes.
5342 ;; - Modes where the shape is made up of from 2 points to an
5343 ;; arbitrary number of points (poly-point modes).
5344 ;; Example: the poly-line mode
5346 ;; - Modes where the shape is made up of 2 points (2-point
5347 ;; modes).
5348 ;; Example: lines, rectangles
5350 ;; - Modes where the shape is made up of 1 point (1-point
5351 ;; modes). This mode differs from the continous modes in
5352 ;; that the shape is drawn only once when the mouse button
5353 ;; is pressed.
5354 ;; Examples: paste, a flood-fill, vaporize modes
5357 ;; 2. To make it easier and more flexible to program new drawing
5358 ;; modes, you might choose to specify
5359 ;; init-fn: a function to be called at the very beginning
5360 ;; of the drawing phase,
5361 ;; prep-fill-fn: a function to be called before filling,
5362 ;; arrow-set-fn: a function for setting arrows, to be called
5363 ;; after filling, and
5364 ;; exit-fn: a function to be called at the very end of
5365 ;; the drawing phase.
5366 ;; For each of the cases below, the arguments given to the init-fn,
5367 ;; prep-fill-fn, arrow-set-fn and exit-fn are stated.
5369 ;; If your mode matches the continous mode or the 1-point mode:
5371 ;; a. Create a draw-function that draws your shape. Your function
5372 ;; must take x and y as arguments. The return value is not
5373 ;; used.
5375 ;; b. Add your mode to the master table, `artist-mt'.
5377 ;; init-fn: x y
5378 ;; prep-fill-fn: x y
5379 ;; arrow-set-fn: x y
5380 ;; exit-fn: x y
5382 ;; If your mode matches the 2-point mode:
5384 ;; a. Create one draw-function that draws your shape and one
5385 ;; undraw-function that undraws it.
5387 ;; The draw-function must take x1, y1, x2 and y2 as
5388 ;; arguments. It must return a list with three elements:
5389 ;; Endpoint1: a vector [x1 y1]
5390 ;; Endpoint2: a vector [x2 y2]
5391 ;; Shapeinfo: all info necessary for your undraw-function to
5392 ;; be able to undraw the shape
5393 ;; Use the artist-endpoint-* accessors to create and inspect
5394 ;; the endpoints.
5396 ;; If applicable, you must be able to draw your shape without
5397 ;; borders if the `artist-borderless-shapes' is non-nil.
5398 ;; See `artist-draw-rect' for an example.
5400 ;; The undraw-function must take one argument: the list created
5401 ;; by your draw-function. The return value is not used.
5403 ;; b. If you want to provide a fill-function, then create a
5404 ;; function that takes 5 arguments: the list created by your
5405 ;; draw-function, x1, y1, x2 and y2. The return value is not
5406 ;; used.
5408 ;; c. Add your mode to the master table, `artist-mt'.
5410 ;; init-fn: x1 y1
5411 ;; prep-fill-fn: shape x1 y1 x2 y2
5412 ;; arrow-set-fn: shape x1 y1 x2 y2
5413 ;; exit-fn: shape x1 y1 x2 y2
5415 ;; If your mode matches the poly-point mode:
5417 ;; a. Create one draw-function that draws your shape and one
5418 ;; undraw-function that undraws it. The draw- and
5419 ;; undraw-functions are used to draw/undraw a segment of
5420 ;; your poly-point mode between 2 points. The draw- and
5421 ;; undraw-functions are then really 2-point mode functions.
5422 ;; They must take the same arguments and return the same
5423 ;; values as those of the 2-point mode.
5425 ;; If applicable, you must be able to draw your shape without
5426 ;; borders if the `artist-borderless-shapes' is non-nil.
5427 ;; See `artist-draw-rect' for an example.
5429 ;; b. If you want to provide a fill-function, then create a
5430 ;; function that takes 1 argument: a list of points where each
5431 ;; point is a vector, [x, y].
5433 ;; c. Add your mode to the master table, `artist-mt'.
5435 ;; init-fn: x1 y1
5436 ;; prep-fill-fn: point-list
5437 ;; arrow-set-fn: point-list
5438 ;; exit-fn: point-list
5440 ;; The arrow-set-fn must set the variables `artist-arrow-point-1'
5441 ;; and `artist-arrow-point-2'. If your mode does not take arrows,
5442 ;; you must set the variables to nil. Use the accessors
5443 ;; artist-arrow-point-* to create and inspect arrow-points.
5446 ;; 3. If your mode doesn't match any of the categories, you are facing
5447 ;; a bit more work, and I cannot be as detailed as above. Here is a
5448 ;; brief outline of what you have to do:
5450 ;; a. Decide on a name for your type of mode. Let's assume that
5451 ;; you decided on `xxx'. Then you should use the draw-how
5452 ;; symbol artist-do-xxx.
5454 ;; b. Create a function artist-mouse-draw-xxx for drawing with
5455 ;; mouse. It should be called from `artist-down-mouse-1'.
5457 ;; The all coordinates must be converted from window-relative
5458 ;; to buffer relative before saved or handed over to
5459 ;; any other function. Converting is done with
5460 ;; the function `artist-coord-win-to-buf'.
5462 ;; It must take care to the `artist-rubber-banding' variable
5463 ;; and perform rubber-banding accordingly. Use the
5464 ;; artist-no-rb-* functions if not rubber-banding.
5466 ;; If applicable, you must be able to draw your shape without
5467 ;; borders if the `artist-borderless-shapes' is non-nil.
5468 ;; See `artist-draw-rect' for an example.
5470 ;; You must call the init-fn, the prep-fill-fn, arrow-set-fn
5471 ;; and the exit-fn at the apropriate points.
5473 ;; When artist-mouse-draw-xxx ends, the shape for your mode
5474 ;; must be completely drawn.
5476 ;; c. Create functions for drawing with keys:
5478 ;; - artist-key-set-point-xxx for setting a point in the
5479 ;; mode, to be called from `artist-key-set-point-common'.
5481 ;; - artist-key-do-continously-xxx to be called from
5482 ;; `artist-key-do-continously-common' whenever the user
5483 ;; moves around.
5485 ;; As for the artist-mouse-draw-xxx, these two functions must
5486 ;; take care to do rubber-banding, borderless shapes and to
5487 ;; set arrows.
5489 ;; These functions should set the variable `artist-key-shape'
5490 ;; to the shape drawn.
5492 ;; d. Create artist-key-draw-xxx and artist-key-undraw-xxx for
5493 ;; drawing and undrawing. These are needed when the user
5494 ;; switches operation to draw another shape of the same type
5495 ;; of drawing mode.
5497 ;; You should provide these functions. You might think that
5498 ;; only you is using your type of mode, so noone will be able
5499 ;; to switch to another operation of the same type of mode,
5500 ;; but someone else might base a new drawing mode upon your
5501 ;; work.
5503 ;; You must call the init-fn, the prep-fill-fn, arrow-set-fn
5504 ;; and the exit-fn at the apropriate points.
5506 ;; e. Add your new mode to the master table, `artist-mt'.
5509 ;; Happy hacking! Please let me hear if you add any drawing modes!
5510 ;; Don't hesitate to ask me any questions.
5513 ;;; arch-tag: 3e63b881-aaaa-4b83-a072-220d4661a8a3
5514 ;;; artist.el ends here