Merge branch 'develop' of https://github.com/cocos2d/cocos2d-x into develop

This commit is contained in:
yinkaile 2013-12-26 17:47:01 +08:00
commit b1b08b2d18
10 changed files with 86 additions and 54 deletions

View File

@ -38,7 +38,7 @@ Widget* UIHelper::seekWidgetByTag(Widget* root, int tag)
{
return root;
}
Vector<Node*> arrayRootChildren = root->getChildren();
const auto& arrayRootChildren = root->getChildren();
int length = arrayRootChildren.size();
for (int i=0;i<length;i++)
{
@ -62,11 +62,10 @@ Widget* UIHelper::seekWidgetByName(Widget* root, const char *name)
{
return root;
}
Vector<Node*> arrayRootChildren = root->getChildren();
int length = arrayRootChildren.size();
for (int i=0;i<length;i++)
const auto& arrayRootChildren = root->getChildren();
for (auto& subWidget : arrayRootChildren)
{
Widget* child = static_cast<Widget*>(arrayRootChildren.at(i));
Widget* child = static_cast<Widget*>(subWidget);
Widget* res = seekWidgetByName(child,name);
if (res != nullptr)
{
@ -82,11 +81,10 @@ Widget* UIHelper::seekWidgetByRelativeName(Widget *root, const char *name)
{
return nullptr;
}
Vector<Node*> arrayRootChildren = root->getChildren();
int length = arrayRootChildren.size();
for (int i=0;i<length;i++)
const auto& arrayRootChildren = root->getChildren();
for (auto& subWidget : arrayRootChildren)
{
Widget* child = static_cast<Widget*>(arrayRootChildren.at(i));
Widget* child = static_cast<Widget*>(subWidget);
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(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<Node*> arrayRootChildren = root->getChildren();
int length = arrayRootChildren.size();
for (int i=0;i<length;i++)
const auto& arrayRootChildren = root->getChildren();
for (auto& subWidget : arrayRootChildren)
{
Widget* child = static_cast<Widget*>(arrayRootChildren.at(i));
Widget* child = static_cast<Widget*>(subWidget);
Widget* res = seekActionWidgetByActionTag(child,tag);
if (res != nullptr)
{

View File

@ -709,6 +709,11 @@ LayoutType Layout::getLayoutType() const
{
return _layoutType;
}
void Layout::requestDoLayout()
{
_doLayoutDirty = true;
}
void Layout::doLayout()
{
@ -722,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<length; ++i)
for (auto& subWidget : _widgetChildren)
{
Widget* child = static_cast<Widget*>(_widgetChildren.at(i));
Widget* child = static_cast<Widget*>(subWidget);
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR));
if (layoutParameter)
@ -762,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<length; ++i)
for (auto& subWidget : _widgetChildren)
{
Widget* child = static_cast<Widget*>(_widgetChildren.at(i));
Widget* child = static_cast<Widget*>(subWidget);
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR));
if (layoutParameter)
@ -802,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<length; i++)
for (auto& subWidget : _widgetChildren)
{
Widget* child = static_cast<Widget*>(_widgetChildren.at(i));
Widget* child = static_cast<Widget*>(subWidget);
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));
layoutParameter->_put = false;
}
while (unlayoutChildCount > 0)
{
for (int i=0; i<length; i++)
for (auto& subWidget : _widgetChildren)
{
Widget* child = static_cast<Widget*>(_widgetChildren.at(i));
Widget* child = static_cast<Widget*>(subWidget);
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));
if (layoutParameter)

View File

@ -212,6 +212,8 @@ public:
virtual void visit();
virtual void sortAllChildren() override;
void requestDoLayout();
protected:
//override "init" method of widget.
virtual bool init() override;

View File

@ -90,9 +90,8 @@ void ListView::updateInnerContainerSize()
{
int length = _items.size();
float totalHeight = (length - 1) * _itemsMargin;
for (int i=0; i<length; i++)
for (auto& item : _items)
{
Widget* item = _items.at(i);
totalHeight += item->getSize().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; i<length; i++)
for (auto& item : _items)
{
Widget* item = _items.at(i);
totalWidth += item->getSize().width;
}
float finalWidth = totalWidth;
@ -362,6 +360,11 @@ void ListView::setDirection(SCROLLVIEW_DIR dir)
}
ScrollView::setDirection(dir);
}
void ListView::requestRefreshView()
{
_refreshViewDirty = true;
}
void ListView::refreshView()
{
@ -441,12 +444,9 @@ Widget* ListView::createCloneInstance()
void ListView::copyClonedWidgetChildren(Widget* model)
{
Vector<Widget*> arrayItems = getItems();
int length = arrayItems.size();
for (int i=0; i<length; i++)
auto& arrayItems = getItems();
for (auto& item : arrayItems)
{
Widget* item = arrayItems.at(i);
pushBackCustomItem(item->clone());
}
}

View File

@ -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);};

View File

@ -181,7 +181,7 @@ void PageView::insertPage(Layout* page, int idx)
page->setSize(pvSize);
}
int length = _pages.size();
for (int i=(idx+1); i<length; i++) {
for (int i=(idx+1); i<length; i++){
Widget* behindPage = _pages.at(i);
Point formerPos = behindPage->getPosition();
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; i<length; i++)
for (auto& page : _pages)
{
Layout* page = _pages.at(i);
page->setSize(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<Layout*> modelPages = dynamic_cast<PageView*>(model)->getPages();
int length = modelPages.size();
for (int i=0; i<length; i++)
auto& modelPages = dynamic_cast<PageView*>(model)->getPages();
for (auto& page : modelPages)
{
Layout* page = modelPages.at(i);
addPage(dynamic_cast<Layout*>(page->clone()));
}
}

View File

@ -977,10 +977,11 @@ Widget* Widget::createCloneInstance()
void Widget::copyClonedWidgetChildren(Widget* model)
{
int length = model->getChildren().size();
for (int i=0; i<length; i++)
auto& modelChildren = model->getChildren();
for (auto& subWidget : modelChildren)
{
Widget* child = static_cast<Widget*>(model->getChildren().at(i));
Widget* child = static_cast<Widget*>(subWidget);
addChild(child->clone());
}
}

@ -1 +1 @@
Subproject commit afd23aedea6035df78b877da9f6b672c0a0fe346
Subproject commit f8780070ba5aa2b640ef1da1008a6acc77f66217

View File

@ -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()

View File

@ -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