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