浏览代码

improve scroll

/main
xingwei.zhu 6 年前
当前提交
e148e5c0
共有 2 个文件被更改,包括 36 次插入29 次删除
  1. 12
      Runtime/editor/scroll_input.cs
  2. 53
      Runtime/engine/WidgetCanvas.cs

12
Runtime/editor/scroll_input.cs


using System;
readonly int _bufferSize = 10;
readonly int _bufferSize = 20;
readonly float _scrollScale = 10;
float _scrollDeltaX;

float _pointerY;
int _buttonId;
public ScrollInput(int bufferSize = 10, float scrollScale = 10) {
this._bufferIndex = bufferSize;
this._bufferSize = bufferSize;
public ScrollInput(int? bufferSize = null, float? scrollScale = null) {
this._bufferSize = bufferSize ?? this._bufferSize;
this._scrollScale = scrollScale ?? this._scrollScale;
this._bufferIndex = this._bufferSize;
this._scrollScale = scrollScale;
}
public void onScroll(float deltaX, float deltaY, float pointerX, float pointerY, int buttonId) {

53
Runtime/engine/WidgetCanvas.cs


protected override void OnEnable() {
base.OnEnable();
Input.simulateMouseWithTouches = false;
if (_repaintEvent == null) {
_repaintEvent = new Event {type = EventType.Repaint};
}

}
if (this._mouseEntered) {
if (Input.mouseScrollDelta.y != 0 || Input.mouseScrollDelta.x != 0) {
var scaleFactor = this.canvas.scaleFactor;
var pos = this.getPointPosition(Input.mousePosition);
this._scrollInput.onScroll(Input.mouseScrollDelta.x * scaleFactor,
Input.mouseScrollDelta.y * scaleFactor,
pos.x,
pos.y,
this.getScrollButton());
}
var deltaScroll = this._scrollInput.getScrollDelta();
if (deltaScroll != Vector2.zero) {
this._windowAdapter.postPointerEvent(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.handleMouseScroll();
}

physicalY: pos.y
));
}
void handleMouseScroll() {
if (Input.mouseScrollDelta.y != 0 || Input.mouseScrollDelta.x != 0) {
var scaleFactor = this.canvas.scaleFactor;
var pos = this.getPointPosition(Input.mousePosition);
this._scrollInput.onScroll(Input.mouseScrollDelta.x * scaleFactor,
Input.mouseScrollDelta.y * scaleFactor,
pos.x,
pos.y,
this.getScrollButton());
}
var deltaScroll = this._scrollInput.getScrollDelta();
if (deltaScroll != Vector2.zero) {
this._windowAdapter.postPointerEvent(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
));
}
}
int getScrollButton() {
return mouseScrollId;

正在加载...
取消
保存