Function: strokes-read-stroke

strokes-read-stroke is an autoloaded and byte-compiled function defined in strokes.el.gz.

Signature

(strokes-read-stroke &optional PROMPT EVENT)

Documentation

Read a simple stroke (interactively) and return the stroke.

Optional PROMPT in minibuffer displays before and during stroke reading. This function will display the stroke interactively as it is being entered in the strokes buffer if the variable strokes-use-strokes-buffer is non-nil. Optional EVENT is acceptable as the starting event of the stroke.

Source Code

;; Defined in /usr/src/emacs/lisp/strokes.el.gz
;;;###autoload
(defun strokes-read-stroke (&optional prompt event)
  "Read a simple stroke (interactively) and return the stroke.
Optional PROMPT in minibuffer displays before and during stroke reading.
This function will display the stroke interactively as it is being
entered in the strokes buffer if the variable
`strokes-use-strokes-buffer' is non-nil.
Optional EVENT is acceptable as the starting event of the stroke."
  (save-excursion
    (let ((pix-locs nil)
	  (grid-locs nil)
	  (safe-to-draw-p nil))
      (if strokes-use-strokes-buffer
	  ;; switch to the strokes buffer and
	  ;; display the stroke as it's being read
	  (save-window-excursion
	    (set-window-configuration strokes-window-configuration)
	    ;; The frame has been resized, so we need to refill the
	    ;; strokes buffer so that the strokes canvas is the whole
	    ;; visible buffer.
	    (unless (> 1 (abs (- (line-end-position) (window-width))))
	      (strokes-fill-current-buffer-with-whitespace))
	    (when prompt
	      (message "%s" prompt)
	      (setq event (read--potential-mouse-event))
	      (or (strokes-button-press-event-p event)
		  (error "You must draw with the mouse")))
	    (unwind-protect
		(track-mouse
		  (or event (setq event (read--potential-mouse-event)
				  safe-to-draw-p t))
		  (while (not (strokes-button-release-event-p event))
		    (if (strokes-mouse-event-p event)
			(let ((point (strokes-event-closest-point event)))
			  (if (and point safe-to-draw-p)
			      ;; we can draw that point
			      (progn
				(goto-char point)
				(subst-char-in-region point (1+ point)
						      ?\s strokes-character))
			    ;; otherwise, we can start drawing the next time...
			    (setq safe-to-draw-p t))
			  (push (cdr (mouse-pixel-position))
				pix-locs)))
		    (setq event (read--potential-mouse-event)))))
	    ;; protected
	    ;; clean up strokes buffer and then bury it.
	    (when (equal (buffer-name) strokes-buffer-name)
	      (subst-char-in-region (point-min) (point-max)
				    strokes-character ?\s)
	      (goto-char (point-min))
	      (bury-buffer))))
      ;; Otherwise, don't use strokes buffer and read stroke silently
      (when prompt
	(message "%s" prompt)
	(setq event (read--potential-mouse-event))
	(or (strokes-button-press-event-p event)
	    (error "You must draw with the mouse")))
      (track-mouse
	(or event (setq event (read--potential-mouse-event)))
	(while (not (strokes-button-release-event-p event))
	  (if (strokes-mouse-event-p event)
	      (push (cdr (mouse-pixel-position))
		    pix-locs))
	  (setq event (read--potential-mouse-event))))
      (setq grid-locs (strokes-renormalize-to-grid (nreverse pix-locs)))
      (strokes-fill-stroke
       (strokes-eliminate-consecutive-redundancies grid-locs)))))