/libs/cocos2d/CCTouchDispatcher.h

http://github.com/kstenerud/ObjectAL-for-iPhone · C Header · 116 lines · 43 code · 16 blank · 57 comment · 0 complexity · 11463393fd5879ce2428cd93eecbd682 MD5 · raw file

  1. /*
  2. * cocos2d for iPhone: http://www.cocos2d-iphone.org
  3. *
  4. * Copyright (c) 2009 Valentin Milea
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. *
  24. */
  25. #import "CCTouchDelegateProtocol.h"
  26. #import "Support/EAGLView.h"
  27. typedef enum
  28. {
  29. ccTouchSelectorBeganBit = 1 << 0,
  30. ccTouchSelectorMovedBit = 1 << 1,
  31. ccTouchSelectorEndedBit = 1 << 2,
  32. ccTouchSelectorCancelledBit = 1 << 3,
  33. ccTouchSelectorAllBits = ( ccTouchSelectorBeganBit | ccTouchSelectorMovedBit | ccTouchSelectorEndedBit | ccTouchSelectorCancelledBit),
  34. } ccTouchSelectorFlag;
  35. enum {
  36. ccTouchBegan,
  37. ccTouchMoved,
  38. ccTouchEnded,
  39. ccTouchCancelled,
  40. ccTouchMax,
  41. };
  42. struct ccTouchHandlerHelperData {
  43. SEL touchesSel;
  44. SEL touchSel;
  45. ccTouchSelectorFlag type;
  46. };
  47. /** CCTouchDispatcher.
  48. Singleton that handles all the touch events.
  49. The dispatcher dispatches events to the registered TouchHandlers.
  50. There are 2 different type of touch handlers:
  51. - Standard Touch Handlers
  52. - Targeted Touch Handlers
  53. The Standard Touch Handlers work like the CocoaTouch touch handler: a set of touches is passed to the delegate.
  54. On the other hand, the Targeted Touch Handlers only receive 1 touch at the time, and they can "swallow" touches (avoid the propagation of the event).
  55. Firstly, the dispatcher sends the received touches to the targeted touches.
  56. These touches can be swallowed by the Targeted Touch Handlers. If there are still remaining touches, then the remaining touches will be sent
  57. to the Standard Touch Handlers.
  58. @since v0.8.0
  59. */
  60. @interface CCTouchDispatcher : NSObject <EAGLTouchDelegate>
  61. {
  62. NSMutableArray *targetedHandlers;
  63. NSMutableArray *standardHandlers;
  64. BOOL locked;
  65. BOOL toAdd;
  66. BOOL toRemove;
  67. NSMutableArray *handlersToAdd;
  68. NSMutableArray *handlersToRemove;
  69. BOOL toQuit;
  70. BOOL dispatchEvents;
  71. // 4, 1 for each type of event
  72. struct ccTouchHandlerHelperData handlerHelperData[ccTouchMax];
  73. }
  74. /** singleton of the CCTouchDispatcher */
  75. + (CCTouchDispatcher*)sharedDispatcher;
  76. /** Whether or not the events are going to be dispatched. Default: YES */
  77. @property (nonatomic,readwrite, assign) BOOL dispatchEvents;
  78. /** Adds a standard touch delegate to the dispatcher's list.
  79. See StandardTouchDelegate description.
  80. IMPORTANT: The delegate will be retained.
  81. */
  82. -(void) addStandardDelegate:(id<CCStandardTouchDelegate>) delegate priority:(int)priority;
  83. /** Adds a targeted touch delegate to the dispatcher's list.
  84. See TargetedTouchDelegate description.
  85. IMPORTANT: The delegate will be retained.
  86. */
  87. -(void) addTargetedDelegate:(id<CCTargetedTouchDelegate>) delegate priority:(int)priority swallowsTouches:(BOOL)swallowsTouches;
  88. /** Removes a touch delegate.
  89. The delegate will be released
  90. */
  91. -(void) removeDelegate:(id) delegate;
  92. /** Removes all touch delegates, releasing all the delegates */
  93. -(void) removeAllDelegates;
  94. /** Changes the priority of a previously added delegate. The lower the number,
  95. the higher the priority */
  96. -(void) setPriority:(int) priority forDelegate:(id) delegate;
  97. @end