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