Function: artist-mouse-draw-2points

artist-mouse-draw-2points is an interactive and byte-compiled function defined in artist.el.gz.

Signature

(artist-mouse-draw-2points EV)

Documentation

Generic function for shapes requiring 2 points as input.

The event, EV, is the mouse event.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/artist.el.gz
(defun artist-mouse-draw-2points (ev)
  "Generic function for shapes requiring 2 points as input.
The event, EV, is the mouse event."
  (interactive "@e")
  (let* ((unshifted    (artist-go-get-symbol-shift artist-curr-go nil))
	 (shifted      (artist-go-get-symbol-shift artist-curr-go t))
	 (shift-state  (artist-event-is-shifted ev))
	 (op           (if shift-state shifted unshifted))
	 (draw-how     (artist-go-get-draw-how-from-symbol op))
	 (init-fn      (artist-go-get-init-fn-from-symbol op))
	 (prep-fill-fn (artist-go-get-prep-fill-fn-from-symbol op))
	 (exit-fn      (artist-go-get-exit-fn-from-symbol op))
	 (draw-fn      (artist-go-get-draw-fn-from-symbol op))
	 (undraw-fn    (artist-go-get-undraw-fn-from-symbol op))
	 (fill-pred    (artist-go-get-fill-pred-from-symbol op))
	 (fill-fn      (artist-go-get-fill-fn-from-symbol op))
	 (arrow-pred   (artist-go-get-arrow-pred-from-symbol op))
	 (arrow-set-fn (artist-go-get-arrow-set-fn-from-symbol op))
	 (ev-start     (event-start ev))
	 (initial-win  (posn-window ev-start))
	 (ev-start-pos (artist-coord-win-to-buf
                        (posn-col-row ev-start t)))
	 (x1           (artist--adjust-x (car ev-start-pos)))
	 (y1           (cdr ev-start-pos))
	 (x2)
	 (y2)
	 (shape))
    (select-window (posn-window ev-start))
    (artist-funcall init-fn x1 y1)
    (if (not artist-rubber-banding)
	(artist-no-rb-set-point1 x1 y1))
    (track-mouse
      (while (or (mouse-movement-p ev)
		 (member 'down (event-modifiers ev)))
	(setq ev-start-pos (artist-coord-win-to-buf
			    (posn-col-row (event-start ev) t)))
	(setq x2 (artist--adjust-x (car ev-start-pos)))
	(setq y2 (cdr ev-start-pos))

	(if (not (eq initial-win (posn-window (event-start ev))))
	    ;; If we moved outside the window, do nothing
	    nil

	  ;; Still in same window:
	  ;;
	  ;; First undraw last shape (unset last point if not rubberbanding)
	  (if artist-rubber-banding
	      (artist-funcall undraw-fn shape)
	    (artist-no-rb-unset-point2))

	  ;; Check if user presses or releases shift key
	  (if (artist-shift-has-changed shift-state ev)

	      ;; First check that the draw-how is the same as we
	      ;; already have. Otherwise, ignore the changed shift-state.
	      (if (not (eq draw-how
			   (artist-go-get-draw-how-from-symbol
			    (if (not shift-state) shifted unshifted))))
		  (message "Cannot switch to shifted operation")

		(message "Switching")
		;; progn is "implicit" since this is the else-part
		(setq shift-state (not shift-state))
		(setq op          (if shift-state shifted unshifted))
		(setq draw-how    (artist-go-get-draw-how-from-symbol op))
		(setq draw-fn     (artist-go-get-draw-fn-from-symbol op))
		(setq undraw-fn   (artist-go-get-undraw-fn-from-symbol op))
		(setq fill-pred   (artist-go-get-fill-pred-from-symbol op))
		(setq fill-fn     (artist-go-get-fill-fn-from-symbol op))))

	  ;; Draw the new shape
	  (if artist-rubber-banding
	      (setq shape (artist-funcall draw-fn x1 y1 x2 y2))
	    (artist-no-rb-set-point2 x2 y2))
	  ;; Move cursor
	  (artist-move-to-xy x2 y2))


	;; Read next event
	(setq ev (read--potential-mouse-event))))

    ;; If we are not rubber-banding (that is, we were moving around the `2')
    ;; draw the shape
    (if (not artist-rubber-banding)
	(progn
	  (artist-no-rb-unset-points)
	  (setq shape (artist-funcall draw-fn x1 y1 x2 y2))))

    (artist-funcall prep-fill-fn shape x1 y1 x2 y2)

    ;; Maybe fill
    (if (artist-funcall fill-pred)
	(artist-funcall fill-fn shape x1 y1 x2 y2))

    ;; Maybe set arrow-points
    (if (artist-funcall arrow-pred)
	(artist-funcall arrow-set-fn shape x1 y1 x2 y2)
      (artist-clear-arrow-points))

    (artist-funcall exit-fn shape x1 y1 x2 y2)
    (artist-move-to-xy x2 y2)))