|
|
|
|
|
|
public delegate void PointerScrollEventListener(PointerScrollEvent evt); |
|
|
|
|
|
|
|
|
|
|
|
/*public class RenderPointerListener : RenderProxyBoxWithHitTestBehavior { |
|
|
|
public RenderPointerListener( |
|
|
|
PointerDownEventListener onPointerDown = null, |
|
|
|
PointerMoveEventListener onPointerMove = null, |
|
|
|
PointerEnterEventListener onPointerEnter = null, |
|
|
|
PointerHoverEventListener onPointerHover = null, |
|
|
|
PointerExitEventListener onPointerExit = null, |
|
|
|
PointerUpEventListener onPointerUp = null, |
|
|
|
PointerCancelEventListener onPointerCancel = null, |
|
|
|
PointerSignalEventListener onPointerSignal = null, |
|
|
|
PointerScrollEventListener onPointerScroll = null, |
|
|
|
PointerDragFromEditorEnterEventListener onPointerDragFromEditorEnter = null, |
|
|
|
PointerDragFromEditorHoverEventListener onPointerDragFromEditorHover = null, |
|
|
|
PointerDragFromEditorExitEventListener onPointerDragFromEditorExit = null, |
|
|
|
PointerDragFromEditorReleaseEventListener onPointerDragFromEditorRelease = null, |
|
|
|
HitTestBehavior behavior = HitTestBehavior.deferToChild, |
|
|
|
RenderBox child = null |
|
|
|
) : base(behavior: behavior, child: child) { |
|
|
|
this.onPointerDown = onPointerDown; |
|
|
|
this.onPointerMove = onPointerMove; |
|
|
|
this.onPointerUp = onPointerUp; |
|
|
|
this.onPointerCancel = onPointerCancel; |
|
|
|
this.onPointerSignal = onPointerSignal; |
|
|
|
this.onPointerScroll = onPointerScroll; |
|
|
|
|
|
|
|
_onPointerEnter = onPointerEnter; |
|
|
|
_onPointerHover = onPointerHover; |
|
|
|
_onPointerExit = onPointerExit; |
|
|
|
|
|
|
|
_onPointerDragFromEditorEnter = onPointerDragFromEditorEnter; |
|
|
|
_onPointerDragFromEditorHover = onPointerDragFromEditorHover; |
|
|
|
_onPointerDragFromEditorExit = onPointerDragFromEditorExit; |
|
|
|
_onPointerDragFromEditorRelease = onPointerDragFromEditorRelease; |
|
|
|
|
|
|
|
if (_onPointerEnter != null || |
|
|
|
_onPointerHover != null || |
|
|
|
_onPointerExit != null || |
|
|
|
_onPointerDragFromEditorEnter != null || |
|
|
|
_onPointerDragFromEditorHover != null || |
|
|
|
_onPointerDragFromEditorExit != null || |
|
|
|
_onPointerDragFromEditorRelease != null |
|
|
|
) { |
|
|
|
_hoverAnnotation = new MouseTrackerAnnotation( |
|
|
|
onEnter: _onPointerEnter, |
|
|
|
onHover: _onPointerHover, |
|
|
|
onExit: _onPointerExit, |
|
|
|
onDragFromEditorEnter: _onPointerDragFromEditorEnter, |
|
|
|
onDragFromEditorHover: _onPointerDragFromEditorHover, |
|
|
|
onDragFromEditorExit: _onPointerDragFromEditorExit, |
|
|
|
onDragFromEditorRelease: _onPointerDragFromEditorRelease |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
PointerDragFromEditorEnterEventListener _onPointerDragFromEditorEnter; |
|
|
|
|
|
|
|
public PointerDragFromEditorEnterEventListener onPointerDragFromEditorEnter { |
|
|
|
get { return _onPointerDragFromEditorEnter; } |
|
|
|
set { |
|
|
|
if (_onPointerDragFromEditorEnter != value) { |
|
|
|
_onPointerDragFromEditorEnter = value; |
|
|
|
_updateAnnotations(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
PointerDragFromEditorExitEventListener _onPointerDragFromEditorExit; |
|
|
|
|
|
|
|
public PointerDragFromEditorExitEventListener onPointerDragFromEditorExit { |
|
|
|
get { return _onPointerDragFromEditorExit; } |
|
|
|
set { |
|
|
|
if (_onPointerDragFromEditorExit != value) { |
|
|
|
_onPointerDragFromEditorExit = value; |
|
|
|
_updateAnnotations(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
PointerDragFromEditorHoverEventListener _onPointerDragFromEditorHover; |
|
|
|
|
|
|
|
public PointerDragFromEditorHoverEventListener onPointerDragFromEditorHover { |
|
|
|
get { return _onPointerDragFromEditorHover; } |
|
|
|
set { |
|
|
|
if (_onPointerDragFromEditorHover != value) { |
|
|
|
_onPointerDragFromEditorHover = value; |
|
|
|
_updateAnnotations(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
PointerDragFromEditorReleaseEventListener _onPointerDragFromEditorRelease; |
|
|
|
|
|
|
|
public PointerDragFromEditorReleaseEventListener onPointerDragFromEditorRelease { |
|
|
|
get { return _onPointerDragFromEditorRelease; } |
|
|
|
set { |
|
|
|
if (_onPointerDragFromEditorRelease != value) { |
|
|
|
_onPointerDragFromEditorRelease = value; |
|
|
|
_updateAnnotations(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public PointerEnterEventListener onPointerEnter { |
|
|
|
get { return _onPointerEnter; } |
|
|
|
set { |
|
|
|
if (_onPointerEnter != value) { |
|
|
|
_onPointerEnter = value; |
|
|
|
_updateAnnotations(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
PointerEnterEventListener _onPointerEnter; |
|
|
|
|
|
|
|
public PointerHoverEventListener onPointerHover { |
|
|
|
get { return _onPointerHover; } |
|
|
|
set { |
|
|
|
if (_onPointerHover != value) { |
|
|
|
_onPointerHover = value; |
|
|
|
_updateAnnotations(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
PointerHoverEventListener _onPointerHover; |
|
|
|
|
|
|
|
public PointerExitEventListener onPointerExit { |
|
|
|
get { return _onPointerExit; } |
|
|
|
set { |
|
|
|
if (_onPointerExit != value) { |
|
|
|
_onPointerExit = value; |
|
|
|
_updateAnnotations(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
PointerExitEventListener _onPointerExit; |
|
|
|
|
|
|
|
public PointerDownEventListener onPointerDown; |
|
|
|
|
|
|
|
public PointerMoveEventListener onPointerMove; |
|
|
|
|
|
|
|
public PointerUpEventListener onPointerUp; |
|
|
|
|
|
|
|
public PointerCancelEventListener onPointerCancel; |
|
|
|
|
|
|
|
public PointerSignalEventListener onPointerSignal; |
|
|
|
|
|
|
|
public PointerScrollEventListener onPointerScroll; |
|
|
|
|
|
|
|
MouseTrackerAnnotation _hoverAnnotation; |
|
|
|
|
|
|
|
public MouseTrackerAnnotation hoverAnnotation { |
|
|
|
get { return _hoverAnnotation; } |
|
|
|
} |
|
|
|
|
|
|
|
void _updateAnnotations() { |
|
|
|
D.assert(_onPointerEnter != _hoverAnnotation.onEnter || |
|
|
|
_onPointerHover != _hoverAnnotation.onHover || |
|
|
|
_onPointerExit != _hoverAnnotation.onExit |
|
|
|
#if UNITY_EDITOR
|
|
|
|
|| _onPointerDragFromEditorEnter != _hoverAnnotation.onDragFromEditorEnter |
|
|
|
|| _onPointerDragFromEditorHover != _hoverAnnotation.onDragFromEditorHover |
|
|
|
|| _onPointerDragFromEditorExit != _hoverAnnotation.onDragFromEditorExit |
|
|
|
|| _onPointerDragFromEditorRelease != _hoverAnnotation.onDragFromEditorRelease |
|
|
|
#endif
|
|
|
|
, () => "Shouldn't call _updateAnnotations if nothing has changed."); |
|
|
|
|
|
|
|
if (_hoverAnnotation != null && attached) { |
|
|
|
RendererBinding.instance.mouseTracker.detachAnnotation(_hoverAnnotation); |
|
|
|
} |
|
|
|
|
|
|
|
if (_onPointerEnter != null || |
|
|
|
_onPointerHover != null || |
|
|
|
_onPointerExit != null |
|
|
|
#if UNITY_EDITOR
|
|
|
|
|| _onPointerDragFromEditorEnter != null |
|
|
|
|| _onPointerDragFromEditorHover != null |
|
|
|
|| _onPointerDragFromEditorExit != null |
|
|
|
|| _onPointerDragFromEditorRelease != null |
|
|
|
#endif
|
|
|
|
) { |
|
|
|
_hoverAnnotation = new MouseTrackerAnnotation( |
|
|
|
onEnter: _onPointerEnter, |
|
|
|
onHover: _onPointerHover, |
|
|
|
onExit: _onPointerExit |
|
|
|
#if UNITY_EDITOR
|
|
|
|
, onDragFromEditorEnter: _onPointerDragFromEditorEnter |
|
|
|
, onDragFromEditorHover: _onPointerDragFromEditorHover |
|
|
|
, onDragFromEditorExit: _onPointerDragFromEditorExit |
|
|
|
, onDragFromEditorRelease: _onPointerDragFromEditorRelease |
|
|
|
#endif
|
|
|
|
); |
|
|
|
|
|
|
|
if (attached) { |
|
|
|
RendererBinding.instance.mouseTracker.attachAnnotation(_hoverAnnotation); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
_hoverAnnotation = null; |
|
|
|
} |
|
|
|
|
|
|
|
markNeedsPaint(); |
|
|
|
} |
|
|
|
|
|
|
|
public override void attach(object owner) { |
|
|
|
base.attach(owner); |
|
|
|
if (_hoverAnnotation != null) { |
|
|
|
RendererBinding.instance.mouseTracker.attachAnnotation(_hoverAnnotation); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public override void detach() { |
|
|
|
base.detach(); |
|
|
|
if (_hoverAnnotation != null) { |
|
|
|
RendererBinding.instance.mouseTracker.detachAnnotation(_hoverAnnotation); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public override void paint(PaintingContext context, Offset offset) { |
|
|
|
if (_hoverAnnotation != null) { |
|
|
|
AnnotatedRegionLayer<MouseTrackerAnnotation> layer = new AnnotatedRegionLayer<MouseTrackerAnnotation>( |
|
|
|
_hoverAnnotation, size: size, offset: offset); |
|
|
|
|
|
|
|
context.pushLayer(layer, base.paint, offset); |
|
|
|
} |
|
|
|
else { |
|
|
|
base.paint(context, offset); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected override void performResize() { |
|
|
|
size = constraints.biggest; |
|
|
|
} |
|
|
|
|
|
|
|
public override void handleEvent(PointerEvent evt, HitTestEntry entry) { |
|
|
|
D.assert(debugHandleEvent(evt, entry)); |
|
|
|
|
|
|
|
if (onPointerDown != null && evt is PointerDownEvent) { |
|
|
|
onPointerDown((PointerDownEvent) evt); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (onPointerMove != null && evt is PointerMoveEvent) { |
|
|
|
onPointerMove((PointerMoveEvent) evt); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (onPointerUp != null && evt is PointerUpEvent) { |
|
|
|
onPointerUp((PointerUpEvent) evt); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (onPointerCancel != null && evt is PointerCancelEvent) { |
|
|
|
onPointerCancel((PointerCancelEvent) evt); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (onPointerSignal != null && evt is PointerSignalEvent) { |
|
|
|
onPointerSignal((PointerSignalEvent) evt); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (onPointerScroll != null && evt is PointerScrollEvent) { |
|
|
|
onPointerScroll((PointerScrollEvent) evt); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { |
|
|
|
base.debugFillProperties(properties); |
|
|
|
var listeners = new List<string>(); |
|
|
|
if (onPointerDown != null) { |
|
|
|
listeners.Add("down"); |
|
|
|
} |
|
|
|
|
|
|
|
if (onPointerMove != null) { |
|
|
|
listeners.Add("move"); |
|
|
|
} |
|
|
|
|
|
|
|
if (onPointerEnter != null) { |
|
|
|
listeners.Add("enter"); |
|
|
|
} |
|
|
|
|
|
|
|
if (onPointerHover != null) { |
|
|
|
listeners.Add("hover"); |
|
|
|
} |
|
|
|
|
|
|
|
if (onPointerExit != null) { |
|
|
|
listeners.Add("exit"); |
|
|
|
} |
|
|
|
|
|
|
|
if (onPointerUp != null) { |
|
|
|
listeners.Add("up"); |
|
|
|
} |
|
|
|
|
|
|
|
if (onPointerCancel != null) { |
|
|
|
listeners.Add("cancel"); |
|
|
|
} |
|
|
|
|
|
|
|
if (onPointerSignal != null) { |
|
|
|
listeners.Add("signal"); |
|
|
|
} |
|
|
|
|
|
|
|
if (listeners.isEmpty()) { |
|
|
|
listeners.Add("<none>"); |
|
|
|
} |
|
|
|
|
|
|
|
properties.add(new EnumerableProperty<string>("listeners", listeners)); |
|
|
|
} |
|
|
|
}*/ |
|
|
|
|
|
|
|
class RenderPointerListener : RenderProxyBoxWithHitTestBehavior { |
|
|
|
public RenderPointerListener( |
|
|
|
PointerDownEventListener onPointerDown = null, |
|
|
|