From 1b0583214b6ae7171cc7a8f5faff7d0e6b253afe Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 2 Apr 2014 11:48:42 +0800 Subject: [PATCH 01/66] issue #4636, add parameter create method to UIButton --- cocos/ui/UIButton.cpp | 32 +++++++++++++++++++ cocos/ui/UIButton.h | 29 ++++++++++++++--- .../UIButtonTest/UIButtonTest.cpp | 6 ++-- 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/cocos/ui/UIButton.cpp b/cocos/ui/UIButton.cpp index 89627b5ea6..6ec0d0a644 100644 --- a/cocos/ui/UIButton.cpp +++ b/cocos/ui/UIButton.cpp @@ -83,6 +83,38 @@ Button* Button::create() CC_SAFE_DELETE(widget); return nullptr; } + +Button* Button::create(const std::string &normalImage, + const std::string& selectedImage , + const std::string& disableImage, + TextureResType texType) +{ + Button *btn = new Button; + if (btn && btn->init(normalImage,selectedImage,disableImage,texType)) { + btn->autorelease(); + return btn; + } + CC_SAFE_DELETE(btn); + return nullptr; +} + +bool Button::init(const std::string &normalImage, + const std::string& selectedImage , + const std::string& disableImage, + TextureResType texType) +{ + bool bRet = true; + do { + if (!Widget::init()) { + bRet = false; + break; + } + + setTouchEnabled(true); + this->loadTextures(normalImage.c_str(), selectedImage.c_str(), disableImage.c_str(),texType); + } while (0); + return bRet; +} bool Button::init() { diff --git a/cocos/ui/UIButton.h b/cocos/ui/UIButton.h index ec3d9d23b5..95de110c44 100644 --- a/cocos/ui/UIButton.h +++ b/cocos/ui/UIButton.h @@ -55,19 +55,35 @@ public: * Allocates and initializes. */ static Button* create(); + + /** + * create a button with custom textures + * @normalImage normal state texture name + * @selectedImage selected state texture name + * @disableImage disable state texture name + * @param texType @see UI_TEX_TYPE_LOCAL + */ + static Button* create(const std::string& normalImage, + const std::string& selectedImage = "", + const std::string& disableImage = "", + TextureResType texType = UI_TEX_TYPE_LOCAL); + /** * Load textures for button. * - * @param normal normal state texture. + * @param normal normal state texture name. * - * @param selected selected state texture. + * @param selected selected state texture name. * - * @param disabled dark state texture. + * @param disabled disable state texture name. * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadTextures(const char* normal,const char* selected,const char* disabled,TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadTextures(const char* normal, + const char* selected, + const char* disabled = "", + TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Load normal state texture for button. @@ -174,6 +190,11 @@ public: CC_CONSTRUCTOR_ACCESS: virtual bool init() override; + virtual bool init(const std::string& normalImage, + const std::string& selectedImage = "", + const std::string& disableImage = "", + TextureResType texType = UI_TEX_TYPE_LOCAL); + protected: virtual void initRenderer() override; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp index 3a337ef3fa..f31cd5673c 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp @@ -40,10 +40,10 @@ bool UIButtonTest::init() _uiLayer->addChild(alert); // Create the button - Button* button = Button::create(); + Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setTouchEnabled(true); - button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); - button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); +// button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); button->addTouchEventListener(this, toucheventselector(UIButtonTest::touchEvent)); _uiLayer->addChild(button); From ba9a605568826b04216fddaad3b6e8fda27cb52d Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 2 Apr 2014 15:58:18 +0800 Subject: [PATCH 02/66] issue #4636, add parameter create method to UICheckBox --- cocos/ui/UICheckBox.cpp | 70 ++++++++++++++++--- cocos/ui/UICheckBox.h | 43 ++++++++++-- .../UICheckBoxTest/UICheckBoxTest.cpp | 16 +++-- 3 files changed, 106 insertions(+), 23 deletions(-) diff --git a/cocos/ui/UICheckBox.cpp b/cocos/ui/UICheckBox.cpp index d24edfdacb..16c1628600 100644 --- a/cocos/ui/UICheckBox.cpp +++ b/cocos/ui/UICheckBox.cpp @@ -75,6 +75,49 @@ CheckBox* CheckBox::create() CC_SAFE_DELETE(widget); return nullptr; } + +CheckBox* CheckBox::create(const std::string& backGround, + const std::string& backGroundSeleted, + const std::string& cross, + const std::string& backGroundDisabled, + const std::string& frontCrossDisabled, + TextureResType texType) +{ + CheckBox *pWidget = new CheckBox; + if (pWidget && pWidget->init(backGround, + backGroundSeleted, + cross, + backGroundDisabled, + frontCrossDisabled, + texType)) + { + pWidget->autorelease(); + return pWidget; + } + CC_SAFE_DELETE(pWidget); + return nullptr; +} + +bool CheckBox::init(const std::string& backGround, + const std::string& backGroundSeleted, + const std::string& cross, + const std::string& backGroundDisabled, + const std::string& frontCrossDisabled, + TextureResType texType) +{ + bool bRet = true; + do { + if (!Widget::init()) { + bRet = false; + break; + } + + setSelectedState(false); + setTouchEnabled(true); + loadTextures(backGround, backGroundSeleted, cross, backGroundDisabled, frontCrossDisabled,texType); + } while (0); + return bRet; +} bool CheckBox::init() { @@ -102,7 +145,12 @@ void CheckBox::initRenderer() addProtectedChild(_frontCrossDisabledRenderer, FRONTCROSSDISABLED_RENDERER_Z, -1); } -void CheckBox::loadTextures(const char *backGround, const char *backGroundSelected, const char *cross,const char* backGroundDisabled,const char* frontCrossDisabled,TextureResType texType) +void CheckBox::loadTextures(const std::string& backGround, + const std::string& backGroundSelected, + const std::string& cross, + const std::string& backGroundDisabled, + const std::string& frontCrossDisabled, + TextureResType texType) { loadTextureBackGround(backGround,texType); loadTextureBackGroundSelected(backGroundSelected,texType); @@ -111,9 +159,9 @@ void CheckBox::loadTextures(const char *backGround, const char *backGroundSelect loadTextureFrontCrossDisabled(frontCrossDisabled,texType); } -void CheckBox::loadTextureBackGround(const char *backGround,TextureResType texType) +void CheckBox::loadTextureBackGround(const std::string& backGround,TextureResType texType) { - if (!backGround || strcmp(backGround, "") == 0) + if (backGround.empty()) { return; } @@ -137,9 +185,9 @@ void CheckBox::loadTextureBackGround(const char *backGround,TextureResType texTy updateRGBAToRenderer(_backGroundBoxRenderer); } -void CheckBox::loadTextureBackGroundSelected(const char *backGroundSelected,TextureResType texType) +void CheckBox::loadTextureBackGroundSelected(const std::string& backGroundSelected,TextureResType texType) { - if (!backGroundSelected || strcmp(backGroundSelected, "") == 0) + if (backGroundSelected.empty()) { return; } @@ -163,9 +211,9 @@ void CheckBox::loadTextureBackGroundSelected(const char *backGroundSelected,Text updateRGBAToRenderer(_backGroundSelectedBoxRenderer); } -void CheckBox::loadTextureFrontCross(const char *cross,TextureResType texType) +void CheckBox::loadTextureFrontCross(const std::string& cross,TextureResType texType) { - if (!cross || strcmp(cross, "") == 0) + if (cross.empty()) { return; } @@ -189,9 +237,9 @@ void CheckBox::loadTextureFrontCross(const char *cross,TextureResType texType) updateRGBAToRenderer(_frontCrossRenderer); } -void CheckBox::loadTextureBackGroundDisabled(const char *backGroundDisabled,TextureResType texType) +void CheckBox::loadTextureBackGroundDisabled(const std::string& backGroundDisabled,TextureResType texType) { - if (!backGroundDisabled || strcmp(backGroundDisabled, "") == 0) + if (backGroundDisabled.empty()) { return; } @@ -215,9 +263,9 @@ void CheckBox::loadTextureBackGroundDisabled(const char *backGroundDisabled,Text updateRGBAToRenderer(_backGroundBoxDisabledRenderer); } -void CheckBox::loadTextureFrontCrossDisabled(const char *frontCrossDisabled,TextureResType texType) +void CheckBox::loadTextureFrontCrossDisabled(const std::string& frontCrossDisabled,TextureResType texType) { - if (!frontCrossDisabled || strcmp(frontCrossDisabled, "") == 0) + if (frontCrossDisabled.empty()) { return; } diff --git a/cocos/ui/UICheckBox.h b/cocos/ui/UICheckBox.h index 86aef77e94..ab704a547c 100644 --- a/cocos/ui/UICheckBox.h +++ b/cocos/ui/UICheckBox.h @@ -64,6 +64,26 @@ public: * Allocates and initializes. */ static CheckBox* create(); + + /** + * create an checkbox + * + * @param backGround backGround texture. + * + * @param backGroundSelected backGround selected state texture. + * + * @param cross cross texture. + * + * @param frontCrossDisabled cross dark state texture. + * + * @param texType @see UI_TEX_TYPE_LOCAL + */ + static CheckBox* create(const std::string& backGround, + const std::string& backGroundSeleted, + const std::string& cross, + const std::string& backGroundDisabled, + const std::string& frontCrossDisabled, + TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Load textures for checkbox. @@ -78,7 +98,12 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadTextures(const char* backGround,const char* backGroundSelected,const char* cross,const char* backGroundDisabled,const char* frontCrossDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadTextures(const std::string& backGround, + const std::string& backGroundSelected, + const std::string& cross, + const std::string& backGroundDisabled, + const std::string& frontCrossDisabled, + TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Load backGround texture for checkbox. @@ -87,7 +112,7 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadTextureBackGround(const char* backGround,TextureResType type = UI_TEX_TYPE_LOCAL); + void loadTextureBackGround(const std::string& backGround,TextureResType type = UI_TEX_TYPE_LOCAL); /** * Load backGroundSelected texture for checkbox. @@ -96,7 +121,7 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadTextureBackGroundSelected(const char* backGroundSelected,TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadTextureBackGroundSelected(const std::string& backGroundSelected,TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Load cross texture for checkbox. @@ -105,7 +130,7 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadTextureFrontCross(const char* cross,TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadTextureFrontCross(const std::string&,TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Load backGroundDisabled texture for checkbox. @@ -114,7 +139,7 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadTextureBackGroundDisabled(const char* backGroundDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadTextureBackGroundDisabled(const std::string& backGroundDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Load frontCrossDisabled texture for checkbox. @@ -123,7 +148,7 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadTextureFrontCrossDisabled(const char* frontCrossDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadTextureFrontCrossDisabled(const std::string& frontCrossDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Sets selcted state for checkbox. @@ -161,6 +186,12 @@ public: CC_CONSTRUCTOR_ACCESS: virtual bool init() override; + virtual bool init(const std::string& backGround, + const std::string& backGroundSeleted, + const std::string& cross, + const std::string& backGroundDisabled, + const std::string& frontCrossDisabled, + TextureResType texType = UI_TEX_TYPE_LOCAL); protected: virtual void initRenderer() override; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp index 0b5f68f63a..4e71babee2 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp @@ -39,13 +39,17 @@ bool UICheckBoxTest::init() _uiLayer->addChild(alert); // Create the checkbox - CheckBox* checkBox = CheckBox::create(); + CheckBox* checkBox = CheckBox::create("cocosui/check_box_normal.png", + "cocosui/check_box_normal_press.png", + "cocosui/check_box_active.png", + "cocosui/check_box_normal_disable.png", + "cocosui/check_box_active_disable.png"); checkBox->setTouchEnabled(true); - checkBox->loadTextures("cocosui/check_box_normal.png", - "cocosui/check_box_normal_press.png", - "cocosui/check_box_active.png", - "cocosui/check_box_normal_disable.png", - "cocosui/check_box_active_disable.png"); +// checkBox->loadTextures("cocosui/check_box_normal.png", +// "cocosui/check_box_normal_press.png", +// "cocosui/check_box_active.png", +// "cocosui/check_box_normal_disable.png", +// "cocosui/check_box_active_disable.png"); checkBox->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); checkBox->addEventListenerCheckBox(this, checkboxselectedeventselector(UICheckBoxTest::selectedEvent)); From 18c072beff3d3a29f9e8dacce2fb9528cb7d1ed6 Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 2 Apr 2014 16:08:45 +0800 Subject: [PATCH 03/66] issue #4636, replace const char* to const std::string& in UIButton --- cocos/ui/UIButton.cpp | 31 +++++++++++++++++-------------- cocos/ui/UIButton.h | 12 ++++++------ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/cocos/ui/UIButton.cpp b/cocos/ui/UIButton.cpp index 6ec0d0a644..634cfa1e10 100644 --- a/cocos/ui/UIButton.cpp +++ b/cocos/ui/UIButton.cpp @@ -111,7 +111,7 @@ bool Button::init(const std::string &normalImage, } setTouchEnabled(true); - this->loadTextures(normalImage.c_str(), selectedImage.c_str(), disableImage.c_str(),texType); + this->loadTextures(normalImage, selectedImage, disableImage,texType); } while (0); return bRet; } @@ -203,16 +203,19 @@ void Button::ignoreContentAdaptWithSize(bool ignore) } } -void Button::loadTextures(const char* normal,const char* selected,const char* disabled,TextureResType texType) +void Button::loadTextures(const std::string& normal, + const std::string& selected, + const std::string& disabled, + TextureResType texType) { loadTextureNormal(normal,texType); loadTexturePressed(selected,texType); loadTextureDisabled(disabled,texType); } -void Button::loadTextureNormal(const char* normal,TextureResType texType) +void Button::loadTextureNormal(const std::string& normal,TextureResType texType) { - if (!normal || strcmp(normal, "") == 0) + if (normal.empty()) { return; } @@ -224,10 +227,10 @@ void Button::loadTextureNormal(const char* normal,TextureResType texType) switch (_normalTexType) { case UI_TEX_TYPE_LOCAL: - normalRendererScale9->initWithFile(normal); + normalRendererScale9->initWithFile(normal.c_str()); break; case UI_TEX_TYPE_PLIST: - normalRendererScale9->initWithSpriteFrameName(normal); + normalRendererScale9->initWithSpriteFrameName(normal.c_str()); break; default: break; @@ -258,9 +261,9 @@ void Button::loadTextureNormal(const char* normal,TextureResType texType) _normalTextureLoaded = true; } -void Button::loadTexturePressed(const char* selected,TextureResType texType) +void Button::loadTexturePressed(const std::string& selected,TextureResType texType) { - if (!selected || strcmp(selected, "") == 0) + if (selected.empty()) { return; } @@ -272,10 +275,10 @@ void Button::loadTexturePressed(const char* selected,TextureResType texType) switch (_pressedTexType) { case UI_TEX_TYPE_LOCAL: - clickedRendererScale9->initWithFile(selected); + clickedRendererScale9->initWithFile(selected.c_str()); break; case UI_TEX_TYPE_PLIST: - clickedRendererScale9->initWithSpriteFrameName(selected); + clickedRendererScale9->initWithSpriteFrameName(selected.c_str()); break; default: break; @@ -306,9 +309,9 @@ void Button::loadTexturePressed(const char* selected,TextureResType texType) _pressedTextureLoaded = true; } -void Button::loadTextureDisabled(const char* disabled,TextureResType texType) +void Button::loadTextureDisabled(const std::string& disabled,TextureResType texType) { - if (!disabled || strcmp(disabled, "") == 0) + if (disabled.empty()) { return; } @@ -320,10 +323,10 @@ void Button::loadTextureDisabled(const char* disabled,TextureResType texType) switch (_disabledTexType) { case UI_TEX_TYPE_LOCAL: - disabledScale9->initWithFile(disabled); + disabledScale9->initWithFile(disabled.c_str()); break; case UI_TEX_TYPE_PLIST: - disabledScale9->initWithSpriteFrameName(disabled); + disabledScale9->initWithSpriteFrameName(disabled.c_str()); break; default: break; diff --git a/cocos/ui/UIButton.h b/cocos/ui/UIButton.h index 95de110c44..b170a72e89 100644 --- a/cocos/ui/UIButton.h +++ b/cocos/ui/UIButton.h @@ -80,9 +80,9 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadTextures(const char* normal, - const char* selected, - const char* disabled = "", + void loadTextures(const std::string& normal, + const std::string& selected, + const std::string& disabled = "", TextureResType texType = UI_TEX_TYPE_LOCAL); /** @@ -92,7 +92,7 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadTextureNormal(const char* normal, TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadTextureNormal(const std::string& normal, TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Load selected state texture for button. @@ -101,7 +101,7 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadTexturePressed(const char* selected, TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadTexturePressed(const std::string& selected, TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Load dark state texture for button. @@ -110,7 +110,7 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadTextureDisabled(const char* disabled, TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadTextureDisabled(const std::string& disabled, TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Sets capinsets for button, if button is using scale9 renderer. From 558abf1a6b3184f0625b58e0bdbb6b02a7f05394 Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 2 Apr 2014 16:37:09 +0800 Subject: [PATCH 04/66] issue #4636, add parameter create method to UIImageView --- cocos/ui/UIImageView.cpp | 46 +++++++++++++++++-- cocos/ui/UIImageView.h | 18 +++++++- .../UIImageViewTest/UIImageViewTest.cpp | 4 +- 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/cocos/ui/UIImageView.cpp b/cocos/ui/UIImageView.cpp index 097bc0ff7d..0cde1d7e16 100644 --- a/cocos/ui/UIImageView.cpp +++ b/cocos/ui/UIImageView.cpp @@ -53,6 +53,17 @@ ImageView::~ImageView() { } + +ImageView* ImageView::create(const std::string &imageFileName, TextureResType texType) +{ + ImageView *widget = new ImageView; + if (widget && widget->init(imageFileName, texType)) { + widget->autorelease(); + return widget; + } + CC_SAFE_DELETE(widget); + return nullptr; +} ImageView* ImageView::create() { @@ -65,6 +76,33 @@ ImageView* ImageView::create() CC_SAFE_DELETE(widget); return nullptr; } + +bool ImageView::init() +{ + bool bRet = true; + do { + if (!Widget::init()) { + bRet = false; + break; + } + _imageTexType = UI_TEX_TYPE_LOCAL; + } while (0); + return bRet; +} + +bool ImageView::init(const std::string &imageFileName, TextureResType texType) +{ + bool bRet = true; + do { + if (!Widget::init()) { + bRet = false; + break; + } + + this->loadTexture(imageFileName, texType); + } while (0); + return bRet; +} void ImageView::initRenderer() { @@ -72,9 +110,9 @@ void ImageView::initRenderer() addProtectedChild(_imageRenderer, IMAGE_RENDERER_Z, -1); } -void ImageView::loadTexture(const char *fileName, TextureResType texType) +void ImageView::loadTexture(const std::string& fileName, TextureResType texType) { - if (!fileName || strcmp(fileName, "") == 0) + if (fileName.empty()) { return; } @@ -86,7 +124,7 @@ void ImageView::loadTexture(const char *fileName, TextureResType texType) if (_scale9Enabled) { extension::Scale9Sprite* imageRendererScale9 = STATIC_CAST_SCALE9SPRITE; - imageRendererScale9->initWithFile(fileName); + imageRendererScale9->initWithFile(fileName.c_str()); imageRendererScale9->setCapInsets(_capInsets); } else @@ -99,7 +137,7 @@ void ImageView::loadTexture(const char *fileName, TextureResType texType) if (_scale9Enabled) { extension::Scale9Sprite* imageRendererScale9 = STATIC_CAST_SCALE9SPRITE; - imageRendererScale9->initWithSpriteFrameName(fileName); + imageRendererScale9->initWithSpriteFrameName(fileName.c_str()); imageRendererScale9->setCapInsets(_capInsets); } else diff --git a/cocos/ui/UIImageView.h b/cocos/ui/UIImageView.h index 24d0d481a3..3c8861dedd 100644 --- a/cocos/ui/UIImageView.h +++ b/cocos/ui/UIImageView.h @@ -55,6 +55,16 @@ public: * Allocates and initializes. */ static ImageView* create(); + + /** + * create a imageview object + * + * @param fileName file name of texture. + * + * @param texType @see UI_TEX_TYPE_LOCAL + */ + static ImageView* create(const std::string& imageFileName, TextureResType texType = UI_TEX_TYPE_LOCAL); + /** * Load texture for imageview. @@ -63,7 +73,7 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadTexture(const char* fileName,TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadTexture(const std::string& fileName,TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Updates the texture rect of the ImageView in points. @@ -102,6 +112,12 @@ public: virtual const Size& getContentSize() const override; virtual Node* getVirtualRenderer() override; + +CC_CONSTRUCTOR_ACCESS: + //initializes state of widget. + virtual bool init() override; + virtual bool init(const std::string& imageFileName, TextureResType texType = UI_TEX_TYPE_LOCAL); + protected: virtual void initRenderer() override; virtual void onSizeChanged() override; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp index 53572e9c07..5831741232 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp @@ -20,8 +20,8 @@ bool UIImageViewTest::init() _uiLayer->addChild(alert); // Create the imageview - ImageView* imageView = ImageView::create(); - imageView->loadTexture("cocosui/ccicon.png"); + ImageView* imageView = ImageView::create("cocosui/ccicon.png"); +// imageView->loadTexture("cocosui/ccicon.png"); imageView->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + imageView->getSize().height / 4.0f)); // imageView->setOpacity(64); From 92945715eb6dc91f357f471c0a98c96198048ede Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 2 Apr 2014 17:40:09 +0800 Subject: [PATCH 05/66] issue #4636. add parameter create function for UIText --- cocos/ui/UIText.cpp | 26 +++++++++++++++++++ cocos/ui/UIText.h | 10 +++++++ .../UITextTest/UITextTest.cpp | 16 ++++++------ 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/cocos/ui/UIText.cpp b/cocos/ui/UIText.cpp index 15a021c15d..f5d381e7f8 100644 --- a/cocos/ui/UIText.cpp +++ b/cocos/ui/UIText.cpp @@ -68,6 +68,32 @@ bool Text::init() } return false; } + +Text* Text::create(const std::string &textContent, const std::string &fontName, int fontSize) +{ + Text *text = new Text; + if (text && text->init(textContent, fontName, fontSize)) { + text->autorelease(); + return text; + } + CC_SAFE_DELETE(text); + return text; +} + +bool Text::init(const std::string &textContent, const std::string &fontName, int fontSize) +{ + bool bRet = true; + do { + if (!Widget::init()) { + bRet = false; + break; + } + this->setText(textContent); + this->setFontName(fontName); + this->setFontSize(fontSize); + } while (0); + return bRet; +} void Text::initRenderer() { diff --git a/cocos/ui/UIText.h b/cocos/ui/UIText.h index b18f41ed1a..4113397787 100644 --- a/cocos/ui/UIText.h +++ b/cocos/ui/UIText.h @@ -55,6 +55,13 @@ public: * Allocates and initializes. */ static Text* create(); + + /** + * create a Text object with textContent, fontName and fontSize + */ + static Text* create(const std::string& textContent, + const std::string& fontName, + int fontSize); /** * Changes the string value of label. @@ -137,6 +144,9 @@ public: CC_CONSTRUCTOR_ACCESS: virtual bool init() override; + virtual bool init(const std::string& textContent, + const std::string& fontName, + int fontSize); protected: virtual void initRenderer() override; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextTest/UITextTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextTest/UITextTest.cpp index de1c800a8f..364b55d3a4 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextTest/UITextTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextTest/UITextTest.cpp @@ -11,19 +11,19 @@ bool UITextTest::init() { Size widgetSize = _widget->getSize(); - Text* alert = Text::create(); - alert->setText("Text"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("Text","fonts/Marker Felt.ttf", 30); +// alert->setText("Text"); +// alert->setFontName("fonts/Marker Felt.ttf"); +// alert->setFontSize(30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); _uiLayer->addChild(alert); // Create the text - Text* text = Text::create(); - text->setText("Text"); - text->setFontName("AmericanTypewriter"); - text->setFontSize(30); + Text* text = Text::create("Text", "AmericanTypewriter", 30); +// text->setText("Text"); +// text->setFontName("AmericanTypewriter"); +// text->setFontSize(30); text->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + text->getSize().height / 4.0f)); _uiLayer->addChild(text); From a03dc76f7de24127d9c0699b38f5b5d9cfb934c4 Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 2 Apr 2014 17:53:06 +0800 Subject: [PATCH 06/66] issue #4636, add parameter create method for UILoadingBar --- cocos/ui/UILoadingBar.cpp | 21 +++++++++++++++---- cocos/ui/UILoadingBar.h | 7 ++++++- .../UILoadingBarTest/UILoadingBarTest.cpp | 6 +++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/cocos/ui/UILoadingBar.cpp b/cocos/ui/UILoadingBar.cpp index cefe8ed382..8a19c6e2f9 100644 --- a/cocos/ui/UILoadingBar.cpp +++ b/cocos/ui/UILoadingBar.cpp @@ -63,6 +63,19 @@ LoadingBar* LoadingBar::create() CC_SAFE_DELETE(widget); return nullptr; } + +LoadingBar* LoadingBar::create(const std::string &textureName, int percentage) +{ + LoadingBar* widget = new LoadingBar; + if (widget && widget->init()) { + widget->autorelease(); + widget->loadTexture(textureName); + widget->setPercent(percentage); + return widget; + } + CC_SAFE_DELETE(widget); + return nullptr; +} void LoadingBar::initRenderer() { @@ -105,9 +118,9 @@ int LoadingBar::getDirection() return _barType; } -void LoadingBar::loadTexture(const char* texture,TextureResType texType) + void LoadingBar::loadTexture(const std::string& texture,TextureResType texType) { - if (!texture || strcmp(texture, "") == 0) + if (texture.empty()) { return; } @@ -119,7 +132,7 @@ void LoadingBar::loadTexture(const char* texture,TextureResType texType) if (_scale9Enabled) { extension::Scale9Sprite* barRendererScale9 = static_cast(_barRenderer); - barRendererScale9->initWithFile(texture); + barRendererScale9->initWithFile(texture.c_str()); barRendererScale9->setCapInsets(_capInsets); } else @@ -131,7 +144,7 @@ void LoadingBar::loadTexture(const char* texture,TextureResType texType) if (_scale9Enabled) { extension::Scale9Sprite* barRendererScale9 = static_cast(_barRenderer); - barRendererScale9->initWithSpriteFrameName(texture); + barRendererScale9->initWithSpriteFrameName(texture.c_str()); barRendererScale9->setCapInsets(_capInsets); } else diff --git a/cocos/ui/UILoadingBar.h b/cocos/ui/UILoadingBar.h index b6eaeed234..65e9a3e8de 100644 --- a/cocos/ui/UILoadingBar.h +++ b/cocos/ui/UILoadingBar.h @@ -61,6 +61,11 @@ public: */ static LoadingBar* create(); + /** + * create a LoadingBar with a texture and a percentage + **/ + static LoadingBar* create(const std::string& textureName, int percentage = 0); + /** * Changes the progress direction of loadingbar. * @@ -86,7 +91,7 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadTexture(const char* texture,TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadTexture(const std::string& texture,TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Changes the progress direction of loadingbar. diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp index 3f0b595e91..797268c09f 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp @@ -34,10 +34,10 @@ bool UILoadingBarTest_Left::init() _uiLayer->addChild(alert); // Create the loading bar - LoadingBar* loadingBar = LoadingBar::create(); + LoadingBar* loadingBar = LoadingBar::create("cocosui/sliderProgress.png"); loadingBar->setTag(0); - loadingBar->loadTexture("cocosui/sliderProgress.png"); - loadingBar->setPercent(0); +// loadingBar->loadTexture("cocosui/sliderProgress.png"); +// loadingBar->setPercent(0); loadingBar->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f)); _uiLayer->addChild(loadingBar); From 0b5c10a0fbaa491ae615ee2b9bec1e6ab84aebdd Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 2 Apr 2014 18:06:03 +0800 Subject: [PATCH 07/66] issue #4636. add parameter create method to UITextAtlas --- cocos/ui/UITextAtlas.cpp | 17 +++++++++++++++++ cocos/ui/UITextAtlas.h | 15 ++++++++++++++- .../UITextAtlasTest/UITextAtlasTest.cpp | 4 ++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/cocos/ui/UITextAtlas.cpp b/cocos/ui/UITextAtlas.cpp index b3710def7a..f0cbc01421 100644 --- a/cocos/ui/UITextAtlas.cpp +++ b/cocos/ui/UITextAtlas.cpp @@ -64,6 +64,23 @@ void TextAtlas::initRenderer() _labelAtlasRenderer = LabelAtlas::create(); addProtectedChild(_labelAtlasRenderer, LABELATLAS_RENDERER_Z, -1); } + +TextAtlas* TextAtlas::create(const std::string &stringValue, + const std::string &charMapFile, + int itemWidth, + int itemHeight, + const std::string &startCharMap) +{ + TextAtlas* widget = new TextAtlas(); + if (widget && widget->init()) + { + widget->autorelease(); + widget->setProperty(stringValue, charMapFile, itemWidth, itemHeight, startCharMap); + return widget; + } + CC_SAFE_DELETE(widget); + return nullptr; +} void TextAtlas::setProperty(const std::string& stringValue, const std::string& charMapFile, int itemWidth, int itemHeight, const std::string& startCharMap) { diff --git a/cocos/ui/UITextAtlas.h b/cocos/ui/UITextAtlas.h index f6530c315f..501473f7cd 100644 --- a/cocos/ui/UITextAtlas.h +++ b/cocos/ui/UITextAtlas.h @@ -56,8 +56,21 @@ public: */ static TextAtlas* create(); + /** + * create a LabelAtlas from a char map file + */ + static TextAtlas* create(const std::string& stringValue, + const std::string& charMapFile, + int itemWidth, + int itemHeight, + const std::string& startCharMap); + /** initializes the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas */ - void setProperty(const std::string& stringValue,const std::string& charMapFile, int itemWidth, int itemHeight, const std::string& startCharMap); + void setProperty(const std::string& stringValue, + const std::string& charMapFile, + int itemWidth, + int itemHeight, + const std::string& startCharMap); //set string value for labelatlas. void setStringValue(const std::string& value); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp index e1d2b3ee34..f980f5be3f 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp @@ -21,8 +21,8 @@ bool UITextAtlasTest::init() _uiLayer->addChild(alert); // Create the text atlas - TextAtlas* textAtlas = TextAtlas::create(); - textAtlas->setProperty("1234567890", "cocosui/labelatlas.png", 17, 22, "0"); + TextAtlas* textAtlas = TextAtlas::create("1234567890", "cocosui/labelatlas.png", 17, 22, "0"); +// textAtlas->setProperty("1234567890", "cocosui/labelatlas.png", 17, 22, "0"); textAtlas->setPosition(Point((widgetSize.width) / 2, widgetSize.height / 2.0f)); _uiLayer->addChild(textAtlas); From b27fe6ecc2a442007db3038a91d5cf157307b797 Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 2 Apr 2014 18:16:17 +0800 Subject: [PATCH 08/66] issue #4636. add parameter create method to UITextBMFont --- cocos/ui/UITextBMFont.cpp | 28 +++++++++++++------ cocos/ui/UITextBMFont.h | 8 ++++-- .../UITextBMFontTest/UITextBMFontTest.cpp | 6 ++-- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/cocos/ui/UITextBMFont.cpp b/cocos/ui/UITextBMFont.cpp index 8bb1950bb0..6574d3ee20 100644 --- a/cocos/ui/UITextBMFont.cpp +++ b/cocos/ui/UITextBMFont.cpp @@ -56,6 +56,20 @@ TextBMFont* TextBMFont::create() CC_SAFE_DELETE(widget); return nullptr; } + +TextBMFont* TextBMFont::create(const std::string &text, const std::string &filename) +{ + TextBMFont* widget = new TextBMFont(); + if (widget && widget->init()) + { + widget->setFntFile(filename); + widget->setText(text); + widget->autorelease(); + return widget; + } + CC_SAFE_DELETE(widget); + return nullptr; +} void TextBMFont::initRenderer() { @@ -63,9 +77,9 @@ void TextBMFont::initRenderer() addProtectedChild(_labelBMFontRenderer, LABELBMFONT_RENDERER_Z, -1); } -void TextBMFont::setFntFile(const char *fileName) +void TextBMFont::setFntFile(const std::string& fileName) { - if (!fileName || strcmp(fileName, "") == 0) + if (fileName.empty()) { return; } @@ -77,12 +91,8 @@ void TextBMFont::setFntFile(const char *fileName) setText(_stringValue.c_str()); } -void TextBMFont::setText(const char* value) +void TextBMFont::setText(const std::string& value) { - if (!value) - { - return; - } _stringValue = value; if (!_fntFileHasInit) { @@ -92,9 +102,9 @@ void TextBMFont::setText(const char* value) labelBMFontScaleChangedWithSize(); } -const char* TextBMFont::getStringValue() +const std::string TextBMFont::getStringValue() { - return _stringValue.c_str(); + return _stringValue; } void TextBMFont::setAnchorPoint(const Point &pt) diff --git a/cocos/ui/UITextBMFont.h b/cocos/ui/UITextBMFont.h index df96ceb937..e41cbea7fc 100644 --- a/cocos/ui/UITextBMFont.h +++ b/cocos/ui/UITextBMFont.h @@ -56,14 +56,16 @@ public: */ static TextBMFont* create(); + static TextBMFont* create(const std::string& text, const std::string& filename); + /** init a bitmap font atlas with an initial string and the FNT file */ - void setFntFile(const char* fileName); + void setFntFile(const std::string& fileName); /** set string value for labelbmfont*/ - void setText(const char* value); + void setText(const std::string& value); /** get string value for labelbmfont*/ - const char* getStringValue(); + const std::string getStringValue(); virtual void setAnchorPoint(const Point &pt) override; virtual const Size& getContentSize() const override; virtual Node* getVirtualRenderer() override; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp index ab203af60e..95f2081358 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp @@ -20,9 +20,9 @@ bool UITextBMFontTest::init() _uiLayer->addChild(alert); // Create the TextBMFont - TextBMFont* textBMFont = TextBMFont::create(); - textBMFont->setFntFile("cocosui/bitmapFontTest2.fnt"); - textBMFont->setText("BMFont"); + TextBMFont* textBMFont = TextBMFont::create("BMFont", "cocosui/bitmapFontTest2.fnt"); +// textBMFont->setFntFile("cocosui/bitmapFontTest2.fnt"); +// textBMFont->setText("BMFont"); textBMFont->setPosition(Point(widgetSize.width / 2, widgetSize.height / 2.0f + textBMFont->getSize().height / 8.0f)); _uiLayer->addChild(textBMFont); From 0a6b0a43899807e42170c03f4eb614cfa5ff9108 Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 2 Apr 2014 18:35:08 +0800 Subject: [PATCH 09/66] issue #4636. refactor Scale9Sprite --- cocos/ui/UIButton.cpp | 24 +++++++------- cocos/ui/UITextField.cpp | 16 ++++++++++ cocos/ui/UITextField.h | 3 ++ .../GUI/CCControlExtension/CCScale9Sprite.cpp | 31 ++++++++----------- .../GUI/CCControlExtension/CCScale9Sprite.h | 24 +++++++------- .../UITextFieldTest/UITextFieldTest.cpp | 7 ++--- 6 files changed, 58 insertions(+), 47 deletions(-) diff --git a/cocos/ui/UIButton.cpp b/cocos/ui/UIButton.cpp index 634cfa1e10..8cf9eb3016 100644 --- a/cocos/ui/UIButton.cpp +++ b/cocos/ui/UIButton.cpp @@ -167,9 +167,9 @@ void Button::setScale9Enabled(bool able) _buttonDisableRenderer = Sprite::create(); } - loadTextureNormal(_normalFileName.c_str(), _normalTexType); - loadTexturePressed(_clickedFileName.c_str(), _pressedTexType); - loadTextureDisabled(_disabledFileName.c_str(), _disabledTexType); + loadTextureNormal(_normalFileName, _normalTexType); + loadTexturePressed(_clickedFileName, _pressedTexType); + loadTextureDisabled(_disabledFileName, _disabledTexType); addProtectedChild(_buttonNormalRenderer, NORMAL_RENDERER_Z, -1); addProtectedChild(_buttonClickedRenderer, PRESSED_RENDERER_Z, -1); addProtectedChild(_buttonDisableRenderer, DISABLED_RENDERER_Z, -1); @@ -227,10 +227,10 @@ void Button::loadTextureNormal(const std::string& normal,TextureResType texType) switch (_normalTexType) { case UI_TEX_TYPE_LOCAL: - normalRendererScale9->initWithFile(normal.c_str()); + normalRendererScale9->initWithFile(normal); break; case UI_TEX_TYPE_PLIST: - normalRendererScale9->initWithSpriteFrameName(normal.c_str()); + normalRendererScale9->initWithSpriteFrameName(normal); break; default: break; @@ -275,10 +275,10 @@ void Button::loadTexturePressed(const std::string& selected,TextureResType texTy switch (_pressedTexType) { case UI_TEX_TYPE_LOCAL: - clickedRendererScale9->initWithFile(selected.c_str()); + clickedRendererScale9->initWithFile(selected); break; case UI_TEX_TYPE_PLIST: - clickedRendererScale9->initWithSpriteFrameName(selected.c_str()); + clickedRendererScale9->initWithSpriteFrameName(selected); break; default: break; @@ -323,10 +323,10 @@ void Button::loadTextureDisabled(const std::string& disabled,TextureResType texT switch (_disabledTexType) { case UI_TEX_TYPE_LOCAL: - disabledScale9->initWithFile(disabled.c_str()); + disabledScale9->initWithFile(disabled); break; case UI_TEX_TYPE_PLIST: - disabledScale9->initWithSpriteFrameName(disabled.c_str()); + disabledScale9->initWithSpriteFrameName(disabled); break; default: break; @@ -745,9 +745,9 @@ void Button::copySpecialProperties(Widget *widget) { _prevIgnoreSize = button->_prevIgnoreSize; setScale9Enabled(button->_scale9Enabled); - loadTextureNormal(button->_normalFileName.c_str(), button->_normalTexType); - loadTexturePressed(button->_clickedFileName.c_str(), button->_pressedTexType); - loadTextureDisabled(button->_disabledFileName.c_str(), button->_disabledTexType); + loadTextureNormal(button->_normalFileName, button->_normalTexType); + loadTexturePressed(button->_clickedFileName, button->_pressedTexType); + loadTextureDisabled(button->_disabledFileName, button->_disabledTexType); setCapInsetsNormalRenderer(button->_capInsetsNormal); setCapInsetsPressedRenderer(button->_capInsetsPressed); setCapInsetsDisabledRenderer(button->_capInsetsDisabled); diff --git a/cocos/ui/UITextField.cpp b/cocos/ui/UITextField.cpp index 15b36fd40c..b9878a20d4 100644 --- a/cocos/ui/UITextField.cpp +++ b/cocos/ui/UITextField.cpp @@ -386,6 +386,22 @@ TextField* TextField::create() return nullptr; } +TextField* TextField::create(const std::string &placeholder, const std::string &fontName, int fontSize) +{ + TextField* widget = new TextField(); + if (widget && widget->init()) + { + widget->setTouchEnabled(true); + widget->setPlaceHolder(placeholder); + widget->setFontName(fontName); + widget->setFontSize(fontSize); + widget->autorelease(); + return widget; + } + CC_SAFE_DELETE(widget); + return nullptr; +} + bool TextField::init() { if (Widget::init()) diff --git a/cocos/ui/UITextField.h b/cocos/ui/UITextField.h index 01b51137de..73e728cb8b 100644 --- a/cocos/ui/UITextField.h +++ b/cocos/ui/UITextField.h @@ -110,6 +110,9 @@ public: TextField(); virtual ~TextField(); static TextField* create(); + static TextField* create(const std::string& placeholder, + const std::string& fontName, + int fontSize); void setTouchSize(const Size &size); Size getTouchSize(); void setTouchAreaEnabled(bool enable); diff --git a/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp b/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp index 01f9e1a05b..2f8437cd19 100644 --- a/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp +++ b/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp @@ -458,16 +458,14 @@ void Scale9Sprite::updatePositions() _centre->setPosition(Point(leftWidth, bottomHeight)); } -bool Scale9Sprite::initWithFile(const char* file, const Rect& rect, const Rect& capInsets) -{ - CCASSERT(file != NULL, "Invalid file for sprite"); - +bool Scale9Sprite::initWithFile(const std::string& file, const Rect& rect, const Rect& capInsets) +{ SpriteBatchNode *batchnode = SpriteBatchNode::create(file, 9); bool pReturn = this->initWithBatchNode(batchnode, rect, capInsets); return pReturn; } -Scale9Sprite* Scale9Sprite::create(const char* file, const Rect& rect, const Rect& capInsets) +Scale9Sprite* Scale9Sprite::create(const std::string& file, const Rect& rect, const Rect& capInsets) { Scale9Sprite* pReturn = new Scale9Sprite(); if ( pReturn && pReturn->initWithFile(file, rect, capInsets) ) @@ -479,14 +477,13 @@ Scale9Sprite* Scale9Sprite::create(const char* file, const Rect& rect, const Re return NULL; } -bool Scale9Sprite::initWithFile(const char* file, const Rect& rect) +bool Scale9Sprite::initWithFile(const std::string& file, const Rect& rect) { - CCASSERT(file != NULL, "Invalid file for sprite"); bool pReturn = this->initWithFile(file, rect, Rect::ZERO); return pReturn; } -Scale9Sprite* Scale9Sprite::create(const char* file, const Rect& rect) +Scale9Sprite* Scale9Sprite::create(const std::string& file, const Rect& rect) { Scale9Sprite* pReturn = new Scale9Sprite(); if ( pReturn && pReturn->initWithFile(file, rect) ) @@ -499,13 +496,13 @@ Scale9Sprite* Scale9Sprite::create(const char* file, const Rect& rect) } -bool Scale9Sprite::initWithFile(const Rect& capInsets, const char* file) +bool Scale9Sprite::initWithFile(const Rect& capInsets, const std::string& file) { bool pReturn = this->initWithFile(file, Rect::ZERO, capInsets); return pReturn; } -Scale9Sprite* Scale9Sprite::create(const Rect& capInsets, const char* file) +Scale9Sprite* Scale9Sprite::create(const Rect& capInsets, const std::string& file) { Scale9Sprite* pReturn = new Scale9Sprite(); if ( pReturn && pReturn->initWithFile(capInsets, file) ) @@ -517,14 +514,14 @@ Scale9Sprite* Scale9Sprite::create(const Rect& capInsets, const char* file) return NULL; } -bool Scale9Sprite::initWithFile(const char* file) +bool Scale9Sprite::initWithFile(const std::string& file) { bool pReturn = this->initWithFile(file, Rect::ZERO); return pReturn; } -Scale9Sprite* Scale9Sprite::create(const char* file) +Scale9Sprite* Scale9Sprite::create(const std::string& file) { Scale9Sprite* pReturn = new Scale9Sprite(); if ( pReturn && pReturn->initWithFile(file) ) @@ -578,7 +575,7 @@ Scale9Sprite* Scale9Sprite::createWithSpriteFrame(SpriteFrame* spriteFrame) return NULL; } -bool Scale9Sprite::initWithSpriteFrameName(const char* spriteFrameName, const Rect& capInsets) +bool Scale9Sprite::initWithSpriteFrameName(const std::string& spriteFrameName, const Rect& capInsets) { CCASSERT((SpriteFrameCache::getInstance()) != NULL, "SpriteFrameCache::getInstance() must be non-NULL"); @@ -591,7 +588,7 @@ bool Scale9Sprite::initWithSpriteFrameName(const char* spriteFrameName, const Re return pReturn; } -Scale9Sprite* Scale9Sprite::createWithSpriteFrameName(const char* spriteFrameName, const Rect& capInsets) +Scale9Sprite* Scale9Sprite::createWithSpriteFrameName(const std::string& spriteFrameName, const Rect& capInsets) { Scale9Sprite* pReturn = new Scale9Sprite(); if ( pReturn && pReturn->initWithSpriteFrameName(spriteFrameName, capInsets) ) @@ -603,16 +600,14 @@ Scale9Sprite* Scale9Sprite::createWithSpriteFrameName(const char* spriteFrameNam return NULL; } -bool Scale9Sprite::initWithSpriteFrameName(const char* spriteFrameName) +bool Scale9Sprite::initWithSpriteFrameName(const std::string& spriteFrameName) { bool pReturn = this->initWithSpriteFrameName(spriteFrameName, Rect::ZERO); return pReturn; } -Scale9Sprite* Scale9Sprite::createWithSpriteFrameName(const char* spriteFrameName) +Scale9Sprite* Scale9Sprite::createWithSpriteFrameName(const std::string& spriteFrameName) { - CCASSERT(spriteFrameName != NULL, "spriteFrameName must be non-NULL"); - Scale9Sprite* pReturn = new Scale9Sprite(); if ( pReturn && pReturn->initWithSpriteFrameName(spriteFrameName) ) { diff --git a/extensions/GUI/CCControlExtension/CCScale9Sprite.h b/extensions/GUI/CCControlExtension/CCScale9Sprite.h index 6c2ee432bd..14cc00c402 100644 --- a/extensions/GUI/CCControlExtension/CCScale9Sprite.h +++ b/extensions/GUI/CCControlExtension/CCScale9Sprite.h @@ -75,7 +75,7 @@ public: * * @see initWithFile(const char *file, const Rect& rect, const Rect& capInsets) */ - static Scale9Sprite* create(const char* file, const Rect& rect, const Rect& capInsets); + static Scale9Sprite* create(const std::string& file, const Rect& rect, const Rect& capInsets); /** * Creates a 9-slice sprite with a texture file. The whole texture will be @@ -83,7 +83,7 @@ public: * * @see initWithFile(const Rect& capInsets, const char *file) */ - static Scale9Sprite* create(const Rect& capInsets, const char* file); + static Scale9Sprite* create(const Rect& capInsets, const std::string& file); /** * Creates a 9-slice sprite with a texture file and a delimitation zone. The @@ -91,7 +91,7 @@ public: * * @see initWithFile(const char *file, const Rect& rect) */ - static Scale9Sprite* create(const char* file, const Rect& rect); + static Scale9Sprite* create(const std::string& file, const Rect& rect); /** * Creates a 9-slice sprite with a texture file. The whole texture will be @@ -99,7 +99,7 @@ public: * * @see initWithFile(const char *file) */ - static Scale9Sprite* create(const char* file); + static Scale9Sprite* create(const std::string& file); /** * Creates a 9-slice sprite with an sprite frame. @@ -129,7 +129,7 @@ public: * * @see initWithSpriteFrameName(const char *spriteFrameName) */ - static Scale9Sprite* createWithSpriteFrameName(const char*spriteFrameName); + static Scale9Sprite* createWithSpriteFrameName(const std::string& spriteFrameName); /** * Creates a 9-slice sprite with an sprite frame name and the centre of its @@ -140,7 +140,7 @@ public: * * @see initWithSpriteFrameName(const char *spriteFrameName, const Rect& capInsets) */ - static Scale9Sprite* createWithSpriteFrameName(const char*spriteFrameName, const Rect& capInsets); + static Scale9Sprite* createWithSpriteFrameName(const std::string& spriteFrameName, const Rect& capInsets); /** * Initializes a 9-slice sprite with a texture file, a delimitation zone and @@ -155,7 +155,7 @@ public: * texture's full rect. * @param capInsets The values to use for the cap insets. */ - virtual bool initWithFile(const char* file, const Rect& rect, const Rect& capInsets); + virtual bool initWithFile(const std::string& file, const Rect& rect, const Rect& capInsets); /** * Initializes a 9-slice sprite with a texture file and a delimitation zone. The @@ -169,7 +169,7 @@ public: * is the whole image. If the shape is the whole texture, set this to the * texture's full rect. */ - virtual bool initWithFile(const char* file, const Rect& rect); + virtual bool initWithFile(const std::string& file, const Rect& rect); /** * Initializes a 9-slice sprite with a texture file and with the specified cap @@ -181,7 +181,7 @@ public: * @param file The name of the texture file. * @param capInsets The values to use for the cap insets. */ - virtual bool initWithFile(const Rect& capInsets, const char* file); + virtual bool initWithFile(const Rect& capInsets, const std::string& file); /** * Initializes a 9-slice sprite with a texture file. The whole texture will be @@ -192,7 +192,7 @@ public: * * @param file The name of the texture file. */ - virtual bool initWithFile(const char* file); + virtual bool initWithFile(const std::string& file); /** * Initializes a 9-slice sprite with an sprite frame and with the specified @@ -226,7 +226,7 @@ public: * @param spriteFrameName The sprite frame name. * @param capInsets The values to use for the cap insets. */ - virtual bool initWithSpriteFrameName(const char*spriteFrameName, const Rect& capInsets); + virtual bool initWithSpriteFrameName(const std::string& spriteFrameName, const Rect& capInsets); /** * Initializes a 9-slice sprite with an sprite frame name. @@ -236,7 +236,7 @@ public: * * @param spriteFrameName The sprite frame name. */ - virtual bool initWithSpriteFrameName(const char*spriteFrameName); + virtual bool initWithSpriteFrameName(const std::string& spriteFrameName); virtual bool init(); virtual bool initWithBatchNode(SpriteBatchNode* batchnode, const Rect& rect, bool rotated, const Rect& capInsets); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp index 66f63ec4a5..a958f30932 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp @@ -38,11 +38,8 @@ bool UITextFieldTest::init() _uiLayer->addChild(alert); // Create the textfield - TextField* textField = TextField::create(); - textField->setTouchEnabled(true); - textField->setFontName("fonts/Marker Felt.ttf"); - textField->setFontSize(30); - textField->setPlaceHolder("input words here"); + TextField* textField = TextField::create("input words here","fonts/Marker Felt.ttf",30); + textField->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); textField->addEventListenerTextField(this, textfieldeventselector(UITextFieldTest::textFieldEvent)); _uiLayer->addChild(textField); From 10134ccc65e144182d3bc0a3e064d158ff81deb3 Mon Sep 17 00:00:00 2001 From: andyque Date: Thu, 3 Apr 2014 10:31:10 +0800 Subject: [PATCH 10/66] issue #4636. finish button --- cocos/ui/UIButton.cpp | 6 +- cocos/ui/UIButton.h | 4 +- .../UIButtonTest/UIButtonTest.cpp | 72 +++++++------------ 3 files changed, 29 insertions(+), 53 deletions(-) diff --git a/cocos/ui/UIButton.cpp b/cocos/ui/UIButton.cpp index 8cf9eb3016..a79eaa20de 100644 --- a/cocos/ui/UIButton.cpp +++ b/cocos/ui/UIButton.cpp @@ -697,14 +697,14 @@ float Button::getTitleFontSize() const return _titleRenderer->getFontSize(); } -void Button::setTitleFontName(const char* fontName) +void Button::setTitleFontName(const std::string& fontName) { _titleRenderer->setFontName(fontName); } -const char* Button::getTitleFontName() const +const std::string& Button::getTitleFontName() const { - return _titleRenderer->getFontName().c_str(); + return _titleRenderer->getFontName(); } std::string Button::getDescription() const diff --git a/cocos/ui/UIButton.h b/cocos/ui/UIButton.h index b170a72e89..101d75bd74 100644 --- a/cocos/ui/UIButton.h +++ b/cocos/ui/UIButton.h @@ -185,8 +185,8 @@ public: const Color3B& getTitleColor() const; void setTitleFontSize(float size); float getTitleFontSize() const; - void setTitleFontName(const char* fontName); - const char* getTitleFontName() const; + void setTitleFontName(const std::string& fontName); + const std::string& getTitleFontName() const; CC_CONSTRUCTOR_ACCESS: virtual bool init() override; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp index f31cd5673c..725a96ce9f 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp @@ -21,28 +21,23 @@ bool UIButtonTest::init() Size widgetSize = _widget->getSize(); // Add a label in which the button events will be displayed - _displayValueLabel = Text::create(); - _displayValueLabel->setText("No Event"); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); - _displayValueLabel->setFontSize(32); + _displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf",32); _displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f)); _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); _uiLayer->addChild(_displayValueLabel); // Add the alert - Text* alert = Text::create(); - alert->setText("Button"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("Button","fonts/Marker Felt.ttf",30); alert->setColor(Color3B(159, 168, 176)); - alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); + alert->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); + _uiLayer->addChild(alert); // Create the button - Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); - button->setTouchEnabled(true); -// button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); button->addTouchEventListener(this, toucheventselector(UIButtonTest::touchEvent)); _uiLayer->addChild(button); @@ -97,29 +92,22 @@ bool UIButtonTest_Scale9::init() Size widgetSize = _widget->getSize(); // Add a label in which the button events will be displayed - _displayValueLabel = Text::create(); - _displayValueLabel->setText("No Event"); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); - _displayValueLabel->setFontSize(32); + _displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf", 32); _displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f)); _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); _uiLayer->addChild(_displayValueLabel); // Add the alert - Text* alert = Text::create(); - alert->setText("Button scale9 render"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("Button scale9 render", "fonts/Marker Felt.ttf",30); alert->setColor(Color3B(159, 168, 176)); - alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); + alert->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); _uiLayer->addChild(alert); // Create the button - Button* button = Button::create(); - button->setTouchEnabled(true); + Button* button = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); // open scale9 render button->setScale9Enabled(true); - button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); button->setSize(Size(150, button->getContentSize().height * 1.5f)); button->addTouchEventListener(this, toucheventselector(UIButtonTest_Scale9::touchEvent)); @@ -172,29 +160,23 @@ bool UIButtonTest_PressedAction::init() Size widgetSize = _widget->getSize(); // Add a label in which the button events will be displayed - _displayValueLabel = Text::create(); - _displayValueLabel->setText("No Event"); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); - _displayValueLabel->setFontSize(32); + _displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf",32); _displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f)); _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); _uiLayer->addChild(_displayValueLabel); // Add the alert - Text* alert = Text::create(); - alert->setText("Button Pressed Action"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("Button Pressed Action", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); - alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); + alert->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); + _uiLayer->addChild(alert); // Create the button - Button* button = Button::create(); - button->setTouchEnabled(true); + Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setPressedActionEnabled(true); - button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); button->addTouchEventListener(this, toucheventselector(UIButtonTest_PressedAction::touchEvent)); _uiLayer->addChild(button); @@ -247,27 +229,21 @@ bool UIButtonTest_Title::init() Size widgetSize = _widget->getSize(); // Add a label in which the text button events will be displayed - _displayValueLabel = Text::create(); - _displayValueLabel->setText("No Event"); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); - _displayValueLabel->setFontSize(32); + _displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf", 32); _displayValueLabel->setAnchorPoint(Point(0.5f, -1)); _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); _uiLayer->addChild(_displayValueLabel); // Add the alert - Text* alert = Text::create(); - alert->setText("Button with title"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("Button with title", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); - alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); + alert->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); + _uiLayer->addChild(alert); // Create the button with title - Button* button = Button::create(); - button->setTouchEnabled(true); - button->loadTextures("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png", ""); + Button* button = Button::create("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png"); button->setTitleText("Title Button"); button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); button->addTouchEventListener(this, toucheventselector(UIButtonTest_Title::touchEvent)); From 52bdb840ee87abe4a46f4a8f464f891aec13247b Mon Sep 17 00:00:00 2001 From: andyque Date: Thu, 3 Apr 2014 10:34:20 +0800 Subject: [PATCH 11/66] issue #4636. finish UICheckBox --- cocos/ui/UICheckBox.cpp | 10 +++++----- .../UICheckBoxTest/UICheckBoxTest.cpp | 16 ++-------------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/cocos/ui/UICheckBox.cpp b/cocos/ui/UICheckBox.cpp index 16c1628600..7b6b68507f 100644 --- a/cocos/ui/UICheckBox.cpp +++ b/cocos/ui/UICheckBox.cpp @@ -574,11 +574,11 @@ void CheckBox::copySpecialProperties(Widget *widget) CheckBox* checkBox = dynamic_cast(widget); if (checkBox) { - loadTextureBackGround(checkBox->_backGroundFileName.c_str(), checkBox->_backGroundTexType); - loadTextureBackGroundSelected(checkBox->_backGroundSelectedFileName.c_str(), checkBox->_backGroundSelectedTexType); - loadTextureFrontCross(checkBox->_frontCrossFileName.c_str(), checkBox->_frontCrossTexType); - loadTextureBackGroundDisabled(checkBox->_backGroundDisabledFileName.c_str(), checkBox->_backGroundDisabledTexType); - loadTextureFrontCrossDisabled(checkBox->_frontCrossDisabledFileName.c_str(), checkBox->_frontCrossDisabledTexType); + loadTextureBackGround(checkBox->_backGroundFileName, checkBox->_backGroundTexType); + loadTextureBackGroundSelected(checkBox->_backGroundSelectedFileName, checkBox->_backGroundSelectedTexType); + loadTextureFrontCross(checkBox->_frontCrossFileName, checkBox->_frontCrossTexType); + loadTextureBackGroundDisabled(checkBox->_backGroundDisabledFileName, checkBox->_backGroundDisabledTexType); + loadTextureFrontCrossDisabled(checkBox->_frontCrossDisabledFileName, checkBox->_frontCrossDisabledTexType); setSelectedState(checkBox->_isSelected); } } diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp index 4e71babee2..bea4659fa4 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp @@ -21,19 +21,13 @@ bool UICheckBoxTest::init() Size widgetSize = _widget->getSize();; // Add a label in which the checkbox events will be displayed - _displayValueLabel = Text::create(); - _displayValueLabel->setText("No Event"); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); - _displayValueLabel->setFontSize(32); + _displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf", 32); _displayValueLabel->setAnchorPoint(Point(0.5f, -1)); _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); _uiLayer->addChild(_displayValueLabel); // Add the alert - Text* alert = Text::create(); - alert->setText("CheckBox"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("CheckBox","fonts/Marker Felt.ttf",30 ); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); _uiLayer->addChild(alert); @@ -44,12 +38,6 @@ bool UICheckBoxTest::init() "cocosui/check_box_active.png", "cocosui/check_box_normal_disable.png", "cocosui/check_box_active_disable.png"); - checkBox->setTouchEnabled(true); -// checkBox->loadTextures("cocosui/check_box_normal.png", -// "cocosui/check_box_normal_press.png", -// "cocosui/check_box_active.png", -// "cocosui/check_box_normal_disable.png", -// "cocosui/check_box_active_disable.png"); checkBox->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); checkBox->addEventListenerCheckBox(this, checkboxselectedeventselector(UICheckBoxTest::selectedEvent)); From 1a97ebdcb0f8cdd46f3a1af1872103bf60869fce Mon Sep 17 00:00:00 2001 From: andyque Date: Thu, 3 Apr 2014 10:42:30 +0800 Subject: [PATCH 12/66] issue #4636. finish UIImageView --- cocos/ui/UIImageView.cpp | 8 +-- .../UIImageViewTest/UIImageViewTest.cpp | 63 +++++-------------- 2 files changed, 20 insertions(+), 51 deletions(-) diff --git a/cocos/ui/UIImageView.cpp b/cocos/ui/UIImageView.cpp index 0cde1d7e16..ecd901f657 100644 --- a/cocos/ui/UIImageView.cpp +++ b/cocos/ui/UIImageView.cpp @@ -124,7 +124,7 @@ void ImageView::loadTexture(const std::string& fileName, TextureResType texType) if (_scale9Enabled) { extension::Scale9Sprite* imageRendererScale9 = STATIC_CAST_SCALE9SPRITE; - imageRendererScale9->initWithFile(fileName.c_str()); + imageRendererScale9->initWithFile(fileName); imageRendererScale9->setCapInsets(_capInsets); } else @@ -137,7 +137,7 @@ void ImageView::loadTexture(const std::string& fileName, TextureResType texType) if (_scale9Enabled) { extension::Scale9Sprite* imageRendererScale9 = STATIC_CAST_SCALE9SPRITE; - imageRendererScale9->initWithSpriteFrameName(fileName.c_str()); + imageRendererScale9->initWithSpriteFrameName(fileName); imageRendererScale9->setCapInsets(_capInsets); } else @@ -214,7 +214,7 @@ void ImageView::setScale9Enabled(bool able) { _imageRenderer = Sprite::create(); } - loadTexture(_textureFile.c_str(),_imageTexType); + loadTexture(_textureFile,_imageTexType); addProtectedChild(_imageRenderer, IMAGE_RENDERER_Z, -1); if (_scale9Enabled) { @@ -344,7 +344,7 @@ void ImageView::copySpecialProperties(Widget *widget) { _prevIgnoreSize = imageView->_prevIgnoreSize; setScale9Enabled(imageView->_scale9Enabled); - loadTexture(imageView->_textureFile.c_str(), imageView->_imageTexType); + loadTexture(imageView->_textureFile, imageView->_imageTexType); setCapInsets(imageView->_capInsets); } } diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp index 5831741232..9445db0c9a 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp @@ -11,52 +11,21 @@ bool UIImageViewTest::init() { Size widgetSize = _widget->getSize(); - Text* alert = Text::create(); - alert->setText("ImageView"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("ImageView", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); - alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); + alert->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); + _uiLayer->addChild(alert); // Create the imageview ImageView* imageView = ImageView::create("cocosui/ccicon.png"); -// imageView->loadTexture("cocosui/ccicon.png"); - imageView->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + imageView->getSize().height / 4.0f)); + imageView->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f + imageView->getSize().height / 4.0f)); -// imageView->setOpacity(64); _uiLayer->addChild(imageView); - /* - NodeRGBA* root = NodeRGBA::create(); - root->setCascadeOpacityEnabled(true); - NodeRGBA* render = Sprite::create(); - static_cast(render)->setTexture("cocosui/ccicon.png"); - root->addChild(render); -// root->setOpacity(64); - root->setPosition(Point(200, 180)); - _uiLayer->addChild(root); - */ - - /* - NodeRGBA* nodergba = NodeRGBA::create(); - Sprite* child = Sprite::create(); - child->setTexture("cocosui/ccicon.png"); - nodergba->addChild(child); - nodergba->setPosition(Point(120, 80)); - nodergba->setOpacity(64); - _uiLayer->addChild(nodergba); - */ - - /* - Sprite* sprite = Sprite::create(); - sprite->setTexture("cocosui/ccicon.png"); - sprite->setPosition(Point(200, 180)); -// sprite->setOpacity(64); - _uiLayer->addChild(sprite); - */ - -// imageView->setZOrder(20); + return true; } @@ -72,20 +41,20 @@ bool UIImageViewTest_Scale9::init() { Size widgetSize = _widget->getSize(); - Text* alert = Text::create(); - alert->setText("ImageView scale9 render"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(26); + Text* alert = Text::create("ImageView scale9 render", "fonts/Marker Felt.ttf", 26); alert->setColor(Color3B(159, 168, 176)); - alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.125f)); + alert->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f - alert->getSize().height * 2.125f)); + _uiLayer->addChild(alert); // Create the imageview - ImageView* imageView = ImageView::create(); + ImageView* imageView = ImageView::create("cocosui/buttonHighlighted.png"); imageView->setScale9Enabled(true); - imageView->loadTexture("cocosui/buttonHighlighted.png"); - imageView->setSize(Size(200, 85)); - imageView->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + imageView->getSize().height / 4.0f)); + imageView->setSize(Size(300, 115)); + imageView->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f + imageView->getSize().height / 4.0f)); + _uiLayer->addChild(imageView); return true; From fe3358803802374b5fb1fbfb03cc1dc0c42bf987 Mon Sep 17 00:00:00 2001 From: andyque Date: Thu, 3 Apr 2014 11:14:35 +0800 Subject: [PATCH 13/66] issue #4636. finish UILayout --- cocos/ui/UILayout.cpp | 8 +- cocos/ui/UILayout.h | 2 +- .../UILayoutTest/UILayoutTest.cpp | 334 +++++------------- 3 files changed, 98 insertions(+), 246 deletions(-) diff --git a/cocos/ui/UILayout.cpp b/cocos/ui/UILayout.cpp index 9808553d62..27ce84dfa4 100644 --- a/cocos/ui/UILayout.cpp +++ b/cocos/ui/UILayout.cpp @@ -1111,7 +1111,7 @@ void Layout::setBackGroundImageScale9Enabled(bool able) _backGroundImage = nullptr; _backGroundScale9Enabled = able; addBackGroundImage(); - setBackGroundImage(_backGroundImageFileName.c_str(),_bgImageTexType); + setBackGroundImage(_backGroundImageFileName,_bgImageTexType); setBackGroundImageCapInsets(_backGroundImageCapInsets); } @@ -1120,9 +1120,9 @@ bool Layout::isBackGroundImageScale9Enabled() return _backGroundScale9Enabled; } -void Layout::setBackGroundImage(const char* fileName,TextureResType texType) +void Layout::setBackGroundImage(const std::string& fileName,TextureResType texType) { - if (!fileName || strcmp(fileName, "") == 0) + if (fileName.empty()) { return; } @@ -1519,7 +1519,7 @@ void Layout::copySpecialProperties(Widget *widget) if (layout) { setBackGroundImageScale9Enabled(layout->_backGroundScale9Enabled); - setBackGroundImage(layout->_backGroundImageFileName.c_str(),layout->_bgImageTexType); + setBackGroundImage(layout->_backGroundImageFileName,layout->_bgImageTexType); setBackGroundImageCapInsets(layout->_backGroundImageCapInsets); setBackGroundColorType(layout->_colorType); setBackGroundColor(layout->_cColor); diff --git a/cocos/ui/UILayout.h b/cocos/ui/UILayout.h index 3155332793..8d56d44610 100644 --- a/cocos/ui/UILayout.h +++ b/cocos/ui/UILayout.h @@ -86,7 +86,7 @@ public: * * @param texType @see TextureResType. UI_TEX_TYPE_LOCAL means local file, UI_TEX_TYPE_PLIST means sprite frame. */ - void setBackGroundImage(const char* fileName,TextureResType texType = UI_TEX_TYPE_LOCAL); + void setBackGroundImage(const std::string& fileName,TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Sets a background image capinsets for layout, if the background image is a scale9 render. diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp index aa3b617afc..89d7347866 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp @@ -20,12 +20,11 @@ bool UILayoutTest::init() Size widgetSize = _widget->getSize(); // Add the alert - Text* alert = Text::create(); - alert->setText("Layout"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("Layout", "fonts/Marker Felt.ttf", 30 ); alert->setColor(Color3B(159, 168, 176)); - alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); + alert->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); + _uiLayer->addChild(alert); Layout* root = static_cast(_uiLayer->getChildByTag(81)) ; @@ -42,25 +41,22 @@ bool UILayoutTest::init() (backgroundSize.height - layout->getSize().height) / 2.0f)); _uiLayer->addChild(layout); - Button* button = Button::create(); - button->setTouchEnabled(true); - button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); - button->setPosition(Point(button->getSize().width / 2.0f, layout->getSize().height - button->getSize().height / 2.0f)); + Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); + button->setPosition(Point(button->getSize().width / 2.0f, + layout->getSize().height - button->getSize().height / 2.0f)); layout->addChild(button); - Button* titleButton = Button::create(); - titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); + Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); titleButton->setTitleText("Title Button"); titleButton->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(titleButton); - Button* button_scale9 = Button::create(); - button_scale9->setTouchEnabled(true); - button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); + Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); - button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f)); + button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, + button_scale9->getSize().height / 2.0f)); + layout->addChild(button_scale9); return true; @@ -86,12 +82,11 @@ bool UILayoutTest_Color::init() Size widgetSize = _widget->getSize(); // Add the alert - Text* alert = Text::create(); - alert->setText("Layout color render"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("Layout color render", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); - alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); + alert->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); + _uiLayer->addChild(alert); Layout* root = static_cast(_uiLayer->getChildByTag(81)); @@ -110,25 +105,23 @@ bool UILayoutTest_Color::init() (backgroundSize.height - layout->getSize().height) / 2.0f)); _uiLayer->addChild(layout); - Button* button = Button::create(); - button->setTouchEnabled(true); - button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); - button->setPosition(Point(button->getSize().width / 2.0f, layout->getSize().height - button->getSize().height / 2.0f)); + Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); + button->setPosition(Point(button->getSize().width / 2.0f, + layout->getSize().height - button->getSize().height / 2.0f)); + layout->addChild(button); - Button* titleButton = Button::create(); - titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); + Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); titleButton->setTitleText("Title Button"); titleButton->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(titleButton); - Button* button_scale9 = Button::create(); - button_scale9->setTouchEnabled(true); - button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); + Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); - button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f)); + button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, + button_scale9->getSize().height / 2.0f)); + layout->addChild(button_scale9); return true; @@ -153,12 +146,11 @@ bool UILayoutTest_Gradient::init() Size widgetSize = _widget->getSize(); // Add the alert - Text* alert = Text::create(); - alert->setText("Layout gradient render"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("Layout gradient render", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); - alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); + alert->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); + _uiLayer->addChild(alert); Layout* root = static_cast(_uiLayer->getChildByTag(81)); @@ -177,25 +169,23 @@ bool UILayoutTest_Gradient::init() (backgroundSize.height - layout->getSize().height) / 2.0f)); _uiLayer->addChild(layout); - Button* button = Button::create(); - button->setTouchEnabled(true); - button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); - button->setPosition(Point(button->getSize().width / 2.0f, layout->getSize().height - button->getSize().height / 2.0f)); + Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); + button->setPosition(Point(button->getSize().width / 2.0f, + layout->getSize().height - button->getSize().height / 2.0f)); + layout->addChild(button); - Button* titleButton = Button::create(); - titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); + Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); titleButton->setTitleText("Title Button"); titleButton->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(titleButton); - Button* button_scale9 = Button::create(); - button_scale9->setTouchEnabled(true); - button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); + Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); - button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f)); + button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, + button_scale9->getSize().height / 2.0f)); + layout->addChild(button_scale9); return true; @@ -220,10 +210,7 @@ bool UILayoutTest_BackGroundImage::init() Size widgetSize = _widget->getSize(); // Add the alert - Text* alert = Text::create(); - alert->setText("Layout background image"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(20); + Text* alert = Text::create("Layout background image", "fonts/Marker Felt.ttf", 20); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5f)); _uiLayer->addChild(alert); @@ -244,25 +231,22 @@ bool UILayoutTest_BackGroundImage::init() (backgroundSize.height - layout->getSize().height) / 2.0f)); _uiLayer->addChild(layout); - Button* button = Button::create(); - button->setTouchEnabled(true); - button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); - button->setPosition(Point(button->getSize().width / 2.0f, layout->getSize().height - button->getSize().height / 2.0f)); + Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); + button->setPosition(Point(button->getSize().width / 2.0f, + layout->getSize().height - button->getSize().height / 2.0f)); layout->addChild(button); - Button* titleButton = Button::create(); - titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); + Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); titleButton->setTitleText("Title Button"); titleButton->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(titleButton); - Button* button_scale9 = Button::create(); - button_scale9->setTouchEnabled(true); - button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); + Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); - button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f)); + button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, + button_scale9->getSize().height / 2.0f)); + layout->addChild(button_scale9); return true; @@ -287,10 +271,7 @@ bool UILayoutTest_BackGroundImage_Scale9::init() Size widgetSize = _widget->getSize(); // Add the alert - Text* alert = Text::create(); - alert->setText("Layout background image scale9"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(20); + Text* alert = Text::create("Layout background image scale9", "fonts/Marker Felt.ttf", 20); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5f)); _uiLayer->addChild(alert); @@ -311,26 +292,23 @@ bool UILayoutTest_BackGroundImage_Scale9::init() (backgroundSize.height - layout->getSize().height) / 2.0f)); _uiLayer->addChild(layout); - Button* button = Button::create(); - button->setTouchEnabled(true); - button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); - button->setPosition(Point(button->getSize().width / 2.0f, layout->getSize().height - button->getSize().height / 2.0f)); + Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); + button->setPosition(Point(button->getSize().width / 2.0f, + layout->getSize().height - button->getSize().height / 2.0f)); + layout->addChild(button); - Button* titleButton = Button::create(); - titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); + Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); titleButton->setTitleText("Title Button"); titleButton->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(titleButton); - Button* button_scale9 = Button::create(); - button_scale9->setTouchEnabled(true); - button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); + Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); - button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f)); - layout->addChild(button_scale9); + button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, + button_scale9->getSize().height / 2.0f)); + layout->addChild(button_scale9); return true; } @@ -354,12 +332,11 @@ bool UILayoutTest_Layout_Linear_Vertical::init() Size widgetSize = _widget->getSize(); // Add the alert - Text* alert = Text::create(); - alert->setText("Layout Linear Vertical"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(20); + Text* alert = Text::create("Layout Linear Vertical", "fonts/Marker Felt.ttf", 20); alert->setColor(Color3B(159, 168, 176)); - alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5f)); + alert->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f - alert->getSize().height * 4.5f)); + _uiLayer->addChild(alert); Layout* root = static_cast(_uiLayer->getChildByTag(81)); @@ -378,9 +355,7 @@ bool UILayoutTest_Layout_Linear_Vertical::init() _uiLayer->addChild(layout); - Button* button = Button::create(); - button->setTouchEnabled(true); - button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); layout->addChild(button); LinearLayoutParameter* lp1 = LinearLayoutParameter::create(); @@ -389,9 +364,7 @@ bool UILayoutTest_Layout_Linear_Vertical::init() lp1->setMargin(Margin(0.0f, 5.0f, 0.0f, 10.0f)); - Button* titleButton = Button::create(); - titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); + Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); titleButton->setTitleText("Title Button"); layout->addChild(titleButton); @@ -401,9 +374,7 @@ bool UILayoutTest_Layout_Linear_Vertical::init() lp2->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f)); - Button* button_scale9 = Button::create(); - button_scale9->setTouchEnabled(true); - button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); + Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); layout->addChild(button_scale9); @@ -414,8 +385,6 @@ bool UILayoutTest_Layout_Linear_Vertical::init() lp3->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f)); -// layout->doLayout(); - return true; } @@ -439,10 +408,7 @@ bool UILayoutTest_Layout_Linear_Horizontal::init() Size widgetSize = _widget->getSize(); // Add the alert - Text* alert = Text::create(); - alert->setText("Layout Linear Horizontal"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(20); + Text* alert = Text::create("Layout Linear Horizontal", "fonts/Marker Felt.ttf", 20); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5f)); _uiLayer->addChild(alert); @@ -463,9 +429,7 @@ bool UILayoutTest_Layout_Linear_Horizontal::init() (backgroundSize.height - layout->getSize().height) / 2.0f)); _uiLayer->addChild(layout); - Button* button = Button::create(); - button->setTouchEnabled(true); - button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); layout->addChild(button); LinearLayoutParameter* lp1 = LinearLayoutParameter::create(); @@ -474,9 +438,7 @@ bool UILayoutTest_Layout_Linear_Horizontal::init() lp1->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f)); - Button* titleButton = Button::create(); - titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); + Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); titleButton->setTitleText("Title Button"); layout->addChild(titleButton); @@ -486,9 +448,7 @@ bool UILayoutTest_Layout_Linear_Horizontal::init() lp2->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f)); - Button* button_scale9 = Button::create(); - button_scale9->setTouchEnabled(true); - button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); + Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); layout->addChild(button_scale9); @@ -499,8 +459,6 @@ bool UILayoutTest_Layout_Linear_Horizontal::init() lp3->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f)); -// layout->doLayout(); - return true; } @@ -524,10 +482,7 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() Size widgetSize = _widget->getSize(); // Add the alert - Text* alert = Text::create(); - alert->setText("Layout Relative Align Parent"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(20); + Text* alert = Text::create("Layout Relative Align Parent", "fonts/Marker Felt.ttf", 20); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5f)); _uiLayer->addChild(alert); @@ -550,9 +505,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() _uiLayer->addChild(layout); // top left - Button* button_TopLeft = Button::create(); - button_TopLeft->setTouchEnabled(true); - button_TopLeft->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button_TopLeft = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); layout->addChild(button_TopLeft); RelativeLayoutParameter* rp_TopLeft = RelativeLayoutParameter::create(); @@ -561,9 +515,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // top center horizontal - Button* button_TopCenter = Button::create(); - button_TopCenter->setTouchEnabled(true); - button_TopCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button_TopCenter = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); layout->addChild(button_TopCenter); RelativeLayoutParameter* rp_TopCenter = RelativeLayoutParameter::create(); @@ -572,9 +525,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // top right - Button* button_TopRight = Button::create(); - button_TopRight->setTouchEnabled(true); - button_TopRight->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button_TopRight = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); layout->addChild(button_TopRight); RelativeLayoutParameter* rp_TopRight = RelativeLayoutParameter::create(); @@ -583,9 +535,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // left center - Button* button_LeftCenter = Button::create(); - button_LeftCenter->setTouchEnabled(true); - button_LeftCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button_LeftCenter = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); layout->addChild(button_LeftCenter); RelativeLayoutParameter* rp_LeftCenter = RelativeLayoutParameter::create(); @@ -594,9 +545,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // center - Button* buttonCenter = Button::create(); - buttonCenter->setTouchEnabled(true); - buttonCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* buttonCenter = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); layout->addChild(buttonCenter); RelativeLayoutParameter* rpCenter = RelativeLayoutParameter::create(); @@ -605,9 +555,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // right center - Button* button_RightCenter = Button::create(); - button_RightCenter->setTouchEnabled(true); - button_RightCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button_RightCenter = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); layout->addChild(button_RightCenter); RelativeLayoutParameter* rp_RightCenter = RelativeLayoutParameter::create(); @@ -616,9 +565,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // left bottom - Button* button_LeftBottom = Button::create(); - button_LeftBottom->setTouchEnabled(true); - button_LeftBottom->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button_LeftBottom = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); layout->addChild(button_LeftBottom); RelativeLayoutParameter* rp_LeftBottom = RelativeLayoutParameter::create(); @@ -627,9 +575,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // bottom center - Button* button_BottomCenter = Button::create(); - button_BottomCenter->setTouchEnabled(true); - button_BottomCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button_BottomCenter = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); layout->addChild(button_BottomCenter); RelativeLayoutParameter* rp_BottomCenter = RelativeLayoutParameter::create(); @@ -638,9 +585,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // right bottom - Button* button_RightBottom = Button::create(); - button_RightBottom->setTouchEnabled(true); - button_RightBottom->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button_RightBottom = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); layout->addChild(button_RightBottom); RelativeLayoutParameter* rp_RightBottom = RelativeLayoutParameter::create(); @@ -648,8 +594,6 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() button_RightBottom->setLayoutParameter(rp_RightBottom); -// layout->doLayout(); - return true; } @@ -673,10 +617,7 @@ bool UILayoutTest_Layout_Relative_Location::init() Size widgetSize = _widget->getSize(); // Add the alert - Text* alert = Text::create(); - alert->setText("Layout Relative Location"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(20); + Text* alert = Text::create("Layout Relative Location", "fonts/Marker Felt.ttf", 20); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5f)); _uiLayer->addChild(alert); @@ -697,8 +638,7 @@ bool UILayoutTest_Layout_Relative_Location::init() _uiLayer->addChild(layout); // center - ImageView* imageView_Center = ImageView::create(); - imageView_Center->loadTexture("cocosui/scrollviewbg.png"); + ImageView* imageView_Center = ImageView::create("cocosui/scrollviewbg.png"); layout->addChild(imageView_Center); RelativeLayoutParameter* rp_Center = RelativeLayoutParameter::create(); @@ -708,8 +648,7 @@ bool UILayoutTest_Layout_Relative_Location::init() // above center - ImageView* imageView_AboveCenter = ImageView::create(); - imageView_AboveCenter->loadTexture("cocosui/switch-mask.png"); + ImageView* imageView_AboveCenter = ImageView::create("cocosui/switch-mask.png"); layout->addChild(imageView_AboveCenter); RelativeLayoutParameter* rp_AboveCenter = RelativeLayoutParameter::create(); @@ -719,8 +658,7 @@ bool UILayoutTest_Layout_Relative_Location::init() // below center - ImageView* imageView_BelowCenter = ImageView::create(); - imageView_BelowCenter->loadTexture("cocosui/switch-mask.png"); + ImageView* imageView_BelowCenter = ImageView::create("cocosui/switch-mask.png"); layout->addChild(imageView_BelowCenter); RelativeLayoutParameter* rp_BelowCenter = RelativeLayoutParameter::create(); @@ -730,8 +668,7 @@ bool UILayoutTest_Layout_Relative_Location::init() // left center - ImageView* imageView_LeftCenter = ImageView::create(); - imageView_LeftCenter->loadTexture("cocosui/switch-mask.png"); + ImageView* imageView_LeftCenter = ImageView::create("cocosui/switch-mask.png"); layout->addChild(imageView_LeftCenter); RelativeLayoutParameter* rp_LeftCenter = RelativeLayoutParameter::create(); @@ -742,8 +679,7 @@ bool UILayoutTest_Layout_Relative_Location::init() // right center - ImageView* imageView_RightCenter = ImageView::create(); - imageView_RightCenter->loadTexture("cocosui/switch-mask.png"); + ImageView* imageView_RightCenter = ImageView::create("cocosui/switch-mask.png"); layout->addChild(imageView_RightCenter); RelativeLayoutParameter* rp_RightCenter = RelativeLayoutParameter::create(); @@ -752,93 +688,9 @@ bool UILayoutTest_Layout_Relative_Location::init() imageView_RightCenter->setLayoutParameter(rp_RightCenter); -// layout->doLayout(); - return true; } return false; } -// UILayoutTest_Layout_Grid -/* -UILayoutTest_Layout_Grid::UILayoutTest_Layout_Grid() -{ -} - -UILayoutTest_Layout_Grid::~UILayoutTest_Layout_Grid() -{ -} - -bool UILayoutTest_Layout_Grid::init() -{ - if (UIScene::init()) - { - Size widgetSize = _widget->getSize(); - - // Add the alert - Text* alert = Text::create(); - alert->setText("Layout Grid"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(20); - alert->setColor(Color3B(159, 168, 176)); - alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5f)); - _uiLayer->addChild(alert); - - Layout* root = static_cast(_uiLayer->getChildByTag(81)); - - Layout* background = dynamic_cast(root->getChildByName("background_Panel")); - - // Create the layout - Layout* layout = Layout::create(); - layout->setLayoutType(LAYOUT_GRID_MODE_COLUMN); - layout->setSize(Size(280, 150)); - Size backgroundSize = background->getSize(); - layout->setPosition(Point((widgetSize.width - backgroundSize.width) / 2.0f + - (backgroundSize.width - layout->getSize().width) / 2.0f, - (widgetSize.height - backgroundSize.height) / 2.0f + - (backgroundSize.height - layout->getSize().height) / 2.0f)); - _uiLayer->addChild(layout); - - - // create items - for (int i = 0; i < 14; ++i) - { - Button* button = Button::create(); - button->setName("TextButton"); - button->setTouchEnabled(true); - button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); - button->setScale9Enabled(true); - AffineTransform transform = AffineTransformMakeIdentity(); - transform = AffineTransformScale(transform, 3.0f, 1.3f); - button->setSize(SizeApplyAffineTransform(button->getContentSize(), transform)); - button->setTitleText(CCString::createWithFormat("grid_%d", i)->getCString()); - - Layout* item = Layout::create(); - item->setTouchEnabled(true); - item->setSize(button->getSize()); - button->setPosition(Point(item->getSize().width / 2.0f, item->getSize().height / 2.0f)); - item->addChild(button); - - GridLayoutParameter* gp = GridLayoutParameter::create(); - item->setLayoutParameter(gp); - gp->setMargin(Margin(0.0f, 0.0f, 0.0f, 0.0f)); - - layout->addChild(item); - } - - // set grid view row and column - Widget* item = static_cast(layout->getChildren().at(0)); - int rowCount = layout->getSize().height / item->getSize().height; - int columnCount = layout->getSize().width / item->getSize().width; - layout->setGridLayoutRowAndColumnCount(rowCount, columnCount); - -// layout->doLayout(); - - return true; - } - - return false; -} - */ - From 278e2c3e3b44625e05a05386eb8fdbd145e456bb Mon Sep 17 00:00:00 2001 From: andyque Date: Thu, 3 Apr 2014 11:23:12 +0800 Subject: [PATCH 14/66] issue #4636. finish UIListViewTest --- .../UIListViewTest/UIListViewTest.cpp | 58 +++++++------------ 1 file changed, 20 insertions(+), 38 deletions(-) diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp index b62cc9224c..513fd81637 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp @@ -24,21 +24,17 @@ bool UIListViewTest_Vertical::init() { Size widgetSize = _widget->getSize(); - _displayValueLabel = Text::create(); - _displayValueLabel->setText("Move by vertical direction"); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); - _displayValueLabel->setFontSize(32); + _displayValueLabel = Text::create("Move by vertical direction", "fonts/Marker Felt.ttf", 32); _displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f)); - _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f)); + _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f)); _uiLayer->addChild(_displayValueLabel); - Text* alert = Text::create(); - alert->setText("ListView vertical"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("ListView vertical", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); - alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); + alert->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); _uiLayer->addChild(alert); Layout* root = static_cast(_uiLayer->getChildByTag(81)); @@ -75,15 +71,14 @@ bool UIListViewTest_Vertical::init() // create model - Button* default_button = Button::create(); + Button* default_button = Button::create("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png"); default_button->setName("Title Button"); - default_button->setTouchEnabled(true); - default_button->loadTextures("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png", ""); Layout* default_item = Layout::create(); default_item->setTouchEnabled(true); default_item->setSize(default_button->getSize()); - default_button->setPosition(Point(default_item->getSize().width / 2.0f, default_item->getSize().height / 2.0f)); + default_button->setPosition(Point(default_item->getSize().width / 2.0f, + default_item->getSize().height / 2.0f)); default_item->addChild(default_button); // set model @@ -104,10 +99,8 @@ bool UIListViewTest_Vertical::init() // add custom item for (int i = 0; i < count / 4; ++i) { - Button* custom_button = Button::create(); + Button* custom_button = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); custom_button->setName("Title Button"); - custom_button->setTouchEnabled(true); - custom_button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); custom_button->setScale9Enabled(true); custom_button->setSize(default_button->getSize()); @@ -123,10 +116,8 @@ bool UIListViewTest_Vertical::init() ssize_t items_count = items.size(); for (int i = 0; i < count / 4; ++i) { - Button* custom_button = Button::create(); + Button* custom_button = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); custom_button->setName("Title Button"); - custom_button->setTouchEnabled(true); - custom_button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); custom_button->setScale9Enabled(true); custom_button->setSize(default_button->getSize()); @@ -209,19 +200,16 @@ bool UIListViewTest_Horizontal::init() { Size widgetSize = _widget->getSize(); - _displayValueLabel = Text::create(); - _displayValueLabel->setText("Move by horizontal direction"); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); - _displayValueLabel->setFontSize(32); + _displayValueLabel = Text::create("Move by horizontal direction", "fonts/Marker Felt.ttf", 32); _displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f)); - _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f)); + _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f + + _displayValueLabel->getContentSize().height * 1.5f)); + _uiLayer->addChild(_displayValueLabel); - Text* alert = Text::create(); - alert->setText("ListView horizontal"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("ListView horizontal", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); _uiLayer->addChild(alert); @@ -260,10 +248,8 @@ bool UIListViewTest_Horizontal::init() // create model - Button* default_button = Button::create(); + Button* default_button = Button::create("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png"); default_button->setName("Title Button"); - default_button->setTouchEnabled(true); - default_button->loadTextures("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png", ""); Layout *default_item = Layout::create(); default_item->setTouchEnabled(true); @@ -289,10 +275,8 @@ bool UIListViewTest_Horizontal::init() // add custom item for (int i = 0; i < count / 4; ++i) { - Button* custom_button = Button::create(); + Button* custom_button = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); custom_button->setName("Title Button"); - custom_button->setTouchEnabled(true); - custom_button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); custom_button->setScale9Enabled(true); custom_button->setSize(default_button->getSize()); @@ -308,10 +292,8 @@ bool UIListViewTest_Horizontal::init() ssize_t items_count = items.size(); for (int i = 0; i < count / 4; ++i) { - Button* custom_button = Button::create(); + Button* custom_button = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); custom_button->setName("Title Button"); - custom_button->setTouchEnabled(true); - custom_button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); custom_button->setScale9Enabled(true); custom_button->setSize(default_button->getSize()); From 48429f5738249f0f790fcdcbb750c327c05c6a28 Mon Sep 17 00:00:00 2001 From: andyque Date: Thu, 3 Apr 2014 11:34:06 +0800 Subject: [PATCH 15/66] issue #4636. finish UILoadingBar --- cocos/ui/UILoadingBar.cpp | 8 +-- .../UILoadingBarTest/UILoadingBarTest.cpp | 49 +++++++------------ 2 files changed, 22 insertions(+), 35 deletions(-) diff --git a/cocos/ui/UILoadingBar.cpp b/cocos/ui/UILoadingBar.cpp index 8a19c6e2f9..c6b5191bd0 100644 --- a/cocos/ui/UILoadingBar.cpp +++ b/cocos/ui/UILoadingBar.cpp @@ -132,7 +132,7 @@ int LoadingBar::getDirection() if (_scale9Enabled) { extension::Scale9Sprite* barRendererScale9 = static_cast(_barRenderer); - barRendererScale9->initWithFile(texture.c_str()); + barRendererScale9->initWithFile(texture); barRendererScale9->setCapInsets(_capInsets); } else @@ -144,7 +144,7 @@ int LoadingBar::getDirection() if (_scale9Enabled) { extension::Scale9Sprite* barRendererScale9 = static_cast(_barRenderer); - barRendererScale9->initWithSpriteFrameName(texture.c_str()); + barRendererScale9->initWithSpriteFrameName(texture); barRendererScale9->setCapInsets(_capInsets); } else @@ -195,7 +195,7 @@ void LoadingBar::setScale9Enabled(bool enabled) { _barRenderer = Sprite::create(); } - loadTexture(_textureFile.c_str(),_renderBarTexType); + loadTexture(_textureFile,_renderBarTexType); addProtectedChild(_barRenderer, BAR_RENDERER_Z, -1); if (_scale9Enabled) { @@ -371,7 +371,7 @@ void LoadingBar::copySpecialProperties(Widget *widget) { _prevIgnoreSize = loadingBar->_prevIgnoreSize; setScale9Enabled(loadingBar->_scale9Enabled); - loadTexture(loadingBar->_textureFile.c_str(), loadingBar->_renderBarTexType); + loadTexture(loadingBar->_textureFile, loadingBar->_renderBarTexType); setCapInsets(loadingBar->_capInsets); setPercent(loadingBar->_percent); setDirection(loadingBar->_barType); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp index 797268c09f..b728db0634 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp @@ -25,10 +25,7 @@ bool UILoadingBarTest_Left::init() Size widgetSize = _widget->getSize(); // Add the alert - Text* alert = Text::create(); - alert->setText("LoadingBar left"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("LoadingBar left", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); _uiLayer->addChild(alert); @@ -36,10 +33,9 @@ bool UILoadingBarTest_Left::init() // Create the loading bar LoadingBar* loadingBar = LoadingBar::create("cocosui/sliderProgress.png"); loadingBar->setTag(0); -// loadingBar->loadTexture("cocosui/sliderProgress.png"); -// loadingBar->setPercent(0); + loadingBar->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f)); - loadingBar->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f)); _uiLayer->addChild(loadingBar); return true; @@ -107,22 +103,19 @@ bool UILoadingBarTest_Right::init() Size widgetSize = _widget->getSize(); // Add the alert - Text *alert = Text::create(); - alert->setText("LoadingBar right"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text *alert = Text::create("LoadingBar right", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); _uiLayer->addChild(alert); // Create the loading bar - LoadingBar* loadingBar = LoadingBar::create(); + LoadingBar* loadingBar = LoadingBar::create("cocosui/sliderProgress.png"); loadingBar->setTag(0); - loadingBar->loadTexture("cocosui/sliderProgress.png"); loadingBar->setDirection(LoadingBarTypeRight); - loadingBar->setPercent(0); - loadingBar->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f)); + loadingBar->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f)); + _uiLayer->addChild(loadingBar); return true; @@ -190,24 +183,21 @@ bool UILoadingBarTest_Left_Scale9::init() Size widgetSize = _widget->getSize(); // Add the alert - Text* alert = Text::create(); - alert->setText("LoadingBar left scale9 render"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(20); + Text* alert = Text::create("LoadingBar left scale9 render", "fonts/Marker Felt.ttf", 20); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.7f)); _uiLayer->addChild(alert); // Create the loading bar - LoadingBar* loadingBar = LoadingBar::create(); + LoadingBar* loadingBar = LoadingBar::create("cocosui/slider_bar_active_9patch.png"); loadingBar->setTag(0); - loadingBar->loadTexture("cocosui/slider_bar_active_9patch.png"); loadingBar->setScale9Enabled(true); loadingBar->setCapInsets(Rect(0, 0, 0, 0)); loadingBar->setSize(Size(300, loadingBar->getContentSize().height)); - loadingBar->setPercent(0); - loadingBar->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f)); + loadingBar->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f)); + _uiLayer->addChild(loadingBar); return true; @@ -275,25 +265,22 @@ bool UILoadingBarTest_Right_Scale9::init() Size widgetSize = _widget->getSize(); // Add the alert - Text *alert = Text::create(); - alert->setText("LoadingBar right scale9 render"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(20); + Text *alert = Text::create("LoadingBar right scale9 render", "fonts/Marker Felt.ttf", 20); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.7f)); _uiLayer->addChild(alert); // Create the loading bar - LoadingBar* loadingBar = LoadingBar::create(); + LoadingBar* loadingBar = LoadingBar::create("cocosui/slider_bar_active_9patch.png"); loadingBar->setTag(0); - loadingBar->loadTexture("cocosui/slider_bar_active_9patch.png"); loadingBar->setScale9Enabled(true); loadingBar->setCapInsets(Rect(0, 0, 0, 0)); loadingBar->setSize(Size(300, loadingBar->getContentSize().height)); loadingBar->setDirection(LoadingBarTypeRight); - loadingBar->setPercent(0); - loadingBar->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f)); + loadingBar->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f)); + _uiLayer->addChild(loadingBar); return true; From 8b9af0e94c5cb9b89bd1c72a6735e123a7afea1d Mon Sep 17 00:00:00 2001 From: andyque Date: Thu, 3 Apr 2014 11:52:35 +0800 Subject: [PATCH 16/66] issue #4636. finish UIPageViewTest --- .../UIPageViewTest/UIPageViewTest.cpp | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp index 175eb55651..2680ef031c 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp @@ -21,19 +21,15 @@ bool UIPageViewTest::init() Size widgetSize = _widget->getSize(); // Add a label in which the dragpanel events will be displayed - _displayValueLabel = Text::create(); - _displayValueLabel->setText("Move by horizontal direction"); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); - _displayValueLabel->setFontSize(32); + _displayValueLabel = Text::create("Move by horizontal direction", "fonts/Marker Felt.ttf", 32); _displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f)); - _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5)); + _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f + + _displayValueLabel->getContentSize().height * 1.5)); _uiLayer->addChild(_displayValueLabel); // Add the black background - Text* alert = Text::create(); - alert->setText("PageView"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("PageView", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); _uiLayer->addChild(alert); @@ -44,7 +40,6 @@ bool UIPageViewTest::init() // Create the page view PageView* pageView = PageView::create(); - pageView->setTouchEnabled(true); pageView->setSize(Size(240.0f, 130.0f)); Size backgroundSize = background->getContentSize(); pageView->setPosition(Point((widgetSize.width - backgroundSize.width) / 2.0f + @@ -57,18 +52,14 @@ bool UIPageViewTest::init() Layout* layout = Layout::create(); layout->setSize(Size(240.0f, 130.0f)); - ImageView* imageView = ImageView::create(); - imageView->setTouchEnabled(true); + ImageView* imageView = ImageView::create("cocosui/scrollviewbg.png"); imageView->setScale9Enabled(true); - imageView->loadTexture("cocosui/scrollviewbg.png"); imageView->setSize(Size(240, 130)); imageView->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(imageView); - Text* label = Text::create(); - label->setText(CCString::createWithFormat("page %d", (i + 1))->getCString()); - label->setFontName("fonts/Marker Felt.ttf"); - label->setFontSize(30); + __String *textContent = __String::createWithFormat("page %d", (i + 1)); + Text* label = Text::create(textContent->getCString(), "fonts/Marker Felt.ttf", 30); label->setColor(Color3B(192, 192, 192)); label->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(label); From a7a1a6b05b8593fe1566a9d4278af686d1f82790 Mon Sep 17 00:00:00 2001 From: andyque Date: Thu, 3 Apr 2014 15:22:23 +0800 Subject: [PATCH 17/66] issue #4636, finish UIRichTextTest and UIScrollViewTest --- .../UIRichTextTest/UIRichTextTest.cpp | 8 +- .../UIScrollViewTest/UIScrollViewTest.cpp | 95 +++++-------------- 2 files changed, 25 insertions(+), 78 deletions(-) diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp index 84b3af3f59..b1031d616d 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp @@ -21,18 +21,14 @@ bool UIRichTextTest::init() Size widgetSize = _widget->getSize(); // Add the alert - Text *alert = Text::create(); - alert->setText("RichText"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.125)); _widget->addChild(alert); - Button* button = Button::create(); + Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setTouchEnabled(true); - button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); button->setTitleText("switch"); button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + button->getSize().height * 2.5)); button->addTouchEventListener(this, toucheventselector(UIRichTextTest::touchEvent)); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp index 3edbc63428..40fe24d6d3 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp @@ -21,19 +21,14 @@ bool UIScrollViewTest_Vertical::init() Size widgetSize = _widget->getSize(); // Add a label in which the scrollview alert will be displayed - _displayValueLabel = Text::create(); - _displayValueLabel->setText("Move by vertical direction"); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); - _displayValueLabel->setFontSize(32); + _displayValueLabel = Text::create("Move by vertical direction", "fonts/Marker Felt.ttf", 32); _displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f)); - _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f)); + _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f)); _uiLayer->addChild(_displayValueLabel); // Add the alert - Text* alert = Text::create(); - alert->setText("ScrollView vertical"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("ScrollView vertical", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); _uiLayer->addChild(alert); @@ -44,7 +39,6 @@ bool UIScrollViewTest_Vertical::init() // Create the scrollview by vertical ui::ScrollView* scrollView = ui::ScrollView::create(); - scrollView->setTouchEnabled(true); scrollView->setSize(Size(280.0f, 150.0f)); Size backgroundSize = background->getContentSize(); scrollView->setPosition(Point((widgetSize.width - backgroundSize.width) / 2.0f + @@ -53,31 +47,24 @@ bool UIScrollViewTest_Vertical::init() (backgroundSize.height - scrollView->getSize().height) / 2.0f)); _uiLayer->addChild(scrollView); - ImageView* imageView = ImageView::create(); - imageView->loadTexture("cocosui/ccicon.png"); + ImageView* imageView = ImageView::create("cocosui/ccicon.png"); float innerWidth = scrollView->getSize().width; float innerHeight = scrollView->getSize().height + imageView->getSize().height; scrollView->setInnerContainerSize(Size(innerWidth, innerHeight)); - Button* button = Button::create(); - button->setTouchEnabled(true); - button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setPosition(Point(innerWidth / 2.0f, scrollView->getInnerContainerSize().height - button->getSize().height / 2.0f)); scrollView->addChild(button); - Button* titleButton = Button::create(); - titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); + Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); titleButton->setTitleText("Title Button"); titleButton->setPosition(Point(innerWidth / 2.0f, button->getBottomInParent() - button->getSize().height)); scrollView->addChild(titleButton); - Button* button_scale9 = Button::create(); - button_scale9->setTouchEnabled(true); + Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); button_scale9->setPosition(Point(innerWidth / 2.0f, titleButton->getBottomInParent() - titleButton->getSize().height)); scrollView->addChild(button_scale9); @@ -109,18 +96,12 @@ bool UIScrollViewTest_Horizontal::init() Size widgetSize = _widget->getSize(); // Add a label in which the scrollview alert will be displayed - _displayValueLabel = Text::create(); - _displayValueLabel->setText("Move by horizontal direction"); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); - _displayValueLabel->setFontSize(32); + _displayValueLabel = Text::create("Move by horizontal direction","fonts/Marker Felt.ttf",32); _displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f)); _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f)); _uiLayer->addChild(_displayValueLabel); - Text* alert = Text::create(); - alert->setText("ScrollView horizontal"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("ScrollView horizontal","fonts/Marker Felt.ttf",30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); _uiLayer->addChild(alert); @@ -133,7 +114,6 @@ bool UIScrollViewTest_Horizontal::init() ui::ScrollView* scrollView = ui::ScrollView::create(); scrollView->setBounceEnabled(true); scrollView->setDirection(SCROLLVIEW_DIR_HORIZONTAL); - scrollView->setTouchEnabled(true); scrollView->setSize(Size(280.0f, 150.0f)); scrollView->setInnerContainerSize(scrollView->getSize()); Size backgroundSize = background->getContentSize(); @@ -143,33 +123,26 @@ bool UIScrollViewTest_Horizontal::init() (backgroundSize.height - scrollView->getSize().height) / 2.0f)); _uiLayer->addChild(scrollView); - ImageView* imageView = ImageView::create(); - imageView->loadTexture("cocosui/ccicon.png"); + ImageView* imageView = ImageView::create("cocosui/ccicon.png"); float innerWidth = scrollView->getSize().width + imageView->getSize().width; float innerHeight = scrollView->getSize().height; scrollView->setInnerContainerSize(Size(innerWidth, innerHeight)); - Button* button = Button::create(); - button->setTouchEnabled(true); - button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setPosition(Point(button->getSize().width / 2.0f, scrollView->getInnerContainerSize().height - button->getSize().height / 2.0f)); scrollView->addChild(button); - Button* titleButton = Button::create(); - titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); + Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); titleButton->setTitleText("Title Button"); titleButton->setPosition(Point(button->getRightInParent() + button->getSize().width / 2.0f, button->getBottomInParent() - button->getSize().height / 2.0f)); scrollView->addChild(titleButton); - Button* button_scale9 = Button::create(); - button_scale9->setTouchEnabled(true); + Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); button_scale9->setPosition(Point(titleButton->getRightInParent() + titleButton->getSize().width / 2.0f, titleButton->getBottomInParent() - titleButton->getSize().height / 2.0f)); @@ -203,19 +176,13 @@ bool UIScrollViewTest_Both::init() Size widgetSize = _widget->getSize();; // Add a label in which the dragpanel events will be displayed - _displayValueLabel = Text::create(); - _displayValueLabel->setText("Move by any direction"); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); - _displayValueLabel->setFontSize(32); + _displayValueLabel = Text::create("Move by any direction","fonts/Marker Felt.ttf",32); _displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f)); _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getSize().height * 1.5f)); _uiLayer->addChild(_displayValueLabel); // Add the alert - Text* alert = Text::create(); - alert->setText("ScrollView both"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("ScrollView both","fonts/Marker Felt.ttf",30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); _uiLayer->addChild(alert); @@ -237,9 +204,7 @@ bool UIScrollViewTest_Both::init() (backgroundSize.width - scrollView->getSize().width) / 2.0f, (widgetSize.height - backgroundSize.height) / 2.0f + (backgroundSize.height - scrollView->getSize().height) / 2.0f)); - ImageView* imageView = ImageView::create(); - imageView->setTouchEnabled(true); - imageView->loadTexture("Hello.png"); + ImageView* imageView = ImageView::create("Hello.png"); scrollView->addChild(imageView); scrollView->setInnerContainerSize(imageView->getContentSize()); @@ -272,19 +237,13 @@ bool UIScrollViewTest_ScrollToPercentBothDirection::init() Size widgetSize = _widget->getSize(); // Add a label in which the dragpanel events will be displayed - _displayValueLabel = Text::create(); -// _displayValueLabel->setText("No Event"); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); - _displayValueLabel->setFontSize(32); + _displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf",30); _displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f)); _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getSize().height * 1.5f)); _uiLayer->addChild(_displayValueLabel); // Add the alert - Text* alert = Text::create(); - alert->setText("ScrollView scroll to percent both directrion"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(20); + Text* alert = Text::create("ScrollView scroll to percent both directrion","fonts/Marker Felt.ttf",20); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5)); _uiLayer->addChild(alert); @@ -305,8 +264,7 @@ bool UIScrollViewTest_ScrollToPercentBothDirection::init() (widgetSize.height - backgroundSize.height) / 2.0f + (backgroundSize.height - sc->getSize().height) / 2.0f)); sc->scrollToPercentBothDirection(Point(50, 50), 1, true); - ImageView* iv = ImageView::create(); - iv->loadTexture("cocosui/Hello.png"); + ImageView* iv = ImageView::create("cocosui/Hello.png"); iv->setPosition(Point(240, 160)); sc->addChild(iv); _uiLayer->addChild(sc); @@ -334,19 +292,13 @@ bool UIScrollViewTest_ScrollToPercentBothDirection_Bounce::init() Size widgetSize = _widget->getSize(); // Add a label in which the dragpanel events will be displayed - _displayValueLabel = Text::create(); -// _displayValueLabel->setText("No Event"); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); - _displayValueLabel->setFontSize(32); + _displayValueLabel = Text::create("No Event","fonts/Marker Felt.ttf",32); _displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f)); _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getSize().height * 1.5f)); _uiLayer->addChild(_displayValueLabel); // Add the alert - Text* alert = Text::create(); - alert->setText("ScrollView scroll to percent both directrion bounce"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(20); + Text* alert = Text::create("ScrollView scroll to percent both directrion bounce","fonts/Marker Felt.ttf",20); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5)); _uiLayer->addChild(alert); @@ -368,8 +320,7 @@ bool UIScrollViewTest_ScrollToPercentBothDirection_Bounce::init() (widgetSize.height - backgroundSize.height) / 2.0f + (backgroundSize.height - sc->getSize().height) / 2.0f)); sc->scrollToPercentBothDirection(Point(50, 50), 1, true); - ImageView* iv = ImageView::create(); - iv->loadTexture("cocosui/Hello.png"); + ImageView* iv = ImageView::create("cocosui/Hello.png"); iv->setPosition(Point(240, 160)); sc->addChild(iv); _uiLayer->addChild(sc); From b59beab61a3dd776f6630bde1b5117017f61f280 Mon Sep 17 00:00:00 2001 From: andyque Date: Thu, 3 Apr 2014 15:33:57 +0800 Subject: [PATCH 18/66] issue #4636, finish UISlider --- cocos/ui/UISlider.cpp | 36 ++++++------- cocos/ui/UISlider.h | 15 +++--- .../UISliderTest/UISliderTest.cpp | 51 ++----------------- 3 files changed, 31 insertions(+), 71 deletions(-) diff --git a/cocos/ui/UISlider.cpp b/cocos/ui/UISlider.cpp index 7d03f3d0f4..a50279cba2 100644 --- a/cocos/ui/UISlider.cpp +++ b/cocos/ui/UISlider.cpp @@ -111,9 +111,9 @@ void Slider::initRenderer() addProtectedChild(_slidBallRenderer, SLIDBALL_RENDERER_Z, -1); } -void Slider::loadBarTexture(const char* fileName, TextureResType texType) +void Slider::loadBarTexture(const std::string& fileName, TextureResType texType) { - if (!fileName || strcmp(fileName, "") == 0) + if (fileName.empty()) { return; } @@ -149,9 +149,9 @@ void Slider::loadBarTexture(const char* fileName, TextureResType texType) progressBarRendererScaleChangedWithSize(); } -void Slider::loadProgressBarTexture(const char *fileName, TextureResType texType) +void Slider::loadProgressBarTexture(const std::string& fileName, TextureResType texType) { - if (!fileName || strcmp(fileName, "") == 0) + if (fileName.empty()) { return; } @@ -210,8 +210,8 @@ void Slider::setScale9Enabled(bool able) _barRenderer = Sprite::create(); _progressBarRenderer = Sprite::create(); } - loadBarTexture(_textureFile.c_str(), _barTexType); - loadProgressBarTexture(_progressBarTextureFile.c_str(), _progressBarTexType); + loadBarTexture(_textureFile, _barTexType); + loadProgressBarTexture(_progressBarTextureFile, _progressBarTexType); addProtectedChild(_barRenderer, BASEBAR_RENDERER_Z, -1); addProtectedChild(_progressBarRenderer, PROGRESSBAR_RENDERER_Z, -1); if (_scale9Enabled) @@ -278,16 +278,16 @@ const Rect& Slider::getCapInsetsProgressBarRebderer() return _capInsetsProgressBarRenderer; } -void Slider::loadSlidBallTextures(const char* normal,const char* pressed,const char* disabled,TextureResType texType) + void Slider::loadSlidBallTextures(const std::string& normal,const std::string& pressed,const std::string& disabled,TextureResType texType) { loadSlidBallTextureNormal(normal, texType); loadSlidBallTexturePressed(pressed,texType); loadSlidBallTextureDisabled(disabled,texType); } -void Slider::loadSlidBallTextureNormal(const char* normal,TextureResType texType) +void Slider::loadSlidBallTextureNormal(const std::string& normal,TextureResType texType) { - if (!normal || strcmp(normal, "") == 0) + if (normal.empty()) { return; } @@ -307,9 +307,9 @@ void Slider::loadSlidBallTextureNormal(const char* normal,TextureResType texType updateRGBAToRenderer(_slidBallNormalRenderer); } -void Slider::loadSlidBallTexturePressed(const char* pressed,TextureResType texType) +void Slider::loadSlidBallTexturePressed(const std::string& pressed,TextureResType texType) { - if (!pressed || strcmp(pressed, "") == 0) + if (pressed.empty()) { return; } @@ -329,9 +329,9 @@ void Slider::loadSlidBallTexturePressed(const char* pressed,TextureResType texTy updateRGBAToRenderer(_slidBallPressedRenderer); } -void Slider::loadSlidBallTextureDisabled(const char* disabled,TextureResType texType) + void Slider::loadSlidBallTextureDisabled(const std::string& disabled,TextureResType texType) { - if (!disabled || strcmp(disabled, "") == 0) + if (disabled.empty()) { return; } @@ -596,11 +596,11 @@ void Slider::copySpecialProperties(Widget *widget) { _prevIgnoreSize = slider->_prevIgnoreSize; setScale9Enabled(slider->_scale9Enabled); - loadBarTexture(slider->_textureFile.c_str(), slider->_barTexType); - loadProgressBarTexture(slider->_progressBarTextureFile.c_str(), slider->_progressBarTexType); - loadSlidBallTextureNormal(slider->_slidBallNormalTextureFile.c_str(), slider->_ballNTexType); - loadSlidBallTexturePressed(slider->_slidBallPressedTextureFile.c_str(), slider->_ballPTexType); - loadSlidBallTextureDisabled(slider->_slidBallDisabledTextureFile.c_str(), slider->_ballDTexType); + loadBarTexture(slider->_textureFile, slider->_barTexType); + loadProgressBarTexture(slider->_progressBarTextureFile, slider->_progressBarTexType); + loadSlidBallTextureNormal(slider->_slidBallNormalTextureFile, slider->_ballNTexType); + loadSlidBallTexturePressed(slider->_slidBallPressedTextureFile, slider->_ballPTexType); + loadSlidBallTextureDisabled(slider->_slidBallDisabledTextureFile, slider->_ballDTexType); setPercent(slider->getPercent()); } } diff --git a/cocos/ui/UISlider.h b/cocos/ui/UISlider.h index de702eacef..3a109b3ac4 100644 --- a/cocos/ui/UISlider.h +++ b/cocos/ui/UISlider.h @@ -71,7 +71,7 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadBarTexture(const char* fileName,TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadBarTexture(const std::string& fileName,TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Sets if slider is using scale9 renderer. @@ -118,7 +118,10 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadSlidBallTextures(const char* normal,const char* pressed,const char* disabled,TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadSlidBallTextures(const std::string& normal, + const std::string& pressed, + const std::string& disabled, + TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Load normal state texture for slider ball. @@ -127,7 +130,7 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadSlidBallTextureNormal(const char* normal,TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadSlidBallTextureNormal(const std::string& normal,TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Load selected state texture for slider ball. @@ -136,7 +139,7 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadSlidBallTexturePressed(const char* pressed,TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadSlidBallTexturePressed(const std::string& pressed,TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Load dark state texture for slider ball. @@ -145,7 +148,7 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadSlidBallTextureDisabled(const char* disabled,TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadSlidBallTextureDisabled(const std::string& disabled,TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Load dark state texture for slider progress bar. @@ -154,7 +157,7 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadProgressBarTexture(const char* fileName, TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadProgressBarTexture(const std::string& fileName, TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Changes the progress direction of slider. diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp index a87171c2c2..263cf5da0a 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp @@ -22,26 +22,19 @@ bool UISliderTest::init() Size widgetSize = _widget->getSize(); // Add a label in which the slider alert will be displayed - _displayValueLabel = Text::create(); - _displayValueLabel->setText("Move the slider thumb"); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); - _displayValueLabel->setFontSize(32); + _displayValueLabel = Text::create("Move the slider thumb","Move the slider thumb",32); _displayValueLabel->setAnchorPoint(Point(0.5f, -1)); _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); _uiLayer->addChild(_displayValueLabel); // Add the alert - Text* alert = Text::create(); - alert->setText("Slider"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("Slider","fonts/Marker Felt.ttf",30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); _uiLayer->addChild(alert); // Create the slider Slider* slider = Slider::create(); - slider->setTouchEnabled(true); slider->loadBarTexture("cocosui/sliderTrack.png"); slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", ""); slider->loadProgressBarTexture("cocosui/sliderProgress.png"); @@ -49,19 +42,6 @@ bool UISliderTest::init() slider->addEventListenerSlider(this, sliderpercentchangedselector(UISliderTest::sliderEvent)); _uiLayer->addChild(slider); - /* - // Create the slider that set allow min progress and allow max progress - Slider* sliderAllow = Slider::create(); -// sliderAllow->setMinAllowPercent(20); -// sliderAllow->setMaxAllowPercent(80); - sliderAllow->setTouchEnabled(true); - sliderAllow->loadBarTexture("cocosui/sliderTrack.png"); - sliderAllow->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", ""); - sliderAllow->loadProgressBarTexture("cocosui/sliderProgress.png"); - sliderAllow->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - sliderAllow->getSize().height * 2.0f)); - sliderAllow->addEventListenerSlider(this, sliderpercentchangedselector(UISliderTest::sliderEvent)); - _uiLayer->addChild(sliderAllow); - */ return true; } @@ -97,26 +77,19 @@ bool UISliderTest_Scale9::init() Size widgetSize = _widget->getSize(); // Add a label in which the slider alert will be displayed - _displayValueLabel = Text::create(); - _displayValueLabel->setText("Move the slider thumb"); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); - _displayValueLabel->setFontSize(32); + _displayValueLabel = Text::create("Move the slider thumb","fonts/Marker Felt.ttf",32); _displayValueLabel->setAnchorPoint(Point(0.5f, -1)); _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); _uiLayer->addChild(_displayValueLabel); // Add the alert - Text *alert = Text::create(); - alert->setText("Slider scale9 render"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text *alert = Text::create("Slider scale9 render","fonts/Marker Felt.ttf",30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); _uiLayer->addChild(alert); // Create the slider Slider* slider = Slider::create(); - slider->setTouchEnabled(true); slider->loadBarTexture("cocosui/sliderTrack2.png"); slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", ""); slider->loadProgressBarTexture("cocosui/slider_bar_active_9patch.png"); @@ -127,22 +100,6 @@ bool UISliderTest_Scale9::init() slider->addEventListenerSlider(this, sliderpercentchangedselector(UISliderTest_Scale9::sliderEvent)); _uiLayer->addChild(slider); - /* - // Create the slider that set allow min progress and allow max progress - Slider* sliderAllow = Slider::create(); -// sliderAllow->setMinAllowPercent(20); -// sliderAllow->setMaxAllowPercent(80); - sliderAllow->setTouchEnabled(true); - sliderAllow->loadBarTexture("cocosui/sliderTrack2.png"); - sliderAllow->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", ""); - sliderAllow->loadProgressBarTexture("cocosui/slider_bar_active_9patch.png"); - sliderAllow->setScale9Enabled(true); - sliderAllow->setCapInsets(Rect(0, 0, 0, 0)); - sliderAllow->setSize(Size(250.0f, 10.0f / Director::getInstance()->getContentScaleFactor())); - sliderAllow->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - slider->getSize().height * 3.0f)); - sliderAllow->addEventListenerSlider(this, sliderpercentchangedselector(UISliderTest_Scale9::sliderEvent)); - _uiLayer->addChild(sliderAllow); - */ return true; } From 08bf6c27f4f226e6632fa716e2cd9e1b8bbfc683 Mon Sep 17 00:00:00 2001 From: andyque Date: Thu, 3 Apr 2014 15:38:52 +0800 Subject: [PATCH 19/66] issue #4636. finish UITextAtlasTest --- .../CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp index f980f5be3f..a557b33637 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp @@ -12,17 +12,13 @@ bool UITextAtlasTest::init() Size widgetSize = _widget->getSize(); // Add the alert - Text* alert = Text::create(); - alert->setText("TextAtlas"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("TextAtlas","fonts/Marker Felt.ttf",30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); _uiLayer->addChild(alert); // Create the text atlas TextAtlas* textAtlas = TextAtlas::create("1234567890", "cocosui/labelatlas.png", 17, 22, "0"); -// textAtlas->setProperty("1234567890", "cocosui/labelatlas.png", 17, 22, "0"); textAtlas->setPosition(Point((widgetSize.width) / 2, widgetSize.height / 2.0f)); _uiLayer->addChild(textAtlas); From ed2c38eb9851bc9ae75cf793894c59f03ed183a5 Mon Sep 17 00:00:00 2001 From: andyque Date: Thu, 3 Apr 2014 15:45:06 +0800 Subject: [PATCH 20/66] issue #4636, finish UITextBMFont --- cocos/ui/UITextBMFont.cpp | 6 +++--- .../UITextBMFontTest/UITextBMFontTest.cpp | 7 +------ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/cocos/ui/UITextBMFont.cpp b/cocos/ui/UITextBMFont.cpp index 6574d3ee20..85b893fa9f 100644 --- a/cocos/ui/UITextBMFont.cpp +++ b/cocos/ui/UITextBMFont.cpp @@ -88,7 +88,7 @@ void TextBMFont::setFntFile(const std::string& fileName) updateAnchorPoint(); labelBMFontScaleChangedWithSize(); _fntFileHasInit = true; - setText(_stringValue.c_str()); + setText(_stringValue); } void TextBMFont::setText(const std::string& value) @@ -181,8 +181,8 @@ void TextBMFont::copySpecialProperties(Widget *widget) TextBMFont* labelBMFont = dynamic_cast(widget); if (labelBMFont) { - setFntFile(labelBMFont->_fntFileName.c_str()); - setText(labelBMFont->_stringValue.c_str()); + setFntFile(labelBMFont->_fntFileName); + setText(labelBMFont->_stringValue); } } diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp index 95f2081358..3af4948c3f 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp @@ -11,18 +11,13 @@ bool UITextBMFontTest::init() { Size widgetSize = _widget->getSize(); - Text* alert = Text::create(); - alert->setText("TextBMFont"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("TextBMFont","TextBMFont",30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); _uiLayer->addChild(alert); // Create the TextBMFont TextBMFont* textBMFont = TextBMFont::create("BMFont", "cocosui/bitmapFontTest2.fnt"); -// textBMFont->setFntFile("cocosui/bitmapFontTest2.fnt"); -// textBMFont->setText("BMFont"); textBMFont->setPosition(Point(widgetSize.width / 2, widgetSize.height / 2.0f + textBMFont->getSize().height / 8.0f)); _uiLayer->addChild(textBMFont); From 8996ab195607214f467435c002d5a528b0a0a21b Mon Sep 17 00:00:00 2001 From: andyque Date: Thu, 3 Apr 2014 15:52:42 +0800 Subject: [PATCH 21/66] issue #4636, finish refactorying UITextFieldTest --- .../UITextFieldTest/UITextFieldTest.cpp | 60 ++++--------------- 1 file changed, 11 insertions(+), 49 deletions(-) diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp index a958f30932..caea297d54 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp @@ -20,19 +20,13 @@ bool UITextFieldTest::init() Size widgetSize = _widget->getSize(); // Add a label in which the textfield events will be displayed - _displayValueLabel = Text::create(); - _displayValueLabel->setText("No Event"); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); - _displayValueLabel->setFontSize(32); + _displayValueLabel = Text::create("No Event","fonts/Marker Felt.ttf",32); _displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f)); _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getSize().height * 1.5f)); _uiLayer->addChild(_displayValueLabel); // Add the alert - Text* alert = Text::create(); - alert->setText("TextField"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("TextField","fonts/Marker Felt.ttf",30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); _uiLayer->addChild(alert); @@ -44,8 +38,6 @@ bool UITextFieldTest::init() textField->addEventListenerTextField(this, textfieldeventselector(UITextFieldTest::textFieldEvent)); _uiLayer->addChild(textField); -// textField->setColor(Color3B(255, 0, 0)); -// textField->setColorSpaceHolder(Color3B(255, 255, 255)); return true; } @@ -106,31 +98,21 @@ bool UITextFieldTest_MaxLength::init() Size screenSize = CCDirector::getInstance()->getWinSize(); // Add a label in which the textfield events will be displayed - _displayValueLabel = Text::create(); - _displayValueLabel->setText("No Event"); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); - _displayValueLabel->setFontSize(32); + _displayValueLabel = Text::create("No Event","fonts/Marker Felt.ttf",32); _displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f)); _displayValueLabel->setPosition(Point(screenSize.width / 2.0f, screenSize.height / 2.0f + _displayValueLabel->getSize().height * 1.5f)); _uiLayer->addChild(_displayValueLabel); // Add the alert - Text *alert = Text::create(); - alert->setText("TextField max length"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text *alert = Text::create("TextField max length","fonts/Marker Felt.ttf",30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getSize().height * 3.075f)); _uiLayer->addChild(alert); // Create the textfield - TextField* textField = TextField::create(); + TextField* textField = TextField::create("input words here","fonts/Marker Felt.ttf",30); textField->setMaxLengthEnabled(true); textField->setMaxLength(3); - textField->setTouchEnabled(true); - textField->setFontName("fonts/Marker Felt.ttf"); - textField->setFontSize(30); - textField->setPlaceHolder("input words here"); textField->setPosition(Point(screenSize.width / 2.0f, screenSize.height / 2.0f)); textField->addEventListenerTextField(this, textfieldeventselector(UITextFieldTest_MaxLength::textFieldEvent)); _uiLayer->addChild(textField); @@ -200,31 +182,21 @@ bool UITextFieldTest_Password::init() Size screenSize = CCDirector::getInstance()->getWinSize(); // Add a label in which the textfield events will be displayed - _displayValueLabel = Text::create(); - _displayValueLabel->setText("No Event"); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); - _displayValueLabel->setFontSize(32); + _displayValueLabel = Text::create("No Event","fonts/Marker Felt.ttf",32); _displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f)); _displayValueLabel->setPosition(Point(screenSize.width / 2.0f, screenSize.height / 2.0f + _displayValueLabel->getSize().height * 1.5f)); _uiLayer->addChild(_displayValueLabel); // Add the alert - Text *alert = Text::create(); - alert->setText("TextField password"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text *alert = Text::create("TextField password","fonts/Marker Felt.ttf",30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getSize().height * 3.075f)); _uiLayer->addChild(alert); // Create the textfield - TextField* textField = TextField::create(); + TextField* textField = TextField::create("input password here","fonts/Marker Felt.ttf",30); textField->setPasswordEnabled(true); textField->setPasswordStyleText("*"); - textField->setTouchEnabled(true); - textField->setFontName("fonts/Marker Felt.ttf"); - textField->setFontSize(30); - textField->setPlaceHolder("input password here"); textField->setPosition(Point(screenSize.width / 2.0f, screenSize.height / 2.0f)); textField->addEventListenerTextField(this, textfieldeventselector(UITextFieldTest_Password::textFieldEvent)); _uiLayer->addChild(textField); @@ -289,33 +261,23 @@ bool UITextFieldTest_LineWrap::init() Size widgetSize = _widget->getSize(); // Add a label in which the textfield events will be displayed - _displayValueLabel = Text::create(); - _displayValueLabel->setText("No Event"); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); - _displayValueLabel->setFontSize(30); + _displayValueLabel = Text::create("No Event","fonts/Marker Felt.ttf",30); _displayValueLabel->setAnchorPoint(Point(0.5f, -1)); _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getSize().height * 1.5)); _uiLayer->addChild(_displayValueLabel); // Add the alert - Text *alert = Text::create(); - alert->setText("TextField line wrap"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text *alert = Text::create("TextField line wrap","fonts/Marker Felt.ttf",30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075)); _uiLayer->addChild(alert); // Create the textfield - TextField* textField = TextField::create(); + TextField* textField = TextField::create("input words here","fonts/Marker Felt.ttf",30); textField->ignoreContentAdaptWithSize(false); textField->setSize(Size(240, 160)); textField->setTextHorizontalAlignment(TextHAlignment::CENTER); textField->setTextVerticalAlignment(TextVAlignment::CENTER); - textField->setTouchEnabled(true); - textField->setFontName("fonts/Marker Felt.ttf"); - textField->setFontSize(30); - textField->setPlaceHolder("input words here"); textField->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); textField->addEventListenerTextField(this, textfieldeventselector(UITextFieldTest_LineWrap::textFieldEvent)); _uiLayer->addChild(textField); From 0875b4e51fedffd501e5e2e44a0eb7f7ca2fd30c Mon Sep 17 00:00:00 2001 From: andyque Date: Thu, 3 Apr 2014 15:56:45 +0800 Subject: [PATCH 22/66] closed #4636. Done --- cocos/ui/UIText.cpp | 2 +- .../UITextTest/UITextTest.cpp | 26 +++---------------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/cocos/ui/UIText.cpp b/cocos/ui/UIText.cpp index f5d381e7f8..15fd6b5d57 100644 --- a/cocos/ui/UIText.cpp +++ b/cocos/ui/UIText.cpp @@ -313,7 +313,7 @@ void Text::copySpecialProperties(Widget *widget) Text* label = dynamic_cast(widget); if (label) { - setFontName(label->_fontName.c_str()); + setFontName(label->_fontName); setFontSize(label->_labelRenderer->getFontSize()); setText(label->getStringValue()); setTouchScaleChangeEnabled(label->_touchScaleChangeEnabled); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextTest/UITextTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextTest/UITextTest.cpp index 364b55d3a4..84a2de90af 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextTest/UITextTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextTest/UITextTest.cpp @@ -12,18 +12,12 @@ bool UITextTest::init() Size widgetSize = _widget->getSize(); Text* alert = Text::create("Text","fonts/Marker Felt.ttf", 30); -// alert->setText("Text"); -// alert->setFontName("fonts/Marker Felt.ttf"); -// alert->setFontSize(30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); _uiLayer->addChild(alert); // Create the text Text* text = Text::create("Text", "AmericanTypewriter", 30); -// text->setText("Text"); -// text->setFontName("AmericanTypewriter"); -// text->setFontSize(30); text->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + text->getSize().height / 4.0f)); _uiLayer->addChild(text); @@ -40,22 +34,16 @@ bool UITextTest_LineWrap::init() { Size widgetSize = _widget->getSize(); - Text* alert = Text::create(); - alert->setText("Text line wrap"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("Text line wrap","fonts/Marker Felt.ttf",30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); _uiLayer->addChild(alert); // Create the line wrap - Text* text = Text::create(); + Text* text = Text::create("Text can line wrap","AmericanTypewriter",32); text->ignoreContentAdaptWithSize(false); text->setSize(Size(280, 150)); text->setTextHorizontalAlignment(TextHAlignment::CENTER); - text->setText("Text can line wrap"); - text->setFontName("AmericanTypewriter"); - text->setFontSize(32); text->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - text->getSize().height / 8.0f)); _uiLayer->addChild(text); @@ -171,19 +159,13 @@ bool UITextTest_TTF::init() { Size widgetSize = _widget->getSize(); - Text* alert = Text::create(); - alert->setText("Text set TTF font"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("Text set TTF font","fonts/Marker Felt.ttf",30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); _uiLayer->addChild(alert); // Create the text, and set font with .ttf - Text* text = Text::create(); - text->setText("Text"); - text->setFontName("fonts/A Damn Mess.ttf"); - text->setFontSize(30); + Text* text = Text::create("Text","fonts/A Damn Mess.ttf",30); text->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + text->getSize().height / 4.0f)); _uiLayer->addChild(text); From 9bcfea2279be071d9c5d2e898c65fde986fa71a9 Mon Sep 17 00:00:00 2001 From: andyque Date: Thu, 3 Apr 2014 17:13:24 +0800 Subject: [PATCH 23/66] issue #4636. fix some typo --- cocos/ui/UIButton.h | 4 ++-- cocos/ui/UIImageView.h | 2 +- cocos/ui/UIText.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos/ui/UIButton.h b/cocos/ui/UIButton.h index 101d75bd74..42d9c1d22d 100644 --- a/cocos/ui/UIButton.h +++ b/cocos/ui/UIButton.h @@ -60,7 +60,7 @@ public: * create a button with custom textures * @normalImage normal state texture name * @selectedImage selected state texture name - * @disableImage disable state texture name + * @disableImage disabled state texture name * @param texType @see UI_TEX_TYPE_LOCAL */ static Button* create(const std::string& normalImage, @@ -76,7 +76,7 @@ public: * * @param selected selected state texture name. * - * @param disabled disable state texture name. + * @param disabled disabled state texture name. * * @param texType @see UI_TEX_TYPE_LOCAL */ diff --git a/cocos/ui/UIImageView.h b/cocos/ui/UIImageView.h index 3c8861dedd..97e1051e6e 100644 --- a/cocos/ui/UIImageView.h +++ b/cocos/ui/UIImageView.h @@ -57,7 +57,7 @@ public: static ImageView* create(); /** - * create a imageview object + * create a imageview * * @param fileName file name of texture. * diff --git a/cocos/ui/UIText.cpp b/cocos/ui/UIText.cpp index 15fd6b5d57..2cf57e5c65 100644 --- a/cocos/ui/UIText.cpp +++ b/cocos/ui/UIText.cpp @@ -77,7 +77,7 @@ Text* Text::create(const std::string &textContent, const std::string &fontName, return text; } CC_SAFE_DELETE(text); - return text; + return nullptr; } bool Text::init(const std::string &textContent, const std::string &fontName, int fontSize) From c501aa2dec85a9670a22e2ac9374408f6e916026 Mon Sep 17 00:00:00 2001 From: andyque Date: Thu, 3 Apr 2014 17:42:04 +0800 Subject: [PATCH 24/66] issue #4636. replace __String with StringUtils::format --- .../CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp index 2680ef031c..01d9e7d41c 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp @@ -58,8 +58,7 @@ bool UIPageViewTest::init() imageView->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(imageView); - __String *textContent = __String::createWithFormat("page %d", (i + 1)); - Text* label = Text::create(textContent->getCString(), "fonts/Marker Felt.ttf", 30); + Text* label = Text::create(StringUtils::format("page %d",(i+1)), "fonts/Marker Felt.ttf", 30); label->setColor(Color3B(192, 192, 192)); label->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(label); From 7b4a1308eab2efd233d08db314ef00016171476e Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 4 Apr 2014 12:48:16 +0800 Subject: [PATCH 25/66] Adds `Renderer::clean`, and fixes crash in `PerformanceTest/Node children Test`. --- cocos/2d/renderer/CCRenderer.cpp | 16 ++++++++++++++-- cocos/2d/renderer/CCRenderer.h | 5 ++++- .../PerformanceNodeChildrenTest.cpp | 4 ++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/cocos/2d/renderer/CCRenderer.cpp b/cocos/2d/renderer/CCRenderer.cpp index 78f8eea2b1..164a82ebad 100644 --- a/cocos/2d/renderer/CCRenderer.cpp +++ b/cocos/2d/renderer/CCRenderer.cpp @@ -359,6 +359,12 @@ void Renderer::render() } } + clean(); +} + +void Renderer::clean() +{ + // Clear render group for (size_t j = 0 ; j < _renderGroups.size(); j++) { //commands are owned by nodes @@ -368,12 +374,18 @@ void Renderer::render() // } _renderGroups[j].clear(); } - - //Clear the stack incase gl view hasn't been initialized yet + + // Clear batch quad commands + _batchedQuadCommands.clear(); + _numQuads = 0; + + // Clear the stack incase gl view hasn't been initialized yet while(!_renderStack.empty()) { _renderStack.pop(); } + + // Reset render stack RenderStackElement element = {DEFAULT_RENDER_QUEUE, 0}; _renderStack.push(element); _lastMaterialID = 0; diff --git a/cocos/2d/renderer/CCRenderer.h b/cocos/2d/renderer/CCRenderer.h index 1e1750bbf7..e88fc40adf 100644 --- a/cocos/2d/renderer/CCRenderer.h +++ b/cocos/2d/renderer/CCRenderer.h @@ -79,7 +79,7 @@ public: //TODO manage GLView inside Render itself void initGLView(); - + /** Adds a `RenderComamnd` into the renderer */ void addCommand(RenderCommand* command); @@ -98,6 +98,9 @@ public: /** Renders into the GLView all the queued `RenderCommand` objects */ void render(); + /** Cleans all `RenderCommand`s in the queue */ + void clean(); + /* returns the number of drawn batches in the last frame */ ssize_t getDrawnBatches() const { return _drawnBatches; } /* RenderCommands (except) QuadCommand should update this value */ diff --git a/tests/cpp-tests/Classes/PerformanceTest/PerformanceNodeChildrenTest.cpp b/tests/cpp-tests/Classes/PerformanceTest/PerformanceNodeChildrenTest.cpp index 05b520349b..f1d36680da 100644 --- a/tests/cpp-tests/Classes/PerformanceTest/PerformanceNodeChildrenTest.cpp +++ b/tests/cpp-tests/Classes/PerformanceTest/PerformanceNodeChildrenTest.cpp @@ -947,6 +947,10 @@ void VisitSceneGraph::update(float dt) CC_PROFILER_START( this->profilerName() ); this->visit(); CC_PROFILER_STOP( this->profilerName() ); + + // Call `Renderer::clean` to prevent crash if current scene is destroyed. + // The render commands associated with current scene should be cleaned. + Director::getInstance()->getRenderer()->clean(); } std::string VisitSceneGraph::title() const From ec83b3db0447387c544e465a924021b9633ff7e3 Mon Sep 17 00:00:00 2001 From: andyque Date: Fri, 4 Apr 2014 15:21:28 +0800 Subject: [PATCH 26/66] issue #4636. fix ButtonReader --- .../ButtonReader/ButtonReader.cpp | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp index 96f7f96ebe..751a5924a9 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp @@ -55,14 +55,21 @@ namespace cocostudio { std::string tp_n = jsonPath; const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path"); - const char* normalFileName_tp = (normalFileName && (strcmp(normalFileName, "") != 0))?tp_n.append(normalFileName).c_str():nullptr; + std::string normalFileName_tp = ""; + if (nullptr != normalFileName) { + normalFileName_tp = tp_n.append(normalFileName); + } button->loadTextureNormal(normalFileName_tp); break; } case 1: { + std::string normalString; const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path"); - button->loadTextureNormal(normalFileName,UI_TEX_TYPE_PLIST); + if (nullptr != normalFileName) { + normalString = std::string(normalFileName); + } + button->loadTextureNormal(normalString,UI_TEX_TYPE_PLIST); break; } default: @@ -76,14 +83,21 @@ namespace cocostudio { std::string tp_p = jsonPath; const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path"); - const char* pressedFileName_tp = (pressedFileName && (strcmp(pressedFileName, "") != 0))?tp_p.append(pressedFileName).c_str():nullptr; + std::string pressedFileName_tp ; + if (nullptr != pressedFileName) { + pressedFileName_tp = tp_p.append(pressedFileName); + } button->loadTexturePressed(pressedFileName_tp); break; } case 1: { const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path"); - button->loadTexturePressed(pressedFileName,UI_TEX_TYPE_PLIST); + std::string pressedString; + if (nullptr != pressedFileName) { + pressedString = std::string(pressedFileName); + } + button->loadTexturePressed(pressedString,UI_TEX_TYPE_PLIST); break; } default: @@ -97,14 +111,21 @@ namespace cocostudio { std::string tp_d = jsonPath; const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path"); - const char* disabledFileName_tp = (disabledFileName && (strcmp(disabledFileName, "") != 0))?tp_d.append(disabledFileName).c_str():nullptr; + std::string disabledFileName_tp = ""; + if ( nullptr != disabledFileName) { + disabledFileName_tp = tp_d.append(disabledFileName); + } button->loadTextureDisabled(disabledFileName_tp); break; } case 1: { + std::string disabledString; const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path"); - button->loadTextureDisabled(disabledFileName,UI_TEX_TYPE_PLIST); + if (nullptr != disabledFileName) { + disabledString = std::string(disabledFileName); + } + button->loadTextureDisabled(disabledString,UI_TEX_TYPE_PLIST); break; } default: From 51404500b713954135e285e83c576f7f69c1cd2c Mon Sep 17 00:00:00 2001 From: andyque Date: Fri, 4 Apr 2014 16:24:54 +0800 Subject: [PATCH 27/66] issue #4636. fixed WidgetReader error --- .../ButtonReader/ButtonReader.cpp | 9 +-- .../CheckBoxReader/CheckBoxReader.cpp | 60 ++++++++++++++----- .../LayoutReader/LayoutReader.cpp | 12 +++- 3 files changed, 57 insertions(+), 24 deletions(-) diff --git a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp index 751a5924a9..10f02d3c9e 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp @@ -53,11 +53,10 @@ namespace cocostudio { case 0: { - std::string tp_n = jsonPath; const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path"); std::string normalFileName_tp = ""; if (nullptr != normalFileName) { - normalFileName_tp = tp_n.append(normalFileName); + normalFileName_tp = jsonPath + normalFileName; } button->loadTextureNormal(normalFileName_tp); break; @@ -81,11 +80,10 @@ namespace cocostudio { case 0: { - std::string tp_p = jsonPath; const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path"); std::string pressedFileName_tp ; if (nullptr != pressedFileName) { - pressedFileName_tp = tp_p.append(pressedFileName); + pressedFileName_tp = jsonPath + pressedFileName; } button->loadTexturePressed(pressedFileName_tp); break; @@ -109,11 +107,10 @@ namespace cocostudio { case 0: { - std::string tp_d = jsonPath; const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path"); std::string disabledFileName_tp = ""; if ( nullptr != disabledFileName) { - disabledFileName_tp = tp_d.append(disabledFileName); + disabledFileName_tp = jsonPath + disabledFileName; } button->loadTextureDisabled(disabledFileName_tp); break; diff --git a/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp index 8bd0898f8b..b186b1855b 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp @@ -46,16 +46,22 @@ namespace cocostudio { case 0: { - std::string tp_b = jsonPath; const char* backGroundFileName = DICTOOL->getStringValue_json(backGroundDic, "path"); - const char* backGroundFileName_tp = (backGroundFileName && (strcmp(backGroundFileName, "") != 0))?tp_b.append(backGroundFileName).c_str():nullptr; + std::string backGroundFileName_tp; + if (nullptr != backGroundFileName) { + backGroundFileName_tp = jsonPath + backGroundFileName; + } checkBox->loadTextureBackGround(backGroundFileName_tp); break; } case 1: { + std::string backGroundFileNameStr; const char* backGroundFileName = DICTOOL->getStringValue_json(backGroundDic, "path"); - checkBox->loadTextureBackGround(backGroundFileName,UI_TEX_TYPE_PLIST); + if (nullptr != backGroundFileName) { + backGroundFileNameStr = std::string(backGroundFileName); + } + checkBox->loadTextureBackGround(backGroundFileNameStr,UI_TEX_TYPE_PLIST); break; } default: @@ -68,16 +74,22 @@ namespace cocostudio { case 0: { - std::string tp_bs = jsonPath; const char* backGroundSelectedFileName = DICTOOL->getStringValue_json(backGroundSelectedDic, "path"); - const char* backGroundSelectedFileName_tp = (backGroundSelectedFileName && (strcmp(backGroundSelectedFileName, "") != 0))?tp_bs.append(backGroundSelectedFileName).c_str():nullptr; + std::string backGroundSelectedFileName_tp; + if (nullptr != backGroundSelectedFileName) { + backGroundSelectedFileName_tp = jsonPath + backGroundSelectedFileName; + } checkBox->loadTextureBackGroundSelected(backGroundSelectedFileName_tp); break; } case 1: { const char* backGroundSelectedFileName = DICTOOL->getStringValue_json(backGroundSelectedDic, "path"); - checkBox->loadTextureBackGroundSelected(backGroundSelectedFileName,UI_TEX_TYPE_PLIST); + std::string backGroundSelectedFileNameString; + if (nullptr != backGroundSelectedFileName) { + backGroundSelectedFileNameString = std::string(backGroundSelectedFileName); + } + checkBox->loadTextureBackGroundSelected(backGroundSelectedFileNameString,UI_TEX_TYPE_PLIST); break; } default: @@ -90,15 +102,21 @@ namespace cocostudio { case 0: { - std::string tp_c = jsonPath; const char* frontCrossFileName = DICTOOL->getStringValue_json(frontCrossDic, "path"); - const char* frontCrossFileName_tp = (frontCrossFileName && (strcmp(frontCrossFileName, "") != 0))?tp_c.append(frontCrossFileName).c_str():nullptr; + std::string frontCrossFileName_tp; + if (nullptr != frontCrossFileName) { + frontCrossFileName_tp = jsonPath + frontCrossFileName; + } checkBox->loadTextureFrontCross(frontCrossFileName_tp); break; } case 1: { - const char* frontCrossFileName = DICTOOL->getStringValue_json(frontCrossDic, "path"); + const char* frontCrossFileNamePath = DICTOOL->getStringValue_json(frontCrossDic, "path"); + std::string frontCrossFileName; + if (nullptr != frontCrossFileNamePath) { + frontCrossFileName = std::string(frontCrossFileNamePath); + } checkBox->loadTextureFrontCross(frontCrossFileName,UI_TEX_TYPE_PLIST); break; } @@ -112,15 +130,21 @@ namespace cocostudio { case 0: { - std::string tp_bd = jsonPath; const char* backGroundDisabledFileName = DICTOOL->getStringValue_json(backGroundDisabledDic, "path"); - const char* backGroundDisabledFileName_tp = (backGroundDisabledFileName && (strcmp(backGroundDisabledFileName, "") != 0))?tp_bd.append(backGroundDisabledFileName).c_str():nullptr; + std::string backGroundDisabledFileName_tp; + if (nullptr != backGroundDisabledFileName) { + backGroundDisabledFileName_tp = jsonPath + backGroundDisabledFileName; + } checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName_tp); break; } case 1: { - const char* backGroundDisabledFileName = DICTOOL->getStringValue_json(backGroundDisabledDic, "path"); + const char* backGroundDisabledFileNamePath = DICTOOL->getStringValue_json(backGroundDisabledDic, "path"); + std::string backGroundDisabledFileName; + if (nullptr != backGroundDisabledFileNamePath) { + backGroundDisabledFileName = std::string(backGroundDisabledFileNamePath); + } checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName,UI_TEX_TYPE_PLIST); break; } @@ -134,15 +158,21 @@ namespace cocostudio { case 0: { - std::string tp_cd = jsonPath; const char* frontCrossDisabledFileName = DICTOOL->getStringValue_json(options, "path"); - const char* frontCrossDisabledFileName_tp = (frontCrossDisabledFileName && (strcmp(frontCrossDisabledFileName, "") != 0))?tp_cd.append(frontCrossDisabledFileName).c_str():nullptr; + std::string frontCrossDisabledFileName_tp; + if (nullptr != frontCrossDisabledFileName) { + frontCrossDisabledFileName_tp = jsonPath + frontCrossDisabledFileName; + } checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName_tp); break; } case 1: { - const char* frontCrossDisabledFileName = DICTOOL->getStringValue_json(options, "path"); + const char* frontCrossDisabledFileNamePath = DICTOOL->getStringValue_json(options, "path"); + std::string frontCrossDisabledFileName; + if (nullptr != frontCrossDisabledFileNamePath) { + frontCrossDisabledFileName = std::string(frontCrossDisabledFileNamePath); + } checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName,UI_TEX_TYPE_PLIST); break; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp index 4bd5573fee..926cabcd61 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp @@ -90,15 +90,21 @@ namespace cocostudio { case 0: { - std::string tp_b = jsonPath; const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr; + std::string imageFileName_tp; + if (nullptr != imageFileName) { + imageFileName_tp = jsonPath + imageFileName; + } panel->setBackGroundImage(imageFileName_tp); break; } case 1: { - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); + const char* imageFileNamePath = DICTOOL->getStringValue_json(imageFileNameDic, "path"); + std::string imageFileName; + if (nullptr != imageFileNamePath) { + imageFileName = std::string(imageFileNamePath); + } panel->setBackGroundImage(imageFileName,UI_TEX_TYPE_PLIST); break; } From 77aee27f05ab2c0fb26e70be7a9a3b14d658e67e Mon Sep 17 00:00:00 2001 From: andyque Date: Fri, 4 Apr 2014 16:51:07 +0800 Subject: [PATCH 28/66] issue #4636. refactor ButtonReader --- .../ButtonReader/ButtonReader.cpp | 91 +++---------------- .../WidgetReader/ButtonReader/ButtonReader.h | 4 +- .../ImageViewReader/ImageViewReader.cpp | 15 +-- .../cocostudio/WidgetReader/WidgetReader.cpp | 22 +++++ .../cocostudio/WidgetReader/WidgetReader.h | 12 ++- cocos/ui/UIWidget.h | 4 +- 6 files changed, 60 insertions(+), 88 deletions(-) diff --git a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp index 10f02d3c9e..fe475ed136 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp @@ -41,93 +41,30 @@ namespace cocostudio WidgetReader::setPropsFromJsonDictionary(widget, options); - std::string jsonPath = GUIReader::getInstance()->getFilePath(); - Button* button = static_cast(widget); bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable"); button->setScale9Enabled(scale9Enable); + const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "normalData"); int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType"); - switch (normalType) - { - case 0: - { - const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path"); - std::string normalFileName_tp = ""; - if (nullptr != normalFileName) { - normalFileName_tp = jsonPath + normalFileName; - } - button->loadTextureNormal(normalFileName_tp); - break; - } - case 1: - { - std::string normalString; - const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path"); - if (nullptr != normalFileName) { - normalString = std::string(normalFileName); - } - button->loadTextureNormal(normalString,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } + std::string normalTexturePath = this->getResourcePath(normalDic, "path", (TextureResType)normalType); + button->loadTextureNormal(normalTexturePath, (TextureResType)normalType); + + const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "pressedData"); int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType"); - switch (pressedType) - { - case 0: - { - const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path"); - std::string pressedFileName_tp ; - if (nullptr != pressedFileName) { - pressedFileName_tp = jsonPath + pressedFileName; - } - button->loadTexturePressed(pressedFileName_tp); - break; - } - case 1: - { - const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path"); - std::string pressedString; - if (nullptr != pressedFileName) { - pressedString = std::string(pressedFileName); - } - button->loadTexturePressed(pressedString,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } + + std::string pressedTexturePath = this->getResourcePath(pressedDic, "path", (TextureResType)pressedType); + button->loadTexturePressed(pressedTexturePath, (TextureResType)pressedType); + + const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "disabledData"); int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType"); - switch (disabledType) - { - case 0: - { - const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path"); - std::string disabledFileName_tp = ""; - if ( nullptr != disabledFileName) { - disabledFileName_tp = jsonPath + disabledFileName; - } - button->loadTextureDisabled(disabledFileName_tp); - break; - } - case 1: - { - std::string disabledString; - const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path"); - if (nullptr != disabledFileName) { - disabledString = std::string(disabledFileName); - } - button->loadTextureDisabled(disabledString,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } + + std::string disabledTexturePath = this->getResourcePath(disabledDic, "path", (TextureResType)disabledType); + button->loadTextureDisabled(disabledTexturePath, (TextureResType)disabledType); + if (scale9Enable) { float cx = DICTOOL->getFloatValue_json(options, "capInsetsX"); diff --git a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.h b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.h index 93e0a9577b..379897676a 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.h @@ -40,7 +40,9 @@ namespace cocostudio static ButtonReader* getInstance(); static void purge(); - virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options); + virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, + const rapidjson::Value& options); + }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp index ea2755c8fc..42ded95c1a 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp @@ -46,19 +46,22 @@ namespace cocostudio { case 0: { - std::string tp_i = jsonPath; const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - const char* imageFileName_tp = nullptr; - if (imageFileName && (strcmp(imageFileName, "") != 0)) + std::string imageFileName_tp; + if (nullptr != imageFileName) { - imageFileName_tp = tp_i.append(imageFileName).c_str(); - imageView->loadTexture(imageFileName_tp); + imageFileName_tp = jsonPath + imageFileName; } + imageView->loadTexture(imageFileName_tp); break; } case 1: { - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); + const char* imageFileNamePath = DICTOOL->getStringValue_json(imageFileNameDic, "path"); + std::string imageFileName; + if (nullptr != imageFileNamePath) { + imageFileName = std::string(imageFileNamePath); + } imageView->loadTexture(imageFileName,UI_TEX_TYPE_PLIST); break; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp index bc577423c9..7490b9dc2c 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp @@ -172,4 +172,26 @@ namespace cocostudio widget->setFlippedX(flipX); widget->setFlippedY(flipY); } + + std::string WidgetReader::getResourcePath(const rapidjson::Value &dict, + const std::string &key, + cocos2d::ui::TextureResType texType) + { + std::string jsonPath = GUIReader::getInstance()->getFilePath(); + const char* imageFileName = DICTOOL->getStringValue_json(dict, key.c_str()); + std::string imageFileName_tp; + if (nullptr != imageFileName) + { + if (texType == UI_TEX_TYPE_LOCAL) { + imageFileName_tp = jsonPath + imageFileName; + } + else if(texType == UI_TEX_TYPE_PLIST){ + imageFileName_tp = std::string(imageFileName); + } + else{ + CCASSERT(0, "invalid TextureResType!!!"); + } + } + return imageFileName_tp; + } } diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h index fbd2c28411..fe0bb7c5c8 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h @@ -43,8 +43,16 @@ namespace cocostudio static WidgetReader* getInstance(); static void purge(); - virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options); - virtual void setColorPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options); + virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, + const rapidjson::Value& options); + + virtual void setColorPropsFromJsonDictionary(cocos2d::ui::Widget* widget, + const rapidjson::Value& options); + + protected: + std::string getResourcePath(const rapidjson::Value& dict, + const std::string& key, + cocos2d::ui::TextureResType texType); }; } diff --git a/cocos/ui/UIWidget.h b/cocos/ui/UIWidget.h index fd08ce6d41..0f2aa4d40c 100644 --- a/cocos/ui/UIWidget.h +++ b/cocos/ui/UIWidget.h @@ -49,8 +49,8 @@ typedef enum typedef enum { - UI_TEX_TYPE_LOCAL, - UI_TEX_TYPE_PLIST + UI_TEX_TYPE_LOCAL = 0, + UI_TEX_TYPE_PLIST = 1 }TextureResType; typedef enum From c252aa5a55141ab87793aa8cb2aa5bc49ce60c3e Mon Sep 17 00:00:00 2001 From: andyque Date: Fri, 4 Apr 2014 17:12:47 +0800 Subject: [PATCH 29/66] issue #4636. refactor CheckBoxReader --- .../CheckBoxReader/CheckBoxReader.cpp | 144 ++---------------- 1 file changed, 16 insertions(+), 128 deletions(-) diff --git a/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp index b186b1855b..72bc3193d8 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp @@ -35,150 +35,38 @@ namespace cocostudio { WidgetReader::setPropsFromJsonDictionary(widget, options); - - std::string jsonPath = GUIReader::getInstance()->getFilePath(); - CheckBox* checkBox = static_cast(widget); + + //load background image const rapidjson::Value& backGroundDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxData"); int backGroundType = DICTOOL->getIntValue_json(backGroundDic, "resourceType"); - switch (backGroundType) - { - case 0: - { - const char* backGroundFileName = DICTOOL->getStringValue_json(backGroundDic, "path"); - std::string backGroundFileName_tp; - if (nullptr != backGroundFileName) { - backGroundFileName_tp = jsonPath + backGroundFileName; - } - checkBox->loadTextureBackGround(backGroundFileName_tp); - break; - } - case 1: - { - std::string backGroundFileNameStr; - const char* backGroundFileName = DICTOOL->getStringValue_json(backGroundDic, "path"); - if (nullptr != backGroundFileName) { - backGroundFileNameStr = std::string(backGroundFileName); - } - checkBox->loadTextureBackGround(backGroundFileNameStr,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } + std::string backGroundTexturePath = this->getResourcePath(backGroundDic, "path", (TextureResType)backGroundType); + checkBox->loadTextureBackGround(backGroundTexturePath, (TextureResType)backGroundType); + //load background selected image const rapidjson::Value& backGroundSelectedDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxSelectedData"); int backGroundSelectedType = DICTOOL->getIntValue_json(backGroundSelectedDic, "resourceType"); - switch (backGroundSelectedType) - { - case 0: - { - const char* backGroundSelectedFileName = DICTOOL->getStringValue_json(backGroundSelectedDic, "path"); - std::string backGroundSelectedFileName_tp; - if (nullptr != backGroundSelectedFileName) { - backGroundSelectedFileName_tp = jsonPath + backGroundSelectedFileName; - } - checkBox->loadTextureBackGroundSelected(backGroundSelectedFileName_tp); - break; - } - case 1: - { - const char* backGroundSelectedFileName = DICTOOL->getStringValue_json(backGroundSelectedDic, "path"); - std::string backGroundSelectedFileNameString; - if (nullptr != backGroundSelectedFileName) { - backGroundSelectedFileNameString = std::string(backGroundSelectedFileName); - } - checkBox->loadTextureBackGroundSelected(backGroundSelectedFileNameString,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } + std::string backGroundSelectedTexturePath = this->getResourcePath(backGroundSelectedDic, "path", (TextureResType)backGroundSelectedType); + checkBox->loadTextureBackGroundSelected(backGroundSelectedTexturePath, (TextureResType)backGroundSelectedType); + //load frontCross image const rapidjson::Value& frontCrossDic = DICTOOL->getSubDictionary_json(options, "frontCrossData"); int frontCrossType = DICTOOL->getIntValue_json(frontCrossDic, "resourceType"); - switch (frontCrossType) - { - case 0: - { - const char* frontCrossFileName = DICTOOL->getStringValue_json(frontCrossDic, "path"); - std::string frontCrossFileName_tp; - if (nullptr != frontCrossFileName) { - frontCrossFileName_tp = jsonPath + frontCrossFileName; - } - checkBox->loadTextureFrontCross(frontCrossFileName_tp); - break; - } - case 1: - { - const char* frontCrossFileNamePath = DICTOOL->getStringValue_json(frontCrossDic, "path"); - std::string frontCrossFileName; - if (nullptr != frontCrossFileNamePath) { - frontCrossFileName = std::string(frontCrossFileNamePath); - } - checkBox->loadTextureFrontCross(frontCrossFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } + std::string frontCrossFileName = this->getResourcePath(frontCrossDic, "path", (TextureResType)frontCrossType); + checkBox->loadTextureFrontCross(frontCrossFileName, (TextureResType)frontCrossType); + //load backGroundBoxDisabledData const rapidjson::Value& backGroundDisabledDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxDisabledData"); int backGroundDisabledType = DICTOOL->getIntValue_json(backGroundDisabledDic, "resourceType"); - switch (backGroundDisabledType) - { - case 0: - { - const char* backGroundDisabledFileName = DICTOOL->getStringValue_json(backGroundDisabledDic, "path"); - std::string backGroundDisabledFileName_tp; - if (nullptr != backGroundDisabledFileName) { - backGroundDisabledFileName_tp = jsonPath + backGroundDisabledFileName; - } - checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName_tp); - break; - } - case 1: - { - const char* backGroundDisabledFileNamePath = DICTOOL->getStringValue_json(backGroundDisabledDic, "path"); - std::string backGroundDisabledFileName; - if (nullptr != backGroundDisabledFileNamePath) { - backGroundDisabledFileName = std::string(backGroundDisabledFileNamePath); - } - checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } + std::string backGroundDisabledFileName = this->getResourcePath(backGroundDisabledDic, "path", (TextureResType)backGroundDisabledType); + checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName, (TextureResType)backGroundDisabledType); + ///load frontCrossDisabledData const rapidjson::Value& frontCrossDisabledDic = DICTOOL->getSubDictionary_json(options, "frontCrossDisabledData"); int frontCrossDisabledType = DICTOOL->getIntValue_json(frontCrossDisabledDic, "resourceType"); - switch (frontCrossDisabledType) - { - case 0: - { - const char* frontCrossDisabledFileName = DICTOOL->getStringValue_json(options, "path"); - std::string frontCrossDisabledFileName_tp; - if (nullptr != frontCrossDisabledFileName) { - frontCrossDisabledFileName_tp = jsonPath + frontCrossDisabledFileName; - } - checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName_tp); - break; - } - case 1: - { - const char* frontCrossDisabledFileNamePath = DICTOOL->getStringValue_json(options, "path"); - std::string frontCrossDisabledFileName; - if (nullptr != frontCrossDisabledFileNamePath) { - frontCrossDisabledFileName = std::string(frontCrossDisabledFileNamePath); - } - checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } + std::string frontCrossDisabledFileName = this->getResourcePath(frontCrossDisabledDic, "path", (TextureResType)frontCrossDisabledType); + checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName, (TextureResType)frontCrossDisabledType); WidgetReader::setColorPropsFromJsonDictionary(widget, options); From 3482815e69649625857c633afc6dcabdf41ced0e Mon Sep 17 00:00:00 2001 From: andyque Date: Fri, 4 Apr 2014 17:18:24 +0800 Subject: [PATCH 30/66] issue #4636. refactor ImageViewReader --- .../ImageViewReader/ImageViewReader.cpp | 30 ++----------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp index 42ded95c1a..42b05593e0 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp @@ -36,38 +36,14 @@ namespace cocostudio WidgetReader::setPropsFromJsonDictionary(widget, options); - std::string jsonPath = GUIReader::getInstance()->getFilePath(); ImageView* imageView = static_cast(widget); const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "fileNameData"); int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); - switch (imageFileNameType) - { - case 0: - { - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - std::string imageFileName_tp; - if (nullptr != imageFileName) - { - imageFileName_tp = jsonPath + imageFileName; - } - imageView->loadTexture(imageFileName_tp); - break; - } - case 1: - { - const char* imageFileNamePath = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - std::string imageFileName; - if (nullptr != imageFileNamePath) { - imageFileName = std::string(imageFileNamePath); - } - imageView->loadTexture(imageFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } + std::string imageFileName = this->getResourcePath(imageFileNameDic, "path", (TextureResType)imageFileNameType); + imageView->loadTexture(imageFileName, (TextureResType)imageFileNameType); + bool scale9EnableExist = DICTOOL->checkObjectExist_json(options, "scale9Enable"); bool scale9Enable = false; From a4e0c1a6e21a2c1b0360fe5fc0fc7e6eee1ee3eb Mon Sep 17 00:00:00 2001 From: andyque Date: Fri, 4 Apr 2014 17:21:23 +0800 Subject: [PATCH 31/66] issue #4636. refactor LayoutReader --- .../LayoutReader/LayoutReader.cpp | 31 ++----------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp index 926cabcd61..a6d4b02be8 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp @@ -35,9 +35,6 @@ namespace cocostudio { WidgetReader::setPropsFromJsonDictionary(widget, options); - - std::string jsonPath = GUIReader::getInstance()->getFilePath(); - Layout* panel = static_cast(widget); /* adapt screen gui */ @@ -86,31 +83,9 @@ namespace cocostudio const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "backGroundImageData"); int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); - switch (imageFileNameType) - { - case 0: - { - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - std::string imageFileName_tp; - if (nullptr != imageFileName) { - imageFileName_tp = jsonPath + imageFileName; - } - panel->setBackGroundImage(imageFileName_tp); - break; - } - case 1: - { - const char* imageFileNamePath = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - std::string imageFileName; - if (nullptr != imageFileNamePath) { - imageFileName = std::string(imageFileNamePath); - } - panel->setBackGroundImage(imageFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } + std::string imageFileName = this->getResourcePath(imageFileNameDic, "path", (TextureResType)imageFileNameType); + panel->setBackGroundImage(imageFileName, (TextureResType)imageFileNameType); + if (backGroundScale9Enable) { From af5fe044806003c172f9f168ae5415afb5a68a03 Mon Sep 17 00:00:00 2001 From: andyque Date: Fri, 4 Apr 2014 17:25:20 +0800 Subject: [PATCH 32/66] issue #4636. refactor LoadingBarReader --- .../LoadingBarReader/LoadingBarReader.cpp | 28 ++----------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp index db62cc4cac..caa6bc2714 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp @@ -36,35 +36,13 @@ namespace cocostudio WidgetReader::setPropsFromJsonDictionary(widget, options); - std::string jsonPath = GUIReader::getInstance()->getFilePath(); - LoadingBar* loadingBar = static_cast(widget); const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "textureData"); int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); - switch (imageFileNameType) - { - case 0: - { - std::string tp_i = jsonPath; - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - const char* imageFileName_tp = nullptr; - if (imageFileName && (strcmp(imageFileName, "") != 0)) - { - imageFileName_tp = tp_i.append(imageFileName).c_str(); - loadingBar->loadTexture(imageFileName_tp); - } - break; - } - case 1: - { - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - loadingBar->loadTexture(imageFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } + std::string imageFileName = this->getResourcePath(imageFileNameDic, "path", (TextureResType)imageFileNameType); + loadingBar->loadTexture(imageFileName, (TextureResType)imageFileNameType); + /* gui mark add load bar scale9 parse */ bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable"); From e20b3d8eb827e3a12f72c5d81f4f44782f97a4d5 Mon Sep 17 00:00:00 2001 From: andyque Date: Fri, 4 Apr 2014 17:35:15 +0800 Subject: [PATCH 33/66] issue #4636. refactor SliderReader --- .../SliderReader/SliderReader.cpp | 152 +++--------------- 1 file changed, 24 insertions(+), 128 deletions(-) diff --git a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp index 6d3793a226..564dd1866b 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp @@ -35,159 +35,55 @@ namespace cocostudio { WidgetReader::setPropsFromJsonDictionary(widget, options); - - std::string jsonPath = GUIReader::getInstance()->getFilePath(); - + Slider* slider = static_cast(widget); bool barTextureScale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable"); slider->setScale9Enabled(barTextureScale9Enable); + + slider->setPercent(DICTOOL->getIntValue_json(options, "percent")); + + bool bt = DICTOOL->checkObjectExist_json(options, "barFileName"); float barLength = DICTOOL->getFloatValue_json(options, "length"); if (bt) { + const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData"); + int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); + std::string imageFileName = this->getResourcePath(imageFileNameDic, "path", (TextureResType)imageFileNameType); + slider->loadBarTexture(imageFileName, (TextureResType)imageFileNameType); + if (barTextureScale9Enable) { - - const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData"); - int imageFileType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); - switch (imageFileType) - { - case 0: - { - std::string tp_b = jsonPath; - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr; - slider->loadBarTexture(imageFileName_tp); - break; - } - case 1: - { - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - slider->loadBarTexture(imageFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } - slider->setSize(Size(barLength, slider->getContentSize().height)); } - else - { - const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData"); - int imageFileType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); - switch (imageFileType) - { - case 0: - { - std::string tp_b = jsonPath; - const char*imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr; - slider->loadBarTexture(imageFileName_tp); - break; - } - case 1: - { - const char*imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - slider->loadBarTexture(imageFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } - } } + //loading normal slider ball texture const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "ballNormalData"); int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType"); - switch (normalType) - { - case 0: - { - std::string tp_n = jsonPath; - const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path"); - const char* normalFileName_tp = (normalFileName && (strcmp(normalFileName, "") != 0))?tp_n.append(normalFileName).c_str():nullptr; - slider->loadSlidBallTextureNormal(normalFileName_tp); - break; - } - case 1: - { - const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path"); - slider->loadSlidBallTextureNormal(normalFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } + std::string imageFileName = this->getResourcePath(normalDic, "path", (TextureResType)normalType); + slider->loadSlidBallTextureNormal(imageFileName, (TextureResType)normalType); + + //loading slider ball press texture const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "ballPressedData"); int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType"); - switch (pressedType) - { - case 0: - { - std::string tp_p = jsonPath; - const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path"); - const char* pressedFileName_tp = (pressedFileName && (strcmp(pressedFileName, "") != 0))?tp_p.append(pressedFileName).c_str():nullptr; - slider->loadSlidBallTexturePressed(pressedFileName_tp); - break; - } - case 1: - { - const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path"); - slider->loadSlidBallTexturePressed(pressedFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } + std::string pressedFileName = this->getResourcePath(pressedDic, "path", (TextureResType)pressedType); + slider->loadSlidBallTexturePressed(pressedFileName, (TextureResType)pressedType); + //loading silder ball disable texture const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "ballDisabledData"); int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType"); - switch (disabledType) - { - case 0: - { - std::string tp_d = jsonPath; - const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path"); - const char* disabledFileName_tp = (disabledFileName && (strcmp(disabledFileName, "") != 0))?tp_d.append(disabledFileName).c_str():nullptr; - slider->loadSlidBallTextureDisabled(disabledFileName_tp); - break; - } - case 1: - { - const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path"); - slider->loadSlidBallTextureDisabled(disabledFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } - - slider->setPercent(DICTOOL->getIntValue_json(options, "percent")); + std::string disabledFileName = this->getResourcePath(disabledDic, "path", (TextureResType)disabledType); + slider->loadSlidBallTextureDisabled(disabledFileName, (TextureResType)disabledType); + //load slider progress texture const rapidjson::Value& progressBarDic = DICTOOL->getSubDictionary_json(options, "progressBarData"); int progressBarType = DICTOOL->getIntValue_json(progressBarDic, "resourceType"); - switch (progressBarType) - { - case 0: - { - std::string tp_b = jsonPath; - const char* imageFileName = DICTOOL->getStringValue_json(progressBarDic, "path"); - const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr; - slider->loadProgressBarTexture(imageFileName_tp); - break; - } - case 1: - { - const char* imageFileName = DICTOOL->getStringValue_json(progressBarDic, "path"); - slider->loadProgressBarTexture(imageFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } + std::string progressBarFileName = this->getResourcePath(progressBarDic, "path", (TextureResType)progressBarType); + slider->loadProgressBarTexture(progressBarFileName, (TextureResType)progressBarType); + WidgetReader::setColorPropsFromJsonDictionary(widget, options); From e346ed35595e0ce7d7720aca5492f3b60b248c31 Mon Sep 17 00:00:00 2001 From: andyque Date: Fri, 4 Apr 2014 17:38:58 +0800 Subject: [PATCH 34/66] closed #4636. done --- cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp index 7490b9dc2c..39845671bf 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp @@ -186,7 +186,7 @@ namespace cocostudio imageFileName_tp = jsonPath + imageFileName; } else if(texType == UI_TEX_TYPE_PLIST){ - imageFileName_tp = std::string(imageFileName); + imageFileName_tp = imageFileName; } else{ CCASSERT(0, "invalid TextureResType!!!"); From 4b6aa2a22c5f0048864d1131890594e14f15ca73 Mon Sep 17 00:00:00 2001 From: andyque Date: Fri, 4 Apr 2014 18:26:53 +0800 Subject: [PATCH 35/66] closed #4636. remove Hungary style --- cocos/ui/UIButton.cpp | 6 +++--- cocos/ui/UICheckBox.cpp | 6 +++--- cocos/ui/UIImageView.cpp | 6 +++--- cocos/ui/UIText.cpp | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cocos/ui/UIButton.cpp b/cocos/ui/UIButton.cpp index a79eaa20de..7db30e09ff 100644 --- a/cocos/ui/UIButton.cpp +++ b/cocos/ui/UIButton.cpp @@ -103,17 +103,17 @@ bool Button::init(const std::string &normalImage, const std::string& disableImage, TextureResType texType) { - bool bRet = true; + bool ret = true; do { if (!Widget::init()) { - bRet = false; + ret = false; break; } setTouchEnabled(true); this->loadTextures(normalImage, selectedImage, disableImage,texType); } while (0); - return bRet; + return ret; } bool Button::init() diff --git a/cocos/ui/UICheckBox.cpp b/cocos/ui/UICheckBox.cpp index 7b6b68507f..1393d7fdb3 100644 --- a/cocos/ui/UICheckBox.cpp +++ b/cocos/ui/UICheckBox.cpp @@ -105,10 +105,10 @@ bool CheckBox::init(const std::string& backGround, const std::string& frontCrossDisabled, TextureResType texType) { - bool bRet = true; + bool ret = true; do { if (!Widget::init()) { - bRet = false; + ret = false; break; } @@ -116,7 +116,7 @@ bool CheckBox::init(const std::string& backGround, setTouchEnabled(true); loadTextures(backGround, backGroundSeleted, cross, backGroundDisabled, frontCrossDisabled,texType); } while (0); - return bRet; + return ret; } bool CheckBox::init() diff --git a/cocos/ui/UIImageView.cpp b/cocos/ui/UIImageView.cpp index ecd901f657..691a33bd97 100644 --- a/cocos/ui/UIImageView.cpp +++ b/cocos/ui/UIImageView.cpp @@ -79,15 +79,15 @@ ImageView* ImageView::create() bool ImageView::init() { - bool bRet = true; + bool ret = true; do { if (!Widget::init()) { - bRet = false; + ret = false; break; } _imageTexType = UI_TEX_TYPE_LOCAL; } while (0); - return bRet; + return ret; } bool ImageView::init(const std::string &imageFileName, TextureResType texType) diff --git a/cocos/ui/UIText.cpp b/cocos/ui/UIText.cpp index 2cf57e5c65..1e504a52e7 100644 --- a/cocos/ui/UIText.cpp +++ b/cocos/ui/UIText.cpp @@ -82,17 +82,17 @@ Text* Text::create(const std::string &textContent, const std::string &fontName, bool Text::init(const std::string &textContent, const std::string &fontName, int fontSize) { - bool bRet = true; + bool ret = true; do { if (!Widget::init()) { - bRet = false; + ret = false; break; } this->setText(textContent); this->setFontName(fontName); this->setFontSize(fontSize); } while (0); - return bRet; + return ret; } void Text::initRenderer() From cd33967dc460193dcf1f62654545c190948eb19a Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Fri, 4 Apr 2014 10:45:34 +0000 Subject: [PATCH 36/66] [AUTO]: updating luabinding automatically --- .../lua-bindings/auto/api/Button.lua | 30 ++++++++++------ .../lua-bindings/auto/api/CheckBox.lua | 36 ++++++++++++------- .../lua-bindings/auto/api/ImageView.lua | 14 +++++--- .../lua-bindings/auto/api/Layout.lua | 2 +- .../lua-bindings/auto/api/LoadingBar.lua | 14 +++++--- .../lua-bindings/auto/api/Scale9Sprite.lua | 32 ++++++++--------- .../lua-bindings/auto/api/Slider.lua | 16 ++++----- .../scripting/lua-bindings/auto/api/Text.lua | 13 +++++-- .../lua-bindings/auto/api/TextAtlas.lua | 15 ++++++-- .../lua-bindings/auto/api/TextBMFont.lua | 18 ++++++---- .../lua-bindings/auto/api/TextField.lua | 13 +++++-- ...cocos2dx_extension_auto.cpp.REMOVED.git-id | 2 +- .../lua_cocos2dx_ui_auto.cpp.REMOVED.git-id | 2 +- 13 files changed, 133 insertions(+), 74 deletions(-) diff --git a/cocos/scripting/lua-bindings/auto/api/Button.lua b/cocos/scripting/lua-bindings/auto/api/Button.lua index 934052eac0..203ab720b4 100644 --- a/cocos/scripting/lua-bindings/auto/api/Button.lua +++ b/cocos/scripting/lua-bindings/auto/api/Button.lua @@ -41,7 +41,7 @@ -------------------------------- -- @function [parent=#Button] loadTextureDisabled -- @param self --- @param #char char +-- @param #string str -- @param #ccui.TextureResType texturerestype -------------------------------- @@ -57,13 +57,13 @@ -------------------------------- -- @function [parent=#Button] loadTexturePressed -- @param self --- @param #char char +-- @param #string str -- @param #ccui.TextureResType texturerestype -------------------------------- -- @function [parent=#Button] setTitleFontName -- @param self --- @param #char char +-- @param #string str -------------------------------- -- @function [parent=#Button] getCapInsetsNormalRenderer @@ -78,9 +78,9 @@ -------------------------------- -- @function [parent=#Button] loadTextures -- @param self --- @param #char char --- @param #char char --- @param #char char +-- @param #string str +-- @param #string str +-- @param #string str -- @param #ccui.TextureResType texturerestype -------------------------------- @@ -91,7 +91,7 @@ -------------------------------- -- @function [parent=#Button] loadTextureNormal -- @param self --- @param #char char +-- @param #string str -- @param #ccui.TextureResType texturerestype -------------------------------- @@ -107,7 +107,7 @@ -------------------------------- -- @function [parent=#Button] getTitleFontName -- @param self --- @return char#char ret (return value: char) +-- @return string#string ret (return value: string) -------------------------------- -- @function [parent=#Button] getTitleColor @@ -120,10 +120,18 @@ -- @param #bool bool -------------------------------- --- @function [parent=#Button] create +-- overload function: create(string, string, string, ccui.TextureResType) +-- +-- overload function: create() +-- +-- @function [parent=#Button] create -- @param self --- @return Button#Button ret (return value: ccui.Button) - +-- @param #string str +-- @param #string str +-- @param #string str +-- @param #ccui.TextureResType texturerestype +-- @return Button#Button ret (retunr value: ccui.Button) + -------------------------------- -- @function [parent=#Button] createInstance -- @param self diff --git a/cocos/scripting/lua-bindings/auto/api/CheckBox.lua b/cocos/scripting/lua-bindings/auto/api/CheckBox.lua index 39585c6ba6..c2a9ed2d91 100644 --- a/cocos/scripting/lua-bindings/auto/api/CheckBox.lua +++ b/cocos/scripting/lua-bindings/auto/api/CheckBox.lua @@ -11,35 +11,35 @@ -------------------------------- -- @function [parent=#CheckBox] loadTextureBackGroundSelected -- @param self --- @param #char char +-- @param #string str -- @param #ccui.TextureResType texturerestype -------------------------------- -- @function [parent=#CheckBox] loadTextureBackGroundDisabled -- @param self --- @param #char char +-- @param #string str -- @param #ccui.TextureResType texturerestype -------------------------------- -- @function [parent=#CheckBox] loadTextureFrontCross -- @param self --- @param #char char +-- @param #string str -- @param #ccui.TextureResType texturerestype -------------------------------- -- @function [parent=#CheckBox] loadTextures -- @param self --- @param #char char --- @param #char char --- @param #char char --- @param #char char --- @param #char char +-- @param #string str +-- @param #string str +-- @param #string str +-- @param #string str +-- @param #string str -- @param #ccui.TextureResType texturerestype -------------------------------- -- @function [parent=#CheckBox] loadTextureBackGround -- @param self --- @param #char char +-- @param #string str -- @param #ccui.TextureResType texturerestype -------------------------------- @@ -50,14 +50,24 @@ -------------------------------- -- @function [parent=#CheckBox] loadTextureFrontCrossDisabled -- @param self --- @param #char char +-- @param #string str -- @param #ccui.TextureResType texturerestype -------------------------------- --- @function [parent=#CheckBox] create +-- overload function: create(string, string, string, string, string, ccui.TextureResType) +-- +-- overload function: create() +-- +-- @function [parent=#CheckBox] create -- @param self --- @return CheckBox#CheckBox ret (return value: ccui.CheckBox) - +-- @param #string str +-- @param #string str +-- @param #string str +-- @param #string str +-- @param #string str +-- @param #ccui.TextureResType texturerestype +-- @return CheckBox#CheckBox ret (retunr value: ccui.CheckBox) + -------------------------------- -- @function [parent=#CheckBox] createInstance -- @param self diff --git a/cocos/scripting/lua-bindings/auto/api/ImageView.lua b/cocos/scripting/lua-bindings/auto/api/ImageView.lua index d05cd9ac20..d841c5b850 100644 --- a/cocos/scripting/lua-bindings/auto/api/ImageView.lua +++ b/cocos/scripting/lua-bindings/auto/api/ImageView.lua @@ -6,7 +6,7 @@ -------------------------------- -- @function [parent=#ImageView] loadTexture -- @param self --- @param #char char +-- @param #string str -- @param #ccui.TextureResType texturerestype -------------------------------- @@ -35,10 +35,16 @@ -- @return bool#bool ret (return value: bool) -------------------------------- --- @function [parent=#ImageView] create +-- overload function: create(string, ccui.TextureResType) +-- +-- overload function: create() +-- +-- @function [parent=#ImageView] create -- @param self --- @return ImageView#ImageView ret (return value: ccui.ImageView) - +-- @param #string str +-- @param #ccui.TextureResType texturerestype +-- @return ImageView#ImageView ret (retunr value: ccui.ImageView) + -------------------------------- -- @function [parent=#ImageView] createInstance -- @param self diff --git a/cocos/scripting/lua-bindings/auto/api/Layout.lua b/cocos/scripting/lua-bindings/auto/api/Layout.lua index 1a5a5ea65c..bcfe778653 100644 --- a/cocos/scripting/lua-bindings/auto/api/Layout.lua +++ b/cocos/scripting/lua-bindings/auto/api/Layout.lua @@ -55,7 +55,7 @@ -------------------------------- -- @function [parent=#Layout] setBackGroundImage -- @param self --- @param #char char +-- @param #string str -- @param #ccui.TextureResType texturerestype -------------------------------- diff --git a/cocos/scripting/lua-bindings/auto/api/LoadingBar.lua b/cocos/scripting/lua-bindings/auto/api/LoadingBar.lua index bfff41cbec..a4fc57235c 100644 --- a/cocos/scripting/lua-bindings/auto/api/LoadingBar.lua +++ b/cocos/scripting/lua-bindings/auto/api/LoadingBar.lua @@ -11,7 +11,7 @@ -------------------------------- -- @function [parent=#LoadingBar] loadTexture -- @param self --- @param #char char +-- @param #string str -- @param #ccui.TextureResType texturerestype -------------------------------- @@ -50,10 +50,16 @@ -- @return int#int ret (return value: int) -------------------------------- --- @function [parent=#LoadingBar] create +-- overload function: create(string, int) +-- +-- overload function: create() +-- +-- @function [parent=#LoadingBar] create -- @param self --- @return LoadingBar#LoadingBar ret (return value: ccui.LoadingBar) - +-- @param #string str +-- @param #int int +-- @return LoadingBar#LoadingBar ret (retunr value: ccui.LoadingBar) + -------------------------------- -- @function [parent=#LoadingBar] createInstance -- @param self diff --git a/cocos/scripting/lua-bindings/auto/api/Scale9Sprite.lua b/cocos/scripting/lua-bindings/auto/api/Scale9Sprite.lua index 525e13fd4f..cb3883ab06 100644 --- a/cocos/scripting/lua-bindings/auto/api/Scale9Sprite.lua +++ b/cocos/scripting/lua-bindings/auto/api/Scale9Sprite.lua @@ -15,13 +15,13 @@ -- @param #float float -------------------------------- --- overload function: initWithSpriteFrameName(char) +-- overload function: initWithSpriteFrameName(string) -- --- overload function: initWithSpriteFrameName(char, rect_table) +-- overload function: initWithSpriteFrameName(string, rect_table) -- -- @function [parent=#Scale9Sprite] initWithSpriteFrameName -- @param self --- @param #char char +-- @param #string str -- @param #rect_table rect -- @return bool#bool ret (retunr value: bool) @@ -88,17 +88,17 @@ -- @return size_table#size_table ret (return value: size_table) -------------------------------- --- overload function: initWithFile(char, rect_table) +-- overload function: initWithFile(string, rect_table) -- --- overload function: initWithFile(char, rect_table, rect_table) +-- overload function: initWithFile(string, rect_table, rect_table) -- --- overload function: initWithFile(rect_table, char) +-- overload function: initWithFile(rect_table, string) -- --- overload function: initWithFile(char) +-- overload function: initWithFile(string) -- -- @function [parent=#Scale9Sprite] initWithFile -- @param self --- @param #char char +-- @param #string str -- @param #rect_table rect -- @param #rect_table rect -- @return bool#bool ret (retunr value: bool) @@ -145,31 +145,31 @@ -- @param #float float -------------------------------- --- overload function: create(char, rect_table, rect_table) +-- overload function: create(string, rect_table, rect_table) -- -- overload function: create() -- --- overload function: create(rect_table, char) +-- overload function: create(rect_table, string) -- --- overload function: create(char, rect_table) +-- overload function: create(string, rect_table) -- --- overload function: create(char) +-- overload function: create(string) -- -- @function [parent=#Scale9Sprite] create -- @param self --- @param #char char +-- @param #string str -- @param #rect_table rect -- @param #rect_table rect -- @return Scale9Sprite#Scale9Sprite ret (retunr value: cc.Scale9Sprite) -------------------------------- --- overload function: createWithSpriteFrameName(char, rect_table) +-- overload function: createWithSpriteFrameName(string, rect_table) -- --- overload function: createWithSpriteFrameName(char) +-- overload function: createWithSpriteFrameName(string) -- -- @function [parent=#Scale9Sprite] createWithSpriteFrameName -- @param self --- @param #char char +-- @param #string str -- @param #rect_table rect -- @return Scale9Sprite#Scale9Sprite ret (retunr value: cc.Scale9Sprite) diff --git a/cocos/scripting/lua-bindings/auto/api/Slider.lua b/cocos/scripting/lua-bindings/auto/api/Slider.lua index 7ac618430b..e3a6e6b2ad 100644 --- a/cocos/scripting/lua-bindings/auto/api/Slider.lua +++ b/cocos/scripting/lua-bindings/auto/api/Slider.lua @@ -11,33 +11,33 @@ -------------------------------- -- @function [parent=#Slider] loadSlidBallTextureDisabled -- @param self --- @param #char char +-- @param #string str -- @param #ccui.TextureResType texturerestype -------------------------------- -- @function [parent=#Slider] loadSlidBallTextureNormal -- @param self --- @param #char char +-- @param #string str -- @param #ccui.TextureResType texturerestype -------------------------------- -- @function [parent=#Slider] loadBarTexture -- @param self --- @param #char char +-- @param #string str -- @param #ccui.TextureResType texturerestype -------------------------------- -- @function [parent=#Slider] loadProgressBarTexture -- @param self --- @param #char char +-- @param #string str -- @param #ccui.TextureResType texturerestype -------------------------------- -- @function [parent=#Slider] loadSlidBallTextures -- @param self --- @param #char char --- @param #char char --- @param #char char +-- @param #string str +-- @param #string str +-- @param #string str -- @param #ccui.TextureResType texturerestype -------------------------------- @@ -68,7 +68,7 @@ -------------------------------- -- @function [parent=#Slider] loadSlidBallTexturePressed -- @param self --- @param #char char +-- @param #string str -- @param #ccui.TextureResType texturerestype -------------------------------- diff --git a/cocos/scripting/lua-bindings/auto/api/Text.lua b/cocos/scripting/lua-bindings/auto/api/Text.lua index b5d48a6e85..ff84275e98 100644 --- a/cocos/scripting/lua-bindings/auto/api/Text.lua +++ b/cocos/scripting/lua-bindings/auto/api/Text.lua @@ -79,10 +79,17 @@ -- @param #size_table size -------------------------------- --- @function [parent=#Text] create +-- overload function: create(string, string, int) +-- +-- overload function: create() +-- +-- @function [parent=#Text] create -- @param self --- @return Text#Text ret (return value: ccui.Text) - +-- @param #string str +-- @param #string str +-- @param #int int +-- @return Text#Text ret (retunr value: ccui.Text) + -------------------------------- -- @function [parent=#Text] createInstance -- @param self diff --git a/cocos/scripting/lua-bindings/auto/api/TextAtlas.lua b/cocos/scripting/lua-bindings/auto/api/TextAtlas.lua index 8c95bae354..1fe2b105f7 100644 --- a/cocos/scripting/lua-bindings/auto/api/TextAtlas.lua +++ b/cocos/scripting/lua-bindings/auto/api/TextAtlas.lua @@ -23,10 +23,19 @@ -- @param #string str -------------------------------- --- @function [parent=#TextAtlas] create +-- overload function: create(string, string, int, int, string) +-- +-- overload function: create() +-- +-- @function [parent=#TextAtlas] create -- @param self --- @return TextAtlas#TextAtlas ret (return value: ccui.TextAtlas) - +-- @param #string str +-- @param #string str +-- @param #int int +-- @param #int int +-- @param #string str +-- @return TextAtlas#TextAtlas ret (retunr value: ccui.TextAtlas) + -------------------------------- -- @function [parent=#TextAtlas] createInstance -- @param self diff --git a/cocos/scripting/lua-bindings/auto/api/TextBMFont.lua b/cocos/scripting/lua-bindings/auto/api/TextBMFont.lua index e0efb0e9ff..961683e0ce 100644 --- a/cocos/scripting/lua-bindings/auto/api/TextBMFont.lua +++ b/cocos/scripting/lua-bindings/auto/api/TextBMFont.lua @@ -6,23 +6,29 @@ -------------------------------- -- @function [parent=#TextBMFont] setFntFile -- @param self --- @param #char char +-- @param #string str -------------------------------- -- @function [parent=#TextBMFont] getStringValue -- @param self --- @return char#char ret (return value: char) +-- @return string#string ret (return value: string) -------------------------------- -- @function [parent=#TextBMFont] setText -- @param self --- @param #char char +-- @param #string str -------------------------------- --- @function [parent=#TextBMFont] create +-- overload function: create(string, string) +-- +-- overload function: create() +-- +-- @function [parent=#TextBMFont] create -- @param self --- @return TextBMFont#TextBMFont ret (return value: ccui.TextBMFont) - +-- @param #string str +-- @param #string str +-- @return TextBMFont#TextBMFont ret (retunr value: ccui.TextBMFont) + -------------------------------- -- @function [parent=#TextBMFont] createInstance -- @param self diff --git a/cocos/scripting/lua-bindings/auto/api/TextField.lua b/cocos/scripting/lua-bindings/auto/api/TextField.lua index e8963cb846..1e318ed19a 100644 --- a/cocos/scripting/lua-bindings/auto/api/TextField.lua +++ b/cocos/scripting/lua-bindings/auto/api/TextField.lua @@ -168,10 +168,17 @@ -- @return size_table#size_table ret (return value: size_table) -------------------------------- --- @function [parent=#TextField] create +-- overload function: create(string, string, int) +-- +-- overload function: create() +-- +-- @function [parent=#TextField] create -- @param self --- @return TextField#TextField ret (return value: ccui.TextField) - +-- @param #string str +-- @param #string str +-- @param #int int +-- @return TextField#TextField ret (retunr value: ccui.TextField) + -------------------------------- -- @function [parent=#TextField] createInstance -- @param self diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_extension_auto.cpp.REMOVED.git-id b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_extension_auto.cpp.REMOVED.git-id index 599ec47f51..78c90309c0 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_extension_auto.cpp.REMOVED.git-id +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_extension_auto.cpp.REMOVED.git-id @@ -1 +1 @@ -cfd5546826cceb88f4a37396516b6863abb122c6 \ No newline at end of file +427b621d028746e72000086b320b1b9b3adf7a19 \ No newline at end of file diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id index 6dff430fb1..db0a19197c 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id @@ -1 +1 @@ -d608beef525313b9c497786a1dd7b2460ff65d84 \ No newline at end of file +a1f2ceee65fe7b4bdae2cd2c32ff84fa332a6b50 \ No newline at end of file From a3a3fa090762fd6bf03f9d5b9dff2dea249c0ea5 Mon Sep 17 00:00:00 2001 From: mgcL Date: Sat, 5 Apr 2014 18:55:55 +0800 Subject: [PATCH 37/66] fix Value's memory leak --- cocos/base/CCValue.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos/base/CCValue.cpp b/cocos/base/CCValue.cpp index c2829ab17e..ae26429a55 100644 --- a/cocos/base/CCValue.cpp +++ b/cocos/base/CCValue.cpp @@ -31,9 +31,9 @@ NS_CC_BEGIN const Value Value::Null; Value::Value() -: _vectorData(new ValueVector()) -, _mapData(new ValueMap()) -, _intKeyMapData(new ValueMapIntKey()) +: _vectorData(nullptr) +, _mapData(nullptr) +, _intKeyMapData(nullptr) , _type(Type::NONE) { From a5da6d71b434b4866cc97aa99c714e084c60ebfa Mon Sep 17 00:00:00 2001 From: mgcL Date: Sat, 5 Apr 2014 21:09:49 +0800 Subject: [PATCH 38/66] add destroyInstance for ScriptHandlerMgr --- .../scripting/lua-bindings/manual/LuaScriptHandlerMgr.cpp | 7 +++++++ cocos/scripting/lua-bindings/manual/LuaScriptHandlerMgr.h | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cocos/scripting/lua-bindings/manual/LuaScriptHandlerMgr.cpp b/cocos/scripting/lua-bindings/manual/LuaScriptHandlerMgr.cpp index 5d571b778e..765f0ac756 100644 --- a/cocos/scripting/lua-bindings/manual/LuaScriptHandlerMgr.cpp +++ b/cocos/scripting/lua-bindings/manual/LuaScriptHandlerMgr.cpp @@ -124,10 +124,12 @@ ScriptHandlerMgr::ScriptHandlerMgr() { } + ScriptHandlerMgr::~ScriptHandlerMgr() { CC_SAFE_DELETE(_scriptHandlerMgr); } + ScriptHandlerMgr* ScriptHandlerMgr::getInstance() { if (NULL == _scriptHandlerMgr) @@ -138,6 +140,11 @@ ScriptHandlerMgr* ScriptHandlerMgr::getInstance() return _scriptHandlerMgr; } +void ScriptHandlerMgr::destroyInstance() +{ + CC_SAFE_DELETE(_scriptHandlerMgr); +} + void ScriptHandlerMgr::init() { _mapObjectHandlers.clear(); diff --git a/cocos/scripting/lua-bindings/manual/LuaScriptHandlerMgr.h b/cocos/scripting/lua-bindings/manual/LuaScriptHandlerMgr.h index f367859afc..aab6f716ae 100644 --- a/cocos/scripting/lua-bindings/manual/LuaScriptHandlerMgr.h +++ b/cocos/scripting/lua-bindings/manual/LuaScriptHandlerMgr.h @@ -173,7 +173,8 @@ public: ScriptHandlerMgr(void); virtual ~ScriptHandlerMgr(void); static ScriptHandlerMgr* getInstance(void); - + static void destroyInstance(void); + void addObjectHandler(void* object,int handler,ScriptHandlerMgr::HandlerType handlerType); void removeObjectHandler(void* object,ScriptHandlerMgr::HandlerType handlerType); int getObjectHandler(void* object,ScriptHandlerMgr::HandlerType handlerType); From d9e0124ff8a8ebc55d0748b14207743727a8f73e Mon Sep 17 00:00:00 2001 From: mgcL Date: Sat, 5 Apr 2014 21:26:56 +0800 Subject: [PATCH 39/66] delete _scriptHandlerMgr in destruct will cause stack overflow --- cocos/scripting/lua-bindings/manual/LuaScriptHandlerMgr.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/cocos/scripting/lua-bindings/manual/LuaScriptHandlerMgr.cpp b/cocos/scripting/lua-bindings/manual/LuaScriptHandlerMgr.cpp index 765f0ac756..6f5fa121e4 100644 --- a/cocos/scripting/lua-bindings/manual/LuaScriptHandlerMgr.cpp +++ b/cocos/scripting/lua-bindings/manual/LuaScriptHandlerMgr.cpp @@ -127,7 +127,6 @@ ScriptHandlerMgr::ScriptHandlerMgr() ScriptHandlerMgr::~ScriptHandlerMgr() { - CC_SAFE_DELETE(_scriptHandlerMgr); } ScriptHandlerMgr* ScriptHandlerMgr::getInstance() From 03b5c879a7e969a7a4c512980953c279ce4388b5 Mon Sep 17 00:00:00 2001 From: Zak Mandhro Date: Sun, 6 Apr 2014 21:42:34 -0700 Subject: [PATCH 40/66] Update RELEASE_NOTES.md --- docs/RELEASE_NOTES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/RELEASE_NOTES.md b/docs/RELEASE_NOTES.md index b354e0b892..6e6e52b0a1 100644 --- a/docs/RELEASE_NOTES.md +++ b/docs/RELEASE_NOTES.md @@ -141,7 +141,7 @@ Please refer to [ReadMe](../README.md) # Highlights of v3.0 -* Replaced Objective-C patters with C++ (C++11) patterns and best practices +* Replaced Objective-C patterns with C++ (C++11) patterns and best practices * Improved Labels * Improved renderer (much faster than in v2.2!!) * New Event Dispatcher From 6262c9c91036581855496fdc2bacb179b13ad40c Mon Sep 17 00:00:00 2001 From: dbaack Date: Sun, 6 Apr 2014 21:59:40 -0700 Subject: [PATCH 41/66] Fixed a bug where an event listener removed from the event dispatcher while it is still in the _toAddedListeners vector would never have _isRegistered set to false on removal. This causes it to fail an assert if it is attempted to be added to the event dispatcher again later. --- cocos/2d/CCEventDispatcher.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cocos/2d/CCEventDispatcher.cpp b/cocos/2d/CCEventDispatcher.cpp index 6156453487..15e3dfc2a0 100644 --- a/cocos/2d/CCEventDispatcher.cpp +++ b/cocos/2d/CCEventDispatcher.cpp @@ -637,6 +637,7 @@ void EventDispatcher::removeEventListener(EventListener* listener) { if (*iter == listener) { + listener->setRegistered(false); listener->release(); _toAddedListeners.erase(iter); break; @@ -1252,6 +1253,7 @@ void EventDispatcher::removeEventListenersForListenerID(const EventListener::Lis { if ((*iter)->getListenerID() == listenerID) { + (*iter)->setRegistered(false); (*iter)->release(); iter = _toAddedListeners.erase(iter); } From 92d11697470e3c4089e317e1079bc4174ad87e93 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 7 Apr 2014 16:16:51 +0800 Subject: [PATCH 42/66] Update AUTHORS [ci skip] --- AUTHORS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AUTHORS b/AUTHORS index 0c6ee6f14e..bf6f688044 100644 --- a/AUTHORS +++ b/AUTHORS @@ -801,6 +801,9 @@ Developers: zukkun Fixed incorrect function invocation in PhysicsBody::setAngularVelocityLimit + + dbaack + Fixed a bug that removing and re-adding an event listener will trigger assert Retired Core Developers: WenSheng Yang From 7019a8cf83cbebc979650d760f13b2815a02eee5 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 7 Apr 2014 16:18:49 +0800 Subject: [PATCH 43/66] Update CHANGELOG [ci skip] --- CHANGELOG.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.REMOVED.git-id b/CHANGELOG.REMOVED.git-id index fda1b07c61..1266b2dcc2 100644 --- a/CHANGELOG.REMOVED.git-id +++ b/CHANGELOG.REMOVED.git-id @@ -1 +1 @@ -95d810c2ae2b7e8792a1557f75ee452b54d2e49e \ No newline at end of file +bf5787ee2ae83b6f9b2da3b848b54fe9d2ae51fc \ No newline at end of file From 0d8c70e93f91957bd6412ea84619f10c498d6ffc Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 7 Apr 2014 16:20:47 +0800 Subject: [PATCH 44/66] Update AUTHORS [ci skip] --- AUTHORS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AUTHORS b/AUTHORS index bf6f688044..6414a9c443 100644 --- a/AUTHORS +++ b/AUTHORS @@ -804,6 +804,9 @@ Developers: dbaack Fixed a bug that removing and re-adding an event listener will trigger assert + + zakmandhro + A typo fix in RELEASE_NOTES.md Retired Core Developers: WenSheng Yang From cdb68cc918a42eb19936dd01784e3f8a0ecc2a14 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 7 Apr 2014 16:33:40 +0800 Subject: [PATCH 45/66] Update AUTHORS [ci skip] --- AUTHORS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AUTHORS b/AUTHORS index 6414a9c443..b27b4d4422 100644 --- a/AUTHORS +++ b/AUTHORS @@ -807,6 +807,9 @@ Developers: zakmandhro A typo fix in RELEASE_NOTES.md + + mgcL + A potential memory leak fix in value's default constructor Retired Core Developers: WenSheng Yang From f9ac3c82fcacfea69bd25a016ae6dbd9bdc9d4d1 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 7 Apr 2014 16:34:56 +0800 Subject: [PATCH 46/66] Update CHANGELOG [ci skip] --- CHANGELOG.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.REMOVED.git-id b/CHANGELOG.REMOVED.git-id index 1266b2dcc2..50419c00e0 100644 --- a/CHANGELOG.REMOVED.git-id +++ b/CHANGELOG.REMOVED.git-id @@ -1 +1 @@ -bf5787ee2ae83b6f9b2da3b848b54fe9d2ae51fc \ No newline at end of file +f739b94904127eeb23d5fcdcb20a4d134c7a3751 \ No newline at end of file From 79b5dff795052b8184493d495d688d5ea0f2ae24 Mon Sep 17 00:00:00 2001 From: Darragh Coy Date: Mon, 7 Apr 2014 16:19:26 -0700 Subject: [PATCH 47/66] CCEventDispatcher crash fix Fix possible crashes which could be caused by the EventDispatcher having listeners associated with nodes are destroyed. Catch the case where a node registers a listener while we are dispatching events and gets destroyed while that event is still being dispatched. Check the list of nodes to be added into the event dispatcher fully when we are cleaning listeners for a target node. This issue was found using the extra debug verification in this pull request: https://github.com/cocos2d/cocos2d-x/pull/6011 --- cocos/2d/CCEventDispatcher.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cocos/2d/CCEventDispatcher.cpp b/cocos/2d/CCEventDispatcher.cpp index 15e3dfc2a0..c673f1c6b4 100644 --- a/cocos/2d/CCEventDispatcher.cpp +++ b/cocos/2d/CCEventDispatcher.cpp @@ -340,6 +340,26 @@ void EventDispatcher::removeEventListenersForTarget(Node* target, bool recursive } } + // Bug fix: ensure there are no references to the node in the list of listeners to be added. + // If we find any listeners associated with the destroyed node in this list then remove them. + // This is to catch the scenario where the node gets destroyed before it's listener + // is added into the event dispatcher fully. This could happen if a node registers a listener + // and gets destroyed while we are dispatching an event (touch etc.) + for (auto iter = _toAddedListeners.begin(); iter != _toAddedListeners.end(); ) + { + EventListener * listener = *iter; + + if (listener->getSceneGraphPriority() == target) + { + listener->release(); + iter = _toAddedListeners.erase(iter); + } + else + { + ++iter; + } + } + if (recursive) { const auto& children = target->getChildren(); From bb85df66b1b49705f120edc0ceceafeede1e7347 Mon Sep 17 00:00:00 2001 From: Darragh Coy Date: Mon, 7 Apr 2014 16:46:03 -0700 Subject: [PATCH 48/66] Add an event dispatcher test Add an event dispatcher test to help reproduce crashes fixed by the previous commit and to verify that the fix still works. --- .../NewEventDispatcherTest.cpp | 45 ++++++++++++++++++- .../NewEventDispatcherTest.h | 10 +++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/tests/cpp-tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp b/tests/cpp-tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp index 77249f91e0..337a8164a2 100644 --- a/tests/cpp-tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp +++ b/tests/cpp-tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp @@ -8,6 +8,7 @@ #include "NewEventDispatcherTest.h" #include "testResource.h" +#include "CCAutoreleasePool.h" namespace { @@ -27,7 +28,8 @@ std::function createFunctions[] = CL(PauseResumeTargetTest), CL(Issue4129), CL(Issue4160), - CL(DanglingNodePointersTest) + CL(DanglingNodePointersTest), + CL(RegisterAndUnregisterWhileEventHanldingTest) }; unsigned int TEST_CASE_COUNT = sizeof(createFunctions) / sizeof(createFunctions[0]); @@ -1413,3 +1415,44 @@ std::string DanglingNodePointersTest::subtitle() const "CC_NODE_DEBUG_VERIFY_EVENT_LISTENERS == 1\n&& COCOS2D_DEBUG > 0"; #endif } + + +RegisterAndUnregisterWhileEventHanldingTest::RegisterAndUnregisterWhileEventHanldingTest() +{ + Point origin = Director::getInstance()->getVisibleOrigin(); + Size size = Director::getInstance()->getVisibleSize(); + + auto callback1 = [=](DanglingNodePointersTestSprite * sprite) + { + auto callback2 = [](DanglingNodePointersTestSprite * sprite) + { + CCASSERT(false, "This should never get called!"); + }; + + { + AutoreleasePool pool; + + auto sprite2 = DanglingNodePointersTestSprite::create(callback2); + sprite2->setTexture("Images/CyanSquare.png"); + sprite2->setPosition(origin+Point(size.width/2, size.height/2)); + + addChild(sprite2, 0); + removeChild(sprite2); + } + }; + + auto sprite1 = DanglingNodePointersTestSprite::create(callback1); + sprite1->setTexture("Images/CyanSquare.png"); + sprite1->setPosition(origin+Point(size.width/2, size.height/2)); + addChild(sprite1, -10); +} + +std::string RegisterAndUnregisterWhileEventHanldingTest::title() const +{ + return "RegisterAndUnregisterWhileEventHanldingTest"; +} + +std::string RegisterAndUnregisterWhileEventHanldingTest::subtitle() const +{ + return "Tap the square multiple times - should not crash!"; +} diff --git a/tests/cpp-tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.h b/tests/cpp-tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.h index 74c692d49c..64b52ed037 100644 --- a/tests/cpp-tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.h +++ b/tests/cpp-tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.h @@ -217,4 +217,14 @@ public: virtual std::string subtitle() const override; }; +class RegisterAndUnregisterWhileEventHanldingTest : public EventDispatcherTestDemo +{ +public: + CREATE_FUNC(RegisterAndUnregisterWhileEventHanldingTest); + RegisterAndUnregisterWhileEventHanldingTest(); + + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + #endif /* defined(__samples__NewEventDispatcherTest__) */ From 9a6b93eae1e8dc443f5b9963c149edabe6d24240 Mon Sep 17 00:00:00 2001 From: Darragh Coy Date: Mon, 7 Apr 2014 17:05:42 -0700 Subject: [PATCH 49/66] Add extra CCNode verification Add a check to the CCNode destructor to catch a common cocos2d-x programming mistake - forgetting to call base class onExit() in derived class onExit() implementations. We can check for this invalid API usage by checking if the node is still marked as running on destruction. If the node still thinks it's running then it's likely the cleanup logic performed by Node::onExit() was not done. --- cocos/2d/CCNode.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index fc5f7c4aec..76e8c678e0 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -184,6 +184,7 @@ Node::~Node() _eventDispatcher->debugCheckNodeHasNoEventListenersOnDestruction(this); #endif + CCASSERT(!_running, "Node still marked as running on node destruction! Was base class onExit() called in derived class onExit() implementations?"); CC_SAFE_RELEASE(_eventDispatcher); } From 546db2de4afd65c01f94a0a2975066b36e740731 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 8 Apr 2014 11:17:38 +0800 Subject: [PATCH 50/66] Unregistered listener when it's removed from _toAddedListeners. --- cocos/2d/CCEventDispatcher.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos/2d/CCEventDispatcher.cpp b/cocos/2d/CCEventDispatcher.cpp index c673f1c6b4..93e3c85bd7 100644 --- a/cocos/2d/CCEventDispatcher.cpp +++ b/cocos/2d/CCEventDispatcher.cpp @@ -351,6 +351,7 @@ void EventDispatcher::removeEventListenersForTarget(Node* target, bool recursive if (listener->getSceneGraphPriority() == target) { + listener->setRegistered(false); listener->release(); iter = _toAddedListeners.erase(iter); } From ecf784646d4a0e6031778826464d54c80f97459b Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 8 Apr 2014 11:34:01 +0800 Subject: [PATCH 51/66] Update AUTHORS [ci skip] --- AUTHORS | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/AUTHORS b/AUTHORS index b27b4d4422..fa12528694 100644 --- a/AUTHORS +++ b/AUTHORS @@ -49,12 +49,19 @@ Developers: Asynchronous Image loading for Emscripten DarraghCoy - Fix a potential crash SimpleAudioEngineOpenSL::playEffect - Fix some bugs with Set class - Add ccDrawSolidCircle - Add Rect::unionWithRect - Fix a memory leak in Set::removeAllObjects. - Fixed potential crashes in event dispatch while using SceneGraphPriroity listeners and added helper function to check it + Fixed a potential crash SimpleAudioEngineOpenSL::playEffect + Fixed some bugs with Set class + Added ccDrawSolidCircle + Added Rect::unionWithRect + Fixed a memory leak in Set::removeAllObjects + Fixed for unaligned memory access crash in CCBReader::readFloat() + Fixed for loading custom fonts on iOS when referenced from a CCB file + Fixed CCUserDefault.cpp compiling on Android. + Fixed CCFileUtils 'createXXXXWithContentsOfFile' path lookup issue + Added CCDirector::popToSceneStackLevel(int level) + Fixed a bug that custom font can't be loaded correctly if using full path of filename on android + Fixed potential crashes in EventDispatch while using SceneGraphPriroity listeners and added helper function to check it + Fixed a protential crash in EventDispatch while unregistering listener right after it was registered. silverscania Pass correct parameter to glPixelStorei when creating a texture @@ -116,13 +123,6 @@ Developers: Jimmy Sambuo fix the bug that SimpleAudioEngine::playEffect() and playBackgroundMusic() play twice on linux - DarraghCoy - fix for loading custom fonts on iOS when referenced from a CCB file - Fix CCUserDefault.cpp compiling on Android. - Fixing CCFileUtils 'createXXXXWithContentsOfFile' path lookup issue. - Add CCDirector::popToSceneStackLevel(int level). - Fixing a bug that custom font can't be loaded correctly if using full path of filename on android. - Waiter fix an error that OpenSLEngine can't load resources from SD card add CCRemoveSelf action @@ -349,9 +349,6 @@ Developers: Fixing a logical error in CCDrawNode::drawPolygon. Fixing a bug that Jsb function getCPBody return type is not right. - DarraghCoy - Fix for unaligned memory access crash in CCBReader::readFloat(). - Sergej Tatarincev (SevInf) Making ScriptingCore.cpp compiled fine with C++11 on iOS. Using shared NodeLoaderLibrary in CCBReader bindings. From 0834c07fa342e83ec0b9734db97d0a4a809f849b Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 8 Apr 2014 11:37:00 +0800 Subject: [PATCH 52/66] Update CHANGELOG [ci skip] --- CHANGELOG.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.REMOVED.git-id b/CHANGELOG.REMOVED.git-id index 50419c00e0..be0d3006f1 100644 --- a/CHANGELOG.REMOVED.git-id +++ b/CHANGELOG.REMOVED.git-id @@ -1 +1 @@ -f739b94904127eeb23d5fcdcb20a4d134c7a3751 \ No newline at end of file +e372561a321895bc0fb6665b38c24a9305aae742 \ No newline at end of file From a2e4aeb857eae644557520e73866631ee7af9949 Mon Sep 17 00:00:00 2001 From: zhangbin Date: Tue, 8 Apr 2014 14:31:21 +0800 Subject: [PATCH 53/66] Update the reference of submodule plugin-x --- plugin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin b/plugin index d177da9b54..547ce2ea62 160000 --- a/plugin +++ b/plugin @@ -1 +1 @@ -Subproject commit d177da9b541ab1b436476f9caa057766d485d9c3 +Subproject commit 547ce2ea62a220a419f5df6bc54ab609437e49f3 From fae742c0b81a41b675cde42045e960aa14e0343d Mon Sep 17 00:00:00 2001 From: shujunqiao Date: Tue, 8 Apr 2014 14:32:25 +0800 Subject: [PATCH 54/66] modify ShaderTest.cpp not crah to autotest. --- tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp index 590cedeba6..db28d8b8f8 100644 --- a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp +++ b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp @@ -770,7 +770,7 @@ colors[8] = vec4(1,0.5,0.5,1); \n\ colors[9] = vec4(0.5,0.5,1,1); \n\ \n\ int y = int( mod(gl_FragCoord.y / 3.0, 10.0 ) ); \n\ -gl_FragColor = colors[z] * texture2D(CC_Texture0, v_texCoord); \n\ +gl_FragColor = colors[y] * texture2D(CC_Texture0, v_texCoord); \n\ } \n\ \n"; From fb777b1a1d4fab425af305f44e35e607c9005b89 Mon Sep 17 00:00:00 2001 From: shujunqiao Date: Tue, 8 Apr 2014 14:52:17 +0800 Subject: [PATCH 55/66] [ci skip], delete ShaderFail sample in ShaderTest.cpp. --- .../Classes/ShaderTest/ShaderTest.cpp | 55 +------------------ .../cpp-tests/Classes/ShaderTest/ShaderTest.h | 8 --- 2 files changed, 1 insertion(+), 62 deletions(-) diff --git a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp index db28d8b8f8..259ba79ef6 100644 --- a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp +++ b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp @@ -6,7 +6,7 @@ static int sceneIdx = -1; -#define MAX_LAYER 9 +#define MAX_LAYER 8 static Layer* createShaderLayer(int nIndex) { @@ -20,7 +20,6 @@ static Layer* createShaderLayer(int nIndex) case 5: return new ShaderPlasma(); case 6: return new ShaderBlur(); case 7: return new ShaderRetroEffect(); - case 8: return new ShaderFail(); } return NULL; @@ -745,58 +744,6 @@ std::string ShaderRetroEffect::subtitle() const return "sin() effect with moving colors"; } -// ShaderFail -const GLchar *shader_frag_fail = "\n\ -#ifdef GL_ES \n\ -precision lowp float; \n\ -#endif \n\ -\n\ -varying vec2 v_texCoord; \n\ -uniform sampler2D CC_Texture0; \n\ -\n\ -vec4 colors[10]; \n\ -\n\ -void main(void) \n\ -{ \n\ -colors[0] = vec4(1,0,0,1); \n\ -colors[1] = vec4(0,1,0,1); \n\ -colors[2] = vec4(0,0,1,1); \n\ -colors[3] = vec4(0,1,1,1); \n\ -colors[4] = vec4(1,0,1,1); \n\ -colors[5] = vec4(1,1,0,1); \n\ -colors[6] = vec4(1,1,1,1); \n\ -colors[7] = vec4(1,0.5,0,1); \n\ -colors[8] = vec4(1,0.5,0.5,1); \n\ -colors[9] = vec4(0.5,0.5,1,1); \n\ -\n\ -int y = int( mod(gl_FragCoord.y / 3.0, 10.0 ) ); \n\ -gl_FragColor = colors[y] * texture2D(CC_Texture0, v_texCoord); \n\ -} \n\ -\n"; - -ShaderFail::ShaderFail() -{ - auto p = new GLProgram(); - p->initWithByteArrays(ccPositionTexture_vert, shader_frag_fail); - - p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION); - p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS); - - p->link(); - p->updateUniforms(); - p->release(); -} - -std::string ShaderFail::title() const -{ - return "Shader: Invalid shader"; -} - -std::string ShaderFail::subtitle() const -{ - return "See console for output with useful error log"; -} - ///--------------------------------------- // // ShaderTestScene diff --git a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.h b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.h index 59e178abc1..ec606e621f 100644 --- a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.h +++ b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.h @@ -137,14 +137,6 @@ protected: CustomCommand _customCommand; }; -class ShaderFail : public ShaderTestDemo -{ -public: - ShaderFail(); - virtual std::string title() const override; - virtual std::string subtitle() const override; -}; - class ShaderTestScene : public TestScene { public: From 4e1284bd454cf63d66f1acfe440697b178daeb6d Mon Sep 17 00:00:00 2001 From: heliclei Date: Tue, 8 Apr 2014 14:52:53 +0800 Subject: [PATCH 56/66] closed #4533:fix console upload hang issue --- cocos/base/CCConsole.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/cocos/base/CCConsole.cpp b/cocos/base/CCConsole.cpp index 792188a97d..b290db9e78 100644 --- a/cocos/base/CCConsole.cpp +++ b/cocos/base/CCConsole.cpp @@ -765,6 +765,8 @@ void Console::commandTouch(int fd, const std::string& args) } } +static char invalid_filename_char[] = {':', '/', '\\', '?', '%', '*', '<', '>', '"', '|', '\r', '\n', '\t'}; + void Console::commandUpload(int fd) { ssize_t n, rc; @@ -775,11 +777,20 @@ void Console::commandUpload(int fd) { if( (rc = recv(fd, &c, 1, 0)) ==1 ) { - *ptr++ = c; + for(char x : invalid_filename_char) + { + if(c == x) + { + const char err[] = "upload: invalid file name!\n"; + send(fd, err, sizeof(err),0); + return; + } + } if(c == ' ') { break; } + *ptr++ = c; } else if( rc == 0 ) { @@ -875,10 +886,10 @@ bool Console::parseCommand(int fd) } else { - const char err[] = "Unknown Command!\n"; - sendPrompt(fd); + const char err[] = "upload: invalid args! Type 'help' for options\n"; send(fd, err, sizeof(err),0); - return false; + sendPrompt(fd); + return true; } } @@ -909,7 +920,7 @@ bool Console::parseCommand(int fd) const char err[] = "Unknown command. Type 'help' for options\n"; send(fd, err, sizeof(err),0); sendPrompt(fd); - return false; + return true; } auto it = _commands.find(trim(args[0])); From e28093ee1a680b603b9c3ec9c95e65514d8473bf Mon Sep 17 00:00:00 2001 From: minggo Date: Tue, 8 Apr 2014 14:53:57 +0800 Subject: [PATCH 57/66] closed #4683: use assert because CCASSERT is not thread safe --- cocos/2d/platform/CCFileUtils.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cocos/2d/platform/CCFileUtils.cpp b/cocos/2d/platform/CCFileUtils.cpp index c6d7a359a9..16cc6cf415 100644 --- a/cocos/2d/platform/CCFileUtils.cpp +++ b/cocos/2d/platform/CCFileUtils.cpp @@ -500,7 +500,9 @@ void FileUtils::purgeCachedEntries() static Data getData(const std::string& filename, bool forString) { - CCASSERT(!filename.empty(), "Invalid filename!"); + // getData is used indirectly in Image::initWithImageFileThreadSafe(), but CCASSERT is not thread-safe +// CCASSERT(!filename.empty(), "Invalid filename!"); + assert(!(filename.empty())); Data ret; unsigned char* buffer = nullptr; From 49bba30409df9a16e017915505b466729febbc90 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 8 Apr 2014 15:08:34 +0800 Subject: [PATCH 58/66] closed #4710: [win32] Crash in EventDispatcher if game starts up with mouse moving frequently --- cocos/2d/CCDirector.cpp | 13 +++++++++---- cocos/2d/CCEventDispatcher.cpp | 26 ++++++++++++++++---------- cocos/2d/CCEventDispatcher.h | 2 +- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/cocos/2d/CCDirector.cpp b/cocos/2d/CCDirector.cpp index 98bdeb83a6..be7757e66c 100644 --- a/cocos/2d/CCDirector.cpp +++ b/cocos/2d/CCDirector.cpp @@ -393,7 +393,10 @@ void Director::setOpenGLView(GLView *openGLView) CHECK_GL_ERROR_DEBUG(); -// _touchDispatcher->setDispatchEvents(true); + if (_eventDispatcher) + { + _eventDispatcher->setEnabled(true); + } } } @@ -747,9 +750,11 @@ void Director::purgeDirector() // cleanup scheduler getScheduler()->unscheduleAll(); - // don't release the event handlers - // They are needed in case the director is run again -// _touchDispatcher->removeAllDelegates(); + // Disable event dispatching + if (_eventDispatcher) + { + _eventDispatcher->setEnabled(false); + } if (_runningScene) { diff --git a/cocos/2d/CCEventDispatcher.cpp b/cocos/2d/CCEventDispatcher.cpp index 93e3c85bd7..54a38a313c 100644 --- a/cocos/2d/CCEventDispatcher.cpp +++ b/cocos/2d/CCEventDispatcher.cpp @@ -31,7 +31,7 @@ #include "CCEventListenerKeyboard.h" #include "CCEventListenerCustom.h" -#include "CCNode.h" +#include "CCScene.h" #include "CCDirector.h" #include "CCEventType.h" @@ -191,7 +191,7 @@ void EventDispatcher::EventListenerVector::clear() EventDispatcher::EventDispatcher() : _inDispatch(0) -, _isEnabled(true) +, _isEnabled(false) , _nodePriorityIndex(0) { _toAddedListeners.reserve(50); @@ -1125,6 +1125,9 @@ void EventDispatcher::sortEventListeners(const EventListener::ListenerID& listen if (dirtyFlag != DirtyFlag::NONE) { + // Clear the dirty flag first, if `rootNode` is nullptr, then set its dirty flag of scene graph priority + dirtyIter->second = DirtyFlag::NONE; + if ((int)dirtyFlag & (int)DirtyFlag::FIXED_PRIORITY) { sortEventListenersOfFixedPriority(listenerID); @@ -1132,14 +1135,20 @@ void EventDispatcher::sortEventListeners(const EventListener::ListenerID& listen if ((int)dirtyFlag & (int)DirtyFlag::SCENE_GRAPH_PRIORITY) { - sortEventListenersOfSceneGraphPriority(listenerID); + auto rootNode = Director::getInstance()->getRunningScene(); + if (rootNode) + { + sortEventListenersOfSceneGraphPriority(listenerID, rootNode); + } + else + { + dirtyIter->second = DirtyFlag::SCENE_GRAPH_PRIORITY; + } } - - dirtyIter->second = DirtyFlag::NONE; } } -void EventDispatcher::sortEventListenersOfSceneGraphPriority(const EventListener::ListenerID& listenerID) +void EventDispatcher::sortEventListenersOfSceneGraphPriority(const EventListener::ListenerID& listenerID, Node* rootNode) { auto listeners = getListeners(listenerID); @@ -1149,8 +1158,7 @@ void EventDispatcher::sortEventListenersOfSceneGraphPriority(const EventListener if (sceneGraphListeners == nullptr) return; - - Node* rootNode = (Node*)Director::getInstance()->getRunningScene(); + // Reset priority index _nodePriorityIndex = 0; _nodePriorityMap.clear(); @@ -1158,7 +1166,6 @@ void EventDispatcher::sortEventListenersOfSceneGraphPriority(const EventListener visitTarget(rootNode, true); // After sort: priority < 0, > 0 - std::sort(sceneGraphListeners->begin(), sceneGraphListeners->end(), [this](const EventListener* l1, const EventListener* l2) { return _nodePriorityMap[l1->getSceneGraphPriority()] > _nodePriorityMap[l2->getSceneGraphPriority()]; }); @@ -1351,7 +1358,6 @@ void EventDispatcher::setEnabled(bool isEnabled) _isEnabled = isEnabled; } - bool EventDispatcher::isEnabled() const { return _isEnabled; diff --git a/cocos/2d/CCEventDispatcher.h b/cocos/2d/CCEventDispatcher.h index 002f42a224..16d7b62149 100644 --- a/cocos/2d/CCEventDispatcher.h +++ b/cocos/2d/CCEventDispatcher.h @@ -207,7 +207,7 @@ protected: void sortEventListeners(const EventListener::ListenerID& listenerID); /** Sorts the listeners of specified type by scene graph priority */ - void sortEventListenersOfSceneGraphPriority(const EventListener::ListenerID& listenerID); + void sortEventListenersOfSceneGraphPriority(const EventListener::ListenerID& listenerID, Node* rootNode); /** Sorts the listeners of specified type by fixed priority */ void sortEventListenersOfFixedPriority(const EventListener::ListenerID& listenerID); From 8f451d48a17e226259130577c8c6ea908f882d3c Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 8 Apr 2014 15:11:04 +0800 Subject: [PATCH 59/66] issue #4710: Fixed wrong indention. --- cocos/2d/CCDirector.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cocos/2d/CCDirector.cpp b/cocos/2d/CCDirector.cpp index be7757e66c..3ca022104e 100644 --- a/cocos/2d/CCDirector.cpp +++ b/cocos/2d/CCDirector.cpp @@ -393,10 +393,10 @@ void Director::setOpenGLView(GLView *openGLView) CHECK_GL_ERROR_DEBUG(); - if (_eventDispatcher) - { - _eventDispatcher->setEnabled(true); - } + if (_eventDispatcher) + { + _eventDispatcher->setEnabled(true); + } } } @@ -751,10 +751,10 @@ void Director::purgeDirector() getScheduler()->unscheduleAll(); // Disable event dispatching - if (_eventDispatcher) - { - _eventDispatcher->setEnabled(false); - } + if (_eventDispatcher) + { + _eventDispatcher->setEnabled(false); + } if (_runningScene) { From e04b820cfcc28383b374c57c8bfe77a8a002e824 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 8 Apr 2014 15:24:47 +0800 Subject: [PATCH 60/66] closed #4711: [win32] Passing empty string to FileUtils::isFileExist may also return true --- cocos/2d/platform/win32/CCFileUtilsWin32.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cocos/2d/platform/win32/CCFileUtilsWin32.cpp b/cocos/2d/platform/win32/CCFileUtilsWin32.cpp index 093f548bbd..b8a1b8f4d3 100644 --- a/cocos/2d/platform/win32/CCFileUtilsWin32.cpp +++ b/cocos/2d/platform/win32/CCFileUtilsWin32.cpp @@ -112,7 +112,10 @@ bool FileUtilsWin32::isFileExistInternal(const std::string& strFilePath) const WCHAR utf16Buf[CC_MAX_PATH] = {0}; MultiByteToWideChar(CP_UTF8, 0, strPath.c_str(), -1, utf16Buf, sizeof(utf16Buf)/sizeof(utf16Buf[0])); - return GetFileAttributesW(utf16Buf) != -1 ? true : false; + DWORD attr = GetFileAttributesW(utf16Buf); + if(attr == INVALID_FILE_ATTRIBUTES || (attr & FILE_ATTRIBUTE_DIRECTORY)) + return false; // not a file + return true; } bool FileUtilsWin32::isAbsolutePath(const std::string& strPath) const From 2703740acd08a8460678cbfced3e757776083f91 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 8 Apr 2014 15:43:38 +0800 Subject: [PATCH 61/66] Update AUTHORS [ci skip] --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index fa12528694..70240227d9 100644 --- a/AUTHORS +++ b/AUTHORS @@ -807,6 +807,7 @@ Developers: mgcL A potential memory leak fix in value's default constructor + Added ScriptHandlerMgr::destroyInstance to avoid memory leak Retired Core Developers: WenSheng Yang From 2d3cb828166618d363e1a173035a7c3d68a4bf62 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 8 Apr 2014 15:45:18 +0800 Subject: [PATCH 62/66] Update CHANGELOG [ci skip] --- CHANGELOG.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.REMOVED.git-id b/CHANGELOG.REMOVED.git-id index be0d3006f1..e07130a4e6 100644 --- a/CHANGELOG.REMOVED.git-id +++ b/CHANGELOG.REMOVED.git-id @@ -1 +1 @@ -e372561a321895bc0fb6665b38c24a9305aae742 \ No newline at end of file +b78af2958c35d67fd0d06f1ca9fd7fce58799235 \ No newline at end of file From 87a3b7e6cbcb3a877edcc583fcd768188a5f6801 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 8 Apr 2014 15:50:26 +0800 Subject: [PATCH 63/66] Update AUTHORS [ci skip] --- AUTHORS | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 70240227d9..fe951760cd 100644 --- a/AUTHORS +++ b/AUTHORS @@ -61,7 +61,8 @@ Developers: Added CCDirector::popToSceneStackLevel(int level) Fixed a bug that custom font can't be loaded correctly if using full path of filename on android Fixed potential crashes in EventDispatch while using SceneGraphPriroity listeners and added helper function to check it - Fixed a protential crash in EventDispatch while unregistering listener right after it was registered. + Fixed a protential crash in EventDispatch while unregistering listener right after it was registered + Adding an extra verification in Node's destructor silverscania Pass correct parameter to glPixelStorei when creating a texture From 12fb27b01e2e6a3d1fe4ff0378694a8970fe27d2 Mon Sep 17 00:00:00 2001 From: zhangbin Date: Tue, 8 Apr 2014 16:23:12 +0800 Subject: [PATCH 64/66] closed #4666, Update the build configuration files in template & update the reference of submodule cocos2d-console. --- tools/cocos2d-console | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cocos2d-console b/tools/cocos2d-console index 47edbdcc88..9aeab189f0 160000 --- a/tools/cocos2d-console +++ b/tools/cocos2d-console @@ -1 +1 @@ -Subproject commit 47edbdcc88c99b4c0125bf70b847f03ad26f463d +Subproject commit 9aeab189f0a734423e7418c5ea11771c1db09592 From ca9b4a319642c3bbbe35eef266e3e922eb084e65 Mon Sep 17 00:00:00 2001 From: lm Date: Tue, 8 Apr 2014 16:35:01 +0800 Subject: [PATCH 65/66] [Jenkins][ci skip]: Fix return value of git fail --- tools/jenkins-scripts/pull-request-builder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/jenkins-scripts/pull-request-builder.py b/tools/jenkins-scripts/pull-request-builder.py index 8b6b8909f6..41dce4da3a 100755 --- a/tools/jenkins-scripts/pull-request-builder.py +++ b/tools/jenkins-scripts/pull-request-builder.py @@ -85,7 +85,7 @@ def main(): git_fetch_pr = "git fetch origin pull/" + str(pr_num) + "/merge" ret = os.system(git_fetch_pr) if(ret != 0): - return(1) + return(2) #checkout git_checkout = "git checkout -b " + "pull" + str(pr_num) + " FETCH_HEAD" @@ -99,7 +99,7 @@ def main(): git_update_submodule = "git submodule update --init --force" ret = os.system(git_update_submodule) if(ret != 0): - return(1) + return(2) # Generate binding glue codes if(branch == 'develop'): From ccbd77309dd80b254d972812f9f47ffefa3cb800 Mon Sep 17 00:00:00 2001 From: minggo Date: Tue, 8 Apr 2014 17:49:18 +0800 Subject: [PATCH 66/66] change QuadCommand::generateMaterialID() to private --- cocos/2d/renderer/CCQuadCommand.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cocos/2d/renderer/CCQuadCommand.h b/cocos/2d/renderer/CCQuadCommand.h index d8f2ded978..48f513fae8 100644 --- a/cocos/2d/renderer/CCQuadCommand.h +++ b/cocos/2d/renderer/CCQuadCommand.h @@ -52,7 +52,6 @@ public: //TODO use material to decide if it is translucent inline bool isTranslucent() const { return true; } - void generateMaterialID(); inline uint32_t getMaterialID() const { return _materialID; } inline GLuint getTextureID() const { return _textureID; } @@ -67,6 +66,9 @@ public: inline const kmMat4& getModelView() const { return _mv; } +private: + void generateMaterialID(); + protected: uint32_t _materialID;