issue #4234: 'Event* event' needs to be in 'TouchScriptData' struct.

This commit is contained in:
James Chen 2014-03-04 13:42:06 +08:00
parent bd0f342692
commit 5c70548742
3 changed files with 52 additions and 48 deletions

View File

@ -99,28 +99,28 @@ Layer *Layer::create()
} }
} }
int Layer::executeScriptTouchHandler(EventTouch::EventCode eventType, Touch* touch) int Layer::executeScriptTouchHandler(EventTouch::EventCode eventType, Touch* touch, Event* event)
{ {
#if CC_ENABLE_SCRIPT_BINDING #if CC_ENABLE_SCRIPT_BINDING
if (kScriptTypeNone != _scriptType) if (kScriptTypeLua == _scriptType)
{ {
TouchScriptData data(eventType, this, touch); TouchScriptData data(eventType, this, touch, event);
ScriptEvent event(kTouchEvent, &data); ScriptEvent scriptEvent(kTouchEvent, &data);
return ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); return ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent);
} }
#endif #endif
//can not reach it //can not reach it
return 0; return 0;
} }
int Layer::executeScriptTouchesHandler(EventTouch::EventCode eventType, const std::vector<Touch*>& touches) int Layer::executeScriptTouchesHandler(EventTouch::EventCode eventType, const std::vector<Touch*>& touches, Event* event)
{ {
#if CC_ENABLE_SCRIPT_BINDING #if CC_ENABLE_SCRIPT_BINDING
if (kScriptTypeNone != _scriptType) if (kScriptTypeLua == _scriptType)
{ {
TouchesScriptData data(eventType, this, touches); TouchesScriptData data(eventType, this, touches, event);
ScriptEvent event(kTouchesEvent, &data); ScriptEvent scriptEvent(kTouchesEvent, &data);
return ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); return ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent);
} }
#endif #endif
return 0; return 0;
@ -325,105 +325,105 @@ void Layer::setKeypadEnabled(bool enabled)
} }
/// Callbacks /// Callbacks
bool Layer::onTouchBegan(Touch *touch, Event *unused_event) bool Layer::onTouchBegan(Touch *touch, Event *event)
{ {
#if CC_ENABLE_SCRIPT_BINDING #if CC_ENABLE_SCRIPT_BINDING
if (kScriptTypeNone != _scriptType) if (kScriptTypeLua == _scriptType)
{ {
return executeScriptTouchHandler(EventTouch::EventCode::BEGAN, touch) == 0 ? false : true; return executeScriptTouchHandler(EventTouch::EventCode::BEGAN, touch, event) == 0 ? false : true;
} }
#endif #endif
CC_UNUSED_PARAM(unused_event); CC_UNUSED_PARAM(event);
CCASSERT(false, "Layer#ccTouchBegan override me"); CCASSERT(false, "Layer#ccTouchBegan override me");
return true; return true;
} }
void Layer::onTouchMoved(Touch *touch, Event *unused_event) void Layer::onTouchMoved(Touch *touch, Event *event)
{ {
#if CC_ENABLE_SCRIPT_BINDING #if CC_ENABLE_SCRIPT_BINDING
if (kScriptTypeNone != _scriptType) if (kScriptTypeLua == _scriptType)
{ {
executeScriptTouchHandler(EventTouch::EventCode::MOVED, touch); executeScriptTouchHandler(EventTouch::EventCode::MOVED, touch, event);
return; return;
} }
#endif #endif
CC_UNUSED_PARAM(unused_event); CC_UNUSED_PARAM(event);
} }
void Layer::onTouchEnded(Touch *touch, Event *unused_event) void Layer::onTouchEnded(Touch *touch, Event *event)
{ {
#if CC_ENABLE_SCRIPT_BINDING #if CC_ENABLE_SCRIPT_BINDING
if (kScriptTypeNone != _scriptType) if (kScriptTypeLua == _scriptType)
{ {
executeScriptTouchHandler(EventTouch::EventCode::ENDED, touch); executeScriptTouchHandler(EventTouch::EventCode::ENDED, touch, event);
return; return;
} }
#endif #endif
CC_UNUSED_PARAM(unused_event); CC_UNUSED_PARAM(event);
} }
void Layer::onTouchCancelled(Touch *touch, Event *unused_event) void Layer::onTouchCancelled(Touch *touch, Event *event)
{ {
#if CC_ENABLE_SCRIPT_BINDING #if CC_ENABLE_SCRIPT_BINDING
if (kScriptTypeNone != _scriptType) if (kScriptTypeLua == _scriptType)
{ {
executeScriptTouchHandler(EventTouch::EventCode::CANCELLED, touch); executeScriptTouchHandler(EventTouch::EventCode::CANCELLED, touch, event);
return; return;
} }
#endif #endif
CC_UNUSED_PARAM(unused_event); CC_UNUSED_PARAM(event);
} }
void Layer::onTouchesBegan(const std::vector<Touch*>& touches, Event *unused_event) void Layer::onTouchesBegan(const std::vector<Touch*>& touches, Event *event)
{ {
#if CC_ENABLE_SCRIPT_BINDING #if CC_ENABLE_SCRIPT_BINDING
if (kScriptTypeNone != _scriptType) if (kScriptTypeLua == _scriptType)
{ {
executeScriptTouchesHandler(EventTouch::EventCode::BEGAN, touches); executeScriptTouchesHandler(EventTouch::EventCode::BEGAN, touches, event);
return; return;
} }
#endif #endif
CC_UNUSED_PARAM(unused_event); CC_UNUSED_PARAM(event);
} }
void Layer::onTouchesMoved(const std::vector<Touch*>& touches, Event *unused_event) void Layer::onTouchesMoved(const std::vector<Touch*>& touches, Event *event)
{ {
#if CC_ENABLE_SCRIPT_BINDING #if CC_ENABLE_SCRIPT_BINDING
if (kScriptTypeNone != _scriptType) if (kScriptTypeLua == _scriptType)
{ {
executeScriptTouchesHandler(EventTouch::EventCode::MOVED, touches); executeScriptTouchesHandler(EventTouch::EventCode::MOVED, touches, event);
return; return;
} }
#endif #endif
CC_UNUSED_PARAM(unused_event); CC_UNUSED_PARAM(event);
} }
void Layer::onTouchesEnded(const std::vector<Touch*>& touches, Event *unused_event) void Layer::onTouchesEnded(const std::vector<Touch*>& touches, Event *event)
{ {
#if CC_ENABLE_SCRIPT_BINDING #if CC_ENABLE_SCRIPT_BINDING
if (kScriptTypeNone != _scriptType) if (kScriptTypeLua == _scriptType)
{ {
executeScriptTouchesHandler(EventTouch::EventCode::ENDED, touches); executeScriptTouchesHandler(EventTouch::EventCode::ENDED, touches, event);
return; return;
} }
#endif #endif
CC_UNUSED_PARAM(unused_event); CC_UNUSED_PARAM(event);
} }
void Layer::onTouchesCancelled(const std::vector<Touch*>& touches, Event *unused_event) void Layer::onTouchesCancelled(const std::vector<Touch*>& touches, Event *event)
{ {
#if CC_ENABLE_SCRIPT_BINDING #if CC_ENABLE_SCRIPT_BINDING
if (kScriptTypeNone != _scriptType) if (kScriptTypeLua == _scriptType)
{ {
executeScriptTouchesHandler(EventTouch::EventCode::CANCELLED, touches); executeScriptTouchesHandler(EventTouch::EventCode::CANCELLED, touches, event);
return; return;
} }
#endif #endif
CC_UNUSED_PARAM(unused_event); CC_UNUSED_PARAM(event);
} }
std::string Layer::getDescription() const std::string Layer::getDescription() const

