API Reference 0.7.1rikulo_gestureZoomGestureState

ZoomGestureState class

The state of a ZoomGesture.

class ZoomGestureState extends GestureState {
 final Point _startPos0, _startPos1, _startMid, _startDiff;
 Point _startDir;
 num _scaleBase;
 Point _pos0, _pos1;
 int _time;

 ZoomGestureState._(this.gesture, this.eventTarget, Point pos0, Point pos1, int time) :
 _startPos0 = pos0, _startPos1 = pos1, _pos0 = pos0, _pos1 = pos1,
 startTime = time, _time = time, _startMid = Points.divide(pos0 + pos1, 2), 
 _startDiff = pos1 - pos0 {
   _scaleBase = Points.norm(_startDiff);
   _startDir = Points.divide(_startDiff, _scaleBase);
 }

 //@onverride
 final EventTarget eventTarget;
 //@onverride
 int get time => _time;

 /** The associated [ZoomGesture].
  */
 final ZoomGesture gesture;
 
 /** The initial touch positions.
  */
 List<Point> get startPositions => [_startPos0, _startPos1];
 
 /** The midpoint of the two initial touch positions.
  */
 Point get startMidpoint => _startMid;
 
 /** The timestamp at which the gesture starts.
  */
 final int startTime;
 
 /** The current positions of gesture touches.
  */
 List<Point> get positions => [_pos0, _pos1];
 
 /** The midpoint of the two current touch positions.
  */
 Point get midpoint => Points.divide(_pos0 + _pos1, 2);
 
 /** The transition component in the gesture, which is defined by the 
  * displacement of the middle point of the two fingers.
  */
 Point get transition => midpoint - _startMid;
 
 /** The scalar component in the gesture, which is defined by the ratio
  * between the current finger distance and the initial finger distance.
  */
 num get scalar => Points.norm(_pos1 - _pos0) / _scaleBase;
 
 /** The rotation component in the gesture, which is defined as the unit 
  * vector representing the relative angular change between the fingers.
  */
 Point get rotation {
   final Point diff = _pos1 - _pos0;
   final num cx = diff.x, cy = diff.y, ix = _startDir.x, iy = _startDir.y;
   return Points.unit(new Point(cx*ix + cy*iy, cy*ix - cx*iy));
 }
 
 /** The rotation component in terms of angle, in the unit of radian.
  */
 num get angle {
   Point r = rotation;
   return r.x.abs() < r.y.abs() ? 
       (r.y < 0 ? -acos(r.x) : acos(r.x)) : 
       (r.x < 0 ? r.y < 0 ? -PI - asin(r.y) : PI - asin(r.y) : asin(r.y));
 }
 
 /** The CSS-compatible martix representing the linear transformation of the
  * gesture state. The transformation origin is the midpoint of the start
  * positions.
  */
 Transformation get transformation { // TODO: shall supply better assistance
   final Point tr = transition, ro = rotation * scalar;
   return new Transformation(ro.x, -ro.y, tr.x, ro.y, ro.x, tr.y);
 }
 
 void snapshot(Point pos0, Point pos1, int time) {
   if (time > _time) {
     _pos0 = pos0;
     _pos1 = pos1;
     _time = time;
   }
 }
}

Extends

GestureState > ZoomGestureState

Properties

final num angle #

The rotation component in terms of angle, in the unit of radian.

num get angle {
 Point r = rotation;
 return r.x.abs() < r.y.abs() ? 
     (r.y < 0 ? -acos(r.x) : acos(r.x)) : 
     (r.x < 0 ? r.y < 0 ? -PI - asin(r.y) : PI - asin(r.y) : asin(r.y));
}

var data #

inherited from GestureState

Custom data. It is useful if you'd like to store something that will be cleaned up automatically when the gesture is finished.

var data

final EventTarget eventTarget #

The element which receives the event.

docs inherited from GestureState
final EventTarget eventTarget

final ZoomGesture gesture #

The associated ZoomGesture.

final ZoomGesture gesture

final Point midpoint #

The midpoint of the two current touch positions.

Point get midpoint => Points.divide(_pos0 + _pos1, 2);

final List<Point> positions #

The current positions of gesture touches.

List<Point> get positions => [_pos0, _pos1];

final Point rotation #

The rotation component in the gesture, which is defined as the unit vector representing the relative angular change between the fingers.

Point get rotation {
 final Point diff = _pos1 - _pos0;
 final num cx = diff.x, cy = diff.y, ix = _startDir.x, iy = _startDir.y;
 return Points.unit(new Point(cx*ix + cy*iy, cy*ix - cx*iy));
}

final num scalar #

The scalar component in the gesture, which is defined by the ratio between the current finger distance and the initial finger distance.

num get scalar => Points.norm(_pos1 - _pos0) / _scaleBase;

final Point startMidpoint #

The midpoint of the two initial touch positions.

Point get startMidpoint => _startMid;

final List<Point> startPositions #

The initial touch positions.

List<Point> get startPositions => [_startPos0, _startPos1];

final int startTime #

The timestamp at which the gesture starts.

final int startTime

final int time #

The latest timestamp of gesture.

docs inherited from GestureState
int get time => _time;

final Transformation transformation #

The CSS-compatible martix representing the linear transformation of the gesture state. The transformation origin is the midpoint of the start positions.

Transformation get transformation { // TODO: shall supply better assistance
 final Point tr = transition, ro = rotation * scalar;
 return new Transformation(ro.x, -ro.y, tr.x, ro.y, ro.x, tr.y);
}

final Point transition #

The transition component in the gesture, which is defined by the displacement of the middle point of the two fingers.

Point get transition => midpoint - _startMid;

Methods

void snapshot(Point pos0, Point pos1, int time) #

void snapshot(Point pos0, Point pos1, int time) {
 if (time > _time) {
   _pos0 = pos0;
   _pos1 = pos1;
   _time = time;
 }
}