浏览代码

scroller version 2

/main
xingwei.zhu 6 年前
当前提交
74197d4c
共有 16 个文件被更改,包括 143 次插入214 次删除
  1. 2
      Runtime/editor/editor_window.cs
  2. 59
      Runtime/engine/WidgetCanvas.cs
  3. 54
      Runtime/gestures/binding.cs
  4. 45
      Runtime/gestures/converter.cs
  5. 6
      Runtime/gestures/drag_details.cs
  6. 44
      Runtime/gestures/events.cs
  7. 42
      Runtime/gestures/monodrag.cs
  8. 5
      Runtime/gestures/multidrag.cs
  9. 5
      Runtime/gestures/multitap.cs
  10. 6
      Runtime/gestures/pointer_router.cs
  11. 17
      Runtime/gestures/recognizer.cs
  12. 6
      Runtime/rendering/proxy_box.cs
  13. 22
      Runtime/ui/pointer.cs
  14. 12
      Runtime/widgets/gesture_detector.cs
  15. 18
      Runtime/widgets/scroll_activity.cs
  16. 14
      Runtime/widgets/scroll_position_with_single_context.cs

2
Runtime/editor/editor_window.cs


physicalX: evt.mousePosition.x * this._devicePixelRatio,
physicalY: evt.mousePosition.y * this._devicePixelRatio
);
} EventType.ScrollWheel
}
if (pointerData != null) {
this.onPointerEvent(new PointerDataPacket(new List<PointerData> {

59
Runtime/engine/WidgetCanvas.cs


Vector2 _lastMouseMove;
bool _mouseEntered;
Vector2 _lastScrollMove;
TimeSpan _lastScrollEndTime = TimeSpan.Zero;
static readonly TimeSpan _ScrollEndInterval = new TimeSpan(0, 0, 0, 0, 200);
protected override void OnEnable() {
base.OnEnable();

this._windowAdapter.attachRootWidget(root);
this._lastMouseMove = Input.mousePosition;
this._lastScrollMove = Input.mouseScrollDelta;
Debug.Log(this._lastScrollMove);
}
public double pixelRatio {

}
if (this._mouseEntered) {
// 0 -> !0 => scroll start, use the current position to perform hit test and set the
// current scroll target (if can, otherwise set it null), this target should be saved
// !0 -> !0 => use the delta to do the scroll thing.
// !0 -> 0 => scroll end. current scroll target = null
if (this._lastScrollMove.y == 0 && Input.mouseScrollDelta.y == 0) {
if (this._lastScrollEndTime != TimeSpan.Zero &&
(Timer.timespanSinceStartup - this._lastScrollEndTime > _ScrollEndInterval)) {
this._lastScrollEndTime = TimeSpan.Zero;
this._windowAdapter.postPointerEvent(new PointerData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.scroll_end,
kind: PointerDeviceKind.mouse,
device: this.getScrollButton(),
physicalX: 0,
physicalY: 0
));
}
}
else if (this._lastScrollMove.y != 0 && Input.mouseScrollDelta.y == 0) {
//Debug.Log("scroll end");
this._lastScrollEndTime = Timer.timespanSinceStartup;
this._windowAdapter.postPointerEvent(new PointerData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.scrolling,
kind: PointerDeviceKind.mouse,
device: this.getScrollButton(),
physicalX: 0,
physicalY: this._lastScrollMove.y
));
} else if (this._lastScrollMove.y == 0 && Input.mouseScrollDelta.y != 0) {
//Debug.Log("scroll start");
if (Input.mouseScrollDelta.y != 0) {
this._windowAdapter.postPointerEvent(new PointerData(
this._windowAdapter.postPointerEvent(new ScrollData(
change: PointerChange.scroll_start,
change: PointerChange.scroll,
physicalY: pos.y
));
} else if (this._lastScrollMove.y != 0 && Input.mouseScrollDelta.y != 0) {
//Debug.Log("scroll continue");
this._windowAdapter.postPointerEvent(new PointerData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.scrolling,
kind: PointerDeviceKind.mouse,
device: this.getScrollButton(),
physicalX: 0,
physicalY: this._lastScrollMove.y
physicalY: pos.y,
scrollX: Input.mouseScrollDelta.x,
scrollY: Input.mouseScrollDelta.y * 5
this._lastScrollMove = Input.mouseScrollDelta;
this._lastMouseMove = Input.mousePosition;

54
Runtime/gestures/binding.cs


this._handlePointerHoverEvent(evt);
}
if (evt is PointerScrollingEvent || evt is PointerScrollStartEvent || evt is PointerScrollEndEvent) {
if (evt is PointerScrollEvent) {
return;
}
HitTestResult result;

result = this._hitTests[evt.pointer];
this._hitTests.Remove(evt.pointer);
}
else if (!(evt is PointerScrollStartEvent) && evt.down) {
else if (evt.down) {
result = this._hitTests[evt.pointer];
}
else {

this.dispatchEvent(evt, result);
}
}
//public Offset lastScrollStartPos = null;
void _handleScrolling(PointerEvent subEvt, bool start) {
//if (this.lastScrollStartPos == null) {
// return;
// }
HitTestResult result = new HitTestResult();
this.hitTest(result, subEvt.position);
foreach (var hitTestEntry in result.path) {
//Debug.Log("hitTestEntry: " + hitTestEntry);
hitTestEntry.target.handleEvent(new PointerScrollingEvent(
timeStamp: subEvt.timeStamp,
pointer: subEvt.pointer,
device: subEvt.device,
kind: subEvt.kind,
position: subEvt.position,
delta: subEvt.delta,
start: start
), hitTestEntry);
}
this.dispatchEvent(evt, result);
}
// scroll start
// evt.position = the current pointer position
if (evt is PointerScrollStartEvent) {
//this.lastScrollStartPos = evt.position;
_handleScrolling(evt, true);
}
else if (evt is PointerScrollEndEvent) {
//this.lastScrollStartPos = null;
_handleScrolling(evt, false);
}
else if (evt is PointerScrollingEvent) {
_handleScrolling(evt, false);
}
this.pointerRouter.clearScrollRoute(evt.pointer);
HitTestResult result = new HitTestResult();
this.hitTest(result, evt.position);
this.dispatchEvent(evt, result);
}
void _handlePointerHoverEvent(PointerEvent evt) {

}
public void handleEvent(PointerEvent evt, HitTestEntry entry) {
if (evt is PointerScrollingEvent) {
Debug.Log("ffffffffff");
}
if (evt is PointerDownEvent || (evt is PointerScrollingEvent && evt.down)) {
if (evt is PointerDownEvent) {
this.gestureArena.close(evt.pointer);
}
else if (evt is PointerUpEvent) {

45
Runtime/gestures/converter.cs


break;
}
case PointerChange.scroll_start: {
case PointerChange.scroll: {
var _scrollData = (ScrollData) datum;
_PointerState state = _ensureStateForPointer(datum, position);
state.initScrollPointer();

yield return new PointerScrollStartEvent(
yield return new PointerScrollEvent(
device: datum.device,
position: position
device: _scrollData.device,
position: position,
delta: new Offset(_scrollData.scrollX, _scrollData.scrollY) / devicePixelRatio
case PointerChange.scroll_end: {
D.assert(_pointers.ContainsKey(datum.device));
_PointerState state = _pointers[datum.device];
Offset startPosition = state.lastPosition;
yield return new PointerScrollEndEvent(
timeStamp: timeStamp,
pointer: state.pointer,
kind: kind,
device: datum.device,
position: startPosition,
delta: position
);
break;
}
case PointerChange.scrolling: {
D.assert(_pointers.ContainsKey(datum.device));
_PointerState state = _pointers[datum.device];
Offset startPosition = state.lastPosition;
yield return new PointerScrollingEvent(
timeStamp: timeStamp,
pointer: state.pointer,
kind: kind,
device: datum.device,
position: startPosition,
delta: position
);
break;
}
case PointerChange.up:
case PointerChange.cancel: {

6
Runtime/gestures/drag_details.cs


TimeSpan sourceTimeStamp,
Offset delta = null,
double? primaryDelta = null,
Offset globalPosition = null) {
Offset globalPosition = null,
bool isScroll = false) {
this.isScroll = isScroll;
D.assert(primaryDelta == null
|| primaryDelta == this.delta.dx && this.delta.dy == 0.0
|| primaryDelta == this.delta.dy && this.delta.dx == 0.0);

public readonly double? primaryDelta;
public readonly Offset globalPosition;
public readonly bool isScroll;
public override string ToString() {
return this.GetType() + "(" + this.delta + ")";

44
Runtime/gestures/events.cs


}
}
public class PointerScrollStartEvent : PointerEvent {
public PointerScrollStartEvent(
TimeSpan timeStamp,
int pointer = 0,
PointerDeviceKind kind = PointerDeviceKind.mouse,
int device = 0,
Offset position = null)
: base(
timeStamp,
pointer: pointer,
kind: kind,
device: device,
position: position,
down: true) {
}
}
public class PointerScrollEndEvent : PointerEvent {
public PointerScrollEndEvent(
public class PointerScrollEvent : PointerEvent {
public PointerScrollEvent(
TimeSpan timeStamp,
int pointer = 0,
PointerDeviceKind kind = PointerDeviceKind.mouse,

kind: kind,
device: device,
position: position,
down: false,
delta : delta) {
}
}
public class PointerScrollingEvent : PointerEvent {
public PointerScrollingEvent(
TimeSpan timeStamp,
int pointer = 0,
PointerDeviceKind kind = PointerDeviceKind.mouse,
int device = 0,
Offset position = null,
Offset delta = null,
bool start = false)
: base(
timeStamp,
pointer: pointer,
kind: kind,
device: device,
position: position,
down: start,
down: true,
public class PointerHoverEvent : PointerEvent {
public PointerHoverEvent(

42
Runtime/gestures/monodrag.cs


readonly Dictionary<int, VelocityTracker> _velocityTrackers = new Dictionary<int, VelocityTracker>();
public override void addPointer(PointerDownEvent evt) {
public override void addPointer(PointerEvent evt) {
if (evt is PointerScrollEvent) {
this.startTrackingScrollerPointer(evt.pointer);
if (this._state == _DragState.ready) {
this._state = _DragState.possible;
this._initialPosition = evt.position;
if (this.onStart != null) {
this.invokeCallback<object>("onStart", () => {
this.onStart(new DragStartDetails(
sourceTimeStamp: evt.timeStamp,
globalPosition: this._initialPosition
));
return null;
});
}
}
return;
}
this.startTrackingPointer(evt.pointer);
this._velocityTrackers[evt.pointer] = new VelocityTracker();
if (this._state == _DragState.ready) {

}
protected override void handleEvent(PointerEvent evt) {
Debug.Log("handle Event >>> " + evt);
&& (evt is PointerDownEvent || evt is PointerMoveEvent || evt is PointerScrollingEvent)) {
&& (evt is PointerDownEvent || evt is PointerMoveEvent)) {
if (evt is PointerScrollingEvent) {
Debug.Log("handle Event >>>>" + evt.position + " == " + evt.delta);
if (evt is PointerScrollEvent) {
Offset delta = evt.delta;
if (this.onUpdate != null) {
this.invokeCallback<object>("onUpdate", () => {

primaryDelta: this._getPrimaryValueFromOffset(delta),
globalPosition: evt.position
globalPosition: evt.position,
isScroll: true
this.invokeCallback<object>("onEnd", () => {
this.onEnd(new DragEndDetails(
velocity: Velocity.zero,
primaryVelocity: 0.0
));
return null;
}, debugReport: () => { return ""; }
);
this._state = _DragState.ready;
}
if (evt is PointerMoveEvent) {

5
Runtime/gestures/multidrag.cs


Dictionary<int, T> _pointers = new Dictionary<int, T>();
public override void addPointer(PointerDownEvent pEvent) {
public override void addPointer(PointerEvent pEvent) {
D.assert(pEvent is PointerDownEvent);
T state = this.createNewPointerState(pEvent);
T state = this.createNewPointerState((PointerDownEvent)pEvent);
this._pointers[pEvent.pointer] = state;
GestureBinding.instance.pointerRouter.addRoute(pEvent.pointer, this._handleEvent);
state._setArenaEntry(GestureBinding.instance.gestureArena.add(pEvent.pointer, this));

5
Runtime/gestures/multitap.cs


_TapTracker _firstTap;
readonly Dictionary<int, _TapTracker> _trackers = new Dictionary<int, _TapTracker>();
public override void addPointer(PointerDownEvent evt) {
public override void addPointer(PointerEvent evt) {
D.assert(evt is PointerDownEvent);
if (this._firstTap != null &&
!this._firstTap.isWithinTolerance(evt, Constants.kDoubleTapSlop)) {
return;

_TapTracker tracker = new _TapTracker(
evt: evt,
evt: (PointerDownEvent)evt,
entry: GestureBinding.instance.gestureArena.add(evt.pointer, this)
);
this._trackers[evt.pointer] = tracker;

6
Runtime/gestures/pointer_router.cs


}
}
public void clearScrollRoute(int pointer) {
if (this._routeMap.ContainsKey(pointer)) {
this._routeMap.Remove(pointer);
}
}
public void addGlobalRoute(PointerRoute route) {
D.assert(!this._globalRoutes.Contains(route));
this._globalRoutes.Add(route);

17
Runtime/gestures/recognizer.cs


public readonly object debugOwner;
public abstract void addPointer(PointerDownEvent evt);
public abstract void addPointer(PointerEvent evt);
public virtual void dispose() {
}

return GestureBinding.instance.gestureArena.add(pointer, this);
}
protected void startTrackingScrollerPointer(int pointer) {
GestureBinding.instance.pointerRouter.addRoute(pointer, this.handleEvent);
}
protected void startTrackingPointer(int pointer) {
GestureBinding.instance.pointerRouter.addRoute(pointer, this.handleEvent);
this._trackedPointers.Add(pointer);

if (evt is PointerUpEvent || evt is PointerCancelEvent) {
this.stopTrackingPointer(evt.pointer);
}
if (evt is PointerScrollingEvent) {
if (evt.delta == Offset.zero && !evt.down) {
this.stopTrackingPointer(evt.pointer);
}
else {
Debug.Log("udddddddddddddd");
}
}
}
}

Timer _timer;
public override void addPointer(PointerDownEvent evt) {
public override void addPointer(PointerEvent evt) {
this.startTrackingPointer(evt.pointer);
if (this.state == GestureRecognizerState.ready) {
this.state = GestureRecognizerState.possible;

6
Runtime/rendering/proxy_box.cs


public delegate void PointerLeaveEventListener(PointerLeaveEvent evt);
public delegate void PointerScrollEventListener(PointerScrollingEvent evt);
public delegate void PointerScrollEventListener(PointerScrollEvent evt);
public class RenderPointerListener : RenderProxyBoxWithHitTestBehavior {
public RenderPointerListener(

return;
}
if (this.onPointerScroll != null && evt is PointerScrollingEvent) {
this.onPointerScroll((PointerScrollingEvent) evt);
if (this.onPointerScroll != null && evt is PointerScrollEvent) {
this.onPointerScroll((PointerScrollEvent) evt);
}
}

22
Runtime/ui/pointer.cs


down,
move,
up,
scroll_start,
scrolling,
scroll_end
scroll
}
public enum PointerDeviceKind {

public int device;
public double physicalX;
public double physicalY;
}
public class ScrollData : PointerData {
public ScrollData(
TimeSpan timeStamp,
PointerChange change,
PointerDeviceKind kind,
int device,
double physicalX,
double physicalY,
double scrollX,
double scrollY) : base(timeStamp, change, kind, device, physicalX, physicalY) {
this.scrollX = scrollX;
this.scrollY = scrollY;
}
public double scrollX;
public double scrollY;
}
public class PointerDataPacket {

12
Runtime/widgets/gesture_detector.cs


}
}
void _handlePointerScroll(PointerScrollingEvent evt) {
if (!evt.down) {
return;
}
void _handlePointerScroll(PointerScrollEvent evt) {
recognizer.addPointer(new PointerDownEvent(
timeStamp:evt.timeStamp,
pointer: evt.pointer,
kind: evt.kind,
device: evt.device,
position: evt.position));
recognizer.addPointer(evt);
}
}

18
Runtime/widgets/scroll_activity.cs


void applyUserOffset(double delta);
void applyUserScrollOffset(double delta);
void goIdle();
void goBallistic(double velocity);

D.assert(details.primaryDelta != null);
this._lastDetails = details;
double offset = details.primaryDelta.Value;
if (details.isScroll) {
if (offset == 0.0) {
return;
}
if (this._reversed) {
offset = -offset;
}
this.del.applyUserScrollOffset(offset);
return;
}
if (offset != 0.0) {
this._lastNonStationaryTimestamp = details.sourceTimeStamp;
}

14
Runtime/widgets/scroll_position_with_single_context.cs


}
}
public virtual void applyUserScrollOffset(double delta) {
this.updateUserScrollDirection(delta > 0.0 ? ScrollDirection.forward : ScrollDirection.reverse);
var pixel = this.pixels - this.physics.applyPhysicsToUserOffset(this, delta);
if (pixel < this.minScrollExtent) {
pixel = this.minScrollExtent;
}
if (pixel > this.maxScrollExtent) {
pixel = this.maxScrollExtent;
}
this.setPixels(pixel);
}
public virtual void applyUserOffset(double delta) {
this.updateUserScrollDirection(delta > 0.0 ? ScrollDirection.forward : ScrollDirection.reverse);
this.setPixels(this.pixels - this.physics.applyPhysicsToUserOffset(this, delta));

正在加载...
取消
保存