View File

@ -171,8 +171,8 @@ protected:
void _addTouchListener(); void _addTouchListener();
CC_DEPRECATED_ATTRIBUTE void addTouchListener() { _addTouchListener();}; CC_DEPRECATED_ATTRIBUTE void addTouchListener() { _addTouchListener();};
CC_DEPRECATED_ATTRIBUTE int executeScriptTouchHandler(EventTouch::EventCode eventType, Touch* touch); CC_DEPRECATED_ATTRIBUTE int executeScriptTouchHandler(EventTouch::EventCode eventType, Touch* touch, Event* event);
CC_DEPRECATED_ATTRIBUTE int executeScriptTouchesHandler(EventTouch::EventCode eventType, const std::vector<Touch*>& touches); CC_DEPRECATED_ATTRIBUTE int executeScriptTouchesHandler(EventTouch::EventCode eventType, const std::vector<Touch*>& touches, Event* event);
bool _touchEnabled; bool _touchEnabled;
bool _accelerometerEnabled; bool _accelerometerEnabled;

View File

@ -258,16 +258,18 @@ struct TouchesScriptData
EventTouch::EventCode actionType; EventTouch::EventCode actionType;
void* nativeObject; void* nativeObject;
const std::vector<Touch*>& touches; const std::vector<Touch*>& touches;
Event* event;
// Constructor // Constructor
/** /**
* @js NA * @js NA
* @lua NA * @lua NA
*/ */
TouchesScriptData(EventTouch::EventCode inActionType, void* inNativeObject, const std::vector<Touch*>& inTouches) TouchesScriptData(EventTouch::EventCode inActionType, void* inNativeObject, const std::vector<Touch*>& inTouches, Event* evt)
: actionType(inActionType), : actionType(inActionType),
nativeObject(inNativeObject), nativeObject(inNativeObject),
touches(inTouches) touches(inTouches),
event(evt)
{ {
} }
}; };
@ -277,16 +279,18 @@ struct TouchScriptData
EventTouch::EventCode actionType; EventTouch::EventCode actionType;
void* nativeObject; void* nativeObject;
Touch* touch; Touch* touch;
Event* event;
// Constructor // Constructor
/** /**
* @js NA * @js NA
* @lua NA * @lua NA
*/ */
TouchScriptData(EventTouch::EventCode inActionType, void* inNativeObject, Touch* inTouch) TouchScriptData(EventTouch::EventCode inActionType, void* inNativeObject, Touch* inTouch, Event* evt)
: actionType(inActionType), : actionType(inActionType),
nativeObject(inNativeObject), nativeObject(inNativeObject),
touch(inTouch) touch(inTouch),
event(evt)
{ {
} }
}; };