Merge branch 'develop' into newRenderer

This commit is contained in:
Nite Luo 2013-11-20 11:14:28 -08:00
commit f438e83104
28 changed files with 347 additions and 278 deletions

View File

@ -43,6 +43,7 @@ cocos2d-x-3.0alpha1 Nov.19 2013
[NEW] Performance Test: Sprite drawing
[NEW] Adjusted folder structure
[NEW] Added tools to simplify upgrading game codes from v2.x to v3.x
[FIX] Added virtual destructors on Interfaces
[Android]
[FIX] Added EGL_RENDERABLE_TYPE to OpenGL attributes
[FIX] Fixed application will crash when pause and resume.

View File

@ -1 +1 @@
d6e37148eeabf54b5fa421de0b544425ae1228f4
a1c60b61d609599593419cf3b32d4b6259880b57

View File

@ -210,7 +210,7 @@ Sequence* Sequence::create(Array* arrayOfActions)
if (count > 1)
{
for (unsigned int i = 1; i < count; ++i)
for (long i = 1; i < count; ++i)
{
prev = createWithTwoActions(prev, static_cast<FiniteTimeAction*>(arrayOfActions->getObjectAtIndex(i)));
}
@ -220,7 +220,7 @@ Sequence* Sequence::create(Array* arrayOfActions)
// If only one action is added to Sequence, make up a Sequence by adding a simplest finite time action.
prev = createWithTwoActions(prev, ExtraAction::create());
}
pRet = (Sequence*)prev;
pRet = static_cast<Sequence*>(prev);
}while (0);
return pRet;
}

View File

