Skip to content

Commit

Permalink
Swipe now called gesture
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-shariff committed Jan 10, 2024
1 parent af531ca commit 7bce98b
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 144 deletions.
2 changes: 1 addition & 1 deletion Editor/HPUIBaseInteractableEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class HPUIBaseInteractableEditor: XRBaseInteractableEditor
{
private HPUIBaseInteractable t;
protected List<SerializedProperty> eventProperties;
protected virtual List<string> EventPropertyNames => new List<string>() { "tapEvent", "swipeEvent" };
protected virtual List<string> EventPropertyNames => new List<string>() { "tapEvent", "gestureEvent" };

protected bool hpuiInteractablesExpanded;

Expand Down
2 changes: 1 addition & 1 deletion Editor/HPUIInteractorEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class HPUIInteractorEditor: XRBaseInteractorEditor
{
private HPUIInteractor t;
protected List<SerializedProperty> eventProperties;
protected List<string> eventPropertyNames = new List<string>() { "tapEvent", "swipeEvent"};
protected List<string> eventPropertyNames = new List<string>() { "tapEvent", "gestureEvent"};

protected bool hpuiInteractablesExpanded;

Expand Down
18 changes: 9 additions & 9 deletions Runtime/Interaction/HPUIBaseInteractable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public Handedness Handedness
public HPUITapEvent TapEvent { get => tapEvent; set => tapEvent = value; }

[SerializeField]
private HPUISwipeEvent swipeEvent = new HPUISwipeEvent();
private HPUIGestureEvent gestureEvent = new HPUIGestureEvent();

/// <summary>
/// Event triggered on swipe
/// Event triggered on gesture
/// </summary>
public HPUISwipeEvent SwipeEvent { get => swipeEvent; set => swipeEvent = value; }
public HPUIGestureEvent GestureEvent { get => gestureEvent; set => gestureEvent = value; }

private Vector2 surfaceBounds, surfaceOrigin;

Expand Down Expand Up @@ -127,20 +127,20 @@ public void OnTap(HPUITapEventArgs args)
}

/// <inheritdoc />
public void OnSwipe(HPUISwipeEventArgs args)
public void OnGesture(HPUIGestureEventArgs args)
{
swipeEvent?.Invoke(args);
gestureEvent?.Invoke(args);
}

/// <inheritdoc />
public bool HandlesGestureState(HPUIGestureState state)
public bool HandlesGesture(HPUIGesture state)
{
switch (state) {
case HPUIGestureState.Tap: {
case HPUIGesture.Tap: {
return TapEvent.GetPersistentEventCount() > 0;
}
case HPUIGestureState.Swipe: {
return SwipeEvent.GetPersistentEventCount() > 0;
case HPUIGesture.Gesture: {
return GestureEvent.GetPersistentEventCount() > 0;
}
default:
throw new InvalidOperationException($"Gesture state {state} is not handled by {typeof(HPUIBaseInteractable)}");
Expand Down
22 changes: 11 additions & 11 deletions Runtime/Interaction/HPUIEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@

namespace ubco.ovilab.HPUI.Interaction
{
public enum HPUIGestureState
public enum HPUIGesture
{
None,
Tap, Swipe,
Tap, Gesture,
Custom // TODO: Custom gestures?
}

public enum HPUISwipeState
public enum HPUIGestureState
{
Started, Updated, Stopped, Invalid
}

#region events classes
public class HPUIGestureEvent: UnityEvent<HPUIGestureEventArgs>
public class HPUIInteractionEvent: UnityEvent<HPUIInteractionEventArgs>
{}

/// <summary>
/// Event data associated with an gesture interaction on HPUI
/// </summary>
public class HPUIGestureEventArgs: BaseInteractionEventArgs
public class HPUIInteractionEventArgs: BaseInteractionEventArgs
{
/// <summary>
/// The Interactor associated with the interaction event.
Expand Down Expand Up @@ -58,19 +58,19 @@ public class HPUITapEvent: UnityEvent<HPUITapEventArgs>
/// <summary>
/// Event data associated with an tap gesture interaction on HPUI
/// </summary>
public class HPUITapEventArgs: HPUIGestureEventArgs
public class HPUITapEventArgs: HPUIInteractionEventArgs
{}

[Serializable]
public class HPUISwipeEvent: UnityEvent<HPUISwipeEventArgs>
public class HPUIGestureEvent: UnityEvent<HPUIGestureEventArgs>
{}

/// <summary>
/// Event data associated with an swipe gesture interaction on HPUI
/// Event data associated with a gesture interaction on HPUI
/// </summary>
public class HPUISwipeEventArgs: HPUIGestureEventArgs
public class HPUIGestureEventArgs: HPUIInteractionEventArgs
{
public HPUISwipeState State { get; private set; }
public HPUIGestureState State { get; private set; }
public float TimeDelta { get; private set; }
public float StartTime { get; private set; }
public Vector2 StartPosition { get; private set; }
Expand All @@ -83,7 +83,7 @@ public override void SetParams(IHPUIInteractor interactor, IHPUIInteractable int
throw new InvalidOperationException("Call overloaded method!");
}

public void SetParams(IHPUIInteractor interactor, IHPUIInteractable interactable, HPUISwipeState state, float timeDelta, float startTime,
public void SetParams(IHPUIInteractor interactor, IHPUIInteractable interactable, HPUIGestureState state, float timeDelta, float startTime,
Vector2 startPosition, Vector2 cumilativeDirection, float cumilativeDistance, Vector2 deltaDirection)
{
base.SetParams(interactor, interactable);
Expand Down
10 changes: 5 additions & 5 deletions Runtime/Interaction/HPUIInteractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public class HPUIInteractor: XRPokeInteractor, IHPUIInteractor
public HPUITapEvent TapEvent { get => tapEvent; set => tapEvent = value; }

[SerializeField]
private HPUISwipeEvent swipeEvent = new HPUISwipeEvent();
private HPUIGestureEvent gestureEvent = new HPUIGestureEvent();

/// <summary>
/// Event triggered on swipe
/// Event triggered on gesture
/// </summary>
public HPUISwipeEvent SwipeEvent { get => swipeEvent; set => swipeEvent = value; }
public HPUIGestureEvent GestureEvent { get => gestureEvent; set => gestureEvent = value; }

protected IHPUIGestureLogic gestureLogic;
private List<IXRInteractable> validTargets = new List<IXRInteractable>();
Expand Down Expand Up @@ -116,9 +116,9 @@ public void OnTap(HPUITapEventArgs args)
}

/// <inheritdoc />
public void OnSwipe(HPUISwipeEventArgs args)
public void OnGesture(HPUIGestureEventArgs args)
{
swipeEvent?.Invoke(args);
gestureEvent?.Invoke(args);
}
#endregion
}
Expand Down
6 changes: 3 additions & 3 deletions Runtime/Interaction/IHPUIInteractable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public interface IHPUIInteractable : IXRInteractable, IXRSelectInteractable
/// happens while this interactable is selected, it'll be passed to
/// the next selected interactable in the priority list.
/// </summary>
bool HandlesGestureState(HPUIGestureState state);
bool HandlesGesture(HPUIGesture gesture);

/// <summary>
/// This is called when a swipe event occurs on the interactable.
/// This is called when a gesture event occurs on the interactable.
/// </summary>
void OnSwipe(HPUISwipeEventArgs args);
void OnGesture(HPUIGestureEventArgs args);
}

}
4 changes: 2 additions & 2 deletions Runtime/Interaction/IHPUIInteractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public interface IHPUIInteractor: IXRInteractor, IXRSelectInteractor
void OnTap(HPUITapEventArgs args);

/// <summary>
/// This is called when a swipe event occurs on the interactable.
/// This is called when a gesture event occurs on the interactable.
/// </summary>
void OnSwipe(HPUISwipeEventArgs args);
void OnGesture(HPUIGestureEventArgs args);
}

}
52 changes: 26 additions & 26 deletions Runtime/Interaction/Logic/HPUIGestureLogicDistributed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class HPUIGestureLogicDistributed: IHPUIGestureLogic
private float previousTime;

private LinkedPool<HPUITapEventArgs> hpuiTapEventArgsPool = new LinkedPool<HPUITapEventArgs>(() => new HPUITapEventArgs());
private LinkedPool<HPUISwipeEventArgs> hpuiSwipeEventArgsPool = new LinkedPool<HPUISwipeEventArgs>(() => new HPUISwipeEventArgs());
private LinkedPool<HPUIGestureEventArgs> hpuiGestureEventArgsPool = new LinkedPool<HPUIGestureEventArgs>(() => new HPUIGestureEventArgs());
private float tapTimeThreshold, tapDistanceThreshold;
private IHPUIInteractor interactor;

Expand All @@ -41,7 +41,7 @@ public void OnSelectEntering(IHPUIInteractable interactable)
}

HPUIInteractionState state = GenericPool<HPUIInteractionState>.Get();
state.SetParams(HPUIGestureState.Tap,
state.SetParams(HPUIGesture.Tap,
Time.time,
interactable.ComputeInteractorPostion(interactor));
states.Add(interactable, state);
Expand All @@ -61,22 +61,22 @@ public void OnSelectExiting(IHPUIInteractable interactable)
{
switch (state.gestureState)
{
case HPUIGestureState.Tap:
case HPUIGesture.Tap:
using (hpuiTapEventArgsPool.Get(out HPUITapEventArgs tapEventArgs))
{
tapEventArgs.SetParams(interactor, interactable);
interactable.OnTap(tapEventArgs);
interactor.OnTap(tapEventArgs);
}
break;
case HPUIGestureState.Swipe:
using (hpuiSwipeEventArgsPool.Get(out HPUISwipeEventArgs swipeEventArgs))
case HPUIGesture.Gesture:
using (hpuiGestureEventArgsPool.Get(out HPUIGestureEventArgs gestureEventArgs))
{
swipeEventArgs.SetParams(interactor, interactable,
HPUISwipeState.Stopped, Time.time - state.startTime, state.startTime, state.startPosition,
gestureEventArgs.SetParams(interactor, interactable,
HPUIGestureState.Stopped, Time.time - state.startTime, state.startTime, state.startPosition,
state.cumilativeDirection, state.cumilativeDistance, state.delta);
interactable.OnSwipe(swipeEventArgs);
interactor.OnSwipe(swipeEventArgs);
interactable.OnGesture(gestureEventArgs);
interactor.OnGesture(gestureEventArgs);

}
break;
Expand Down Expand Up @@ -105,31 +105,31 @@ public void Update()

switch (state.gestureState)
{
case HPUIGestureState.Tap:
case HPUIGesture.Tap:
if (timeDelta > tapTimeThreshold || state.cumilativeDirection.magnitude > tapDistanceThreshold)
{
state.gestureState = HPUIGestureState.Swipe;
using (hpuiSwipeEventArgsPool.Get(out HPUISwipeEventArgs swipeEventArgs))
state.gestureState = HPUIGesture.Gesture;
using (hpuiGestureEventArgsPool.Get(out HPUIGestureEventArgs gestureEventArgs))
{
swipeEventArgs.SetParams(interactor, hpuiInteractable,
HPUISwipeState.Started, timeDelta, state.startTime, state.startPosition,
gestureEventArgs.SetParams(interactor, hpuiInteractable,
HPUIGestureState.Started, timeDelta, state.startTime, state.startPosition,
state.cumilativeDirection, state.cumilativeDistance, state.delta);
hpuiInteractable.OnSwipe(swipeEventArgs);
interactor.OnSwipe(swipeEventArgs);
hpuiInteractable.OnGesture(gestureEventArgs);
interactor.OnGesture(gestureEventArgs);
}
}
break;
case HPUIGestureState.Swipe:
using (hpuiSwipeEventArgsPool.Get(out HPUISwipeEventArgs swipeEventArgs))
case HPUIGesture.Gesture:
using (hpuiGestureEventArgsPool.Get(out HPUIGestureEventArgs gestureEventArgs))
{
swipeEventArgs.SetParams(interactor, hpuiInteractable,
HPUISwipeState.Updated, timeDelta, state.startTime, state.startPosition,
gestureEventArgs.SetParams(interactor, hpuiInteractable,
HPUIGestureState.Updated, timeDelta, state.startTime, state.startPosition,
state.cumilativeDirection, state.cumilativeDistance, state.delta);
hpuiInteractable.OnSwipe(swipeEventArgs);
interactor.OnSwipe(swipeEventArgs);
hpuiInteractable.OnGesture(gestureEventArgs);
interactor.OnGesture(gestureEventArgs);
}
break;
case HPUIGestureState.Custom:
case HPUIGesture.Custom:
// TODO: custom gestures
throw new NotImplementedException();
}
Expand All @@ -146,21 +146,21 @@ public void Update()
public void Dispose()
{
hpuiTapEventArgsPool.Dispose();
hpuiSwipeEventArgsPool.Dispose();
hpuiGestureEventArgsPool.Dispose();
states.Clear();
}

class HPUIInteractionState
{
public HPUIGestureState gestureState;
public HPUIGesture gestureState;
public float startTime;
public Vector2 startPosition;
public Vector2 previousPosition;
public Vector2 delta;
public Vector2 cumilativeDirection;
public float cumilativeDistance;

public HPUIInteractionState SetParams(HPUIGestureState gestureState, float startTime, Vector2 startPosition)
public HPUIInteractionState SetParams(HPUIGesture gestureState, float startTime, Vector2 startPosition)
{
this.gestureState = gestureState;
this.startTime = startTime;
Expand Down
Loading

0 comments on commit 7bce98b

Please sign in to comment.