浏览代码

scroll

/siyaoH-1.17-PlatformMessage
siyao 4 年前
当前提交
dc533e91
共有 6 个文件被更改,包括 96 次插入8 次删除
  1. 16
      com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs
  2. 5
      com.unity.uiwidgets/Runtime/gestures/binding.cs
  3. 19
      com.unity.uiwidgets/Runtime/widgets/nested_scroll_view.cs
  4. 19
      com.unity.uiwidgets/Runtime/widgets/scrollable.cs
  5. 39
      engine/src/shell/platform/unity/windows/uiwidgets_panel.cc
  6. 6
      engine/src/shell/platform/unity/windows/uiwidgets_panel.h

16
com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs


else {
_lastMousePosition = Input.mousePosition;
}
if (Input.mouseScrollDelta.magnitude != 0) {
_onScroll();
}
}
}
}

}
UIWidgetsPanel_onMouseMove(_ptr, pos.Value.x, pos.Value.y);
}
void _onScroll() {
var pos = _getPointerPosition(Input.mousePosition);
if (pos == null) {
return;
}
var delta = Input.mouseScrollDelta;
UIWidgetsPanel_onScroll(_ptr, delta.x, delta.y, pos.Value.x, pos.Value.y);
}
public void OnPointerDown(PointerEventData eventData) {

[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_onMouseLeave(IntPtr ptr);
[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_onScroll(IntPtr ptr, float x, float y, float px, float py);
}
}

5
com.unity.uiwidgets/Runtime/gestures/binding.cs


readonly HashSet<HitTestEntry> _enteredTargets = new HashSet<HitTestEntry>();
void _handlePointerEvent(PointerEvent evt) {
if (evt is PointerScrollEvent) {
_handlePointerScrollEvent(evt);
return;
}
HitTestResult hitTestResult = null;
if (evt is PointerDownEvent || evt is PointerSignalEvent) {
D.assert(!_hitTests.ContainsKey(evt.pointer));

19
com.unity.uiwidgets/Runtime/widgets/nested_scroll_view.cs


return 0.0f;
}
public float applyClampedPointerSignalUpdate(float delta) {
D.assert(delta != 0.0f);
float min = delta > 0.0f
? float.NegativeInfinity
: Mathf.Min(minScrollExtent, pixels);
// The logic for max is equivalent but on the other side.
float max = delta < 0.0f
? float.PositiveInfinity
: Mathf.Max(maxScrollExtent, pixels);
float newPixels = (pixels + delta).clamp(min, max);
float clampedDelta = newPixels - pixels;
if (clampedDelta == 0.0f)
return delta;
forcePixels(newPixels);
didUpdateScrollPositionBy(clampedDelta);
return delta - clampedDelta;
}
public override ScrollDirection userScrollDirection {
get { return coordinator.userScrollDirection; }
}

19
com.unity.uiwidgets/Runtime/widgets/scrollable.cs


}
float _targetScrollOffsetForPointerScroll(PointerScrollEvent e) {
float delta = widget.axis == Axis.horizontal ? e.delta.dx : e.delta.dy;
float delta = widget.axis == Axis.horizontal
? e.scrollDelta.dx
: e.scrollDelta.dy;
delta += -1;
delta *= -1;
}
float _pointerSignalEventDelta(PointerScrollEvent evt) {
float delta = widget.axis == Axis.horizontal
? evt.scrollDelta.dx
: evt.scrollDelta.dy;
if (AxisUtils.axisDirectionIsReversed(widget.axisDirection)) {
delta *= -1;
}
return delta;
}
void _receivedPointerSignal(PointerSignalEvent e) {

39
engine/src/shell/platform/unity/windows/uiwidgets_panel.cc


vsync_batons_.push_back(baton);
}
void UIWidgetsPanel::SetEventLocationFromCursorPosition(
UIWidgetsPointerEvent* event_data) {
POINT point;
GetCursorPos(&point);
// TODO: this is a native method, use unity position instead.
// ScreenToClient(GetWindowHandle(), &point);
event_data->x = point.x;
event_data->y = point.y;
}
void UIWidgetsPanel::SetEventPhaseFromCursorButtonState(
UIWidgetsPointerEvent* event_data) {
MouseState state = GetMouseState();

SendPointerEventWithData(event);
}
void UIWidgetsPanel::SendScroll(float delta_x, float delta_y, float px, float py) {
UIWidgetsPointerEvent event = {};
// TODO: this is a native method, use unity position instead.
event.x = px;
event.y = py;
//SetEventLocationFromCursorPosition(&event);
SetEventPhaseFromCursorButtonState(&event);
event.signal_kind = UIWidgetsPointerSignalKind::kUIWidgetsPointerSignalKindScroll;
// TODO: See if this can be queried from the OS; this value is chosen
// arbitrarily to get something that feels reasonable.
const int kScrollOffsetMultiplier = 20;
event.scroll_delta_x = delta_x * kScrollOffsetMultiplier;
event.scroll_delta_y = delta_y * kScrollOffsetMultiplier;
SendPointerEventWithData(event);
}
void UIWidgetsPanel::SendPointerEventWithData(
const UIWidgetsPointerEvent& event_data) {
MouseState mouse_state = GetMouseState();

void UIWidgetsPanel::OnMouseMove(float x, float y) {
if (process_events_) {
SendMouseMove(x, y);
}
}
void UIWidgetsPanel::OnScroll(float x, float y, float px, float py) {
if (process_events_) {
SendScroll(x, y, px, py);
}
}

UIWIDGETS_API(void)
UIWidgetsPanel_onMouseLeave(UIWidgetsPanel* panel) { panel->OnMouseLeave(); }
UIWIDGETS_API(void)
UIWidgetsPanel_onScroll(UIWidgetsPanel* panel, float x, float y, float px, float py) {
panel->OnScroll(x, y, px, py);
}
} // namespace uiwidgets

6
engine/src/shell/platform/unity/windows/uiwidgets_panel.h


void VSyncCallback(intptr_t baton);
void SetEventLocationFromCursorPosition(UIWidgetsPointerEvent* event_data);
void OnScroll(float x, float y, float px, float py);
void OnMouseDown(float x, float y, int button);

void SendMouseUp(float x, float y);
void SendMouseLeave();
void SendScroll(float delta_x, float delta_y, float px, float py);
void SetEventPhaseFromCursorButtonState(UIWidgetsPointerEvent* event_data);

正在加载...
取消
保存