Commit 7eb387b1 authored by Ian Hickson's avatar Ian Hickson

Merge pull request #760 from Hixie/move-pointer-fixes

Cleanup for the Pointer changes.
parents e0107b05 2965dcb6
...@@ -25,8 +25,7 @@ typedef void GesturePanEndCallback(Offset velocity); ...@@ -25,8 +25,7 @@ typedef void GesturePanEndCallback(Offset velocity);
typedef void _GesturePolymorphicUpdateCallback<T>(T delta); typedef void _GesturePolymorphicUpdateCallback<T>(T delta);
bool _isFlingGesture(Offset velocity) { bool _isFlingGesture(Offset velocity) {
if (velocity == null) assert(velocity != null);
return false;
double velocitySquared = velocity.dx * velocity.dx + velocity.dy * velocity.dy; double velocitySquared = velocity.dx * velocity.dx + velocity.dy * velocity.dy;
return velocitySquared > kMinFlingVelocity * kMinFlingVelocity return velocitySquared > kMinFlingVelocity * kMinFlingVelocity
&& velocitySquared < kMaxFlingVelocity * kMaxFlingVelocity; && velocitySquared < kMaxFlingVelocity * kMaxFlingVelocity;
......
...@@ -193,8 +193,8 @@ class PointerAddedEvent extends PointerEvent { ...@@ -193,8 +193,8 @@ class PointerAddedEvent extends PointerEvent {
PointerDeviceKind kind: PointerDeviceKind.touch, PointerDeviceKind kind: PointerDeviceKind.touch,
Point position: Point.origin, Point position: Point.origin,
bool obscured: false, bool obscured: false,
double pressureMin: 0.0, double pressureMin: 1.0,
double pressureMax: 0.0, double pressureMax: 1.0,
double distance: 0.0, double distance: 0.0,
double distanceMax: 0.0, double distanceMax: 0.0,
double radiusMin: 0.0, double radiusMin: 0.0,
...@@ -224,8 +224,8 @@ class PointerRemovedEvent extends PointerEvent { ...@@ -224,8 +224,8 @@ class PointerRemovedEvent extends PointerEvent {
int pointer: 0, int pointer: 0,
PointerDeviceKind kind: PointerDeviceKind.touch, PointerDeviceKind kind: PointerDeviceKind.touch,
bool obscured: false, bool obscured: false,
double pressureMin: 0.0, double pressureMin: 1.0,
double pressureMax: 0.0, double pressureMax: 1.0,
double distanceMax: 0.0, double distanceMax: 0.0,
double radiusMin: 0.0, double radiusMin: 0.0,
double radiusMax: 0.0 double radiusMax: 0.0
...@@ -251,9 +251,9 @@ class PointerDownEvent extends PointerEvent { ...@@ -251,9 +251,9 @@ class PointerDownEvent extends PointerEvent {
Point position: Point.origin, Point position: Point.origin,
int buttons: 0, int buttons: 0,
bool obscured: false, bool obscured: false,
double pressure: 0.0, double pressure: 1.0,
double pressureMin: 0.0, double pressureMin: 1.0,
double pressureMax: 0.0, double pressureMax: 1.0,
double distanceMax: 0.0, double distanceMax: 0.0,
double radiusMajor: 0.0, double radiusMajor: 0.0,
double radiusMinor: 0.0, double radiusMinor: 0.0,
...@@ -293,9 +293,9 @@ class PointerMoveEvent extends PointerEvent { ...@@ -293,9 +293,9 @@ class PointerMoveEvent extends PointerEvent {
int buttons: 0, int buttons: 0,
bool down: false, bool down: false,
bool obscured: false, bool obscured: false,
double pressure: 0.0, double pressure: 1.0,
double pressureMin: 0.0, double pressureMin: 1.0,
double pressureMax: 0.0, double pressureMax: 1.0,
double distance: 0.0, double distance: 0.0,
double distanceMax: 0.0, double distanceMax: 0.0,
double radiusMajor: 0.0, double radiusMajor: 0.0,
...@@ -335,8 +335,8 @@ class PointerUpEvent extends PointerEvent { ...@@ -335,8 +335,8 @@ class PointerUpEvent extends PointerEvent {
Point position: Point.origin, Point position: Point.origin,
int buttons: 0, int buttons: 0,
bool obscured: false, bool obscured: false,
double pressureMin: 0.0, double pressureMin: 1.0,
double pressureMax: 0.0, double pressureMax: 1.0,
double distance: 0.0, double distance: 0.0,
double distanceMax: 0.0, double distanceMax: 0.0,
double radiusMin: 0.0, double radiusMin: 0.0,
...@@ -369,8 +369,8 @@ class PointerCancelEvent extends PointerEvent { ...@@ -369,8 +369,8 @@ class PointerCancelEvent extends PointerEvent {
Point position: Point.origin, Point position: Point.origin,
int buttons: 0, int buttons: 0,
bool obscured: false, bool obscured: false,
double pressureMin: 0.0, double pressureMin: 1.0,
double pressureMax: 0.0, double pressureMax: 1.0,
double distance: 0.0, double distance: 0.0,
double distanceMax: 0.0, double distanceMax: 0.0,
double radiusMin: 0.0, double radiusMin: 0.0,
......
...@@ -769,10 +769,10 @@ class Node { ...@@ -769,10 +769,10 @@ class Node {
/// } /// }
/// ///
/// bool handleEvent(SpriteBoxEvent event) { /// bool handleEvent(SpriteBoxEvent event) {
/// if (event.type == 'pointerdown) { /// if (event.type == PointerDownEvent) {
/// opacity = 0.5; /// opacity = 0.5;
/// } /// }
/// else if (event.type == 'pointerup') { /// else if (event.type == PointerUpEvent) {
/// opacity = 1.0; /// opacity = 1.0;
/// } /// }
/// return true; /// return true;
......
...@@ -187,57 +187,53 @@ class SpriteBox extends RenderBox { ...@@ -187,57 +187,53 @@ class SpriteBox extends RenderBox {
} }
} }
void handleEvent(InputEvent event, _SpriteBoxHitTestEntry entry) { void handleEvent(PointerEvent event, _SpriteBoxHitTestEntry entry) {
if (!attached) if (!attached)
return; return;
if (event is PointerInputEvent) { if (event is PointerDownEvent) {
// Build list of event targets
if (event.type == 'pointerdown') { if (_eventTargets == null) {
// Build list of event targets _eventTargets = <Node>[];
if (_eventTargets == null) { _addEventTargets(_rootNode, _eventTargets);
_eventTargets = <Node>[]; }
_addEventTargets(_rootNode, _eventTargets);
}
// Find the once that are hit by the pointer // Find the once that are hit by the pointer
List<Node> nodeTargets = <Node>[]; List<Node> nodeTargets = <Node>[];
for (int i = _eventTargets.length - 1; i >= 0; i--) { for (int i = _eventTargets.length - 1; i >= 0; i--) {
Node node = _eventTargets[i]; Node node = _eventTargets[i];
// Check if the node is ready to handle a pointer // Check if the node is ready to handle a pointer
if (node.handleMultiplePointers || node._handlingPointer == null) { if (node.handleMultiplePointers || node._handlingPointer == null) {
// Do the hit test // Do the hit test
Point posInNodeSpace = node.convertPointToNodeSpace(entry.localPosition); Point posInNodeSpace = node.convertPointToNodeSpace(entry.localPosition);
if (node.isPointInside(posInNodeSpace)) { if (node.isPointInside(posInNodeSpace)) {
nodeTargets.add(node); nodeTargets.add(node);
node._handlingPointer = event.pointer; node._handlingPointer = event.pointer;
}
} }
} }
entry.nodeTargets = nodeTargets;
} }
// Pass the event down to nodes that were hit by the pointerdown entry.nodeTargets = nodeTargets;
List<Node> targets = entry.nodeTargets; }
for (Node node in targets) {
// Check if this event should be dispatched
if (node.handleMultiplePointers || event.pointer == node._handlingPointer) {
// Dispatch event
bool consumedEvent = node.handleEvent(new SpriteBoxEvent(new Point(event.x, event.y), event.type, event.pointer));
if (consumedEvent == null || consumedEvent)
break;
}
}
// De-register pointer for nodes that doesn't handle multiple pointers // Pass the event down to nodes that were hit by the pointerdown
for (Node node in targets) { List<Node> targets = entry.nodeTargets;
if (event.type == 'pointerup' || event.type == 'pointercancel') { for (Node node in targets) {
node._handlingPointer = null; // Check if this event should be dispatched
} if (node.handleMultiplePointers || event.pointer == node._handlingPointer) {
// Dispatch event
bool consumedEvent = node.handleEvent(new SpriteBoxEvent(new Point(event.x, event.y), event.runtimeType, event.pointer));
if (consumedEvent == null || consumedEvent)
break;
} }
} }
// De-register pointer for nodes that doesn't handle multiple pointers
for (Node node in targets) {
if (event is PointerUpEvent || event is PointerCancelEvent)
node._handlingPointer = null;
}
} }
bool hitTest(HitTestResult result, { Point position }) { bool hitTest(HitTestResult result, { Point position }) {
...@@ -531,13 +527,13 @@ class SpriteBoxEvent { ...@@ -531,13 +527,13 @@ class SpriteBoxEvent {
/// } /// }
final Point boxPosition; final Point boxPosition;
/// The type of event, there are currently four valid types, 'pointerdown', 'pointermoved', 'pointerup', and /// The type of event, there are currently four valid types, PointerDownEvent, PointerMoveEvent, PointerUpEvent, and
/// 'pointercancel'. /// PointerCancelEvent.
/// ///
/// if (event.type == 'pointerdown') { /// if (event.type == PointerDownEvent) {
/// // Do something! /// // Do something!
/// } /// }
final String type; final Type type;
/// The id of the pointer. Each pointer on the screen will have a unique pointer id. /// The id of the pointer. Each pointer on the screen will have a unique pointer id.
/// ///
......
...@@ -31,18 +31,18 @@ class VirtualJoystick extends NodeWithSize { ...@@ -31,18 +31,18 @@ class VirtualJoystick extends NodeWithSize {
Paint _paintControl; Paint _paintControl;
bool handleEvent(SpriteBoxEvent event) { bool handleEvent(SpriteBoxEvent event) {
if (event.type == "pointerdown") { if (event.type == PointerDownEvent) {
_pointerDownAt = event.boxPosition; _pointerDownAt = event.boxPosition;
actions.stopAll(); actions.stopAll();
_isDown = true; _isDown = true;
} }
else if (event.type == "pointerup" || event.type == "pointercancel") { else if (event.type == PointerUpEvent || event.type == PointerCancelEvent) {
_pointerDownAt = null; _pointerDownAt = null;
_value = Point.origin; _value = Point.origin;
ActionTween moveToCenter = new ActionTween((a) => _handlePos = a, _handlePos, _center, 0.4, Curves.elasticOut); ActionTween moveToCenter = new ActionTween((a) => _handlePos = a, _handlePos, _center, 0.4, Curves.elasticOut);
actions.run(moveToCenter); actions.run(moveToCenter);
_isDown = false; _isDown = false;
} else if (event.type == "pointermove") { } else if (event.type == PointerMoveEvent) {
Offset movedDist = event.boxPosition - _pointerDownAt; Offset movedDist = event.boxPosition - _pointerDownAt;
_value = new Point( _value = new Point(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment