2013-09-13 22:20:20 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:47:11 +08:00
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2013-11-06 16:04:06 +08:00
|
|
|
#include "CocosGUI.h"
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2013-12-23 15:02:52 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2014-02-24 18:56:45 +08:00
|
|
|
namespace ui {
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2014-01-07 16:22:18 +08:00
|
|
|
Widget* Helper::seekWidgetByTag(Widget* root, int tag)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
|
|
|
if (!root)
|
|
|
|
{
|
2013-11-14 11:37:46 +08:00
|
|
|
return nullptr;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
if (root->getTag() == tag)
|
|
|
|
{
|
|
|
|
return root;
|
|
|
|
}
|
2013-12-26 16:17:52 +08:00
|
|
|
const auto& arrayRootChildren = root->getChildren();
|
2013-12-28 14:34:52 +08:00
|
|
|
ssize_t length = arrayRootChildren.size();
|
|
|
|
for (ssize_t i=0;i<length;i++)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-23 15:02:52 +08:00
|
|
|
Widget* child = static_cast<Widget*>(arrayRootChildren.at(i));
|
|
|
|
Widget* res = seekWidgetByTag(child,tag);
|
2013-11-14 11:37:46 +08:00
|
|
|
if (res != nullptr)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
2013-11-14 11:37:46 +08:00
|
|
|
return nullptr;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
|
2014-01-07 16:22:18 +08:00
|
|
|
Widget* Helper::seekWidgetByName(Widget* root, const char *name)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
|
|
|
if (!root)
|
|
|
|
{
|
2013-11-14 11:37:46 +08:00
|
|
|
return nullptr;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
if (strcmp(root->getName(), name) == 0)
|
|
|
|
{
|
|
|
|
return root;
|
|
|
|
}
|
2013-12-26 16:17:52 +08:00
|
|
|
const auto& arrayRootChildren = root->getChildren();
|
|
|
|
for (auto& subWidget : arrayRootChildren)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-26 16:17:52 +08:00
|
|
|
Widget* child = static_cast<Widget*>(subWidget);
|
2013-12-23 15:02:52 +08:00
|
|
|
Widget* res = seekWidgetByName(child,name);
|
2013-11-14 11:37:46 +08:00
|
|
|
if (res != nullptr)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
2013-11-14 11:37:46 +08:00
|
|
|
return nullptr;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
|
2014-01-07 16:22:18 +08:00
|
|
|
Widget* Helper::seekWidgetByRelativeName(Widget *root, const char *name)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
|
|
|
if (!root)
|
|
|
|
{
|
2013-11-14 11:37:46 +08:00
|
|
|
return nullptr;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-12-26 16:17:52 +08:00
|
|
|
const auto& arrayRootChildren = root->getChildren();
|
|
|
|
for (auto& subWidget : arrayRootChildren)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-26 16:17:52 +08:00
|
|
|
Widget* child = static_cast<Widget*>(subWidget);
|
2013-12-23 15:02:52 +08:00
|
|
|
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));
|
2013-09-13 22:20:20 +08:00
|
|
|
if (layoutParameter && strcmp(layoutParameter->getRelativeName(), name) == 0)
|
|
|
|
{
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
2013-11-14 11:37:46 +08:00
|
|
|
return nullptr;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*temp action*/
|
2014-01-07 16:22:18 +08:00
|
|
|
Widget* Helper::seekActionWidgetByActionTag(Widget* root, int tag)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
|
|
|
if (!root)
|
|
|
|
{
|
2013-11-14 11:37:46 +08:00
|
|
|
return nullptr;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
if (root->getActionTag() == tag)
|
|
|
|
{
|
|
|
|
return root;
|
|
|
|
}
|
2013-12-26 16:17:52 +08:00
|
|
|
const auto& arrayRootChildren = root->getChildren();
|
|
|
|
for (auto& subWidget : arrayRootChildren)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-26 16:17:52 +08:00
|
|
|
Widget* child = static_cast<Widget*>(subWidget);
|
2013-12-23 15:02:52 +08:00
|
|
|
Widget* res = seekActionWidgetByActionTag(child,tag);
|
2013-11-14 11:37:46 +08:00
|
|
|
if (res != nullptr)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
2013-11-14 11:37:46 +08:00
|
|
|
return nullptr;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
|
2013-12-23 15:02:52 +08:00
|
|
|
}
|
|
|
|
|
2014-02-24 18:56:45 +08:00
|
|
|
NS_CC_END
|