Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: WebSeed on October 24, 2013, 01:43:58 AM

Title: Mouse vs. touch click cancelling
Post by: WebSeed on October 24, 2013, 01:43:58 AM
Hi,

Came across an issue this morning - seems that using the mouse when I drag over a certain threshold UICamera's "OnClick" event is cancelled - which is expected. However, when I tried this out on my iPhone, the click event always fired. Looking through the UICamera.cs NGUI file I found this line:

  1.     currentTouch.clickNotification = isMouse ? ClickNotification.BasedOnDelta : ClickNotification.Always;
  2.  

The question is, why would I want the click notification to be cancelled when using a mouse, but always fired for touch? It seems a bit inconsistent and had me scratching my head for a bit. If this is deliberate, what's the use of ...

  1.         /// <summary>
  2.         /// How far the touch is allowed to move in pixels before it's no longer considered for click events, if the click notification is based on delta.
  3.         /// </summary>
  4.  
  5.         public float touchClickThreshold = 40f;
  6.  
Title: Re: Mouse vs. touch click cancelling
Post by: ArenMook on October 25, 2013, 12:17:26 AM
Mouse is very precise, but a touch is not, and can vary a fair bit. That's pretty much the only reason.
Title: Re: Mouse vs. touch click cancelling
Post by: WebSeed on October 25, 2013, 03:43:16 AM
Yes, I understand that, but that seems to be accounted for by adapting the thresholds i.e. the defaults are currently:

  1. public float mouseClickThreshold = 10f;
  2. public float touchClickThreshold = 40f;
  3.  

Currently touchClickThreshold is not used (UICamera.cs):

  1. float click  = isMouse ? mouseClickThreshold : touchClickThreshold;
  2. ...
  3. currentTouch.clickNotification = isMouse ? ClickNotification.BasedOnDelta : ClickNotification.Always;
  4. ...
  5. else if (currentTouch.clickNotification == ClickNotification.BasedOnDelta && click < mag)
  6. {
  7.     // We've dragged far enough to cancel the click
  8.     currentTouch.clickNotification = ClickNotification.None;
  9. }
  10.  

As far as I can tell this is essentially equivalent to:

  1. if (isMouse && mouseClickThreshold < mag)
  2. {
  3.     // We've dragged far enough to cancel the click
  4.     currentTouch.clickNotification = ClickNotification.None;
  5. }
  6.  


Not cancelling the click is a bit inconsistent with behaviour of native apps too. I've adapted my local copy of UICamera.cs to:

  1. currentTouch.clickNotification = ClickNotification.BasedOnDelta;
  2.  

... and everything works well. I think that if people are concerned over accidentally triggering click events on touch they can just increase the touch threshold.
Title: Re: Mouse vs. touch click cancelling
Post by: WebSeed on October 27, 2013, 02:36:04 AM
Appears to be fixed in 3.0.3c i.e.

  1. currentTouch.clickNotification = ClickNotification.BasedOnDelta;

Thanks :D
Title: Re: Mouse vs. touch click cancelling
Post by: ArenMook on October 27, 2013, 04:41:57 AM
:)