comparison lisp/textmodes/artist.el @ 55793:812519af46fd

(artist-last, artist-remove-nulls): Simplify. (artist-draw-ellipse-general, artist-draw-ellipse-with-0-height): Make arguments match their use in docstring. (artist-draw-region-trim-line-endings, (artist-mouse-choose-operation): Fix typo in docstring. (artist-key-set-point-common): Doc fix.
author Juanma Barranquero <lekktu@gmail.com>
date Fri, 28 May 2004 19:55:04 +0000
parents 695cf19ef79e
children f467c038c83e 4c90ffeb71c5
comparison
equal deleted inserted replaced
55792:0d890eccf70f 55793:812519af46fd
1 ;;; artist.el --- draw ascii graphics with your mouse 1 ;;; artist.el --- draw ascii graphics with your mouse
2 2
3 ;; Copyright (C) 2000, 2001 Free Software Foundation, Inc. 3 ;; Copyright (C) 2000, 2001, 2004 Free Software Foundation, Inc.
4 4
5 ;; Author: Tomas Abrahamsson <tab@lysator.liu.se> 5 ;; Author: Tomas Abrahamsson <tab@lysator.liu.se>
6 ;; Maintainer: Tomas Abrahamsson <tab@lysator.liu.se> 6 ;; Maintainer: Tomas Abrahamsson <tab@lysator.liu.se>
7 ;; Keywords: mouse 7 ;; Keywords: mouse
8 ;; Version: 1.2.4 8 ;; Version: 1.2.4
1696 (cond ((null l) nil) 1696 (cond ((null l) nil)
1697 ((null (cdr l)) nil) 1697 ((null (cdr l)) nil)
1698 (t (cons (car l) (artist-butlast (cdr l)))))) 1698 (t (cons (car l) (artist-butlast (cdr l))))))
1699 1699
1700 1700
1701 (defun artist-last (seq &optional n) 1701 (defun artist-last (l &optional n)
1702 "Return the last link in the list SEQ. 1702 "Return the last link in the list L.
1703 With optional argument N, returns Nth-to-last link (default 1)." 1703 With optional argument N, returns Nth-to-last link (default 1)."
1704 (if (not n) 1704 (nth (- (length l) (or n 1)) l))
1705 (setq n 1))
1706 (let ((len (length seq)))
1707 (elt seq (- len n))))
1708 1705
1709 (defun artist-remove-nulls (l) 1706 (defun artist-remove-nulls (l)
1710 "Remove nils in list L." 1707 "Remove nils in list L."
1711 (cond ((null l) nil) 1708 (remq nil l))
1712 ((null (car l)) (artist-remove-nulls (cdr l)))
1713 (t (cons (car l) (artist-remove-nulls (cdr l))))))
1714 1709
1715 (defun artist-uniq (l) 1710 (defun artist-uniq (l)
1716 "Remove consecutive duplicates in list L. Comparison is done with `equal'." 1711 "Remove consecutive duplicates in list L. Comparison is done with `equal'."
1717 (cond ((null l) nil) 1712 (cond ((null l) nil)
1718 ((null (cdr l)) l) ; only one element in list 1713 ((null (cdr l)) l) ; only one element in list
3366 ;; and middle bottom char twice. 3361 ;; and middle bottom char twice.
3367 (funcall artist-butlast-fn (cdr (reverse right-half))))) 3362 (funcall artist-butlast-fn (cdr (reverse right-half)))))
3368 (append right-half left-half))) 3363 (append right-half left-half)))
3369 3364
3370 3365
3371 (defun artist-draw-ellipse-general (x y x-radius y-radius) 3366 (defun artist-draw-ellipse-general (x1 y1 x-radius y-radius)
3372 "Draw an ellipse with center at X, Y and X-RADIUS and Y-RADIUS. 3367 "Draw an ellipse with center at X1, Y1 and X-RADIUS and Y-RADIUS.
3373 3368
3374 Output is an ellipse, which is a list (END-POINT-1 END-POINT-2 SHAPE-INFO). 3369 Output is an ellipse, which is a list (END-POINT-1 END-POINT-2 SHAPE-INFO).
3375 3370
3376 END-POINT-1 and END-POINT-2 are two-element vectors on the form [X Y]. 3371 END-POINT-1 and END-POINT-2 are two-element vectors on the form [X Y].
3377 SHAPE-INFO is a two-element vector on the form [POINT-LIST FILL-INFO]. 3372 SHAPE-INFO is a two-element vector on the form [POINT-LIST FILL-INFO].
3378 3373
3379 POINT-LIST is a list of vectors on the form [X Y SAVED-CHAR NEW-CHAR]. 3374 POINT-LIST is a list of vectors on the form [X Y SAVED-CHAR NEW-CHAR].
3380 FILL-INFO is a list of vectors on the form [X Y ELLIPSE-WIDTH-ON-THIS-LINE]. 3375 FILL-INFO is a list of vectors on the form [X Y ELLIPSE-WIDTH-ON-THIS-LINE].
3381 3376
3382 Ellipses with zero y-radius are not drawn correctly." 3377 Ellipses with zero Y-RADIUS are not drawn correctly."
3383 (let* ((point-list (artist-ellipse-generate-quadrant x-radius y-radius)) 3378 (let* ((point-list (artist-ellipse-generate-quadrant x-radius y-radius))
3384 (fill-info (artist-ellipse-compute-fill-info point-list)) 3379 (fill-info (artist-ellipse-compute-fill-info point-list))
3385 (shape-info (make-vector 2 0))) 3380 (shape-info (make-vector 2 0)))
3386 3381
3387 (setq point-list (artist-calculate-new-chars point-list)) 3382 (setq point-list (artist-calculate-new-chars point-list))
3388 (setq point-list (artist-ellipse-mirror-quadrant point-list)) 3383 (setq point-list (artist-ellipse-mirror-quadrant point-list))
3389 (setq point-list (artist-ellipse-point-list-add-center x y point-list)) 3384 (setq point-list (artist-ellipse-point-list-add-center x1 y1 point-list))
3390 (setq fill-info (artist-ellipse-fill-info-add-center x y fill-info)) 3385 (setq fill-info (artist-ellipse-fill-info-add-center x1 y1 fill-info))
3391 3386
3392 ;; Draw the ellipse 3387 ;; Draw the ellipse
3393 (setq point-list 3388 (setq point-list
3394 (mapcar 3389 (mapcar
3395 (lambda (coord) 3390 (lambda (coord)
3402 (artist-modify-new-chars 3397 (artist-modify-new-chars
3403 (artist-save-chars-under-point-list point-list)))) 3398 (artist-save-chars-under-point-list point-list))))
3404 3399
3405 (aset shape-info 0 point-list) 3400 (aset shape-info 0 point-list)
3406 (aset shape-info 1 fill-info) 3401 (aset shape-info 1 fill-info)
3407 (artist-make-2point-object (artist-make-endpoint x y) 3402 (artist-make-2point-object (artist-make-endpoint x1 y1)
3408 (artist-make-endpoint x-radius y-radius) 3403 (artist-make-endpoint x-radius y-radius)
3409 shape-info))) 3404 shape-info)))
3410 3405
3411 (defun artist-draw-ellipse-with-0-height (x y x-radius y-radius) 3406 (defun artist-draw-ellipse-with-0-height (x1 y1 x-radius y-radius)
3412 "Draw an ellipse with center at X, Y and X-RADIUS and Y-RADIUS. 3407 "Draw an ellipse with center at X1, Y1 and X-RADIUS and Y-RADIUS.
3413 3408
3414 Output is an ellipse, which is a list (END-POINT-1 END-POINT-2 SHAPE-INFO). 3409 Output is an ellipse, which is a list (END-POINT-1 END-POINT-2 SHAPE-INFO).
3415 3410
3416 END-POINT-1 and END-POINT-2 are two-element vectors on the form [X Y]. 3411 END-POINT-1 and END-POINT-2 are two-element vectors on the form [X Y].
3417 SHAPE-INFO is a two-element vector on the form [POINT-LIST FILL-INFO]. 3412 SHAPE-INFO is a two-element vector on the form [POINT-LIST FILL-INFO].
3418 3413
3419 POINT-LIST is a list of vectors on the form [X Y SAVED-CHAR NEW-CHAR]. 3414 POINT-LIST is a list of vectors on the form [X Y SAVED-CHAR NEW-CHAR].
3420 FILL-INFO is a list of vectors on the form [X Y ELLIPSE-WIDTH-ON-THIS-LINE]. 3415 FILL-INFO is a list of vectors on the form [X Y ELLIPSE-WIDTH-ON-THIS-LINE].
3421 3416
3422 The Y-RADIUS must be 0, but the X-RADUIS must not be 0." 3417 The Y-RADIUS must be 0, but the X-RADIUS must not be 0."
3423 (let ((point-list nil) 3418 (let ((point-list nil)
3424 (width (max (- (abs (* 2 x-radius)) 1))) 3419 (width (max (- (abs (* 2 x-radius)) 1)))
3425 (left-edge (1+ (- x (abs x-radius)))) 3420 (left-edge (1+ (- x1 (abs x-radius))))
3426 (line-char (if artist-line-char-set artist-line-char ?-)) 3421 (line-char (if artist-line-char-set artist-line-char ?-))
3427 (i 0) 3422 (i 0)
3428 (point-list nil) 3423 (point-list nil)
3429 (fill-info nil) 3424 (fill-info nil)
3430 (shape-info (make-vector 2 0))) 3425 (shape-info (make-vector 2 0)))
3431 (while (< i width) 3426 (while (< i width)
3432 (let* ((line-x (+ left-edge i)) 3427 (let* ((line-x (+ left-edge i))
3433 (line-y y) 3428 (line-y y1)
3434 (new-coord (artist-new-coord line-x line-y))) 3429 (new-coord (artist-new-coord line-x line-y)))
3435 (artist-coord-add-saved-char new-coord 3430 (artist-coord-add-saved-char new-coord
3436 (artist-get-char-at-xy line-x line-y)) 3431 (artist-get-char-at-xy line-x line-y))
3437 (artist-move-to-xy line-x line-y) 3432 (artist-move-to-xy line-x line-y)
3438 (artist-replace-char line-char) 3433 (artist-replace-char line-char)
3439 (setq point-list (append point-list (list new-coord))) 3434 (setq point-list (append point-list (list new-coord)))
3440 (setq i (1+ i)))) 3435 (setq i (1+ i))))
3441 (aset shape-info 0 point-list) 3436 (aset shape-info 0 point-list)
3442 (aset shape-info 1 fill-info) 3437 (aset shape-info 1 fill-info)
3443 (artist-make-2point-object (artist-make-endpoint x y) 3438 (artist-make-2point-object (artist-make-endpoint x1 y1)
3444 (artist-make-endpoint x-radius y-radius) 3439 (artist-make-endpoint x-radius y-radius)
3445 shape-info))) 3440 shape-info)))
3446 3441
3447 (defun artist-draw-ellipse (x1 y1 x2 y2) 3442 (defun artist-draw-ellipse (x1 y1 x2 y2)
3448 "Draw an ellipse with center at X1, Y1 and point X2,Y2. 3443 "Draw an ellipse with center at X1, Y1 and point X2,Y2.
3952 (setq artist-draw-region-max-y 0) 3947 (setq artist-draw-region-max-y 0)
3953 (setq artist-draw-region-min-y 1000000)) 3948 (setq artist-draw-region-min-y 1000000))
3954 3949
3955 (defun artist-draw-region-trim-line-endings (min-y max-y) 3950 (defun artist-draw-region-trim-line-endings (min-y max-y)
3956 "Trim lines in current draw-region from MIN-Y to MAX-Y. 3951 "Trim lines in current draw-region from MIN-Y to MAX-Y.
3957 Trimming here means removing white space at end of a line" 3952 Trimming here means removing white space at end of a line."
3958 ;; Safetyc check: switch min-y and max-y if if max-y is smaller 3953 ;; Safetyc check: switch min-y and max-y if if max-y is smaller
3959 (if (< max-y min-y) 3954 (if (< max-y min-y)
3960 (let ((tmp min-y)) 3955 (let ((tmp min-y))
3961 (setq min-y max-y) 3956 (setq min-y max-y)
3962 (setq max-y tmp))) 3957 (setq max-y tmp)))
4284 (setq artist-key-is-drawing nil))))) 4279 (setq artist-key-is-drawing nil)))))
4285 4280
4286 4281
4287 (defun artist-key-set-point-common (arg) 4282 (defun artist-key-set-point-common (arg)
4288 "Common routine for setting point in current shape. 4283 "Common routine for setting point in current shape.
4289 With ARG set to t, set the last point." 4284 With non-nil ARG, set the last point."
4290 (let ((draw-how (artist-go-get-draw-how-from-symbol artist-curr-go)) 4285 (let ((draw-how (artist-go-get-draw-how-from-symbol artist-curr-go))
4291 (col (artist-current-column)) 4286 (col (artist-current-column))
4292 (row (artist-current-line)) 4287 (row (artist-current-line))
4293 (was-drawing artist-key-is-drawing)) 4288 (was-drawing artist-key-is-drawing))
4294 4289
4791 4786
4792 (artist-mode-line-show-curr-operation artist-key-is-drawing)))) 4787 (artist-mode-line-show-curr-operation artist-key-is-drawing))))
4793 4788
4794 4789
4795 (defun artist-mouse-choose-operation (ev op) 4790 (defun artist-mouse-choose-operation (ev op)
4796 "Choose operation for evenvt EV and operation OP." 4791 "Choose operation for event EV and operation OP."
4797 (interactive 4792 (interactive
4798 (progn 4793 (progn
4799 (select-window (posn-window (event-start last-input-event))) 4794 (select-window (posn-window (event-start last-input-event)))
4800 (list last-input-event 4795 (list last-input-event
4801 (x-popup-menu last-nonmenu-event artist-popup-menu-table)))) 4796 (x-popup-menu last-nonmenu-event artist-popup-menu-table))))