From 530f82ee27fcb6a733eabc8b603bf165629ee44b Mon Sep 17 00:00:00 2001 From: CaiWenzhi Date: Thu, 26 Dec 2013 14:57:30 +0800 Subject: [PATCH 1/5] Add refresh layout method --- cocos/gui/UILayout.cpp | 5 +++++ cocos/gui/UILayout.h | 2 ++ cocos/gui/UIListView.cpp | 5 +++++ cocos/gui/UIListView.h | 2 ++ 4 files changed, 14 insertions(+) diff --git a/cocos/gui/UILayout.cpp b/cocos/gui/UILayout.cpp index aaa41c7fd7..29031e2a29 100644 --- a/cocos/gui/UILayout.cpp +++ b/cocos/gui/UILayout.cpp @@ -709,6 +709,11 @@ LayoutType Layout::getLayoutType() const { return _layoutType; } + +void Layout::requestDoLayout() +{ + _doLayoutDirty = true; +} void Layout::doLayout() { diff --git a/cocos/gui/UILayout.h b/cocos/gui/UILayout.h index a4f7add36e..0feff5447e 100644 --- a/cocos/gui/UILayout.h +++ b/cocos/gui/UILayout.h @@ -212,6 +212,8 @@ public: virtual void visit(); virtual void sortAllChildren() override; + + void requestDoLayout(); protected: //override "init" method of widget. virtual bool init() override; diff --git a/cocos/gui/UIListView.cpp b/cocos/gui/UIListView.cpp index 301093beee..a6cedbb287 100644 --- a/cocos/gui/UIListView.cpp +++ b/cocos/gui/UIListView.cpp @@ -362,6 +362,11 @@ void ListView::setDirection(SCROLLVIEW_DIR dir) } ScrollView::setDirection(dir); } + +void ListView::requestRefreshView() +{ + _refreshViewDirty = true; +} void ListView::refreshView() { diff --git a/cocos/gui/UIListView.h b/cocos/gui/UIListView.h index b7c18c7f0b..0eac270d6e 100644 --- a/cocos/gui/UIListView.h +++ b/cocos/gui/UIListView.h @@ -165,6 +165,8 @@ public: virtual std::string getDescription() const override; + void requestRefreshView(); + protected: virtual void addChild(Node* child) override{ScrollView::addChild(child);}; virtual void addChild(Node * child, int zOrder) override{ScrollView::addChild(child, zOrder);}; From 706d0e185a577eb80c4eb22eb59be521558619a0 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Thu, 26 Dec 2013 16:11:06 +0800 Subject: [PATCH 2/5] fix LabelTestNew --- .../Classes/LabelTest/LabelTestNew.cpp | 31 +++++++++++++++++++ .../TestCpp/Classes/LabelTest/LabelTestNew.h | 4 +++ 2 files changed, 35 insertions(+) diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp index 66455e0ab2..a37038bbe6 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp @@ -1,5 +1,7 @@ #include "LabelTestNew.h" #include "../testResource.h" +#include "renderer/CCRenderer.h" +#include "renderer/CCCustomCommand.h" enum { kTagTileMap = 1, @@ -300,9 +302,24 @@ LabelFNTSpriteActions::LabelFNTSpriteActions() void LabelFNTSpriteActions::draw() { + CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); + cmd->init(0, _vertexZ); + cmd->func = CC_CALLBACK_0(LabelFNTSpriteActions::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(cmd); + +} + +void LabelFNTSpriteActions::onDraw() +{ + kmMat4 oldMat; + kmGLGetMatrix(KM_GL_MODELVIEW, &oldMat); + kmGLLoadMatrix(&_modelViewTransform); + auto s = Director::getInstance()->getWinSize(); DrawPrimitives::drawLine( Point(0, s.height/2), Point(s.width, s.height/2) ); DrawPrimitives::drawLine( Point(s.width/2, 0), Point(s.width/2, s.height) ); + + kmGLLoadMatrix(&oldMat); } void LabelFNTSpriteActions::step(float dt) @@ -897,6 +914,18 @@ std::string LabelFNTBounds::subtitle() const void LabelFNTBounds::draw() { + CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); + cmd->init(0, _vertexZ); + cmd->func = CC_CALLBACK_0(LabelFNTBounds::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(cmd); +} + +void LabelFNTBounds::onDraw() +{ + kmMat4 oldMat; + kmGLGetMatrix(KM_GL_MODELVIEW, &oldMat); + kmGLLoadMatrix(&_modelViewTransform); + auto labelSize = label1->getContentSize(); auto origin = Director::getInstance()->getWinSize(); @@ -911,6 +940,8 @@ void LabelFNTBounds::draw() Point(origin.width, labelSize.height + origin.height) }; DrawPrimitives::drawPoly(vertices, 4, true); + + kmGLLoadMatrix(&oldMat); } LabelTTFLongLineWrapping::LabelTTFLongLineWrapping() diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h index 378964f0ae..c1040bb270 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h @@ -60,6 +60,8 @@ public: virtual std::string title() const override; virtual std::string subtitle() const override; +protected: + void onDraw(); }; class LabelFNTPadding : public AtlasDemoNew @@ -223,6 +225,8 @@ public: virtual std::string subtitle() const override; private: Label *label1; +protected: + void onDraw(); }; class LabelTTFLongLineWrapping : public AtlasDemoNew From 067af2fb938b52c3fa7a259888afef55cd451962 Mon Sep 17 00:00:00 2001 From: CaiWenzhi Date: Thu, 26 Dec 2013 16:17:52 +0800 Subject: [PATCH 3/5] optimize loop --- cocos/gui/UIHelper.cpp | 23 ++++++++++------------- cocos/gui/UILayout.cpp | 24 ++++++++++-------------- cocos/gui/UIListView.cpp | 13 ++++--------- cocos/gui/UIPageView.cpp | 22 ++++++++-------------- cocos/gui/UIWidget.cpp | 7 ++++--- 5 files changed, 36 insertions(+), 53 deletions(-) diff --git a/cocos/gui/UIHelper.cpp b/cocos/gui/UIHelper.cpp index 814a4bdf53..2d9264cb4a 100644 --- a/cocos/gui/UIHelper.cpp +++ b/cocos/gui/UIHelper.cpp @@ -38,7 +38,7 @@ Widget* UIHelper::seekWidgetByTag(Widget* root, int tag) { return root; } - Vector arrayRootChildren = root->getChildren(); + const auto& arrayRootChildren = root->getChildren(); int length = arrayRootChildren.size(); for (int i=0;i arrayRootChildren = root->getChildren(); - int length = arrayRootChildren.size(); - for (int i=0;igetChildren(); + for (auto& subWidget : arrayRootChildren) { - Widget* child = static_cast(arrayRootChildren.at(i)); + Widget* child = static_cast(subWidget); Widget* res = seekWidgetByName(child,name); if (res != nullptr) { @@ -82,11 +81,10 @@ Widget* UIHelper::seekWidgetByRelativeName(Widget *root, const char *name) { return nullptr; } - Vector arrayRootChildren = root->getChildren(); - int length = arrayRootChildren.size(); - for (int i=0;igetChildren(); + for (auto& subWidget : arrayRootChildren) { - Widget* child = static_cast(arrayRootChildren.at(i)); + Widget* child = static_cast(subWidget); RelativeLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE)); if (layoutParameter && strcmp(layoutParameter->getRelativeName(), name) == 0) { @@ -107,11 +105,10 @@ Widget* UIHelper::seekActionWidgetByActionTag(Widget* root, int tag) { return root; } - Vector arrayRootChildren = root->getChildren(); - int length = arrayRootChildren.size(); - for (int i=0;igetChildren(); + for (auto& subWidget : arrayRootChildren) { - Widget* child = static_cast(arrayRootChildren.at(i)); + Widget* child = static_cast(subWidget); Widget* res = seekActionWidgetByActionTag(child,tag); if (res != nullptr) { diff --git a/cocos/gui/UILayout.cpp b/cocos/gui/UILayout.cpp index 29031e2a29..f63ddb2c0d 100644 --- a/cocos/gui/UILayout.cpp +++ b/cocos/gui/UILayout.cpp @@ -727,12 +727,12 @@ void Layout::doLayout() break; case LAYOUT_LINEAR_VERTICAL: { - int length = _widgetChildren.size(); Size layoutSize = getSize(); float topBoundary = layoutSize.height; - for (int i=0; i(_widgetChildren.at(i)); + Widget* child = static_cast(subWidget); LinearLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR)); if (layoutParameter) @@ -767,12 +767,11 @@ void Layout::doLayout() } case LAYOUT_LINEAR_HORIZONTAL: { - int length = _widgetChildren.size(); Size layoutSize = getSize(); float leftBoundary = 0.0f; - for (int i=0; i(_widgetChildren.at(i)); + Widget* child = static_cast(subWidget); LinearLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR)); if (layoutParameter) @@ -807,22 +806,19 @@ void Layout::doLayout() } case LAYOUT_RELATIVE: { - int length = _widgetChildren.size(); - int unlayoutChildCount = length; + int unlayoutChildCount = _widgetChildren.size(); Size layoutSize = getSize(); - - for (int i=0; i(_widgetChildren.at(i)); + Widget* child = static_cast(subWidget); RelativeLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE)); layoutParameter->_put = false; } - while (unlayoutChildCount > 0) { - for (int i=0; i(_widgetChildren.at(i)); + Widget* child = static_cast(subWidget); RelativeLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE)); if (layoutParameter) diff --git a/cocos/gui/UIListView.cpp b/cocos/gui/UIListView.cpp index a6cedbb287..5d608ac6dc 100644 --- a/cocos/gui/UIListView.cpp +++ b/cocos/gui/UIListView.cpp @@ -90,9 +90,8 @@ void ListView::updateInnerContainerSize() { int length = _items.size(); float totalHeight = (length - 1) * _itemsMargin; - for (int i=0; igetSize().height; } float finalWidth = _size.width; @@ -104,9 +103,8 @@ void ListView::updateInnerContainerSize() { int length = _items.size(); float totalWidth = (length - 1) * _itemsMargin; - for (int i=0; igetSize().width; } float finalWidth = totalWidth; @@ -446,12 +444,9 @@ Widget* ListView::createCloneInstance() void ListView::copyClonedWidgetChildren(Widget* model) { - Vector arrayItems = getItems(); - - int length = arrayItems.size(); - for (int i=0; iclone()); } } diff --git a/cocos/gui/UIPageView.cpp b/cocos/gui/UIPageView.cpp index 784fc31b8f..dcc0dbf593 100644 --- a/cocos/gui/UIPageView.cpp +++ b/cocos/gui/UIPageView.cpp @@ -181,7 +181,7 @@ void PageView::insertPage(Layout* page, int idx) page->setSize(pvSize); } int length = _pages.size(); - for (int i=(idx+1); igetPosition(); behindPage->setPosition(Point(formerPos.x+getSize().width, 0)); @@ -268,10 +268,8 @@ void PageView::onSizeChanged() void PageView::updateChildrenSize() { Size selfSize = getSize(); - int length = _pages.size(); - for (long i=0; isetSize(selfSize); } } @@ -410,13 +408,11 @@ void PageView::onTouchCancelled(Touch *touch, Event *unusedEvent) void PageView::movePages(float offset) { - int length = _pages.size(); - for (int i = 0; i < length; i++) + for (auto& page : _pages) { - Widget* child = _pages.at(i); - _movePagePoint.x = child->getPosition().x + offset; - _movePagePoint.y = child->getPosition().y; - child->setPosition(_movePagePoint); + _movePagePoint.x = page->getPosition().x + offset; + _movePagePoint.y = page->getPosition().y; + page->setPosition(_movePagePoint); } } @@ -606,11 +602,9 @@ Widget* PageView::createCloneInstance() void PageView::copyClonedWidgetChildren(Widget* model) { - Vector modelPages = dynamic_cast(model)->getPages(); - int length = modelPages.size(); - for (int i=0; i(model)->getPages(); + for (auto& page : modelPages) { - Layout* page = modelPages.at(i); addPage(dynamic_cast(page->clone())); } } diff --git a/cocos/gui/UIWidget.cpp b/cocos/gui/UIWidget.cpp index 58b3284119..495821cd99 100644 --- a/cocos/gui/UIWidget.cpp +++ b/cocos/gui/UIWidget.cpp @@ -977,10 +977,11 @@ Widget* Widget::createCloneInstance() void Widget::copyClonedWidgetChildren(Widget* model) { - int length = model->getChildren().size(); - for (int i=0; igetChildren(); + + for (auto& subWidget : modelChildren) { - Widget* child = static_cast(model->getChildren().at(i)); + Widget* child = static_cast(subWidget); addChild(child->clone()); } } From 09996ea82c03866d7a4aaeb24c80f60f562916b9 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Thu, 26 Dec 2013 08:20:26 +0000 Subject: [PATCH 4/5] [AUTO] : updating submodule reference to latest autogenerated bindings --- cocos/scripting/auto-generated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/auto-generated b/cocos/scripting/auto-generated index afd23aedea..56286dddef 160000 --- a/cocos/scripting/auto-generated +++ b/cocos/scripting/auto-generated @@ -1 +1 @@ -Subproject commit afd23aedea6035df78b877da9f6b672c0a0fe346 +Subproject commit 56286dddefb8d5775ac508b371d0452c08bfd191 From 50a379b8f0289297a0541545e0d914082d3ea43c Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Thu, 26 Dec 2013 09:04:04 +0000 Subject: [PATCH 5/5] [AUTO] : updating submodule reference to latest autogenerated bindings --- cocos/scripting/auto-generated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/auto-generated b/cocos/scripting/auto-generated index 56286dddef..f8780070ba 160000 --- a/cocos/scripting/auto-generated +++ b/cocos/scripting/auto-generated @@ -1 +1 @@ -Subproject commit 56286dddefb8d5775ac508b371d0452c08bfd191 +Subproject commit f8780070ba5aa2b640ef1da1008a6acc77f66217