|
|
|
|
|
|
|
|
|
|
namespace UnityEditor.Graphing.Drawing |
|
|
|
{ |
|
|
|
public class Clicker : MouseManipulator |
|
|
|
public enum ClickerState |
|
|
|
Inactive, |
|
|
|
Active |
|
|
|
} |
|
|
|
public delegate void StateChangeCallback(); |
|
|
|
public class Clicker : MouseManipulator |
|
|
|
{ |
|
|
|
public delegate void StateChangeCallback(ClickerState newState); |
|
|
|
public StateChangeCallback onStateChange { get; set; } |
|
|
|
bool withinInitialTarget; |
|
|
|
ClickerState state; |
|
|
|
|
|
|
|
public override EventPropagation HandleEvent(Event evt, VisualElement finalTarget) |
|
|
|
{ |
|
|
|
|
|
|
{ |
|
|
|
this.TakeCapture(); |
|
|
|
initialTarget = finalTarget; |
|
|
|
UpdateState(evt); |
|
|
|
case EventType.mouseDrag: |
|
|
|
UpdateState(evt); |
|
|
|
break; |
|
|
|
|
|
|
|
withinInitialTarget = initialTarget != null && initialTarget.ContainsPoint(evt.mousePosition); |
|
|
|
if (withinInitialTarget && onClick != null) |
|
|
|
{ |
|
|
|
// withinInitialTarget = initialTarget != null && initialTarget.ContainsPoint(evt.mousePosition);
|
|
|
|
if (initialTarget != null && state == ClickerState.Active && onClick != null) |
|
|
|
} |
|
|
|
initialTarget = null; |
|
|
|
UpdateState(evt); |
|
|
|
} |
|
|
|
|
|
|
|
void UpdateState(Event evt) |
|
|
|
{ |
|
|
|
ClickerState newState; |
|
|
|
if (initialTarget != null && initialTarget.ContainsPoint(evt.mousePosition)) |
|
|
|
newState = ClickerState.Active; |
|
|
|
else |
|
|
|
newState = ClickerState.Inactive; |
|
|
|
|
|
|
|
if (onStateChange != null && state != newState) |
|
|
|
onStateChange(newState); |
|
|
|
state = newState; |
|
|
|
} |
|
|
|
} |
|
|
|
} |