浏览代码

mouse scroll bug fix

/main
xingwei.zhu 6 年前
当前提交
381f260a
共有 5 个文件被更改,包括 138 次插入29 次删除
  1. 40
      Runtime/editor/editor_window.cs
  2. 80
      Runtime/editor/scroll_input.cs
  3. 23
      Runtime/engine/WidgetCanvas.cs
  4. 8
      Runtime/gestures/binding.cs
  5. 16
      Runtime/gestures/monodrag.cs

40
Runtime/editor/editor_window.cs


readonly TimerProvider _timerProvider = new TimerProvider();
readonly TextInput _textInput = new TextInput();
readonly Rasterizer _rasterizer = new Rasterizer();
readonly ScrollInput _scrollInput = new ScrollInput();
bool _regenerateLayerTree;
Surface _surface;

);
}
else if (evt.type == EventType.ScrollWheel) {
pointerData = new ScrollData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.scroll,
kind: PointerDeviceKind.mouse,
device: evt.button,
physicalX: evt.mousePosition.x * this._devicePixelRatio,
physicalY: evt.mousePosition.y * this._devicePixelRatio,
scrollX: -evt.delta.x,
scrollY: -evt.delta.y
this._scrollInput.OnScroll((float) (-evt.delta.x * this._devicePixelRatio),
(float) (-evt.delta.y * this._devicePixelRatio),
(float) (evt.mousePosition.x * this._devicePixelRatio),
(float) (evt.mousePosition.y * this._devicePixelRatio),
evt.button
);
}

}
}
void _UpdateScrollInput() {
var deltaScroll = this._scrollInput.GetScrollDelta();
if (deltaScroll == Vector2.zero) {
return;
}
PointerData pointerData = new ScrollData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.scroll,
kind: PointerDeviceKind.mouse,
device: this._scrollInput.GetDeviceId(),
physicalX: this._scrollInput.GetPointerPosX(),
physicalY: this._scrollInput.GetPointerPosY(),
scrollX: deltaScroll.x,
scrollY: deltaScroll.y
);
this.onPointerEvent(new PointerDataPacket(new List<PointerData> {
pointerData
}));
}
this._UpdateScrollInput();
this._timerProvider.update(this.flushMicrotasks);
this.flushMicrotasks();
}

80
Runtime/editor/scroll_input.cs


using System;
using UnityEngine;
public class scroll_input {
public class ScrollInput {
float scrollDeltaX;
float scrollDeltaY;
readonly int bufferSize;
readonly float scrollScale = 10;
int bufferIndex = 10;
float CurDeltaX;
float CurDeltaY;
float PointerX;
float PointerY;
int buttonId;
public ScrollInput(int bufferSize = 10, float scrollScale = 10) {
this.bufferIndex = bufferSize;
this.bufferSize = bufferSize;
this.scrollDeltaX = 0;
this.scrollDeltaY = 0;
this.CurDeltaX = 0;
this.CurDeltaY = 0;
this.scrollScale = scrollScale;
}
public void OnScroll(float deltaX, float deltaY, float PointerX, float PointerY, int buttonId) {
this.scrollDeltaX += deltaX * this.scrollScale;
this.scrollDeltaY += deltaY * this.scrollScale;
this.bufferIndex = this.bufferSize;
this.CurDeltaX = this.scrollDeltaX / this.bufferIndex;
this.CurDeltaY = this.scrollDeltaY / this.bufferIndex;
this.PointerX = PointerX;
this.PointerY = PointerY;
this.buttonId = buttonId;
}
public int GetDeviceId() {
return this.buttonId;
}
public float GetPointerPosX() {
return this.PointerX;
}
public float GetPointerPosY() {
return this.PointerY;
}
public Vector2 GetScrollDelta() {
if (this.scrollDeltaX == 0 && this.scrollDeltaY == 0) {
return Vector2.zero;
}
var deltaScroll = new Vector2();
if (this.bufferIndex == 0) {
deltaScroll.x = this.scrollDeltaX;
deltaScroll.y = this.scrollDeltaY;
this.scrollDeltaX = 0;
this.scrollDeltaY = 0;
}
else {
deltaScroll.x = this.CurDeltaX;
deltaScroll.y = this.CurDeltaY;
this.scrollDeltaX = this.CurDeltaX > 0
? Math.Max(0, this.scrollDeltaX - this.CurDeltaX)
: Math.Min(0, this.scrollDeltaX - this.CurDeltaX);
this.scrollDeltaY = this.CurDeltaY > 0
? Math.Max(0, this.scrollDeltaY - this.CurDeltaY)
: Math.Min(0, this.scrollDeltaY - this.CurDeltaY);
this.bufferIndex--;
}
return deltaScroll;
}
}
}

23
Runtime/engine/WidgetCanvas.cs


const int mouseButtonNum = 3;
const int mouseScrollId = mouseButtonNum + 1;
readonly ScrollInput _scrollInput = new ScrollInput();
protected override void OnEnable() {
base.OnEnable();

}
if (this._mouseEntered) {
if (Input.mouseScrollDelta.y != 0) {
if (Input.mouseScrollDelta.y != 0 || Input.mouseScrollDelta.x != 0) {
this._scrollInput.OnScroll((float) (Input.mouseScrollDelta.x * this.pixelRatio),
(float) (Input.mouseScrollDelta.y * this.pixelRatio),
pos.x,
pos.y,
this.getScrollButton());
}
var deltaScroll = this._scrollInput.GetScrollDelta();
if (deltaScroll != Vector2.zero) {
device: this.getScrollButton(),
physicalX: pos.x,
physicalY: pos.y,
scrollX: Input.mouseScrollDelta.x,
scrollY: Input.mouseScrollDelta.y * 5
device: this._scrollInput.GetDeviceId(),
physicalX: this._scrollInput.GetPointerPosX(),
physicalY: this._scrollInput.GetPointerPosY(),
scrollX: deltaScroll.x,
scrollY: deltaScroll.y
));
}
}

8
Runtime/gestures/binding.cs


public readonly HashSet<HitTestTarget> lastMoveTargets = new HashSet<HitTestTarget>();
void _handlePointerEvent(PointerEvent evt) {
if (evt is PointerHoverEvent) {
this._handlePointerHoverEvent(evt);
}
}
if (evt is PointerHoverEvent) {
this._handlePointerHoverEvent(evt);
}
HitTestResult result;

16
Runtime/gestures/monodrag.cs


protected override void handleEvent(PointerEvent evt) {
D.assert(this._state != _DragState.ready);
if (!evt.synthesized
&& (evt is PointerDownEvent || evt is PointerMoveEvent)) {
var tracker = this._velocityTrackers[evt.pointer];
D.assert(tracker != null);
tracker.addPosition(evt.timeStamp, evt.position);
}
if (evt is PointerScrollEvent) {
Offset delta = evt.delta;
if (this.onUpdate != null) {

primaryVelocity: 0.0
));
return null;
}, debugReport: () => { return ""; }
}, debugReport: () => { return "Pointer scroll end"; }
}
if (!evt.synthesized
&& (evt is PointerDownEvent || evt is PointerMoveEvent)) {
var tracker = this._velocityTrackers[evt.pointer];
D.assert(tracker != null);
tracker.addPosition(evt.timeStamp, evt.position);
}
if (evt is PointerMoveEvent) {

正在加载...
取消
保存