EventContext.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System.Collections.Generic;
  2. namespace FairyGUI
  3. {
  4. /// <summary>
  5. ///
  6. /// </summary>
  7. public class EventContext
  8. {
  9. /// <summary>
  10. ///
  11. /// </summary>
  12. public EventDispatcher sender { get; internal set; }
  13. /// <summary>
  14. /// /
  15. /// </summary>
  16. public object initiator { get; internal set; }
  17. /// <summary>
  18. /// /
  19. /// </summary>
  20. public InputEvent inputEvent { get; internal set; }
  21. /// <summary>
  22. ///
  23. /// </summary>
  24. public string type;
  25. /// <summary>
  26. ///
  27. /// </summary>
  28. public object data;
  29. internal bool _defaultPrevented;
  30. internal bool _stopsPropagation;
  31. internal bool _touchCapture;
  32. internal List<EventBridge> callChain = new List<EventBridge>();
  33. /// <summary>
  34. ///
  35. /// </summary>
  36. public void StopPropagation()
  37. {
  38. _stopsPropagation = true;
  39. }
  40. /// <summary>
  41. ///
  42. /// </summary>
  43. public void PreventDefault()
  44. {
  45. _defaultPrevented = true;
  46. }
  47. /// <summary>
  48. ///
  49. /// </summary>
  50. public void CaptureTouch()
  51. {
  52. _touchCapture = true;
  53. }
  54. /// <summary>
  55. ///
  56. /// </summary>
  57. public bool isDefaultPrevented
  58. {
  59. get { return _defaultPrevented; }
  60. }
  61. static Stack<EventContext> pool = new Stack<EventContext>();
  62. internal static EventContext Get()
  63. {
  64. if (pool.Count > 0)
  65. {
  66. EventContext context = pool.Pop();
  67. context._stopsPropagation = false;
  68. context._defaultPrevented = false;
  69. context._touchCapture = false;
  70. return context;
  71. }
  72. else
  73. return new EventContext();
  74. }
  75. internal static void Return(EventContext value)
  76. {
  77. pool.Push(value);
  78. }
  79. }
  80. }