mock_events.dart 2.61 KB
Newer Older
1 2
import 'dart:sky' as sky;

3 4
export 'dart:sky' show Point;

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
class TestPointerEvent extends sky.PointerEvent {
  TestPointerEvent({
    this.type,
    this.pointer,
    this.kind,
    this.x,
    this.y,
    this.dx,
    this.dy,
    this.velocityX,
    this.velocityY,
    this.buttons,
    this.down,
    this.primary,
    this.obscured,
    this.pressure,
    this.pressureMin,
    this.pressureMax,
    this.distance,
    this.distanceMin,
    this.distanceMax,
    this.radiusMajor,
    this.radiusMinor,
    this.radiusMin,
    this.radiusMax,
    this.orientation,
    this.tilt
  });

  // These are all of the PointerEvent members, but not all of Event.
  String type;
  int pointer;
  String kind;
  double x;
  double y;
  double dx;
  double dy;
  double velocityX;
  double velocityY;
  int buttons;
  bool down;
  bool primary;
  bool obscured;
  double pressure;
  double pressureMin;
  double pressureMax;
  double distance;
  double distanceMin;
  double distanceMax;
  double radiusMajor;
  double radiusMinor;
  double radiusMin;
  double radiusMax;
  double orientation;
  double tilt;
}

class TestGestureEvent extends sky.GestureEvent {
  TestGestureEvent({
    this.type,
    this.primaryPointer,
    this.x,
    this.y,
    this.dx,
    this.dy,
    this.velocityX,
    this.velocityY
  });

  // These are all of the GestureEvent members, but not all of Event.
  String type;
  int primaryPointer;
  double x;
  double y;
  double dx;
  double dy;
  double velocityX;
  double velocityY;
}
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140

class TestPointer {
  TestPointer([ this.pointer = 1 ]);

  int pointer;
  bool isDown = false;
  sky.Point location;

  sky.PointerEvent down([sky.Point newLocation = sky.Point.origin ]) {
    assert(!isDown);
    isDown = true;
    location = newLocation;
    return new TestPointerEvent(
      type: 'pointerdown',
      pointer: pointer,
      x: location.x,
      y: location.y
    );
  }

  sky.PointerEvent move([sky.Point newLocation = sky.Point.origin ]) {
    assert(isDown);
    sky.Offset delta = newLocation - location;
    location = newLocation;
    return new TestPointerEvent(
      type: 'pointermove',
      pointer: pointer,
      x: newLocation.x,
      y: newLocation.y,
      dx: delta.dx,
      dy: delta.dy
    );
  }

  sky.PointerEvent up() {
    assert(isDown);
    isDown = false;
    return new TestPointerEvent(
      type: 'pointerup',
      pointer: pointer,
      x: location.x,
      y: location.y
    );
  }

  sky.PointerEvent cancel() {
    assert(isDown);
    isDown = false;
    return new TestPointerEvent(
      type: 'pointercancel',
      pointer: pointer,
      x: location.x,
      y: location.y
    );
  }

}