@ -346,7 +346,7 @@ void DrawNode::drawPolygon(Point *verts, long count, const Color4F &fillColor, f
struct ExtrudeVerts* extrude = (struct ExtrudeVerts*)malloc(sizeof(struct ExtrudeVerts)*count);
memset(extrude, 0, sizeof(struct ExtrudeVerts)*count);
for(unsigned int i = 0; i < count; i++)
for (long i = 0; i < count; i++)
{
Vertex2F v0 = __v2f(verts[(i-1+count)%count]);
Vertex2F v1 = __v2f(verts[i]);
@ -370,7 +370,7 @@ void DrawNode::drawPolygon(Point *verts, long count, const Color4F &fillColor, f
V2F_C4B_T2F_Triangle *cursor = triangles;
float inset = (outline == false ? 0.5 : 0.0);
for(unsigned int i = 0; i < count-2; i++)
for (long i = 0; i < count-2; i++)
{
Vertex2F v0 = v2fsub(__v2f(verts[0 ]), v2fmult(extrude[0 ].offset, inset));
Vertex2F v1 = v2fsub(__v2f(verts[i+1]), v2fmult(extrude[i+1].offset, inset));

View File

@ -491,7 +491,7 @@ void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, s
auto fixedPriorityListeners = listeners->getFixedPriorityListeners();
auto sceneGraphPriorityListeners = listeners->getSceneGraphPriorityListeners();
int i = 0;
long i = 0;
// priority < 0
if (fixedPriorityListeners)
{
@ -527,7 +527,7 @@ void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, s
if (!shouldStopPropagation)
{
// priority > 0
for (; i < fixedPriorityListeners->size(); ++i)
for (; i < static_cast<long>(fixedPriorityListeners->size()); ++i)
{
auto l = fixedPriorityListeners->at(i);
@ -976,7 +976,7 @@ void EventDispatcher::sortEventListenersOfFixedPriority(EventListener::ListenerI
});
// FIXME: Should use binary search
int index = 0;
long index = 0;
for (auto& listener : *fixedlisteners)
{
if (listener->getFixedPriority() >= 0)

View File

@ -136,12 +136,12 @@ private:
inline std::vector<EventListener*>* getFixedPriorityListeners() const { return _fixedListeners; };
inline std::vector<EventListener*>* getSceneGraphPriorityListeners() const { return _sceneGraphListeners; };
inline int getGt0Index() const { return _gt0Index; };
inline void setGt0Index(int index) { _gt0Index = index; };
inline long getGt0Index() const { return _gt0Index; };
inline void setGt0Index(long index) { _gt0Index = index; };
private:
std::vector<EventListener*>* _fixedListeners;
std::vector<EventListener*>* _sceneGraphListeners;
int _gt0Index;
long _gt0Index;
};
/** Adds event listener with item */

View File

@ -42,36 +42,38 @@ struct LetterInfo
class CC_DLL LabelTextFormatProtocol
{
public:
virtual bool recordLetterInfo(const cocos2d::Point& point,unsigned short int theChar, int spriteIndex) = 0;
virtual bool recordPlaceholderInfo(int spriteIndex) = 0;
virtual std::vector<LetterInfo> *getLettersInfo() = 0;
virtual float getLetterPosXLeft(int index) const = 0;
virtual float getLetterPosXRight(int index) const = 0;
virtual ~LabelTextFormatProtocol() {}
virtual bool recordLetterInfo(const cocos2d::Point& point,unsigned short int theChar, int spriteIndex) = 0;
virtual bool recordPlaceholderInfo(int spriteIndex) = 0;
virtual std::vector<LetterInfo> *getLettersInfo() = 0;
virtual float getLetterPosXLeft(int index) const = 0;
virtual float getLetterPosXRight(int index) const = 0;
// sprite related stuff
virtual cocos2d::Sprite *getLetter(int ID) = 0;
virtual cocos2d::Sprite *getLetter(int ID) = 0;
// font related stuff
virtual int getCommonLineHeight() const = 0;
virtual int getKerningForCharsPair(unsigned short first, unsigned short second) const = 0;
virtual int getXOffsetForChar(unsigned short c) const = 0;
virtual int getYOffsetForChar(unsigned short c) const = 0;
virtual int getAdvanceForChar(unsigned short c, int hintPositionInString) const = 0;
virtual cocos2d::Rect getRectForChar(unsigned short c) const = 0;
virtual int getCommonLineHeight() const = 0;
virtual int getKerningForCharsPair(unsigned short first, unsigned short second) const = 0;
virtual int getXOffsetForChar(unsigned short c) const = 0;
virtual int getYOffsetForChar(unsigned short c) const = 0;
virtual int getAdvanceForChar(unsigned short c, int hintPositionInString) const = 0;
virtual cocos2d::Rect getRectForChar(unsigned short c) const = 0;
// string related stuff
virtual int getStringNumLines() const = 0;
virtual int getStringLenght() const = 0;
virtual unsigned short getCharAtStringPosition(int position) const = 0;
virtual unsigned short * getUTF8String() const = 0;
virtual void assignNewUTF8String(unsigned short *newString) = 0;
virtual TextHAlignment getTextAlignment() const = 0;
virtual int getStringNumLines() const = 0;
virtual int getStringLenght() const = 0;
virtual unsigned short getCharAtStringPosition(int position) const = 0;
virtual unsigned short * getUTF8String() const = 0;
virtual void assignNewUTF8String(unsigned short *newString) = 0;
virtual TextHAlignment getTextAlignment() const = 0;
// label related stuff
virtual float getMaxLineWidth() const = 0;
virtual bool breakLineWithoutSpace() const = 0;
virtual cocos2d::Size getLabelContentSize() const = 0;
virtual void setLabelContentSize(const Size &newSize) = 0;
virtual float getMaxLineWidth() const = 0;
virtual bool breakLineWithoutSpace() const = 0;
virtual cocos2d::Size getLabelContentSize() const = 0;
virtual void setLabelContentSize(const Size &newSize) = 0;
};
NS_CC_END

View File

@ -95,128 +95,38 @@ Layer *Layer::create()
}
}
/// Touch and Accelerometer related
void Layer::_addTouchListener()
int Layer::executeScriptTouchHandler(EventTouch::EventCode eventType, Touch* touch)
{
if (_touchListener != nullptr)
return;
if( _touchMode == Touch::DispatchMode::ALL_AT_ONCE )
if (kScriptTypeNone != _scriptType)
{
// Register Touch Event
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesBegan = [=](const std::vector<Touch*>& touches, Event* event){
if (kScriptTypeNone != _scriptType)
{
TouchesScriptData data(EventTouch::EventCode::BEGAN, this, touches);
ScriptEvent event(kTouchesEvent, &data);
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
return;
}
CC_UNUSED_PARAM(touches);
CC_UNUSED_PARAM(event);
};
listener->onTouchesMoved = [=](const std::vector<Touch*>& touches, Event* event){
if (kScriptTypeNone != _scriptType)
{
TouchesScriptData data(EventTouch::EventCode::MOVED, this, touches);
ScriptEvent event(kTouchesEvent, &data);
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
return;
}
CC_UNUSED_PARAM(touches);
CC_UNUSED_PARAM(event);
};
listener->onTouchesEnded = [=](const std::vector<Touch*>& touches, Event* event){
if (kScriptTypeNone != _scriptType)
{
TouchesScriptData data(EventTouch::EventCode::ENDED, this, touches);
ScriptEvent event(kTouchesEvent, &data);
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
return;
}
CC_UNUSED_PARAM(touches);
CC_UNUSED_PARAM(event);
};
listener->onTouchesCancelled = [=](const std::vector<Touch*>& touches, Event* event){
if (kScriptTypeNone != _scriptType)
{
TouchesScriptData data(EventTouch::EventCode::CANCELLED, this, touches);
ScriptEvent event(kTouchesEvent, &data);
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
return;
}
CC_UNUSED_PARAM(touches);
CC_UNUSED_PARAM(event);
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
_touchListener = listener;
TouchScriptData data(eventType, this, touch);
ScriptEvent event(kTouchEvent, &data);
return ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
}
else
{
// Register Touch Event
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(_swallowsTouches);
listener->onTouchBegan = [=](Touch* touch, Event* event){
if (kScriptTypeNone != _scriptType)
{
TouchScriptData data(EventTouch::EventCode::BEGAN, this, touch);
ScriptEvent event(kTouchEvent, &data);
if(ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event))
return true;
else
return false;
}
return false;
};
listener->onTouchMoved = [=](Touch* touch, Event* event){
if (kScriptTypeNone != _scriptType)
{
TouchScriptData data(EventTouch::EventCode::MOVED, this, touch);
ScriptEvent event(kTouchEvent, &data);
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
}
};
listener->onTouchEnded = [=](Touch* touch, Event* event){
if (kScriptTypeNone != _scriptType)
{
TouchScriptData data(EventTouch::EventCode::ENDED, this, touch);
ScriptEvent event(kTouchEvent, &data);
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
}
};
listener->onTouchCancelled = [=](Touch* touch, Event* event){
if (kScriptTypeNone != _scriptType)
{
TouchScriptData data(EventTouch::EventCode::CANCELLED, this, touch);
ScriptEvent event(kTouchEvent, &data);
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
}
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
_touchListener = listener;
}
//can not reach it
return 0;
}
int Layer::executeScriptTouchesHandler(EventTouch::EventCode eventType, const std::vector<Touch*>& touches)
{
if (kScriptTypeNone != _scriptType)
{
TouchesScriptData data(eventType, this, touches);
ScriptEvent event(kTouchesEvent, &data);
return ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
}
return 0;
}
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif _MSC_VER >= 1400 //vs 2005 or higher
#pragma warning (push)
#pragma warning (disable: 4996)
#endif
/// isTouchEnabled getter
bool Layer::isTouchEnabled() const
{
@ -231,7 +141,36 @@ void Layer::setTouchEnabled(bool enabled)
_touchEnabled = enabled;
if (enabled)
{
this->_addTouchListener();
if (_touchListener != nullptr)
return;
if( _touchMode == Touch::DispatchMode::ALL_AT_ONCE )
{
// Register Touch Event
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesBegan = CC_CALLBACK_2(Layer::onTouchesBegan, this);
listener->onTouchesMoved = CC_CALLBACK_2(Layer::onTouchesMoved, this);
listener->onTouchesEnded = CC_CALLBACK_2(Layer::onTouchesEnded, this);
listener->onTouchesCancelled = CC_CALLBACK_2(Layer::onTouchesCancelled, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
_touchListener = listener;
}
else
{
// Register Touch Event
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(_swallowsTouches);
listener->onTouchBegan = CC_CALLBACK_2(Layer::onTouchBegan, this);
listener->onTouchMoved = CC_CALLBACK_2(Layer::onTouchMoved, this);
listener->onTouchEnded = CC_CALLBACK_2(Layer::onTouchEnded, this);
listener->onTouchCancelled = CC_CALLBACK_2(Layer::onTouchCancelled, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
_touchListener = listener;
}
}
else
{
@ -249,9 +188,8 @@ void Layer::setTouchMode(Touch::DispatchMode mode)
if( _touchEnabled)
{
_eventDispatcher->removeEventListener(_touchListener);
_touchListener = nullptr;
this->_addTouchListener();
setTouchEnabled(false);
setTouchEnabled(true);
}
}
}
@ -264,9 +202,8 @@ void Layer::setSwallowsTouches(bool swallowsTouches)
if( _touchEnabled)
{
_eventDispatcher->removeEventListener(_touchListener);
_touchListener = nullptr;
this->_addTouchListener();
setTouchEnabled(false);
setTouchEnabled(true);
}
}
}
@ -281,8 +218,6 @@ bool Layer::isSwallowsTouches() const
return _swallowsTouches;
}
/// isAccelerometerEnabled getter
bool Layer::isAccelerometerEnabled() const
{
@ -297,31 +232,17 @@ void Layer::setAccelerometerEnabled(bool enabled)
Device::setAccelerometerEnabled(enabled);
if (_running)
_eventDispatcher->removeEventListener(_accelerationListener);
_accelerationListener = nullptr;
if (enabled)
{
_eventDispatcher->removeEventListener(_accelerationListener);
_accelerationListener = nullptr;
if (enabled)
{
//Not to use onAcceleration for avoid warn from deprecated api
_accelerationListener = EventListenerAcceleration::create([=](Acceleration* acc, Event* event){
CC_UNUSED_PARAM(acc);
if(kScriptTypeNone != _scriptType)
{
BasicScriptData data(this,(void*)acc);
ScriptEvent event(kAccelerometerEvent,&data);
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
}
});
_eventDispatcher->addEventListenerWithSceneGraphPriority(_accelerationListener, this);
}
_accelerationListener = EventListenerAcceleration::create(CC_CALLBACK_2(Layer::onAcceleration, this));
_eventDispatcher->addEventListenerWithSceneGraphPriority(_accelerationListener, this);
}
}
}
void Layer::setAccelerometerInterval(double interval) {
if (_accelerometerEnabled)
{
@ -332,28 +253,28 @@ void Layer::setAccelerometerInterval(double interval) {
}
}
void Layer::onAcceleration(Acceleration* pAccelerationValue, Event* event)
void Layer::onAcceleration(Acceleration* acc, Event* unused_event)
{
CC_UNUSED_PARAM(pAccelerationValue);
CC_UNUSED_PARAM(acc);
if(kScriptTypeNone != _scriptType)
{
BasicScriptData data(this,(void*)pAccelerationValue);
BasicScriptData data(this,(void*)acc);
ScriptEvent event(kAccelerometerEvent,&data);
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
}
CC_UNUSED_PARAM(unused_event);
}
void Layer::onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event)
void Layer::onKeyPressed(EventKeyboard::KeyCode keyCode, Event* unused_event)
{
CC_UNUSED_PARAM(keyCode);
CC_UNUSED_PARAM(event);
CC_UNUSED_PARAM(unused_event);
}
void Layer::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event)
void Layer::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* unused_event)
{
CC_UNUSED_PARAM(event);
CC_UNUSED_PARAM(unused_event);
if(kScriptTypeNone != _scriptType)
{
KeypadScriptData data(keyCode, this);
@ -380,19 +301,8 @@ void Layer::setKeyboardEnabled(bool enabled)
if (enabled)
{
auto listener = EventListenerKeyboard::create();
listener->onKeyPressed = [](EventKeyboard::KeyCode keyCode, Event* event){
CC_UNUSED_PARAM(keyCode);
CC_UNUSED_PARAM(event);
};
listener->onKeyReleased = [this](EventKeyboard::KeyCode keyCode, Event* event){
CC_UNUSED_PARAM(event);
if(kScriptTypeNone != _scriptType)
{
KeypadScriptData data(keyCode, this);
ScriptEvent event(kKeypadEvent,&data);
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
}
};
listener->onKeyPressed = CC_CALLBACK_2(Layer::onKeyPressed, this);
listener->onKeyReleased = CC_CALLBACK_2(Layer::onKeyReleased, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
_keyboardListener = listener;
@ -402,36 +312,104 @@ void Layer::setKeyboardEnabled(bool enabled)
void Layer::setKeypadEnabled(bool enabled)
{
if (enabled != _keyboardEnabled)
setKeyboardEnabled(enabled);
}
/// Callbacks
bool Layer::onTouchBegan(Touch *touch, Event *unused_event)
{
if (kScriptTypeNone != _scriptType)
{
_keyboardEnabled = enabled;
_eventDispatcher->removeEventListener(_keyboardListener);
_keyboardListener = nullptr;
if (enabled)
{
auto listener = EventListenerKeyboard::create();
listener->onKeyPressed = [](EventKeyboard::KeyCode keyCode, Event* event){
CC_UNUSED_PARAM(keyCode);
CC_UNUSED_PARAM(event);
};
listener->onKeyReleased = [this](EventKeyboard::KeyCode keyCode, Event* event){
CC_UNUSED_PARAM(event);
if(kScriptTypeNone != _scriptType)
{
KeypadScriptData data(keyCode, this);
ScriptEvent event(kKeypadEvent,&data);
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
}
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
_keyboardListener = listener;
}
return executeScriptTouchHandler(EventTouch::EventCode::BEGAN, touch) == 0 ? false : true;
}
CC_UNUSED_PARAM(unused_event);
CCASSERT(false, "Layer#ccTouchBegan override me");
return true;
}
void Layer::onTouchMoved(Touch *touch, Event *unused_event)
{
if (kScriptTypeNone != _scriptType)
{
executeScriptTouchHandler(EventTouch::EventCode::MOVED, touch);
return;
}
CC_UNUSED_PARAM(unused_event);
}
void Layer::onTouchEnded(Touch *touch, Event *unused_event)
{
if (kScriptTypeNone != _scriptType)
{
executeScriptTouchHandler(EventTouch::EventCode::ENDED, touch);
return;
}
CC_UNUSED_PARAM(unused_event);
}
void Layer::onTouchCancelled(Touch *touch, Event *unused_event)
{
if (kScriptTypeNone != _scriptType)
{
executeScriptTouchHandler(EventTouch::EventCode::CANCELLED, touch);
return;
}
CC_UNUSED_PARAM(unused_event);
}
void Layer::onTouchesBegan(const std::vector<Touch*>& touches, Event *unused_event)
{
if (kScriptTypeNone != _scriptType)
{
executeScriptTouchesHandler(EventTouch::EventCode::BEGAN, touches);
return;
}
CC_UNUSED_PARAM(unused_event);
}
void Layer::onTouchesMoved(const std::vector<Touch*>& touches, Event *unused_event)
{
if (kScriptTypeNone != _scriptType)
{
executeScriptTouchesHandler(EventTouch::EventCode::MOVED, touches);
return;
}
CC_UNUSED_PARAM(unused_event);
}
void Layer::onTouchesEnded(const std::vector<Touch*>& touches, Event *unused_event)
{
if (kScriptTypeNone != _scriptType)
{
executeScriptTouchesHandler(EventTouch::EventCode::ENDED, touches);
return;
}
CC_UNUSED_PARAM(unused_event);
}
void Layer::onTouchesCancelled(const std::vector<Touch*>& touches, Event *unused_event)
{
if (kScriptTypeNone != _scriptType)
{
executeScriptTouchesHandler(EventTouch::EventCode::CANCELLED, touches);
return;
}
CC_UNUSED_PARAM(unused_event);
}
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
#elif _MSC_VER >= 1400 //vs 2005 or higher
#pragma warning (pop)
#endif
// LayerRGBA
LayerRGBA::LayerRGBA()
: _displayedOpacity(255)

View File

@ -86,22 +86,25 @@ public:
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesEnded(Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesCancelled(Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);}
// Deprecated touch callbacks.There not have add CC_DEPRECATED_ATTRIBUTE because of menu still use these api
virtual bool onTouchBegan(Touch *touch, Event *event) {CC_UNUSED_PARAM(touch); CC_UNUSED_PARAM(event); return false;}
virtual void onTouchMoved(Touch *touch, Event *event) {CC_UNUSED_PARAM(touch); CC_UNUSED_PARAM(event);}
virtual void onTouchEnded(Touch *touch, Event *event) {CC_UNUSED_PARAM(touch); CC_UNUSED_PARAM(event);}
virtual void onTouchCancelled(Touch *touch, Event *event) {CC_UNUSED_PARAM(touch); CC_UNUSED_PARAM(event);}
// Deprecated touch callbacks.
CC_DEPRECATED_ATTRIBUTE virtual void onTouchesBegan(const std::vector<Touch*>& touches, Event *event) {CC_UNUSED_PARAM(touches); CC_UNUSED_PARAM(event);}
CC_DEPRECATED_ATTRIBUTE virtual void onTouchesMoved(const std::vector<Touch*>& touches, Event *event) {CC_UNUSED_PARAM(touches); CC_UNUSED_PARAM(event);}
CC_DEPRECATED_ATTRIBUTE virtual void onTouchesEnded(const std::vector<Touch*>& touches, Event *event) {CC_UNUSED_PARAM(touches); CC_UNUSED_PARAM(event);}
CC_DEPRECATED_ATTRIBUTE virtual void onTouchesCancelled(const std::vector<Touch*>&touches, Event *event) {CC_UNUSED_PARAM(touches); CC_UNUSED_PARAM(event);}
/* Callback function should not be deprecated, it will generate lots of warnings.
Since 'setTouchEnabled' was deprecated, it will make warnings if developer overrides onTouchXXX and invokes setTouchEnabled(true) instead of using EventDispatcher::addEventListenerWithXXX.
*/
virtual bool onTouchBegan(Touch *touch, Event *unused_event);
virtual void onTouchMoved(Touch *touch, Event *unused_event);
virtual void onTouchEnded(Touch *touch, Event *unused_event);
virtual void onTouchCancelled(Touch *touch, Event *unused_event);
virtual void onTouchesBegan(const std::vector<Touch*>& touches, Event *unused_event);
virtual void onTouchesMoved(const std::vector<Touch*>& touches, Event *unused_event);
virtual void onTouchesEnded(const std::vector<Touch*>& touches, Event *unused_event);
virtual void onTouchesCancelled(const std::vector<Touch*>&touches, Event *unused_event);
/** @deprecated Please override onAcceleration */
CC_DEPRECATED_ATTRIBUTE virtual void didAccelerate(Acceleration* accelerationValue) final {};
CC_DEPRECATED_ATTRIBUTE virtual void onAcceleration(Acceleration* acc, Event* event);
/* Callback function should not be deprecated, it will generate lots of warnings.
Since 'setAccelerometerEnabled' was deprecated, it will make warnings if developer overrides onAcceleration and invokes setAccelerometerEnabled(true) instead of using EventDispatcher::addEventListenerWithXXX.
*/
virtual void onAcceleration(Acceleration* acc, Event* unused_event);
/** If isTouchEnabled, this method is called onEnter. Override it to change the
way Layer receives touch events.
@ -120,8 +123,8 @@ public:
Only the touches of this node will be affected. This "method" is not propagated to it's children.
@since v0.8.1
*/
CC_DEPRECATED_ATTRIBUTE virtual bool isTouchEnabled() const;
CC_DEPRECATED_ATTRIBUTE virtual void setTouchEnabled(bool value);
CC_DEPRECATED_ATTRIBUTE bool isTouchEnabled() const;
CC_DEPRECATED_ATTRIBUTE void setTouchEnabled(bool value);
CC_DEPRECATED_ATTRIBUTE virtual void setTouchMode(Touch::DispatchMode mode);
CC_DEPRECATED_ATTRIBUTE virtual Touch::DispatchMode getTouchMode() const;
@ -147,40 +150,37 @@ public:
CC_DEPRECATED_ATTRIBUTE virtual void setKeyboardEnabled(bool value);
/** Please use onKeyPressed instead. */
virtual void keyPressed(int keyCode) final {};
CC_DEPRECATED_ATTRIBUTE virtual void keyPressed(int keyCode) final {};
/** Please use onKeyReleased instead. */
virtual void keyReleased(int keyCode) final {};
CC_DEPRECATED_ATTRIBUTE virtual void keyReleased(int keyCode) final {};
CC_DEPRECATED_ATTRIBUTE virtual void onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event);
CC_DEPRECATED_ATTRIBUTE virtual void onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event);
/* Callback function should not be deprecated, it will generate lots of warnings.
Since 'setKeyboardEnabled' was deprecated, it will make warnings if developer overrides onKeyXXX and invokes setKeyboardEnabled(true) instead of using EventDispatcher::addEventListenerWithXXX.
*/
virtual void onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event);
virtual void onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event);
CC_DEPRECATED_ATTRIBUTE virtual bool isKeypadEnabled() const final { return _keyboardEnabled; };
CC_DEPRECATED_ATTRIBUTE virtual bool isKeypadEnabled() const final { return _keyboardEnabled; }
CC_DEPRECATED_ATTRIBUTE virtual void setKeypadEnabled(bool value);
/** @deprecated Please override onKeyReleased and check the keycode of KeyboardEvent::KeyCode::Menu(KEY_BACKSPACE) instead. */
CC_DEPRECATED_ATTRIBUTE virtual void keyBackClicked() final {};
CC_DEPRECATED_ATTRIBUTE virtual void keyMenuClicked() final {};
//
// Overrides
//
protected:
CC_DEPRECATED_ATTRIBUTE void addTouchListener() { _addTouchListener();};
bool _touchEnabled;
bool _accelerometerEnabled;
bool _keyboardEnabled;
EventListener* _touchListener;
EventListenerKeyboard* _keyboardListener;
EventListenerAcceleration* _accelerationListener;
private:
//add the api for avoid use deprecated api
void _addTouchListener();
private:
Touch::DispatchMode _touchMode;
bool _swallowsTouches;
CC_DEPRECATED_ATTRIBUTE int executeScriptTouchHandler(EventTouch::EventCode eventType, Touch* touch);
CC_DEPRECATED_ATTRIBUTE int executeScriptTouchesHandler(EventTouch::EventCode eventType, const std::vector<Touch*>& touches);
};
#ifdef __apple__

View File

@ -38,7 +38,9 @@ NS_CC_BEGIN
class CC_DLL RGBAProtocol
{
public:
/**
virtual ~RGBAProtocol() {}
/**
* Changes the color with R,G,B bytes
*
* @param color Example: Color3B(255,100,0) means R=255, G=100, B=0
@ -165,6 +167,8 @@ public:
class CC_DLL BlendProtocol
{
public:
virtual ~BlendProtocol() {}
/**
* Sets the source blending function.
*
@ -197,6 +201,7 @@ public:
class CC_DLL TextureProtocol : public BlendProtocol
{
public:
virtual ~TextureProtocol() {}
/**
* Returns the currently used texture
*
@ -222,6 +227,8 @@ public:
class CC_DLL LabelProtocol
{
public:
virtual ~LabelProtocol() {}
/**
* Sets a new label using a string
*
@ -247,7 +254,9 @@ public:
class CC_DLL DirectorDelegate
{
public:
/**
virtual ~DirectorDelegate() {}
/**
* Will be called by Director when the projection is updated, and "custom" projection is used
* @js NA
* @lua NA

View File

@ -319,7 +319,7 @@ void SpriteFrameCache::removeUnusedSpriteFrames(void)
void SpriteFrameCache::removeSpriteFrameByName(const std::string& name)
{
// explicit nil handling
if( ! name.size()>0 )
if( !(name.size()>0) )
return;
// Is this an alias ?

View File

@ -40,6 +40,8 @@ class TextFieldTTF;
class CC_DLL TextFieldDelegate
{
public:
virtual ~TextFieldDelegate() {}
/**
@brief If the sender doesn't want to attach to the IME, return true;
*/

View File

@ -50,6 +50,8 @@ class Node;
class CC_DLL TransitionEaseScene// : public Object
{
public:
virtual ~TransitionEaseScene() {}
/** returns the Ease action that will be performed on a linear action.
@since v0.8.2
*/

View File

@ -39,6 +39,8 @@ typedef unsigned char CC_XML_CHAR;
class CC_DLL SAXDelegator
{
public:
virtual ~SAXDelegator() {}
/**
* @js NA
* @lua NA

View File

@ -13,6 +13,7 @@ namespace cocosbuilder {
class CCBAnimationManagerDelegate
{
public:
virtual ~CCBAnimationManagerDelegate() {}
virtual void completedAnimationSequenceNamed(const char *name) = 0;
};

View File

@ -8,15 +8,22 @@ using namespace cocos2d;
#define PROPERTY_MOUSE_ENABLED "isMouseEnabled"
#define PROPERTY_KEYBOARD_ENABLED "isKeyboardEnabled"
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif _MSC_VER >= 1400 //vs 2005 or higher
#pragma warning (push)
#pragma warning (disable: 4996)
#endif
using namespace cocos2d;
namespace cocosbuilder {
void LayerLoader::onHandlePropTypeCheck(Node * pNode, Node * pParent, const char * pPropertyName, bool pCheck, CCBReader * ccbReader) {
if(strcmp(pPropertyName, PROPERTY_TOUCH_ENABLED) == 0) {
// FIXME: ((Layer *)pNode)->setTouchEnabled(pCheck);
((Layer *)pNode)->setTouchEnabled(pCheck);
} else if(strcmp(pPropertyName, PROPERTY_ACCELEROMETER_ENABLED) == 0) {
// FIXME: ((Layer *)pNode)->setAccelerometerEnabled(pCheck);
((Layer *)pNode)->setAccelerometerEnabled(pCheck);
} else if(strcmp(pPropertyName, PROPERTY_MOUSE_ENABLED) == 0) {
// TODO XXX
CCLOG("The property '%s' is not supported!", PROPERTY_MOUSE_ENABLED);
@ -30,3 +37,9 @@ void LayerLoader::onHandlePropTypeCheck(Node * pNode, Node * pParent, const char
}
}
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
#elif _MSC_VER >= 1400 //vs 2005 or higher
#pragma warning (pop)
#endif

View File

@ -272,7 +272,7 @@ void UIPageView::updateChildrenSize()
}
cocos2d::Size selfSize = getSize();
for (unsigned int i=0; i<_pages->count(); i++)
for (long i=0; i<_pages->count(); i++)
{
UILayout* page = dynamic_cast<UILayout*>(_pages->getObjectAtIndex(i));
page->setSize(selfSize);

View File

@ -31,6 +31,9 @@ namespace gui {
class UIScrollInterface
{
public:
virtual ~UIScrollInterface() {}
protected:
virtual void handlePressLogic(const cocos2d::Point &touchPoint) = 0;
virtual void handleMoveLogic(const cocos2d::Point &touchPoint) = 0;

View File

@ -293,19 +293,32 @@ void PhysicsBody::setDynamic(bool dynamic)
if (dynamic)
{
cpBodySetMass(_info->getBody(), _mass);
cpBodySetMoment(_info->getBody(), _moment);
if (_world != nullptr)
{
// reset the gravity enable
if (isGravityEnabled())
{
_gravityEnable = false;
setGravityEnable(true);
}
cpSpaceAddBody(_world->_info->getSpace(), _info->getBody());
}
}else
}
else
{
cpBodySetMass(_info->getBody(), PHYSICS_INFINITY);
if (_world != nullptr)
{
cpSpaceRemoveBody(_world->_info->getSpace(), _info->getBody());
}
// avoid incorrect collion simulation.
cpBodySetMass(_info->getBody(), PHYSICS_INFINITY);
cpBodySetMoment(_info->getBody(), PHYSICS_INFINITY);
cpBodySetVel(_info->getBody(), cpvzero);
cpBodySetAngVel(_info->getBody(), 0.0f);
}
}
@ -456,7 +469,11 @@ void PhysicsBody::setMass(float mass)
}
}
cpBodySetMass(_info->getBody(), PhysicsHelper::float2cpfloat(_mass));
// the static body's mass and moment is always infinity
if (_dynamic)
{
cpBodySetMass(_info->getBody(), PhysicsHelper::float2cpfloat(_mass));
}
}
void PhysicsBody::addMass(float mass)
@ -498,7 +515,11 @@ void PhysicsBody::addMass(float mass)
}
}
cpBodySetMass(_info->getBody(), PhysicsHelper::float2cpfloat(_mass));
// the static body's mass and moment is always infinity
if (_dynamic)
{
cpBodySetMass(_info->getBody(), PhysicsHelper::float2cpfloat(_mass));
}
}
void PhysicsBody::addMoment(float moment)
@ -537,7 +558,8 @@ void PhysicsBody::addMoment(float moment)
}
}
if (_rotationEnable)
// the static body's mass and moment is always infinity
if (_rotationEnable && _dynamic)
{
cpBodySetMoment(_info->getBody(), PhysicsHelper::float2cpfloat(_moment));
}
@ -545,6 +567,12 @@ void PhysicsBody::addMoment(float moment)
void PhysicsBody::setVelocity(const Point& velocity)
{
if (!_dynamic)
{
CCLOG("physics warning: your cann't set velocity for a static body.");
return;
}
cpBodySetVel(_info->getBody(), PhysicsHelper::point2cpv(velocity));
}
@ -565,6 +593,12 @@ Point PhysicsBody::getVelocityAtWorldPoint(const Point& point)
void PhysicsBody::setAngularVelocity(float velocity)
{
if (!_dynamic)
{
CCLOG("physics warning: your cann't set angular velocity for a static body.");
return;
}
cpBodySetAngVel(_info->getBody(), PhysicsHelper::float2cpfloat(velocity));
}
@ -598,7 +632,8 @@ void PhysicsBody::setMoment(float moment)
_moment = moment;
_momentDefault = false;
if (_rotationEnable)
// the static body's mass and moment is always infinity
if (_rotationEnable && _dynamic)
{
cpBodySetMoment(_info->getBody(), PhysicsHelper::float2cpfloat(_moment));
}

View File

@ -481,9 +481,25 @@ void PhysicsWorld::removeBody(PhysicsBody* body)
// destory the body's joints
for (auto joint : body->_joints)
{
removeJoint(joint, true);
// set destroy param to false to keep the iterator available
removeJoint(joint, false);
PhysicsBody* other = (joint->getBodyA() == body ? joint->getBodyB() : body);
other->removeJoint(joint);
// test the distraction is delaied or not
if (_delayRemoveJoints.size() > 0 && _delayRemoveJoints.back() == joint)
{
joint->_destoryMark = true;
}
else
{
delete joint;
}
}
body->_joints.clear();
removeBodyOrDelay(body);
_bodies->removeObject(body);
body->_world = nullptr;

@ -1 +1 @@
Subproject commit 8f0159b894e47dd05ce454cf32f8d13bd4b39a63
Subproject commit fd61548d4697e68b5f893bdb919ab0667af26096

View File

@ -68,8 +68,6 @@ bool Control::init()
{
if (Layer::init())
{
//this->setTouchEnabled(true);
//_isTouchEnabled=true;
// Initialise instance variables
_state=Control::State::NORMAL;
setEnabled(true);

View File

@ -177,10 +177,16 @@ void ScrollView::resume(Object* sender)
_container->resume();
}
bool ScrollView::isTouchEnabled() const
{
return _touchListener != nullptr;
}
void ScrollView::setTouchEnabled(bool enabled)
{
_eventDispatcher->removeEventListener(_touchListener);
_touchListener = nullptr;
if (enabled)
{
_touchListener = EventListenerTouchOneByOne::create();

View File

@ -167,6 +167,7 @@ public:
void resume(Object* sender);
void setTouchEnabled(bool enabled);
bool isTouchEnabled() const;
bool isDragging() const {return _dragging;}
bool isTouchMoved() const { return _touchMoved; }
bool isBounceable() const { return _bounceable; }

View File

@ -15,7 +15,7 @@ public:
AccelerometerTest(void);
~AccelerometerTest(void);
virtual void onAcceleration(Acceleration* acc, Event* event);
void onAcceleration(Acceleration* acc, Event* event);
virtual std::string title();
virtual void onEnter();

View File

@ -10,8 +10,8 @@ public:
KeyboardTest();
~KeyboardTest();
virtual void onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event);
virtual void onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event);
void onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event);
void onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event);
private:
LabelTTF* _label;

View File

@ -10,7 +10,7 @@ public:
KeypadTest();
~KeypadTest();
virtual void onKeyReleased(EventKeyboard::KeyCode keycode, Event* event);
void onKeyReleased(EventKeyboard::KeyCode keycode, Event* event);
private:
LabelTTF* _label;

View File

@ -98,7 +98,7 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS
Scheduler::[pause resume unschedule schedule update isTargetPaused],
TextureCache::[addPVRTCImage],
Timer::[getSelector createWithScriptHandler],
*::[copyWith.* onEnter.* onExit.* ^description$ getObjectType (g|s)etDelegate],
*::[copyWith.* onEnter.* onExit.* ^description$ getObjectType (g|s)etDelegate onTouch.* onAcc.* onKey.* onRegisterTouchListener],
FileUtils::[(g|s)etSearchResolutionsOrder$ (g|s)etSearchPaths$],
Application::[^application.* ^run$],
Camera::[getEyeXYZ getCenterXYZ getUpXYZ],