|
| 1 | +/**************************************************************************** |
| 2 | +Copyright (c) 2013-2014 Chukong Technologies Inc. |
| 3 | +
|
| 4 | + http://www.cocos2d-x.org |
| 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 | +#ifndef __LUA_EVENT_NODE_H_ |
| 26 | +#define __LUA_EVENT_NODE_H_ |
| 27 | + |
| 28 | +#include "2d/CCNode.h" |
| 29 | + |
| 30 | +NS_CC_BEGIN |
| 31 | + |
| 32 | +#define NODE_EVENT 0 |
| 33 | +#define NODE_ENTER_FRAME_EVENT 1 |
| 34 | +#define NODE_TOUCH_EVENT 2 |
| 35 | +#define NODE_TOUCH_CAPTURE_EVENT 3 |
| 36 | +#define MENU_ITEM_CLICKED_EVENT 4 |
| 37 | +#define ACCELERATE_EVENT 5 |
| 38 | +#define KEYPAD_EVENT 6 |
| 39 | + |
| 40 | +#define NODE_TOUCH_CAPTURING_PHASE 0 |
| 41 | +#define NODE_TOUCH_TARGETING_PHASE 1 |
| 42 | + |
| 43 | +/** |
| 44 | + * @addtogroup scene |
| 45 | + * @{ |
| 46 | + */ |
| 47 | + |
| 48 | +class CC_DLL LuaEventNode : public Ref |
| 49 | +{ |
| 50 | +public: |
| 51 | + static const int modeTouchesOneByOne = (int)Touch::DispatchMode::ONE_BY_ONE; |
| 52 | + static const int modeTouchesAllAtOnce = (int)Touch::DispatchMode::ALL_AT_ONCE; |
| 53 | + |
| 54 | + static LuaEventNode *create(Node *node); |
| 55 | + |
| 56 | + ~LuaEventNode(); |
| 57 | + |
| 58 | + Node *getNode() const; |
| 59 | + |
| 60 | + virtual LuaEventNode* getParent(); |
| 61 | + |
| 62 | + virtual bool isVisible() const; |
| 63 | + virtual bool isRunning() const; |
| 64 | + |
| 65 | + virtual void registerWithTouchDispatcher(void); |
| 66 | + virtual void unregisterWithTouchDispatcher(void); |
| 67 | + |
| 68 | + virtual bool isTouchCaptureEnabled(); |
| 69 | + virtual void setTouchCaptureEnabled(bool value); |
| 70 | + virtual bool isTouchSwallowEnabled(); |
| 71 | + virtual void setTouchSwallowEnabled(bool value); |
| 72 | + |
| 73 | + virtual bool ccTouchCaptureBegan(Touch *pTouch, LuaEventNode *pTarget); |
| 74 | + virtual bool ccTouchCaptureMoved(Touch *pTouch, LuaEventNode *pTarget); |
| 75 | + virtual void ccTouchCaptureEnded(Touch *pTouch, LuaEventNode *pTarget); |
| 76 | + virtual void ccTouchCaptureCancelled(Touch *pTouch, LuaEventNode *pTarget); |
| 77 | + |
| 78 | + virtual void ccTouchesCaptureBegan(const std::vector<Touch*>& touches, LuaEventNode *pTarget); |
| 79 | + virtual void ccTouchesCaptureMoved(const std::vector<Touch*>& touches, LuaEventNode *pTarget); |
| 80 | + virtual void ccTouchesCaptureEnded(const std::vector<Touch*>& touches, LuaEventNode *pTarget); |
| 81 | + virtual void ccTouchesCaptureCancelled(const std::vector<Touch*>& touches, LuaEventNode *pTarget); |
| 82 | + virtual void ccTouchesCaptureAdded(const std::vector<Touch*>& touches, LuaEventNode *pTarget); |
| 83 | + virtual void ccTouchesCaptureRemoved(const std::vector<Touch*>& touches, LuaEventNode *pTarget); |
| 84 | + |
| 85 | + virtual bool isTouchEnabled(); |
| 86 | + virtual void setTouchEnabled(bool value); |
| 87 | + |
| 88 | + virtual void setTouchMode(int mode); |
| 89 | + virtual int getTouchMode(); |
| 90 | + |
| 91 | + virtual bool ccTouchBegan(Touch *pTouch, Event *pEvent); |
| 92 | + virtual void ccTouchMoved(Touch *pTouch, Event *pEvent); |
| 93 | + virtual void ccTouchEnded(Touch *pTouch, Event *pEvent); |
| 94 | + virtual void ccTouchCancelled(Touch *pTouch, Event *pEvent); |
| 95 | + |
| 96 | + virtual void ccTouchesBegan(const std::vector<Touch*>& touches, Event *pEvent); |
| 97 | + virtual void ccTouchesMoved(const std::vector<Touch*>& touches, Event *pEvent); |
| 98 | + virtual void ccTouchesEnded(const std::vector<Touch*>& touches, Event *pEvent); |
| 99 | + virtual void ccTouchesCancelled(const std::vector<Touch*>& touches, Event *pEvent); |
| 100 | + virtual void ccTouchesAdded(const std::vector<Touch*>& touches, Event *pEvent); |
| 101 | + virtual void ccTouchesRemoved(const std::vector<Touch*>& touches, Event *pEvent); |
| 102 | + |
| 103 | +private: |
| 104 | + LuaEventNode(Node *node); |
| 105 | + |
| 106 | + Node *_node; |
| 107 | + |
| 108 | + // touch events |
| 109 | + bool _bTouchCaptureEnabled; |
| 110 | + bool _bTouchSwallowEnabled; |
| 111 | + bool _bTouchEnabled; |
| 112 | + int _eTouchMode; |
| 113 | + |
| 114 | + virtual int executeScriptTouchHandler(int nEventType, Touch *pTouch, int phase = 1); |
| 115 | + virtual int executeScriptTouchHandler(int nEventType, const std::vector<Touch*>& touches, int phase = 1); |
| 116 | + |
| 117 | +}; |
| 118 | + |
| 119 | +NS_CC_END |
| 120 | + |
| 121 | +#endif // __LUA_EVENT_NODE_H_ |
0 commit comments