ClassPackage: cgToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.1
Unrevised from 10.0 to 10.1.
10.0 version

two-stroke-mixin

This mixin class can be used along with a window class (basic-pane or some subclass of it) for creating windows that interpret certain kinds of touchscreen gestures. This class specializes in interpreting "two-stroke" drags such as three fingers dragged to the right and then downward. It also interprets single-direction drags as well as taps and holds plus two-finger pinches and spreads. As with other touchscreen support, it is currently available only on the Windows platform.

To write code directly on top of Microsoft's touchscreen support, use either gesture-event or touch-event instead of this class. gesture-event interprets certain common gestures for you, but handles only a handful of them, while touch-event requires that you interpret your own gestures from many finger coordinate positions. To make it easier to handle a larger number of gestures, we provide this custom facility on top of the touch-event API, though the particular gestures that it interprets may not be what you want to handle. It specializes in dragging gestures where the user drags one or more fingers either leftward, upward, rightward, or downward, and then perhaps in another one of those directions while their finger are still on the screen.

You probably should put this class before the window class in the precedence for the class that you create for windows, for example:

(defclass my-two-stroke-window (two-sroke-mixin frame-window)())

An application would handle the high-level gestures by adding one or more two-stroke-gesture methods. It could also handle dragging gestures during the actual drag by adding one or more two-stroke-dragging methods.

Here is complete simple example that simply prints the arguments that are passed to the two generic functions.

(in-package :cg-user)

(defclass two-stroke-demo (two-stroke-mixin frame-window)
  ((two-stroke-demo-string :accessor two-stroke-demo-string
                           :initform nil)
   (two-stroke-now-dragging :accessor two-stroke-now-dragging
                            :initform nil))
  (:default-initargs
    :double-buffered t
    :scrollbars nil))

(defmethod redisplay-window ((window two-stroke-demo) &optional box)
  (declare (ignore box))
  (with-boxes (interior)
    (nvisible-box window interior)
    (erase-contents-box window interior)
    (let* ((dragging (two-stroke-now-dragging window))
           (string (two-stroke-demo-string window)))
      (with-font (window (make-font-ex nil "Arial"
                                       (if dragging 24 48)))
        (cond (dragging
               (move-to-x-y window 0 0)
               (princ string window))
              (t (draw-string-in-box
                  window string nil nil interior :center :center)))))))

(defmethod two-stroke-dragging ((window two-stroke-demo) count x y
                                dx-down dy-down dx-prev dy-prev
                                spread-diff spread-factor first last)
  (setf (two-stroke-now-dragging window) t)
  (setf (two-stroke-demo-string window)
    (format nil "~(~r~) finger~:p at ~a ~a~%~
                 distance from start ~a ~a~%~
                 distance from previous ~a ~a~%~
                 spread difference ~a~%~
                 spread factor ~a~%~a"
      count x y dx-down dy-down dx-prev dy-prev spread-diff spread-factor
      (if first "FIRST" "")(if last "LAST" "")))
  (invalidate window)
  t)

(defmethod two-stroke-gesture ((window two-stroke-demo) count gesture)
  (setf (two-stroke-now-dragging window) nil)
  (setf (two-stroke-demo-string window)
    (format nil "~(~r~)   ~s" count gesture))
  (invalidate window)
  t)

#+test
(make-window :two-stroke-demo
  :class 'two-stroke-demo
  :title "Try Some One- and Two-Stroke Finger Gestures"
  :interior (make-box-relative 100 100 800 500))

Copyright (c) 1998-2022, Franz Inc. Lafayette, CA., USA. All rights reserved.
This page was not revised from the 10.0 page.
Created 2019.8.20.

ToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.1
Unrevised from 10.0 to 10.1.
10.0 version