浏览代码

Merge pull request #145 from UnityTech/textselection

gesture 1.0 -> 1.2
/main
GitHub 6 年前
当前提交
f4b44c20
共有 5 个文件被更改,包括 98 次插入25 次删除
  1. 32
      Runtime/foundation/debug.cs
  2. 40
      Runtime/gestures/binding.cs
  3. 6
      Runtime/gestures/converter.cs
  4. 7
      Runtime/gestures/monodrag.cs
  5. 38
      Runtime/gestures/recognizer.cs

32
Runtime/foundation/debug.cs


using Unity.UIWidgets.editor;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using Canvas = Unity.UIWidgets.ui.Canvas;
using Color = Unity.UIWidgets.ui.Color;
using Rect = Unity.UIWidgets.ui.Rect;
public static void logError(string message, Exception ex = null) {
Debug.LogException(new AssertionError(message, ex));
}

#endif
}
}
[Conditional("UIWidgets_DEBUG")]
public static void assert(Func<bool> result, string message = null) {
if (!result()) {

public static bool debugCheckIntrinsicSizes = false;
public static HSVColor debugCurrentRepaintColor =
public static bool debugPrintMouseHoverEvents = false;
public static HSVColor debugCurrentRepaintColor =
HSVColor.fromAHSV(0.4f, 60.0f, 1.0f, 1.0f);
public static void _debugDrawDoubleRect(Canvas canvas, Rect outerRect, Rect innerRect, Color color) {

return true;
});
}
bool? debugPaintPointersEnabled= null,
bool? debugPaintPointersEnabled = null,
bool? debugRepaintRainbowEnabled = null ) {
bool? debugRepaintRainbowEnabled = null) {
if (debugPaintLayerBordersEnabled != null && debugPaintLayerBordersEnabled != D.debugPaintLayerBordersEnabled) {
if (debugPaintLayerBordersEnabled != null &&
debugPaintLayerBordersEnabled != D.debugPaintLayerBordersEnabled) {
if (debugRepaintRainbowEnabled != null && debugRepaintRainbowEnabled != D.debugRepaintRainbowEnabled) {
D.debugRepaintRainbowEnabled = debugRepaintRainbowEnabled.Value;
needRepaint = true;

[Serializable]
public class AssertionError : Exception {
readonly Exception innerException;
public AssertionError(string message) : base(message) {
}

if (this.innerException != null) {
return this.innerException.StackTrace;
}
var stackTrace = base.StackTrace;
var lines = stackTrace.Split('\n');
var strippedLines = lines.Skip(1);

40
Runtime/gestures/binding.cs


this._handlePointerHoverEvent(evt);
}
HitTestResult result;
HitTestResult result = null;
if (evt is PointerDownEvent) {
D.assert(!this._hitTests.ContainsKey(evt.pointer));
result = new HitTestResult();

else if (evt.down) {
result = this._hitTests.getOrDefault(evt.pointer);
}
else {
return;
}
D.assert(() => {
if (D.debugPrintMouseHoverEvents && evt is PointerHoverEvent) {
Debug.LogFormat("{0}", evt);
}
return true;
});
if (result != null) {
if (result != null ||
evt is PointerHoverEvent ||
evt is PointerAddedEvent ||
evt is PointerRemovedEvent
) {
this.dispatchEvent(evt, result);
}
}

}
public void dispatchEvent(PointerEvent evt, HitTestResult result) {
if (result == null) {
D.assert(evt is PointerHoverEvent || evt is PointerAddedEvent || evt is PointerRemovedEvent);
try {
this.pointerRouter.route(evt);
}
catch (Exception ex) {
UIWidgetsError.reportError(new UIWidgetsErrorDetails(
exception: ex,
library: "gesture library",
context: "while dispatching a non-hit-tested pointer event",
informationCollector: information => {
information.AppendLine("Event: ");
information.AppendFormat(" {0}", evt);
}
)
);
}
return;
}
foreach (HitTestEntry entry in result.path) {
try {
entry.target.handleEvent(evt, entry);

6
Runtime/gestures/converter.cs


public static class PointerEventConverter {
static readonly Dictionary<int, _PointerState> _pointers = new Dictionary<int, _PointerState>();
static void clearPointers() {
_pointers.Clear();
}
static _PointerState _ensureStateForPointer(PointerData datum, Offset position) {
return _pointers.putIfAbsent(
datum.device,

if (state == null || !state.down) {
break;
}
D.assert(state.down);
if (position != state.lastPosition) {
Offset offset = position - state.lastPosition;

7
Runtime/gestures/monodrag.cs


public DragGestureRecognizer(
object debugOwner = null,
PointerDeviceKind? kind = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.start)
DragStartBehavior dragStartBehavior = DragStartBehavior.down)
: base(debugOwner: debugOwner, kind: kind) {
this.dragStartBehavior = dragStartBehavior;
}

public override void dispose() {
this._velocityTrackers.Clear();
base.dispose();
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new EnumProperty<DragStartBehavior>("start behavior", this.dragStartBehavior));
}
}

38
Runtime/gestures/recognizer.cs


public enum GestureRecognizerState {
ready,
possible,
accepted,
defunct,
}

object debugOwner = null,
PointerDeviceKind? kind = null
PointerDeviceKind? kind = null,
float? preAcceptSlotTolerance = Constants.kTouchSlop,
float? postAcceptSlotTolerance = Constants.kTouchSlop
D.assert(preAcceptSlotTolerance == null || preAcceptSlotTolerance >= 0,
"The preAcceptSlopTolerance must be positive or null");
D.assert(postAcceptSlotTolerance == null || postAcceptSlotTolerance >= 0,
"The postAcceptSlopTolerance must be positive or null");
this.preAcceptSlotTolerance = preAcceptSlotTolerance;
this.postAcceptSlotTolerance = postAcceptSlotTolerance;
public readonly float? preAcceptSlotTolerance;
public readonly float? postAcceptSlotTolerance;
public GestureRecognizerState state = GestureRecognizerState.ready;

protected override void handleEvent(PointerEvent evt) {
D.assert(this.state != GestureRecognizerState.ready);
if (this.state == GestureRecognizerState.possible && evt.pointer == this.primaryPointer) {
if (evt is PointerMoveEvent && this._getDistance(evt) > Constants.kTouchSlop) {
if (evt.pointer == this.primaryPointer) {
bool isPreAcceptSlopPastTolerance = this.state == GestureRecognizerState.possible &&
this.preAcceptSlotTolerance != null &&
this._getDistance(evt) > this.preAcceptSlotTolerance;
bool isPostAcceptSlopPastTolerance = this.state == GestureRecognizerState.accepted &&
this.postAcceptSlotTolerance != null &&
this._getDistance(evt) > this.postAcceptSlotTolerance;
if (evt is PointerMoveEvent && (isPreAcceptSlopPastTolerance || isPostAcceptSlopPastTolerance)) {
this.resolve(GestureDisposition.rejected);
this.stopTrackingPointer(this.primaryPointer);
}

D.assert(this.deadline == null);
}
public override void acceptGesture(int pointer) {
if (pointer == this.primaryPointer && this.state == GestureRecognizerState.possible) {
this.state = GestureRecognizerState.accepted;
}
}
if (pointer == this.primaryPointer && this.state == GestureRecognizerState.possible) {
if (pointer == this.primaryPointer && (this.state == GestureRecognizerState.possible ||
this.state == GestureRecognizerState.accepted)) {
this._stopTimer();
this.state = GestureRecognizerState.defunct;
}

正在加载...
取消
保存