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