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