axmol/cocos/2d/platform/mac/CCEventDispatcherMac.h

278 lines
8.2 KiB
C
Raw Normal View History

/****************************************************************************
Copyright (c) 2010 Ricardo Quesada
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011 Zynga Inc.
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
2012-07-21 12:23:40 +08:00
// Only compile this code on Mac. These files should not be included on your iOS project.
// But in case they are included, it won't be compiled.
#import <Availability.h>
#ifndef __CC_EVENT_DISPATCHER_MAC_H__
#define __CC_EVENT_DISPATCHER_MAC_H__
2012-07-21 12:23:40 +08:00
#import <Cocoa/Cocoa.h>
#import "EAGLView.h"
//#import "../../Support/uthash.h" // hack: uthash needs to be imported before utlist to prevent warning
//#import "../../Support/utlist.h"
#import "ccConfig.h"
//NS_CC_BEGIN;
2013-11-21 03:26:33 +08:00
#pragma mark - MouseEventDelegate
2012-07-21 12:23:40 +08:00
/** MouseEventDelegate protocol.
2012-07-21 12:23:40 +08:00
Implement it in your node to receive any of mouse events
*/
@protocol CCMouseEventDelegate <NSObject>
2012-07-21 12:23:40 +08:00
@optional
//
// left
//
/** called when the "mouseDown" event is received.
Return YES to avoid propagating the event to other delegates.
*/
-(BOOL) ccMouseDown:(NSEvent*)event;
/** called when the "mouseDragged" event is received.
Return YES to avoid propagating the event to other delegates.
*/
-(BOOL) ccMouseDragged:(NSEvent*)event;
/** called when the "mouseMoved" event is received.
Return YES to avoid propagating the event to other delegates.
By default, "mouseMoved" is disabled. To enable it, send the "setAcceptsMouseMovedEvents:YES" message to the main window.
*/
-(BOOL) ccMouseMoved:(NSEvent*)event;
/** called when the "mouseUp" event is received.
Return YES to avoid propagating the event to other delegates.
*/
-(BOOL) ccMouseUp:(NSEvent*)event;
//
// right
//
/** called when the "rightMouseDown" event is received.
Return YES to avoid propagating the event to other delegates.
*/
-(BOOL) ccRightMouseDown:(NSEvent*)event;
/** called when the "rightMouseDragged" event is received.
Return YES to avoid propagating the event to other delegates.
*/
-(BOOL) ccRightMouseDragged:(NSEvent*)event;
/** called when the "rightMouseUp" event is received.
Return YES to avoid propagating the event to other delegates.
*/
-(BOOL) ccRightMouseUp:(NSEvent*)event;
//
// other
//
/** called when the "otherMouseDown" event is received.
Return YES to avoid propagating the event to other delegates.
*/
-(BOOL) ccOtherMouseDown:(NSEvent*)event;
/** called when the "otherMouseDragged" event is received.
Return YES to avoid propagating the event to other delegates.
*/
-(BOOL) ccOtherMouseDragged:(NSEvent*)event;
/** called when the "otherMouseUp" event is received.
Return YES to avoid propagating the event to other delegates.
*/
-(BOOL) ccOtherMouseUp:(NSEvent*)event;
//
// scroll wheel
//
/** called when the "scrollWheel" event is received.
Return YES to avoid propagating the event to other delegates.
*/
- (BOOL)ccScrollWheel:(NSEvent *)theEvent;
//
// enter / exit
//
/** called when the "mouseEntered" event is received.
Return YES to avoid propagating the event to other delegates.
*/
- (void)ccMouseEntered:(NSEvent *)theEvent;
/** called when the "mouseExited" event is received.
Return YES to avoid propagating the event to other delegates.
*/
- (void)ccMouseExited:(NSEvent *)theEvent;
@end
2013-11-21 03:26:33 +08:00
#pragma mark - KeyboardEventDelegate
2012-07-21 12:23:40 +08:00
/** KeyboardEventDelegate protocol.
2012-07-21 12:23:40 +08:00
Implement it in your node to receive any of keyboard events
*/
@protocol CCKeyboardEventDelegate <NSObject>
2012-07-21 12:23:40 +08:00
@optional
/** called when the "keyUp" event is received.
Return YES to avoid propagating the event to other delegates.
*/
-(BOOL) ccKeyUp:(NSEvent*)event;
/** called when the "keyDown" event is received.
Return YES to avoid propagating the event to other delegates.
*/
-(BOOL) ccKeyDown:(NSEvent*)event;
/** called when the "flagsChanged" event is received.
Return YES to avoid propagating the event to other delegates.
*/
-(BOOL) ccFlagsChanged:(NSEvent*)event;
@end
#pragma mark -
#pragma mark TouchEventDelegate
2012-07-21 12:23:40 +08:00
/** TouchEventDelegate protocol.
2012-07-21 12:23:40 +08:00
Implement it in your node to receive any of touch events
*/
@protocol CCTouchEventDelegate <NSObject>
2012-07-21 12:23:40 +08:00
@optional
/** called when the "touchesBegan" event is received.
Return YES to avoid propagating the event to other delegates.
*/
- (BOOL)ccTouchesBeganWithEvent:(NSEvent *)event;
/** called when the "touchesMoved" event is received.
Return YES to avoid propagating the event to other delegates.
*/
- (BOOL)ccTouchesMovedWithEvent:(NSEvent *)event;
/** called when the "touchesEnded" event is received.
Return YES to avoid propagating the event to other delegates.
*/
- (BOOL)ccTouchesEndedWithEvent:(NSEvent *)event;
/** called when the "touchesCancelled" event is received.
Return YES to avoid propagating the event to other delegates.
*/
- (BOOL)ccTouchesCancelledWithEvent:(NSEvent *)event;
@end
2013-11-21 03:26:33 +08:00
#pragma mark - EventDispatcher
2012-07-21 12:23:40 +08:00
struct _listEntry;
/** EventDispatcher
2012-07-21 12:23:40 +08:00
This is object is responsible for dispatching the events:
- Mouse events
- Keyboard events
- Touch events
Only available on Mac
*/
@interface CCEventDispatcher : NSObject <CCMacEventDelegate> {
2012-07-21 12:23:40 +08:00
BOOL dispatchEvents_;
struct _listEntry *keyboardDelegates_;
struct _listEntry *mouseDelegates_;
struct _listEntry *touchDelegates_;
}
@property (nonatomic, readwrite) BOOL dispatchEvents;
/** EventDispatcher singleton */
+(CCEventDispatcher*) sharedDispatcher;
2012-07-21 12:23:40 +08:00
#pragma mark EventDispatcher - Mouse
2012-07-21 12:23:40 +08:00
/** Adds a mouse delegate to the dispatcher's list.
Delegates with a lower priority value will be called before higher priority values.
All the events will be propgated to all the delegates, unless the one delegate returns YES.
IMPORTANT: The delegate will be retained.
*/
-(void) addMouseDelegate:(id<CCMouseEventDelegate>) delegate priority:(NSInteger)priority;
2012-07-21 12:23:40 +08:00
/** removes a mouse delegate */
-(void) removeMouseDelegate:(id) delegate;
/** Removes all mouse delegates, releasing all the delegates */
-(void) removeAllMouseDelegates;
#pragma mark EventDispatcher - Keyboard
2012-07-21 12:23:40 +08:00
/** Adds a Keyboard delegate to the dispatcher's list.
Delegates with a lower priority value will be called before higher priority values.
All the events will be propgated to all the delegates, unless the one delegate returns YES.
IMPORTANT: The delegate will be retained.
*/
-(void) addKeyboardDelegate:(id<CCKeyboardEventDelegate>) delegate priority:(NSInteger)priority;
2012-07-21 12:23:40 +08:00
/** removes a mouse delegate */
-(void) removeKeyboardDelegate:(id) delegate;
/** Removes all mouse delegates, releasing all the delegates */
-(void) removeAllKeyboardDelegates;
#pragma mark EventDispatcher - Touches
2012-07-21 12:23:40 +08:00
/** Adds a Touch delegate to the dispatcher's list.
Delegates with a lower priority value will be called before higher priority values.
All the events will be propgated to all the delegates, unless the one delegate returns YES.
IMPORTANT: The delegate will be retained.
*/
- (void)addTouchDelegate:(id<CCTouchEventDelegate>)delegate priority:(NSInteger)priority;
2012-07-21 12:23:40 +08:00
/** Removes a touch delegate */
- (void)removeTouchDelegate:(id) delegate;
/** Removes all touch delegates, releasing all the delegates */
- (void)removeAllTouchDelegates;
#pragma mark EventDispatcher - Dispatch Events
2012-07-21 12:23:40 +08:00
#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD
-(void) dispatchQueuedEvents;
#endif
@end
//NS_CC_END;
#endif // __CC_EVENT_DISPATCHER_MAC_H__