浏览代码

Merge pull request #154 from Unity-Technologies/fix_datepicker

fix cupertino datepicker error and relocate mouse_tracking
/main
GitHub 4 年前
当前提交
4a488c8b
共有 7 个文件被更改,包括 275 次插入574 次删除
  1. 2
      Samples/UIWidgetsSamples_2019_4/ProjectSettings/ProjectVersion.txt
  2. 18
      com.unity.uiwidgets/Runtime/cupertino/date_picker.cs
  3. 26
      com.unity.uiwidgets/Runtime/gestures/events.cs
  4. 476
      com.unity.uiwidgets/Runtime/rendering/mouse_tracking.cs
  5. 2
      com.unity.uiwidgets/Runtime/rendering/mouse_tracking.cs.meta
  6. 325
      com.unity.uiwidgets/Runtime/gestures/mouse_tracking.cs
  7. 0
      /com.unity.uiwidgets/Runtime/rendering/mouse_tracking.cs.meta

2
Samples/UIWidgetsSamples_2019_4/ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2019.4.2f1
m_EditorVersionWithRevision: 2019.4.2f1 (f997fc5c673b)
m_EditorVersionWithRevision: 2019.4.2f1 (f997fc5c673b)

18
com.unity.uiwidgets/Runtime/cupertino/date_picker.cs


}
DateTime selectedDateTime {
get {
return new DateTime(
return (new DateTime(
initialDateTime.Day + selectedDayFromInitial,
initialDateTime.Day,
);
)).AddDays(selectedDayFromInitial);
}
}
void _onSelectedItemChange(int index) {

);
}
bool _isValidHour(int meridiemIndex, int hourIndex) {
DateTime rangeStart = new DateTime(
DateTime rangeStart = (new DateTime(
initialDateTime.Day + selectedDayFromInitial,
initialDateTime.Day,
);
)).AddDays(selectedDayFromInitial);
// The end value of the range is exclusive, i.e. [rangeStart, rangeEnd).
DateTime rangeEnd = rangeStart.Add(new TimeSpan(0,1,0,0));

for (int index = 0; index < 24; index++) {
int minute = index * widget.minuteInterval;
DateTime date = new DateTime(
DateTime date = (new DateTime(
initialDateTime.Day + selectedDayFromInitial,
initialDateTime.Day,
);
)).AddDays(selectedDayFromInitial);
bool isInvalidMinute = (widget.minimumDate?.CompareTo(date) < 0 )
|| (widget.maximumDate?.CompareTo(date) > 0);

26
com.unity.uiwidgets/Runtime/gestures/events.cs


properties.add(new IntProperty("buttons", buttons, defaultValue: 0, level: DiagnosticLevel.debug));
properties.add(new DiagnosticsProperty<bool>("down", down, level: DiagnosticLevel.debug));
properties.add(
new FloatProperty("pressure", pressure, defaultValue: 1.0, level: DiagnosticLevel.debug));
properties.add(new FloatProperty("pressureMin", pressureMin, defaultValue: 1.0,
new FloatProperty("pressure", pressure, defaultValue: 1.0f, level: DiagnosticLevel.debug));
properties.add(new FloatProperty("pressureMin", pressureMin, defaultValue: 1.0f,
properties.add(new FloatProperty("pressureMax", pressureMax, defaultValue: 1.0,
properties.add(new FloatProperty("pressureMax", pressureMax, defaultValue: 1.0f,
new FloatProperty("distance", distance, defaultValue: 0.0, level: DiagnosticLevel.debug));
properties.add(new FloatProperty("distanceMin", distanceMin, defaultValue: 0.0,
new FloatProperty("distance", distance, defaultValue: 0.0f, level: DiagnosticLevel.debug));
properties.add(new FloatProperty("distanceMin", distanceMin, defaultValue: 0.0f,
properties.add(new FloatProperty("distanceMax", distanceMax, defaultValue: 0.0,
properties.add(new FloatProperty("distanceMax", distanceMax, defaultValue: 0.0f,
properties.add(new FloatProperty("size", size, defaultValue: 0.0, level: DiagnosticLevel.debug));
properties.add(new FloatProperty("radiusMajor", radiusMajor, defaultValue: 0.0,
properties.add(new FloatProperty("size", size, defaultValue: 0.0f, level: DiagnosticLevel.debug));
properties.add(new FloatProperty("radiusMajor", radiusMajor, defaultValue: 0.0f,
properties.add(new FloatProperty("radiusMinor", radiusMinor, defaultValue: 0.0,
properties.add(new FloatProperty("radiusMinor", radiusMinor, defaultValue: 0.0f,
properties.add(new FloatProperty("radiusMin", radiusMin, defaultValue: 0.0,
properties.add(new FloatProperty("radiusMin", radiusMin, defaultValue: 0.0f,
properties.add(new FloatProperty("radiusMax", radiusMax, defaultValue: 0.0,
properties.add(new FloatProperty("radiusMax", radiusMax, defaultValue: 0.0f,
properties.add(new FloatProperty("orientation", orientation, defaultValue: 0.0,
properties.add(new FloatProperty("orientation", orientation, defaultValue: 0.0f,
properties.add(new FloatProperty("tilt", tilt, defaultValue: 0.0, level: DiagnosticLevel.debug));
properties.add(new FloatProperty("tilt", tilt, defaultValue: 0.0f, level: DiagnosticLevel.debug));
properties.add(new IntProperty("platformData", platformData, defaultValue: 0,
level: DiagnosticLevel.debug));
properties.add(new FlagProperty("obscured", value: obscured, ifTrue: "obscured",

476
com.unity.uiwidgets/Runtime/rendering/mouse_tracking.cs


/*using System;
using Unity.UIWidgets.gestures;
namespace Unity.UIWidgets.rendering {
public delegate void PointerEnterEventListener(PointerEnterEvent _event);
public delegate void PointerExitEventListener(PointerExitEvent _event);
public delegate void PointerHoverEventListener(PointerHoverEvent _event);
public class MouseTrackerAnnotation : Diagnosticable {
namespace Unity.UIWidgets.gestures {
public delegate void PointerHoverEventListener(PointerHoverEvent evt);
public MouseTrackerAnnotation(
PointerEnterEventListener onEnter,
PointerHoverEventListener onHover,
PointerExitEventListener onExit) {
this.onEnter = onEnter;
this.onHover = onHover;
this.onExit = onExit;
}
public delegate void PointerEnterEventListener(PointerEnterEvent evt);
public readonly PointerEnterEventListener onEnter;
public readonly PointerHoverEventListener onHover;
public readonly PointerExitEventListener onExit;
public delegate void PointerExitEventListener(PointerExitEvent evt);
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new FlagsSummary<Delegate>(
"callbacks",
new Dictionary<string, Delegate> {
{"enter", onEnter},
{"hover", onHover},
{"exit", onExit},
},
ifEmpty: "<none>"
));
}
}
public delegate void PointerDragFromEditorEnterEventListener(PointerDragFromEditorEnterEvent evt);
public delegate void PointerDragFromEditorHoverEventListener(PointerDragFromEditorHoverEvent evt);
public delegate void PointerDragFromEditorExitEventListener(PointerDragFromEditorExitEvent evt);
public delegate void PointerDragFromEditorReleaseEventListener(PointerDragFromEditorReleaseEvent evt);
public delegate IEnumerable<MouseTrackerAnnotation> MouseDetectorAnnotationFinder(Offset offset);
public _MouseState(PointerEvent initialEvent) {
public _MouseState(PointerEvent initialEvent = null
) {
get { return _annotations; }
get { return _annotations;}
HashSet<MouseTrackerAnnotation> _annotations = new HashSet<MouseTrackerAnnotation>();
public HashSet<MouseTrackerAnnotation> replaceAnnotations(HashSet<MouseTrackerAnnotation> value) {

}
// The most recently processed mouse event observed from this device.
get {
return _latestEvent;
}
get { return _latestEvent; }
get {
return latestEvent.device;
}
get { return latestEvent.device;}
string describeEvent(PointerEvent _event) {
return _event == null ? "null" : foundation_.describeIdentity(_event);
string describeEvent(PointerEvent Event) {
return Event == null ? "null" : describeIdentity(Event);
return $"{foundation_.describeIdentity(this)}({describeLatestEvent}, {describeAnnotations})";
return $"{describeIdentity(this)}"+$"({describeLatestEvent}, {describeAnnotations})";
}
public class MouseTracker : ChangeNotifier {
public MouseTracker(PointerRouter _router, MouseDetectorAnnotationFinder annotationFinder) {
D.assert(_router != null);
D.assert(annotationFinder != null);
_router.addGlobalRoute(_handleEvent);
}
public string describeIdentity(object Object) {
return $"{Object.GetType()}" + $"{Object.GetHashCode()}";
public override void dispose() {
base.dispose();
_router.removeGlobalRoute(_handleEvent);
}
public readonly MouseDetectorAnnotationFinder annotationFinder;
public readonly PointerRouter _router;
public readonly Dictionary<int, _MouseState> _mouseStates = new Dictionary<int, _MouseState>();
static bool _shouldMarkStateDirty(_MouseState state, PointerEvent value) {
if (state == null)
return true;
D.assert(value != null);
PointerEvent lastEvent = state.latestEvent;
D.assert(value.device == lastEvent.device);
D.assert((value is PointerAddedEvent) == (lastEvent is PointerRemovedEvent));
if (value is PointerSignalEvent)
return false;
return lastEvent is PointerAddedEvent
|| value is PointerRemovedEvent
|| lastEvent.position != value.position;
}
public class MouseTrackerAnnotation {
public MouseTrackerAnnotation(
PointerEnterEventListener onEnter = null,
PointerHoverEventListener onHover = null,
PointerExitEventListener onExit = null,
PointerDragFromEditorEnterEventListener onDragFromEditorEnter = null,
PointerDragFromEditorHoverEventListener onDragFromEditorHover = null,
PointerDragFromEditorExitEventListener onDragFromEditorExit = null,
PointerDragFromEditorReleaseEventListener onDragFromEditorRelease = null
) {
this.onEnter = onEnter;
this.onHover = onHover;
this.onExit = onExit;
void _handleEvent(PointerEvent _event) {
if (_event.kind != PointerDeviceKind.mouse)
return;
if (_event is PointerSignalEvent)
return;
int device = _event.device;
_MouseState existingState = _mouseStates.getOrDefault(device);
if (!_shouldMarkStateDirty(existingState, _event))
return;
this.onDragFromEditorEnter = onDragFromEditorEnter;
this.onDragFromEditorHover = onDragFromEditorHover;
this.onDragFromEditorExit = onDragFromEditorExit;
this.onDragFromEditorRelease = onDragFromEditorRelease;
}
PointerEvent previousEvent = existingState?.latestEvent;
_updateDevices(
targetEvent: _event,
handleUpdatedDevice: (_MouseState mouseState, HashSet<MouseTrackerAnnotation> previousAnnotations) =>{
D.assert(mouseState.device == _event.device);
_dispatchDeviceCallbacks(
lastAnnotations: previousAnnotations,
nextAnnotations: mouseState.annotations,
previousEvent: previousEvent,
unhandledEvent: _event
);
});
}
HashSet<MouseTrackerAnnotation> _findAnnotations(_MouseState state) {
Offset globalPosition = state.latestEvent.position;
int device = state.device;
HashSet<MouseTrackerAnnotation> temp = new HashSet<MouseTrackerAnnotation>();
foreach (var set in annotationFinder(globalPosition)) {
temp.Add(set);
public readonly PointerEnterEventListener onEnter;
public readonly PointerHoverEventListener onHover;
public readonly PointerExitEventListener onExit;
public readonly PointerDragFromEditorEnterEventListener onDragFromEditorEnter;
public readonly PointerDragFromEditorHoverEventListener onDragFromEditorHover;
public readonly PointerDragFromEditorExitEventListener onDragFromEditorExit;
public readonly PointerDragFromEditorReleaseEventListener onDragFromEditorRelease;
public override string ToString() {
return
$"{GetType()}#{GetHashCode()}{(onEnter == null ? "" : " onEnter")}{(onHover == null ? "" : " onHover")}{(onExit == null ? "" : " onExit")}";
return (_mouseStates.ContainsKey(device)) ? temp : new HashSet<MouseTrackerAnnotation>();
static bool _duringBuildPhase {
get {
return SchedulerBinding.instance.schedulerPhase == SchedulerPhase.persistentCallbacks;
public class _TrackedAnnotation {
public _TrackedAnnotation(
MouseTrackerAnnotation annotation) {
this.annotation = annotation;
}
void _updateAllDevices() {
_updateDevices(
handleUpdatedDevice: (_MouseState mouseState, HashSet<MouseTrackerAnnotation> previousAnnotations) => {
_dispatchDeviceCallbacks(
lastAnnotations: previousAnnotations,
nextAnnotations: mouseState.annotations,
previousEvent: mouseState.latestEvent,
unhandledEvent: null
);
});
public readonly MouseTrackerAnnotation annotation;
public HashSet<int> activeDevices = new HashSet<int>();
bool _duringDeviceUpdate = false;
void _updateDevices(
PointerEvent targetEvent = null,
_UpdatedDeviceHandler handleUpdatedDevice = null
) {
D.assert(handleUpdatedDevice != null);
D.assert(!_duringBuildPhase);
D.assert(!_duringDeviceUpdate);
bool mouseWasConnected = mouseIsConnected;
public delegate IEnumerable<MouseTrackerAnnotation> MouseDetectorAnnotationFinder(Offset offset);
_MouseState targetState = null;
if (targetEvent != null) {
targetState = _mouseStates.getOrDefault(targetEvent.device);
if (targetState == null) {
targetState = new _MouseState(initialEvent: targetEvent);
_mouseStates[targetState.device] = targetState;
} else {
D.assert(!(targetEvent is PointerAddedEvent));
targetState.latestEvent = targetEvent;
if (targetEvent is PointerRemovedEvent)
_mouseStates.Remove(targetEvent.device);
}
public class MouseTracker : ChangeNotifier{
public MouseTracker(
PointerRouter router,
MouseDetectorAnnotationFinder annotationFinder
) {
D.assert(router != null);
D.assert(annotationFinder != null);
_router = router;
router.addGlobalRoute(_handleEvent);
this.annotationFinder = annotationFinder;
D.assert(() => {
_duringDeviceUpdate = true;
return true;
});
IEnumerable<_MouseState> dirtyStates = targetEvent == null ? _mouseStates.Values : new List<_MouseState>{targetState};
foreach (_MouseState dirtyState in dirtyStates) {
HashSet<MouseTrackerAnnotation> nextAnnotations = _findAnnotations(dirtyState);
HashSet<MouseTrackerAnnotation> lastAnnotations = dirtyState.replaceAnnotations(nextAnnotations);
handleUpdatedDevice(dirtyState, lastAnnotations);
public override void dispose() {
base.dispose();
_router.removeGlobalRoute(_handleEvent);
D.assert(() => {
_duringDeviceUpdate = false;
return true;
});
public readonly MouseDetectorAnnotationFinder annotationFinder;
readonly Dictionary<int, PointerEvent> _lastMouseEvent = new Dictionary<int, PointerEvent>();
readonly PointerRouter _router;
public readonly Dictionary<int, _MouseState> _mouseStates = new Dictionary<int, _MouseState>();
public bool mouseIsConnected {
get { return _lastMouseEvent.isNotEmpty(); }
}
public static bool _shouldMarkStateDirty(_MouseState state, PointerEvent value) {
if (state == null)
return true;
D.assert(value != null);
PointerEvent lastEvent = state.latestEvent;
D.assert(value.device == lastEvent.device);
D.assert((value is PointerAddedEvent) == (lastEvent is PointerRemovedEvent));
if (value is PointerSignalEvent)
return false;
return lastEvent is PointerAddedEvent
|| value is PointerRemovedEvent
|| lastEvent.position != value.position;
}
if (mouseWasConnected != mouseIsConnected)
notifyListeners();
}
static void _dispatchDeviceCallbacks(
HashSet<MouseTrackerAnnotation> lastAnnotations = null,
HashSet<MouseTrackerAnnotation> nextAnnotations = null,
PointerEvent previousEvent = null,
PointerEvent unhandledEvent = null
) {
D.assert(lastAnnotations != null);
D.assert(nextAnnotations != null);
PointerEvent latestEvent = unhandledEvent ?? previousEvent;
D.assert(latestEvent != null);
public readonly Dictionary<MouseTrackerAnnotation, _TrackedAnnotation> _trackedAnnotations =
new Dictionary<MouseTrackerAnnotation, _TrackedAnnotation>();
List<MouseTrackerAnnotation> exitingAnnotations = new List<MouseTrackerAnnotation>();
foreach (var annotation in lastAnnotations) {
if (!nextAnnotations.Contains(annotation)) {
exitingAnnotations.Add(annotation);
public void _handleEvent(PointerEvent Event) {
if (Event.kind != PointerDeviceKind.mouse)
return;
if (Event is PointerSignalEvent)
return;
int device = Event.device;
_MouseState existingState = _mouseStates.getOrDefault(device);
if (!_shouldMarkStateDirty(existingState, Event))
return;
PointerEvent previousEvent = existingState?.latestEvent;
_updateDevices(
targetEvent: Event,
handleUpdatedDevice: (_MouseState mouseState, HashSet<MouseTrackerAnnotation> previousAnnotations) =>{
D.assert(mouseState.device == Event.device);
_dispatchDeviceCallbacks(
lastAnnotations: previousAnnotations,
nextAnnotations: mouseState.annotations,
previousEvent: previousEvent,
unhandledEvent: Event
);
}
);
}
public static void _dispatchDeviceCallbacks(
HashSet<MouseTrackerAnnotation> lastAnnotations,
HashSet<MouseTrackerAnnotation> nextAnnotations,
PointerEvent previousEvent = null,
PointerEvent unhandledEvent = null
) {
D.assert(lastAnnotations != null);
D.assert(nextAnnotations != null);
PointerEvent latestEvent = unhandledEvent ?? previousEvent;
D.assert(latestEvent != null);
IEnumerable<MouseTrackerAnnotation> exitingAnnotations = new List<MouseTrackerAnnotation>();
foreach (var lastAnnotation in lastAnnotations) {
if (!nextAnnotations.Contains(lastAnnotation)) {
exitingAnnotations.Append(lastAnnotation);
}
}
foreach ( MouseTrackerAnnotation annotation in exitingAnnotations) {
if (annotation.onExit != null) {
annotation.onExit(PointerExitEvent.fromMouseEvent(latestEvent));
}
}
IEnumerable<MouseTrackerAnnotation> enteringAnnotations = new List<MouseTrackerAnnotation>();
List<MouseTrackerAnnotation> entering = new List<MouseTrackerAnnotation>();
foreach (var nextAnnotation in nextAnnotations) {
if (!lastAnnotations.Contains(nextAnnotation)) {
entering.Add(nextAnnotation);
}
}
entering.ToList().Reverse();
enteringAnnotations = entering;
foreach ( MouseTrackerAnnotation annotation in enteringAnnotations) {
if (annotation.onEnter != null) {
annotation.onEnter(PointerEnterEvent.fromMouseEvent(latestEvent));
}
}
if (unhandledEvent is PointerHoverEvent) {
Offset lastHoverPosition = previousEvent is PointerHoverEvent ? previousEvent.position : null;
bool pointerHasMoved = lastHoverPosition == null || lastHoverPosition != unhandledEvent.position;
nextAnnotations.ToList().Reverse();
IEnumerable<MouseTrackerAnnotation> hoveringAnnotations = pointerHasMoved ? nextAnnotations : enteringAnnotations;
foreach ( MouseTrackerAnnotation annotation in hoveringAnnotations) {
if (annotation.onHover != null) {
annotation.onHover((PointerHoverEvent)unhandledEvent);
}
}
foreach (MouseTrackerAnnotation annotation in exitingAnnotations) {
annotation.onExit?.Invoke(PointerExitEvent.fromMouseEvent(latestEvent));
public HashSet<MouseTrackerAnnotation> _findAnnotations(_MouseState state) {
Offset globalPosition = state.latestEvent.position;
int device = state.device;
HashSet<MouseTrackerAnnotation> result = new HashSet<MouseTrackerAnnotation>();
foreach (var values in annotationFinder(globalPosition)) {
result.Add(values);
}
return (_mouseStates.ContainsKey(device))
? result
: new HashSet<MouseTrackerAnnotation>{} as HashSet<MouseTrackerAnnotation>;
List<MouseTrackerAnnotation> enteringAnnotations = new List<MouseTrackerAnnotation>();
foreach (var annotation in nextAnnotations) {
if (!lastAnnotations.Contains(annotation)) {
enteringAnnotations.Add(annotation);
public static bool _duringBuildPhase {
get {
return SchedulerBinding.instance.schedulerPhase == SchedulerPhase.persistentCallbacks;
enteringAnnotations.Reverse();
foreach (MouseTrackerAnnotation annotation in enteringAnnotations) {
annotation.onEnter?.Invoke(PointerEnterEvent.fromMouseEvent(latestEvent));
public void _updateAllDevices() {
_updateDevices(
handleUpdatedDevice: (_MouseState mouseState, HashSet<MouseTrackerAnnotation> previousAnnotations)=> {
_dispatchDeviceCallbacks(
lastAnnotations: previousAnnotations,
nextAnnotations: mouseState.annotations,
previousEvent: mouseState.latestEvent,
unhandledEvent: null
);
}
);
if (unhandledEvent is PointerHoverEvent) {
Offset lastHoverPosition = previousEvent is PointerHoverEvent ? previousEvent.position : null;
bool pointerHasMoved = lastHoverPosition == null || lastHoverPosition != unhandledEvent.position;
List<MouseTrackerAnnotation> nextAnnotationsList = new List<MouseTrackerAnnotation>();
foreach (var annotation in nextAnnotations) {
nextAnnotationsList.Add(annotation);
bool _duringDeviceUpdate = false;
void _updateDevices(
PointerEvent targetEvent = null,
_UpdatedDeviceHandler handleUpdatedDevice = null) {
D.assert(handleUpdatedDevice != null);
D.assert(!_duringBuildPhase);
D.assert(!_duringDeviceUpdate);
bool mouseWasConnected = mouseIsConnected;
_MouseState targetState = null;
if (targetEvent != null) {
targetState = _mouseStates.getOrDefault(targetEvent.device);
if (targetState == null) {
targetState = new _MouseState(initialEvent: targetEvent);
_mouseStates[targetState.device] = targetState;
} else {
D.assert(!(targetEvent is PointerAddedEvent));
targetState.latestEvent = targetEvent;
if (targetEvent is PointerRemovedEvent)
_mouseStates.Remove(targetEvent.device);
}
D.assert((targetState == null) == (targetEvent == null));
nextAnnotationsList.Reverse();
IEnumerable<MouseTrackerAnnotation> hoveringAnnotations = pointerHasMoved ? nextAnnotationsList : enteringAnnotations;
foreach (MouseTrackerAnnotation annotation in hoveringAnnotations) {
annotation.onHover?.Invoke((PointerHoverEvent)unhandledEvent);
D.assert(()=> {
_duringDeviceUpdate = true;
return true;
});
IEnumerable<_MouseState> dirtyStates = targetEvent == null ? (IEnumerable<_MouseState>) _mouseStates.Values : new List<_MouseState>{targetState};
foreach ( _MouseState dirtyState in dirtyStates) {
HashSet<MouseTrackerAnnotation> nextAnnotations = _findAnnotations(dirtyState);
HashSet<MouseTrackerAnnotation> lastAnnotations = dirtyState.replaceAnnotations(nextAnnotations);
handleUpdatedDevice(dirtyState, lastAnnotations);
}
}
D.assert(() =>{
_duringDeviceUpdate = false;
return true;
});
bool _hasScheduledPostFrameCheck = false;
public void schedulePostFrameCheck() {
D.assert(_duringBuildPhase);
D.assert(!_duringDeviceUpdate);
if (!mouseIsConnected)
return;
if (!_hasScheduledPostFrameCheck) {
_hasScheduledPostFrameCheck = true;
SchedulerBinding.instance.addPostFrameCallback((TimeSpan timeSpan) => {
D.assert(_hasScheduledPostFrameCheck);
_hasScheduledPostFrameCheck = false;
_updateAllDevices();
});
if (mouseWasConnected != mouseIsConnected)
notifyListeners();
}
public bool mouseIsConnected {
get {
return _mouseStates.isNotEmpty();
public bool _hasScheduledPostFrameCheck = false;
public void schedulePostFrameCheck() {
D.assert(_duringBuildPhase);
D.assert(!_duringDeviceUpdate);
if (!mouseIsConnected)
return;
if (!_hasScheduledPostFrameCheck) {
_hasScheduledPostFrameCheck = true;
SchedulerBinding.instance.addPostFrameCallback((stamp => {
D.assert(_hasScheduledPostFrameCheck);
_hasScheduledPostFrameCheck = false;
_updateAllDevices();
}));
}*/
}

2
com.unity.uiwidgets/Runtime/rendering/mouse_tracking.cs.meta


fileFormatVersion: 2
guid: 635ab9c5cd0cd4509989d0d108b8b530
guid: 781f038935ea2534ba6940b2fe933460
MonoImporter:
externalObjects: {}
serializedVersion: 2

325
com.unity.uiwidgets/Runtime/gestures/mouse_tracking.cs


using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.scheduler;
using Unity.UIWidgets.ui;
namespace Unity.UIWidgets.gestures {
public delegate void PointerHoverEventListener(PointerHoverEvent evt);
public delegate void PointerEnterEventListener(PointerEnterEvent evt);
public delegate void PointerExitEventListener(PointerExitEvent evt);
public delegate void PointerDragFromEditorEnterEventListener(PointerDragFromEditorEnterEvent evt);
public delegate void PointerDragFromEditorHoverEventListener(PointerDragFromEditorHoverEvent evt);
public delegate void PointerDragFromEditorExitEventListener(PointerDragFromEditorExitEvent evt);
public delegate void PointerDragFromEditorReleaseEventListener(PointerDragFromEditorReleaseEvent evt);
public delegate void _UpdatedDeviceHandler(_MouseState mouseState, HashSet<MouseTrackerAnnotation> previousAnnotations);
public class _MouseState {
public _MouseState(PointerEvent initialEvent = null
) {
D.assert(initialEvent != null);
_latestEvent = initialEvent;
}
public HashSet<MouseTrackerAnnotation> annotations {
get { return _annotations;}
}
HashSet<MouseTrackerAnnotation> _annotations = new HashSet<MouseTrackerAnnotation>();
public HashSet<MouseTrackerAnnotation> replaceAnnotations(HashSet<MouseTrackerAnnotation> value) {
HashSet<MouseTrackerAnnotation> previous = _annotations;
_annotations = value;
return previous;
}
// The most recently processed mouse event observed from this device.
public PointerEvent latestEvent {
get { return _latestEvent; }
set {
D.assert(value != null);
_latestEvent = value;
}
}
PointerEvent _latestEvent;
public int device {
get { return latestEvent.device;}
}
public override string ToString() {
string describeEvent(PointerEvent Event) {
return Event == null ? "null" : describeIdentity(Event);
}
string describeLatestEvent = $"latestEvent: {describeEvent(latestEvent)}";
string describeAnnotations = $"annotations: [list of {annotations.Count}]";
return $"{describeIdentity(this)}"+$"({describeLatestEvent}, {describeAnnotations})";
}
public string describeIdentity(object Object) {
return $"{Object.GetType()}" + $"{Object.GetHashCode()}";
}
}
public class MouseTrackerAnnotation {
public MouseTrackerAnnotation(
PointerEnterEventListener onEnter = null,
PointerHoverEventListener onHover = null,
PointerExitEventListener onExit = null,
PointerDragFromEditorEnterEventListener onDragFromEditorEnter = null,
PointerDragFromEditorHoverEventListener onDragFromEditorHover = null,
PointerDragFromEditorExitEventListener onDragFromEditorExit = null,
PointerDragFromEditorReleaseEventListener onDragFromEditorRelease = null
) {
this.onEnter = onEnter;
this.onHover = onHover;
this.onExit = onExit;
this.onDragFromEditorEnter = onDragFromEditorEnter;
this.onDragFromEditorHover = onDragFromEditorHover;
this.onDragFromEditorExit = onDragFromEditorExit;
this.onDragFromEditorRelease = onDragFromEditorRelease;
}
public readonly PointerEnterEventListener onEnter;
public readonly PointerHoverEventListener onHover;
public readonly PointerExitEventListener onExit;
public readonly PointerDragFromEditorEnterEventListener onDragFromEditorEnter;
public readonly PointerDragFromEditorHoverEventListener onDragFromEditorHover;
public readonly PointerDragFromEditorExitEventListener onDragFromEditorExit;
public readonly PointerDragFromEditorReleaseEventListener onDragFromEditorRelease;
public override string ToString() {
return
$"{GetType()}#{GetHashCode()}{(onEnter == null ? "" : " onEnter")}{(onHover == null ? "" : " onHover")}{(onExit == null ? "" : " onExit")}";
}
}
public class _TrackedAnnotation {
public _TrackedAnnotation(
MouseTrackerAnnotation annotation) {
this.annotation = annotation;
}
public readonly MouseTrackerAnnotation annotation;
public HashSet<int> activeDevices = new HashSet<int>();
}
public delegate IEnumerable<MouseTrackerAnnotation> MouseDetectorAnnotationFinder(Offset offset);
public class MouseTracker : ChangeNotifier{
public MouseTracker(
PointerRouter router,
MouseDetectorAnnotationFinder annotationFinder
) {
D.assert(router != null);
D.assert(annotationFinder != null);
_router = router;
router.addGlobalRoute(_handleEvent);
this.annotationFinder = annotationFinder;
}
public override void dispose() {
base.dispose();
_router.removeGlobalRoute(_handleEvent);
}
public readonly MouseDetectorAnnotationFinder annotationFinder;
readonly Dictionary<int, PointerEvent> _lastMouseEvent = new Dictionary<int, PointerEvent>();
readonly PointerRouter _router;
public readonly Dictionary<int, _MouseState> _mouseStates = new Dictionary<int, _MouseState>();
public bool mouseIsConnected {
get { return _lastMouseEvent.isNotEmpty(); }
}
public static bool _shouldMarkStateDirty(_MouseState state, PointerEvent value) {
if (state == null)
return true;
D.assert(value != null);
PointerEvent lastEvent = state.latestEvent;
D.assert(value.device == lastEvent.device);
D.assert((value is PointerAddedEvent) == (lastEvent is PointerRemovedEvent));
if (value is PointerSignalEvent)
return false;
return lastEvent is PointerAddedEvent
|| value is PointerRemovedEvent
|| lastEvent.position != value.position;
}
public readonly Dictionary<MouseTrackerAnnotation, _TrackedAnnotation> _trackedAnnotations =
new Dictionary<MouseTrackerAnnotation, _TrackedAnnotation>();
public void _handleEvent(PointerEvent Event) {
if (Event.kind != PointerDeviceKind.mouse)
return;
if (Event is PointerSignalEvent)
return;
int device = Event.device;
_MouseState existingState = _mouseStates.getOrDefault(device);
if (!_shouldMarkStateDirty(existingState, Event))
return;
PointerEvent previousEvent = existingState?.latestEvent;
_updateDevices(
targetEvent: Event,
handleUpdatedDevice: (_MouseState mouseState, HashSet<MouseTrackerAnnotation> previousAnnotations) =>{
D.assert(mouseState.device == Event.device);
_dispatchDeviceCallbacks(
lastAnnotations: previousAnnotations,
nextAnnotations: mouseState.annotations,
previousEvent: previousEvent,
unhandledEvent: Event
);
}
);
}
public static void _dispatchDeviceCallbacks(
HashSet<MouseTrackerAnnotation> lastAnnotations,
HashSet<MouseTrackerAnnotation> nextAnnotations,
PointerEvent previousEvent = null,
PointerEvent unhandledEvent = null
) {
D.assert(lastAnnotations != null);
D.assert(nextAnnotations != null);
PointerEvent latestEvent = unhandledEvent ?? previousEvent;
D.assert(latestEvent != null);
IEnumerable<MouseTrackerAnnotation> exitingAnnotations = new List<MouseTrackerAnnotation>();
foreach (var lastAnnotation in lastAnnotations) {
if (!nextAnnotations.Contains(lastAnnotation)) {
exitingAnnotations.Append(lastAnnotation);
}
}
foreach ( MouseTrackerAnnotation annotation in exitingAnnotations) {
if (annotation.onExit != null) {
annotation.onExit(PointerExitEvent.fromMouseEvent(latestEvent));
}
}
IEnumerable<MouseTrackerAnnotation> enteringAnnotations = new List<MouseTrackerAnnotation>();
List<MouseTrackerAnnotation> entering = new List<MouseTrackerAnnotation>();
foreach (var nextAnnotation in nextAnnotations) {
if (!lastAnnotations.Contains(nextAnnotation)) {
entering.Add(nextAnnotation);
}
}
entering.ToList().Reverse();
enteringAnnotations = entering;
foreach ( MouseTrackerAnnotation annotation in enteringAnnotations) {
if (annotation.onEnter != null) {
annotation.onEnter(PointerEnterEvent.fromMouseEvent(latestEvent));
}
}
if (unhandledEvent is PointerHoverEvent) {
Offset lastHoverPosition = previousEvent is PointerHoverEvent ? previousEvent.position : null;
bool pointerHasMoved = lastHoverPosition == null || lastHoverPosition != unhandledEvent.position;
nextAnnotations.ToList().Reverse();
IEnumerable<MouseTrackerAnnotation> hoveringAnnotations = pointerHasMoved ? nextAnnotations : enteringAnnotations;
foreach ( MouseTrackerAnnotation annotation in hoveringAnnotations) {
if (annotation.onHover != null) {
annotation.onHover((PointerHoverEvent)unhandledEvent);
}
}
}
}
public HashSet<MouseTrackerAnnotation> _findAnnotations(_MouseState state) {
Offset globalPosition = state.latestEvent.position;
int device = state.device;
HashSet<MouseTrackerAnnotation> result = new HashSet<MouseTrackerAnnotation>();
foreach (var values in annotationFinder(globalPosition)) {
result.Add(values);
}
return (_mouseStates.ContainsKey(device))
? result
: new HashSet<MouseTrackerAnnotation>{} as HashSet<MouseTrackerAnnotation>;
}
public static bool _duringBuildPhase {
get {
return SchedulerBinding.instance.schedulerPhase == SchedulerPhase.persistentCallbacks;
}
}
public void _updateAllDevices() {
_updateDevices(
handleUpdatedDevice: (_MouseState mouseState, HashSet<MouseTrackerAnnotation> previousAnnotations)=> {
_dispatchDeviceCallbacks(
lastAnnotations: previousAnnotations,
nextAnnotations: mouseState.annotations,
previousEvent: mouseState.latestEvent,
unhandledEvent: null
);
}
);
}
bool _duringDeviceUpdate = false;
void _updateDevices(
PointerEvent targetEvent = null,
_UpdatedDeviceHandler handleUpdatedDevice = null) {
D.assert(handleUpdatedDevice != null);
D.assert(!_duringBuildPhase);
D.assert(!_duringDeviceUpdate);
bool mouseWasConnected = mouseIsConnected;
_MouseState targetState = null;
if (targetEvent != null) {
targetState = _mouseStates.getOrDefault(targetEvent.device);
if (targetState == null) {
targetState = new _MouseState(initialEvent: targetEvent);
_mouseStates[targetState.device] = targetState;
} else {
D.assert(!(targetEvent is PointerAddedEvent));
targetState.latestEvent = targetEvent;
if (targetEvent is PointerRemovedEvent)
_mouseStates.Remove(targetEvent.device);
}
}
D.assert((targetState == null) == (targetEvent == null));
D.assert(()=> {
_duringDeviceUpdate = true;
return true;
});
IEnumerable<_MouseState> dirtyStates = targetEvent == null ? (IEnumerable<_MouseState>) _mouseStates.Values : new List<_MouseState>{targetState};
foreach ( _MouseState dirtyState in dirtyStates) {
HashSet<MouseTrackerAnnotation> nextAnnotations = _findAnnotations(dirtyState);
HashSet<MouseTrackerAnnotation> lastAnnotations = dirtyState.replaceAnnotations(nextAnnotations);
handleUpdatedDevice(dirtyState, lastAnnotations);
}
D.assert(() =>{
_duringDeviceUpdate = false;
return true;
});
if (mouseWasConnected != mouseIsConnected)
notifyListeners();
}
public bool _hasScheduledPostFrameCheck = false;
public void schedulePostFrameCheck() {
D.assert(_duringBuildPhase);
D.assert(!_duringDeviceUpdate);
if (!mouseIsConnected)
return;
if (!_hasScheduledPostFrameCheck) {
_hasScheduledPostFrameCheck = true;
SchedulerBinding.instance.addPostFrameCallback((stamp => {
D.assert(_hasScheduledPostFrameCheck);
_hasScheduledPostFrameCheck = false;
_updateAllDevices();
}));
}
}
}
}

/com.unity.uiwidgets/Runtime/gestures/mouse_tracking.cs.meta → /com.unity.uiwidgets/Runtime/rendering/mouse_tracking.cs.meta

正在加载...
取消
保存