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

This commit is contained in:
samuele3 2013-11-07 15:45:56 +08:00
commit c055b1a3d6
65 changed files with 4110 additions and 5601 deletions

View File

@ -1 +1 @@
695569fbf5580abb74dbc9b9d9fc7ad8d21db805
30ca6c02884f9bc20405b3e657b444c0153bead7

View File

@ -1 +1 @@
13f41d81e48285159fafa45159fdd1c081b4bb06
3ff18018375c71f683a484652678740cc6395eaf

View File

@ -159,7 +159,7 @@ void ActionNode::initActionNodeFromRoot(Object* root)
UIWidget* rootWidget = dynamic_cast<UIWidget*>(root);
if (rootWidget != NULL)
{
UIWidget* widget = UIHelper::instance()->seekActionWidgetByActionTag(rootWidget, getActionTag());
UIWidget* widget = UIHelper::seekActionWidgetByActionTag(rootWidget, getActionTag());
if (widget != NULL)
{
setObject(widget);

View File

@ -152,7 +152,7 @@ UIWidget* CCSGUIReader::widgetFromJsonDictionary(JsonDictionary* data)
}
else if (classname && strcmp(classname, "Panel") == 0)
{
widget = Layout::create();
widget = UILayout::create();
setPropsForPanelFromJsonDictionary(widget, uiOptions);
}
else if (classname && strcmp(classname, "Slider") == 0)
@ -162,8 +162,8 @@ UIWidget* CCSGUIReader::widgetFromJsonDictionary(JsonDictionary* data)
}
else if (classname && strcmp(classname, "ListView") == 0)
{
// widget = UIListView::create();
// setPropsForListViewFromJsonDictionary(widget, uiOptions);
widget = UIListView::create();
setPropsForListViewFromJsonDictionary(widget, uiOptions);
}
else if (classname && strcmp(classname, "PageView") == 0)
{
@ -177,7 +177,7 @@ UIWidget* CCSGUIReader::widgetFromJsonDictionary(JsonDictionary* data)
}
else if (classname && strcmp(classname, "DragPanel") == 0)
{
widget = UIDragPanel::create();
widget = UIScrollView::create();
setPropsForDragPanelFromJsonDictionary(widget, uiOptions);
}
@ -232,20 +232,20 @@ UIWidget* CCSGUIReader::widgetFromJsonFile(const char *fileName)
const char* file = DICTOOL->getStringValueFromArray_json(jsonDict, "textures", i);
std::string tp = m_strFilePath;
tp.append(file);
CCUIHELPER->addSpriteFrame(tp.c_str());
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(tp.c_str());
}
float fileDesignWidth = DICTOOL->getFloatValue_json(jsonDict, "designWidth");
float fileDesignHeight = DICTOOL->getFloatValue_json(jsonDict, "designHeight");
if (fileDesignWidth <= 0 || fileDesignHeight <= 0) {
printf("Read design size error!\n");
Size winSize = Director::getInstance()->getWinSize();
CCUIHELPER->setFileDesignWidth(winSize.width);
CCUIHELPER->setFileDesignHeight(winSize.height);
// CCUIHELPER->setFileDesignWidth(winSize.width);
// CCUIHELPER->setFileDesignHeight(winSize.height);
}
else
{
CCUIHELPER->setFileDesignWidth(fileDesignWidth);
CCUIHELPER->setFileDesignHeight(fileDesignHeight);
// CCUIHELPER->setFileDesignWidth(fileDesignWidth);
// CCUIHELPER->setFileDesignHeight(fileDesignHeight);
}
JsonDictionary* widgetTree = DICTOOL->getSubDictionary_json(jsonDict, "widgetTree");
UIWidget* widget = widgetFromJsonDictionary(widgetTree);
@ -253,7 +253,7 @@ UIWidget* CCSGUIReader::widgetFromJsonFile(const char *fileName)
/* *********temp********* */
if (widget->getContentSize().equals(Size::ZERO))
{
Layout* rootWidget = dynamic_cast<Layout*>(widget);
UILayout* rootWidget = dynamic_cast<UILayout*>(widget);
rootWidget->setSize(Size(fileDesignWidth, fileDesignHeight));
}
/* ********************** */
@ -792,7 +792,7 @@ void CCSGUIReader::setPropsForLabelFromJsonDictionary(UIWidget*widget,JsonDictio
setPropsForWidgetFromJsonDictionary(widget, options);
UILabel* label = (UILabel*)widget;
bool touchScaleChangeAble = DICTOOL->getBooleanValue_json(options, "touchScaleEnable");
label->setTouchScaleChangeAble(touchScaleChangeAble);
label->setTouchScaleChangeEnabled(touchScaleChangeAble);
const char* text = DICTOOL->getStringValue_json(options, "text");
label->setText(text);
bool fs = DICTOOL->checkObjectExist_json(options, "fontSize");
@ -877,10 +877,9 @@ void CCSGUIReader::setPropsForLabelAtlasFromJsonDictionary(UIWidget*widget,JsonD
void CCSGUIReader::setPropsForContainerWidgetFromJsonDictionary(UIWidget *widget, JsonDictionary *options)
{
setPropsForWidgetFromJsonDictionary(widget, options);
Layout* containerWidget = (Layout*)widget;
UILayout* containerWidget = (UILayout*)widget;
if (!dynamic_cast<UIScrollView*>(containerWidget)
&& !dynamic_cast<UIListView*>(containerWidget)
&& !dynamic_cast<UIDragPanel*>(containerWidget))
&& !dynamic_cast<UIListView*>(containerWidget))
{
containerWidget->setClippingEnabled(DICTOOL->getBooleanValue_json(options, "clipAble"));
}
@ -892,7 +891,7 @@ void CCSGUIReader::setPropsForPanelFromJsonDictionary(UIWidget*widget,JsonDictio
if (m_bOlderVersion)
{
setPropsForContainerWidgetFromJsonDictionary(widget, options);
Layout* panel = (Layout*)widget;
UILayout* panel = (UILayout*)widget;
bool backGroundScale9Enable = DICTOOL->getBooleanValue_json(options, "backGroundScale9Enable");
panel->setBackGroundImageScale9Enabled(backGroundScale9Enable);
int cr = DICTOOL->getIntValue_json(options, "bgColorR");
@ -959,7 +958,7 @@ void CCSGUIReader::setPropsForPanelFromJsonDictionary(UIWidget*widget,JsonDictio
else
{
setPropsForContainerWidgetFromJsonDictionary(widget, options);
Layout* panel = (Layout*)widget;
UILayout* panel = (UILayout*)widget;
bool backGroundScale9Enable = DICTOOL->getBooleanValue_json(options, "backGroundScale9Enable");
panel->setBackGroundImageScale9Enabled(backGroundScale9Enable);
int cr = DICTOOL->getIntValue_json(options, "bgColorR");
@ -1394,7 +1393,7 @@ void CCSGUIReader::setPropsForTextFieldFromJsonDictionary(UIWidget*widget,JsonDi
//textField->setSize(CCSizeMake(dw, dh));
}
bool maxLengthEnable = DICTOOL->getBooleanValue_json(options, "maxLengthEnable");
textField->setMaxLengthEnable(maxLengthEnable);
textField->setMaxLengthEnabled(maxLengthEnable);
if (maxLengthEnable)
{
@ -1402,7 +1401,7 @@ void CCSGUIReader::setPropsForTextFieldFromJsonDictionary(UIWidget*widget,JsonDi
textField->setMaxLength(maxLength);
}
bool passwordEnable = DICTOOL->getBooleanValue_json(options, "passwordEnable");
textField->setPasswordEnable(passwordEnable);
textField->setPasswordEnabled(passwordEnable);
if (passwordEnable)
{
textField->setPasswordStyleText(DICTOOL->getStringValue_json(options, "passwordStyleText"));
@ -1557,10 +1556,10 @@ void CCSGUIReader::setPropsForDragPanelFromJsonDictionary(UIWidget *widget, Json
{
setPropsForPanelFromJsonDictionary(widget, options);
UIDragPanel* dragPanel = (UIDragPanel*)widget;
UIScrollView* dragPanel = (UIScrollView*)widget;
bool bounceEnable = DICTOOL->getBooleanValue_json(options, "bounceEnable");
dragPanel->setBounceEnable(bounceEnable);
dragPanel->setBounceEnabled(bounceEnable);
float innerWidth = DICTOOL->getFloatValue_json(options, "innerWidth");
float innerHeight = DICTOOL->getFloatValue_json(options, "innerHeight");

View File

@ -320,8 +320,8 @@ namespace cocostudio {
{
gui::UILayer *pLayer = gui::UILayer::create();
pLayer->scheduleUpdate();
UIWidget* widget= gui::UIHelper::instance()->createWidgetFromJsonFile(pPath.c_str());
pLayer->addWidget(widget);
// UIWidget* widget= gui::UIHelper::instance()->createWidgetFromJsonFile(pPath.c_str());
// pLayer->addWidget(widget);
ComRender *pRender = ComRender::create(pLayer, "GUIComponent");
if (pComName != NULL)
{

View File

@ -7,14 +7,13 @@ LOCAL_MODULE_FILENAME := libgui
LOCAL_SRC_FILES := UIRootWidget.cpp \
UIWidget.cpp \
Layout.cpp \
LayoutParameter.cpp \
UILayout.cpp \
UILayoutParameter.cpp \
UILayoutDefine.cpp \
CocosGUI.cpp \
UIHelper.cpp \
UIInputManager.cpp \
UILayer.cpp \
UIDragPanel.cpp \
UIListView.cpp \
UIPageView.cpp \
UIScrollView.cpp \

View File

@ -1,14 +1,13 @@
set(GUI_SRC
UIRootWidget.cpp
UIWidget.cpp
Layout.cpp
LayoutParameter.cpp
UILayout.cpp
UILayoutParameter.cpp
UILayoutDefine.cpp
CocosGUI.cpp
UIHelper.cpp
UIInputManager.cpp
UILayer.cpp
UIDragPanel.cpp
UIListView.cpp
UIPageView.cpp
UIScrollView.cpp

View File

@ -27,7 +27,7 @@
#include "gui/UIWidget.h"
#include "gui/Layout.h"
#include "gui/UILayout.h"
#include "gui/UIRootWidget.h"
#include "gui/UIButton.h"
#include "gui/UICheckBox.h"
@ -36,10 +36,9 @@
#include "gui/UILabelAtlas.h"
#include "gui/UILoadingBar.h"
#include "gui/UIScrollView.h"
#include "gui/UIListView.h"
#include "gui/UISlider.h"
#include "gui/UITextField.h"
#include "gui/UIListView.h"
#include "gui/UIDragPanel.h"
#include "gui/UILabelBMFont.h"
#include "gui/UIPageView.h"
#include "gui/UIHelper.h"

View File

@ -1,785 +0,0 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
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.
****************************************************************************/
#include "gui/Layout.h"
#include "gui/UILayer.h"
#include "gui/UIHelper.h"
#include "extensions/GUI/CCControlExtension/CCScale9Sprite.h"
using namespace cocos2d;
using namespace cocos2d::extension;
namespace gui {
#define DYNAMIC_CAST_CLIPPINGLAYER dynamic_cast<RectClippingNode*>(_renderer)
Layout::Layout():
_clippingEnabled(false),
_backGroundScale9Enabled(false),
_backGroundImage(NULL),
_backGroundImageFileName(""),
_backGroundImageCapInsets(Rect::ZERO),
_colorType(LAYOUT_COLOR_NONE),
_bgImageTexType(UI_TEX_TYPE_LOCAL),
_colorRender(NULL),
_gradientRender(NULL),
_cColor(Color3B::WHITE),
_gStartColor(Color3B::WHITE),
_gEndColor(Color3B::WHITE),
_alongVector(Point(0.0f, -1.0f)),
_cOpacity(255),
_backGroundImageTextureSize(Size::ZERO),
_layoutType(LAYOUT_ABSOLUTE)
{
_widgetType = WidgetTypeContainer;
}
Layout::~Layout()
{
}
Layout* Layout::create()
{
Layout* layout = new Layout();
if (layout && layout->init())
{
layout->autorelease();
return layout;
}
CC_SAFE_DELETE(layout);
return NULL;
}
bool Layout::init()
{
_children = CCArray::create();
_children->retain();
initRenderer();
_renderer->retain();
_renderer->setZOrder(_widgetZOrder);
RGBAProtocol* renderRGBA = dynamic_cast<RGBAProtocol*>(_renderer);
if (renderRGBA)
{
renderRGBA->setCascadeColorEnabled(false);
renderRGBA->setCascadeOpacityEnabled(false);
}
ignoreContentAdaptWithSize(false);
setSize(Size::ZERO);
setBright(true);
setAnchorPoint(Point(0, 0));
_scheduler = Director::getInstance()->getScheduler();
CC_SAFE_RETAIN(_scheduler);
return true;
}
void Layout::initRenderer()
{
_renderer = RectClippingNode::create();
}
bool Layout::isClippingEnabled()
{
return _clippingEnabled;
}
bool Layout::hitTest(const Point &pt)
{
Point nsp = _renderer->convertToNodeSpace(pt);
Rect bb = Rect(0.0f, 0.0f, _size.width, _size.height);
if (nsp.x >= bb.origin.x && nsp.x <= bb.origin.x + bb.size.width && nsp.y >= bb.origin.y && nsp.y <= bb.origin.y + bb.size.height)
{
return true;
}
return false;
}
void Layout::setClippingEnabled(bool able)
{
_clippingEnabled = able;
DYNAMIC_CAST_CLIPPINGLAYER->setClippingEnabled(able);
}
void Layout::onSizeChanged()
{
DYNAMIC_CAST_CLIPPINGLAYER->setClippingSize(_size);
doLayout();
if (_backGroundImage)
{
_backGroundImage->setPosition(Point(_size.width/2.0f, _size.height/2.0f));
if (_backGroundScale9Enabled)
{
dynamic_cast<Scale9Sprite*>(_backGroundImage)->setPreferredSize(_size);
}
}
if (_colorRender)
{
_colorRender->setContentSize(_size);
}
if (_gradientRender)
{
_gradientRender->setContentSize(_size);
}
}
void Layout::setBackGroundImageScale9Enabled(bool able)
{
if (_backGroundScale9Enabled == able)
{
return;
}
_renderer->removeChild(_backGroundImage, true);
_backGroundImage = NULL;
_backGroundScale9Enabled = able;
if (_backGroundScale9Enabled)
{
_backGroundImage = Scale9Sprite::create();
_renderer->addChild(_backGroundImage);
}
else
{
_backGroundImage = Sprite::create();
_renderer->addChild(_backGroundImage);
}
_backGroundImage->setZOrder(-1);
setBackGroundImage(_backGroundImageFileName.c_str(),_bgImageTexType);
setBackGroundImageCapInsets(_backGroundImageCapInsets);
}
void Layout::setBackGroundImage(const char* fileName,TextureResType texType)
{
if (!fileName || strcmp(fileName, "") == 0)
{
return;
}
if (_backGroundImage == NULL)
{
addBackGroundImage();
}
_backGroundImageFileName = fileName;
_bgImageTexType = texType;
if (_backGroundScale9Enabled)
{
switch (_bgImageTexType)
{
case UI_TEX_TYPE_LOCAL:
dynamic_cast<Scale9Sprite*>(_backGroundImage)->initWithFile(fileName);
break;
case UI_TEX_TYPE_PLIST:
dynamic_cast<Scale9Sprite*>(_backGroundImage)->initWithSpriteFrameName(fileName);
break;
default:
break;
}
dynamic_cast<Scale9Sprite*>(_backGroundImage)->setPreferredSize(_size);
}
else
{
switch (_bgImageTexType)
{
case UI_TEX_TYPE_LOCAL:
dynamic_cast<Sprite*>(_backGroundImage)->initWithFile(fileName);
break;
case UI_TEX_TYPE_PLIST:
dynamic_cast<Sprite*>(_backGroundImage)->initWithSpriteFrameName(fileName);
break;
default:
break;
}
}
if (_backGroundScale9Enabled)
{
dynamic_cast<Scale9Sprite*>(_backGroundImage)->setColor(getColor());
dynamic_cast<Scale9Sprite*>(_backGroundImage)->setOpacity(getOpacity());
}
else
{
dynamic_cast<Sprite*>(_backGroundImage)->setColor(getColor());
dynamic_cast<Sprite*>(_backGroundImage)->setOpacity(getOpacity());
}
_backGroundImageTextureSize = _backGroundImage->getContentSize();
_backGroundImage->setPosition(Point(_size.width/2.0f, _size.height/2.0f));
}
void Layout::setBackGroundImageCapInsets(const Rect &capInsets)
{
_backGroundImageCapInsets = capInsets;
if (_backGroundScale9Enabled)
{
dynamic_cast<Scale9Sprite*>(_backGroundImage)->setCapInsets(capInsets);
}
}
void Layout::addBackGroundImage()
{
if (_backGroundScale9Enabled)
{
_backGroundImage = Scale9Sprite::create();
_backGroundImage->setZOrder(-1);
_renderer->addChild(_backGroundImage);
dynamic_cast<Scale9Sprite*>(_backGroundImage)->setPreferredSize(_size);
}
else
{
_backGroundImage = CCSprite::create();
_backGroundImage->setZOrder(-1);
_renderer->addChild(_backGroundImage);
}
_backGroundImage->setPosition(Point(_size.width/2.0f, _size.height/2.0f));
}
void Layout::removeBackGroundImage()
{
if (!_backGroundImage)
{
return;
}
_renderer->removeChild(_backGroundImage, true);
_backGroundImage = NULL;
_backGroundImageFileName = "";
_backGroundImageTextureSize = Size::ZERO;
}
void Layout::setBackGroundColorType(LayoutBackGroundColorType type)
{
if (_colorType == type)
{
return;
}
switch (_colorType)
{
case LAYOUT_COLOR_NONE:
if (_colorRender)
{
_renderer->removeChild(_colorRender, true);
_colorRender = NULL;
}
if (_gradientRender)
{
_renderer->removeChild(_gradientRender, true);
_gradientRender = NULL;
}
break;
case LAYOUT_COLOR_SOLID:
if (_colorRender)
{
_renderer->removeChild(_colorRender, true);
_colorRender = NULL;
}
break;
case LAYOUT_COLOR_GRADIENT:
if (_gradientRender)
{
_renderer->removeChild(_gradientRender, true);
_gradientRender = NULL;
}
break;
default:
break;
}
_colorType = type;
switch (_colorType)
{
case LAYOUT_COLOR_NONE:
break;
case LAYOUT_COLOR_SOLID:
_colorRender = CCLayerColor::create();
_colorRender->setContentSize(_size);
_colorRender->setOpacity(_cOpacity);
_colorRender->setColor(_cColor);
_renderer->addChild(_colorRender,-2);
break;
case LAYOUT_COLOR_GRADIENT:
_gradientRender = CCLayerGradient::create();
_gradientRender->setContentSize(_size);
_gradientRender->setOpacity(_cOpacity);
_gradientRender->setStartColor(_gStartColor);
_gradientRender->setEndColor(_gEndColor);
_gradientRender->setVector(_alongVector);
_renderer->addChild(_gradientRender,-2);
break;
default:
break;
}
}
void Layout::setBackGroundColor(const Color3B &color)
{
_cColor = color;
if (_colorRender)
{
_colorRender->setColor(color);
}
}
void Layout::setBackGroundColor(const Color3B &startColor, const Color3B &endColor)
{
_gStartColor = startColor;
if (_gradientRender)
{
_gradientRender->setStartColor(startColor);
}
_gEndColor = endColor;
if (_gradientRender)
{
_gradientRender->setEndColor(endColor);
}
}
void Layout::setBackGroundColorOpacity(int opacity)
{
_cOpacity = opacity;
switch (_colorType)
{
case LAYOUT_COLOR_NONE:
break;
case LAYOUT_COLOR_SOLID:
_colorRender->setOpacity(opacity);
break;
case LAYOUT_COLOR_GRADIENT:
_gradientRender->setOpacity(opacity);
break;
default:
break;
}
}
void Layout::setBackGroundColorVector(const Point &vector)
{
_alongVector = vector;
if (_gradientRender)
{
_gradientRender->setVector(vector);
}
}
void Layout::setColor(const Color3B &color)
{
UIWidget::setColor(color);
if (_backGroundImage)
{
RGBAProtocol* rgbap = dynamic_cast<RGBAProtocol*>(_backGroundImage);
if (rgbap)
{
rgbap->setColor(color);
}
}
}
void Layout::setOpacity(int opacity)
{
UIWidget::setOpacity(opacity);
if (_backGroundImage)
{
RGBAProtocol* rgbap = dynamic_cast<RGBAProtocol*>(_backGroundImage);
if (rgbap)
{
rgbap->setOpacity(opacity);
}
}
}
const Size& Layout::getBackGroundImageTextureSize() const
{
return _backGroundImageTextureSize;
}
const Size& Layout::getContentSize() const
{
return _renderer->getContentSize();
}
void Layout::setLayoutType(LayoutType type)
{
_layoutType = type;
}
LayoutType Layout::getLayoutType() const
{
return _layoutType;
}
void Layout::doLayout()
{
switch (_layoutType)
{
case LAYOUT_ABSOLUTE:
break;
case LAYOUT_LINEAR_VERTICAL:
{
ccArray* layoutChildrenArray = getChildren()->data;
int length = layoutChildrenArray->num;
Size layoutSize = getSize();
float topBoundary = layoutSize.height;
for (int i=0; i<length; ++i)
{
UIWidget* child = dynamic_cast<UIWidget*>(layoutChildrenArray->arr[i]);
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter());
if (layoutParameter)
{
WidgetType childType = child->getWidgetType();
UILinearGravity childGravity = layoutParameter->getGravity();
Point ap = child->getAnchorPoint();
Size cs = child->getSize();
float finalPosX = childType == WidgetTypeWidget ? ap.x * cs.width : 0.0f;
float finalPosY = childType == WidgetTypeWidget ? topBoundary - ((1.0f-ap.y) * cs.height) : topBoundary - cs.height;
switch (childGravity)
{
case LINEAR_GRAVITY_NONE:
case LINEAR_GRAVITY_LEFT:
break;
case LINEAR_GRAVITY_RIGHT:
finalPosX = childType == WidgetTypeWidget ? layoutSize.width - ((1.0f - ap.x) * cs.width) : layoutSize.width - cs.width;
break;
case LINEAR_GRAVITY_CENTER_HORIZONTAL:
finalPosX = childType == WidgetTypeWidget ? layoutSize.width / 2.0f - cs.width * (0.5f-ap.x) : (layoutSize.width - cs.width) * 0.5f;
break;
default:
break;
}
UIMargin mg = layoutParameter->getMargin();
finalPosX += mg.left;
finalPosY -= mg.top;
child->setPosition(Point(finalPosX, finalPosY));
topBoundary = child->getBottomInParent() - mg.bottom;
}
}
break;
}
case LAYOUT_LINEAR_HORIZONTAL:
{
ccArray* layoutChildrenArray = getChildren()->data;
int length = layoutChildrenArray->num;
Size layoutSize = getSize();
float leftBoundary = 0.0f;
for (int i=0; i<length; ++i)
{
UIWidget* child = dynamic_cast<UIWidget*>(layoutChildrenArray->arr[i]);
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter());
if (layoutParameter)
{
WidgetType childType = child->getWidgetType();
UILinearGravity childGravity = layoutParameter->getGravity();
Point ap = child->getAnchorPoint();
Size cs = child->getSize();
float finalPosX = childType == WidgetTypeWidget ? leftBoundary + (ap.x * cs.width) : leftBoundary;
float finalPosY = childType == WidgetTypeWidget ? layoutSize.height - (1.0f - ap.y) * cs.height : layoutSize.height - cs.height;
switch (childGravity)
{
case LINEAR_GRAVITY_NONE:
case LINEAR_GRAVITY_TOP:
break;
case LINEAR_GRAVITY_BOTTOM:
finalPosY = childType == WidgetTypeWidget ? ap.y * cs.height : 0.0f;
break;
case LINEAR_GRAVITY_CENTER_VERTICAL:
finalPosY = childType == WidgetTypeWidget ? layoutSize.height/2.0f - cs.height * (0.5f - ap.y) : (layoutSize.height - cs.height) * 0.5f;
break;
default:
break;
}
UIMargin mg = layoutParameter->getMargin();
finalPosX += mg.left;
finalPosY -= mg.top;
child->setPosition(Point(finalPosX, finalPosY));
leftBoundary = child->getRightInParent() + mg.right;
}
}
break;
}
case LAYOUT_RELATIVE:
{
ccArray* layoutChildrenArray = getChildren()->data;
int length = layoutChildrenArray->num;
Size layoutSize = getSize();
for (int i=0; i<length; i++)
{
UIWidget* child = dynamic_cast<UIWidget*>(layoutChildrenArray->arr[i]);
WidgetType childType = child->getWidgetType();
Point ap = child->getAnchorPoint();
Size cs = child->getSize();
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter());
if (layoutParameter)
{
float finalPosX = childType == WidgetTypeWidget ? ap.x * cs.width : 0.0f;
float finalPosY = childType == WidgetTypeWidget ? layoutSize.height - ((1.0f - ap.y) * cs.height) : layoutSize.height - cs.height;
UIRelativeAlign align = layoutParameter->getAlign();
const char* relativeName = layoutParameter->getRelativeToWidgetName();
UIWidget* relativeWidget = NULL;
if (relativeName && strcmp(relativeName, ""))
{
relativeWidget = CCUIHELPER->seekWidgetByRelativeName(this, relativeName);
}
switch (align)
{
case RELATIVE_ALIGN_NONE:
break;
case RELATIVE_ALIGN_PARENT_LEFT:
break;
case RELATIVE_ALIGN_PARENT_TOP:
break;
case RELATIVE_ALIGN_PARENT_RIGHT:
finalPosX = childType == WidgetTypeWidget ? layoutSize.width - ((1.0f - ap.x) * cs.width) : layoutSize.width - cs.width;
break;
case RELATIVE_ALIGN_PARENT_BOTTOM:
finalPosY = childType == WidgetTypeWidget ? ap.y * cs.height : 0.0f;
break;
case RELATIVE_CENTER_IN_PARENT:
finalPosX = childType == WidgetTypeWidget ? layoutSize.width * 0.5f - cs.width * (0.5f - ap.x) : (layoutSize.width - cs.width) * 0.5f;
finalPosY = childType == WidgetTypeWidget ? layoutSize.height * 0.5f - cs.height * (0.5f - ap.y) : (layoutSize.height - cs.height) * 0.5f;
break;
case RELATIVE_CENTER_HORIZONTAL:
finalPosX = childType == WidgetTypeWidget ? layoutSize.width * 0.5f - cs.width * (0.5f - ap.x) : (layoutSize.width - cs.width) * 0.5f;
break;
case RELATIVE_CENTER_VERTICAL:
finalPosY = childType == WidgetTypeWidget ? layoutSize.height * 0.5f - cs.height * (0.5f - ap.y) : (layoutSize.height - cs.height) * 0.5f;
break;
case RELATIVE_LOCATION_LEFT_OF_TOPALIGN:
if (relativeWidget)
{
float locationTop = relativeWidget->getTopInParent();
float locationRight = relativeWidget->getLeftInParent();
finalPosY = childType == WidgetTypeWidget ? locationTop - ap.y * cs.height : locationTop - cs.height;
finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width;
}
break;
case RELATIVE_LOCATION_LEFT_OF_CENTER:
break;
case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN:
if (relativeWidget)
{
float locationRight = relativeWidget->getLeftInParent();
float locationBottom = relativeWidget->getBottomInParent();
finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom;
finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width;
}
break;
case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN:
if (relativeWidget)
{
float locationTop = relativeWidget->getTopInParent();
float locationLeft = relativeWidget->getRightInParent();
finalPosY = childType == WidgetTypeWidget ? locationTop - ap.y * cs.height : locationTop - cs.height;
finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft;
}
break;
case RELATIVE_LOCATION_RIGHT_OF_CENTER:
break;
case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN:
if (relativeWidget)
{
float locationLeft = relativeWidget->getRightInParent();
float locationBottom = relativeWidget->getBottomInParent();
finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom;
finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft;
}
break;
case RELATIVE_LOCATION_ABOVE_LEFTALIGN:
if (relativeWidget)
{
float locationBottom = relativeWidget->getTopInParent();
float locationLeft = relativeWidget->getLeftInParent();
finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom;
finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft;
}
break;
case RELATIVE_LOCATION_ABOVE_CENTER:
break;
case RELATIVE_LOCATION_ABOVE_RIGHTALIGN:
if (relativeWidget)
{
float locationBottom = relativeWidget->getTopInParent();
float locationRight = relativeWidget->getRightInParent();
finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom;
finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width;
}
break;
case RELATIVE_LOCATION_BELOW_LEFTALIGN:
if (relativeWidget)
{
float locationTop = relativeWidget->getBottomInParent();
float locationLeft = relativeWidget->getLeftInParent();
finalPosY = childType == WidgetTypeWidget ? locationTop - (1.0f - ap.y) * cs.height : locationTop - cs.height;
finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft;
}
break;
case RELATIVE_LOCATION_BELOW_CENTER:
break;
case RELATIVE_LOCATION_BELOW_RIGHTALIGN:
if (relativeWidget)
{
float locationTop = relativeWidget->getBottomInParent();
float locationRight = relativeWidget->getRightInParent();
finalPosY = childType == WidgetTypeWidget ? locationTop - (1.0f - ap.y) * cs.height : locationTop - cs.height;
finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width;
}
break;
default:
break;
}
UIMargin relativeWidgetMargin;
UIMargin mg;
if (relativeWidget)
{
relativeWidgetMargin = relativeWidget->getLayoutParameter()->getMargin();
mg = child->getLayoutParameter()->getMargin();
}
//handle margin
switch (align)
{
case RELATIVE_LOCATION_ABOVE_LEFTALIGN:
case RELATIVE_LOCATION_ABOVE_RIGHTALIGN:
case RELATIVE_LOCATION_ABOVE_CENTER:
finalPosY += relativeWidgetMargin.top;
finalPosY += mg.bottom;
break;
case RELATIVE_LOCATION_BELOW_LEFTALIGN:
case RELATIVE_LOCATION_BELOW_RIGHTALIGN:
case RELATIVE_LOCATION_BELOW_CENTER:
finalPosY -= relativeWidgetMargin.bottom;
finalPosY -= mg.top;
break;
case RELATIVE_LOCATION_LEFT_OF_TOPALIGN:
case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN:
case RELATIVE_LOCATION_LEFT_OF_CENTER:
finalPosX -= relativeWidgetMargin.left;
finalPosX -= mg.right;
break;
case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN:
case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN:
case RELATIVE_LOCATION_RIGHT_OF_CENTER:
finalPosX += relativeWidgetMargin.right;
finalPosX += mg.left;
break;
default:
break;
}
child->setPosition(Point(finalPosX, finalPosY));
}
}
break;
}
default:
break;
}
}
const char* Layout::getDescription() const
{
return "Layout";
}
RectClippingNode::RectClippingNode():
m_pInnerStencil(NULL),
_enabled(true),
_clippingSize(Size(50.0f, 50.0f)),
_clippingEnabled(false)
{
}
RectClippingNode::~RectClippingNode()
{
}
RectClippingNode* RectClippingNode::create()
{
RectClippingNode *pRet = new RectClippingNode();
if (pRet && pRet->init())
{
pRet->autorelease();
}
else
{
CC_SAFE_DELETE(pRet);
}
return pRet;
}
bool RectClippingNode::init()
{
m_pInnerStencil = CCDrawNode::create();
rect[0] = Point(0, 0);
rect[1] = Point(_clippingSize.width, 0);
rect[2] = Point(_clippingSize.width, _clippingSize.height);
rect[3] = Point(0, _clippingSize.height);
Color4F green(0, 1, 0, 1);
m_pInnerStencil->drawPolygon(rect, 4, green, 0, green);
if (CCClippingNode::init(m_pInnerStencil))
{
return true;
}
return false;
}
void RectClippingNode::setClippingSize(const Size &size)
{
setContentSize(size);
_clippingSize = size;
rect[0] = Point(0, 0);
rect[1] = Point(_clippingSize.width, 0);
rect[2] = Point(_clippingSize.width, _clippingSize.height);
rect[3] = Point(0, _clippingSize.height);
Color4F green(0, 1, 0, 1);
m_pInnerStencil->clear();
m_pInnerStencil->drawPolygon(rect, 4, green, 0, green);
}
void RectClippingNode::setClippingEnabled(bool enabled)
{
_clippingEnabled = enabled;
}
void RectClippingNode::visit()
{
if (!_enabled)
{
return;
}
if (_clippingEnabled)
{
CCClippingNode::visit();
}
else
{
CCNode::visit();
}
}
void RectClippingNode::setEnabled(bool enabled)
{
_enabled = enabled;
}
bool RectClippingNode::isEnabled() const
{
return _enabled;
}
}

View File

@ -6,14 +6,13 @@ INCLUDES = -I../ \
SOURCES = UIRootWidget.cpp \
UIWidget.cpp \
Layout.cpp \
LayoutParameter.cpp \
UILayout.cpp \
UILayoutParameter.cpp \
UILayoutDefine.cpp \
CocosGUI.cpp \
UIHelper.cpp \
UIInputManager.cpp \
UILayer.cpp \
UIDragPanel.cpp \
UIListView.cpp \
UIPageView.cpp \
UIScrollView.cpp \

View File

@ -25,9 +25,6 @@
#include "gui/UIButton.h"
#include "extensions/GUI/CCControlExtension/CCScale9Sprite.h"
using namespace cocos2d;
using namespace cocos2d::extension;
namespace gui {
#define NORMALRENDERERZ (0)
@ -45,9 +42,9 @@ _clickedFileName(""),
_disabledFileName(""),
_prevIgnoreSize(true),
_scale9Enabled(false),
_capInsetsNormal(Rect::ZERO),
_capInsetsPressed(Rect::ZERO),
_capInsetsDisabled(Rect::ZERO),
_capInsetsNormal(cocos2d::Rect::ZERO),
_capInsetsPressed(cocos2d::Rect::ZERO),
_capInsetsDisabled(cocos2d::Rect::ZERO),
_normalTexType(UI_TEX_TYPE_LOCAL),
_pressedTexType(UI_TEX_TYPE_LOCAL),
_disabledTexType(UI_TEX_TYPE_LOCAL),
@ -55,7 +52,7 @@ _normalTextureSize(_size),
_pressedTextureSize(_size),
_disabledTextureSize(_size),
_pressedActionEnabled(false),
_titleColor(Color3B::WHITE)
_titleColor(cocos2d::Color3B::WHITE)
{
}
@ -88,10 +85,10 @@ bool UIButton::init()
void UIButton::initRenderer()
{
UIWidget::initRenderer();
_buttonNormalRenderer = Sprite::create();
_buttonClickedRenderer = Sprite::create();
_buttonDisableRenderer = Sprite::create();
_titleRenderer = LabelTTF::create();
_buttonNormalRenderer = cocos2d::Sprite::create();
_buttonClickedRenderer = cocos2d::Sprite::create();
_buttonDisableRenderer = cocos2d::Sprite::create();
_titleRenderer = cocos2d::LabelTTF::create();
_renderer->addChild(_buttonNormalRenderer,NORMALRENDERERZ);
_renderer->addChild(_buttonClickedRenderer,PRESSEDRENDERERZ);
_renderer->addChild(_buttonDisableRenderer,DISABLEDRENDERERZ);
@ -117,15 +114,15 @@ void UIButton::setScale9Enabled(bool able)
_buttonDisableRenderer = NULL;
if (_scale9Enabled)
{
_buttonNormalRenderer = Scale9Sprite::create();
_buttonClickedRenderer = Scale9Sprite::create();
_buttonDisableRenderer = Scale9Sprite::create();
_buttonNormalRenderer = cocos2d::extension::Scale9Sprite::create();
_buttonClickedRenderer = cocos2d::extension::Scale9Sprite::create();
_buttonDisableRenderer = cocos2d::extension::Scale9Sprite::create();
}
else
{
_buttonNormalRenderer = CCSprite::create();
_buttonClickedRenderer = CCSprite::create();
_buttonDisableRenderer = CCSprite::create();
_buttonNormalRenderer = cocos2d::Sprite::create();
_buttonClickedRenderer = cocos2d::Sprite::create();
_buttonDisableRenderer = cocos2d::Sprite::create();
}
loadTextureNormal(_normalFileName.c_str(), _normalTexType);
@ -179,32 +176,33 @@ void UIButton::loadTextureNormal(const char* normal,TextureResType texType)
switch (_normalTexType)
{
case UI_TEX_TYPE_LOCAL:
dynamic_cast<Scale9Sprite*>(_buttonNormalRenderer)->initWithFile(normal);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_buttonNormalRenderer)->initWithFile(normal);
break;
case UI_TEX_TYPE_PLIST:
dynamic_cast<Scale9Sprite*>(_buttonNormalRenderer)->initWithSpriteFrameName(normal);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_buttonNormalRenderer)->initWithSpriteFrameName(normal);
break;
default:
break;
}
dynamic_cast<Scale9Sprite*>(_buttonNormalRenderer)->setColor(getColor());
dynamic_cast<Scale9Sprite*>(_buttonNormalRenderer)->setOpacity(getOpacity());
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_buttonNormalRenderer)->setColor(getColor());
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_buttonNormalRenderer)->setOpacity(getOpacity());
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_buttonNormalRenderer)->setCapInsets(_capInsetsNormal);
}
else
{
switch (_normalTexType)
{
case UI_TEX_TYPE_LOCAL:
dynamic_cast<Sprite*>(_buttonNormalRenderer)->initWithFile(normal);
dynamic_cast<cocos2d::Sprite*>(_buttonNormalRenderer)->initWithFile(normal);
break;
case UI_TEX_TYPE_PLIST:
dynamic_cast<Sprite*>(_buttonNormalRenderer)->initWithSpriteFrameName(normal);
dynamic_cast<cocos2d::Sprite*>(_buttonNormalRenderer)->initWithSpriteFrameName(normal);
break;
default:
break;
}
dynamic_cast<Sprite*>(_buttonNormalRenderer)->setColor(getColor());
dynamic_cast<Sprite*>(_buttonNormalRenderer)->setOpacity(getOpacity());
dynamic_cast<cocos2d::Sprite*>(_buttonNormalRenderer)->setColor(getColor());
dynamic_cast<cocos2d::Sprite*>(_buttonNormalRenderer)->setOpacity(getOpacity());
}
_normalTextureSize = _buttonNormalRenderer->getContentSize();
updateAnchorPoint();
@ -224,32 +222,33 @@ void UIButton::loadTexturePressed(const char* selected,TextureResType texType)
switch (_pressedTexType)
{
case UI_TEX_TYPE_LOCAL:
dynamic_cast<Scale9Sprite*>(_buttonClickedRenderer)->initWithFile(selected);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_buttonClickedRenderer)->initWithFile(selected);
break;
case UI_TEX_TYPE_PLIST:
dynamic_cast<Scale9Sprite*>(_buttonClickedRenderer)->initWithSpriteFrameName(selected);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_buttonClickedRenderer)->initWithSpriteFrameName(selected);
break;
default:
break;
}
dynamic_cast<Scale9Sprite*>(_buttonClickedRenderer)->setColor(getColor());
dynamic_cast<Scale9Sprite*>(_buttonClickedRenderer)->setOpacity(getOpacity());
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_buttonClickedRenderer)->setColor(getColor());
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_buttonClickedRenderer)->setOpacity(getOpacity());
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_buttonClickedRenderer)->setCapInsets(_capInsetsPressed);
}
else
{
switch (_pressedTexType)
{
case UI_TEX_TYPE_LOCAL:
dynamic_cast<Sprite*>(_buttonClickedRenderer)->initWithFile(selected);
dynamic_cast<cocos2d::Sprite*>(_buttonClickedRenderer)->initWithFile(selected);
break;
case UI_TEX_TYPE_PLIST:
dynamic_cast<Sprite*>(_buttonClickedRenderer)->initWithSpriteFrameName(selected);
dynamic_cast<cocos2d::Sprite*>(_buttonClickedRenderer)->initWithSpriteFrameName(selected);
break;
default:
break;
}
dynamic_cast<Sprite*>(_buttonClickedRenderer)->setColor(getColor());
dynamic_cast<Sprite*>(_buttonClickedRenderer)->setOpacity(getOpacity());
dynamic_cast<cocos2d::Sprite*>(_buttonClickedRenderer)->setColor(getColor());
dynamic_cast<cocos2d::Sprite*>(_buttonClickedRenderer)->setOpacity(getOpacity());
}
_pressedTextureSize = _buttonClickedRenderer->getContentSize();
updateAnchorPoint();
@ -269,73 +268,74 @@ void UIButton::loadTextureDisabled(const char* disabled,TextureResType texType)
switch (_disabledTexType)
{
case UI_TEX_TYPE_LOCAL:
dynamic_cast<Scale9Sprite*>(_buttonDisableRenderer)->initWithFile(disabled);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_buttonDisableRenderer)->initWithFile(disabled);
break;
case UI_TEX_TYPE_PLIST:
dynamic_cast<Scale9Sprite*>(_buttonDisableRenderer)->initWithSpriteFrameName(disabled);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_buttonDisableRenderer)->initWithSpriteFrameName(disabled);
break;
default:
break;
}
dynamic_cast<Scale9Sprite*>(_buttonDisableRenderer)->setColor(getColor());
dynamic_cast<Scale9Sprite*>(_buttonDisableRenderer)->setOpacity(getOpacity());
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_buttonDisableRenderer)->setColor(getColor());
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_buttonDisableRenderer)->setOpacity(getOpacity());
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_buttonDisableRenderer)->setCapInsets(_capInsetsDisabled);
}
else
{
switch (_disabledTexType)
{
case UI_TEX_TYPE_LOCAL:
dynamic_cast<Sprite*>(_buttonDisableRenderer)->initWithFile(disabled);
dynamic_cast<cocos2d::Sprite*>(_buttonDisableRenderer)->initWithFile(disabled);
break;
case UI_TEX_TYPE_PLIST:
dynamic_cast<Sprite*>(_buttonDisableRenderer)->initWithSpriteFrameName(disabled);
dynamic_cast<cocos2d::Sprite*>(_buttonDisableRenderer)->initWithSpriteFrameName(disabled);
break;
default:
break;
}
dynamic_cast<Sprite*>(_buttonDisableRenderer)->setColor(getColor());
dynamic_cast<Sprite*>(_buttonDisableRenderer)->setOpacity(getOpacity());
dynamic_cast<cocos2d::Sprite*>(_buttonDisableRenderer)->setColor(getColor());
dynamic_cast<cocos2d::Sprite*>(_buttonDisableRenderer)->setOpacity(getOpacity());
}
_disabledTextureSize = _buttonDisableRenderer->getContentSize();
updateAnchorPoint();
disabledTextureScaleChangedWithSize();
}
void UIButton::setCapInsets(const Rect &capInsets)
void UIButton::setCapInsets(const cocos2d::Rect &capInsets)
{
setCapInsetsNormalRenderer(capInsets);
setCapInsetsPressedRenderer(capInsets);
setCapInsetsDisabledRenderer(capInsets);
}
void UIButton::setCapInsetsNormalRenderer(const Rect &capInsets)
void UIButton::setCapInsetsNormalRenderer(const cocos2d::Rect &capInsets)
{
_capInsetsNormal = capInsets;
if (!_scale9Enabled)
{
return;
}
dynamic_cast<Scale9Sprite*>(_buttonNormalRenderer)->setCapInsets(capInsets);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_buttonNormalRenderer)->setCapInsets(capInsets);
}
void UIButton::setCapInsetsPressedRenderer(const Rect &capInsets)
void UIButton::setCapInsetsPressedRenderer(const cocos2d::Rect &capInsets)
{
_capInsetsPressed = capInsets;
if (!_scale9Enabled)
{
return;
}
dynamic_cast<Scale9Sprite*>(_buttonClickedRenderer)->setCapInsets(capInsets);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_buttonClickedRenderer)->setCapInsets(capInsets);
}
void UIButton::setCapInsetsDisabledRenderer(const Rect &capInsets)
void UIButton::setCapInsetsDisabledRenderer(const cocos2d::Rect &capInsets)
{
_capInsetsDisabled = capInsets;
if (!_scale9Enabled)
{
return;
}
dynamic_cast<Scale9Sprite*>(_buttonDisableRenderer)->setCapInsets(capInsets);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_buttonDisableRenderer)->setCapInsets(capInsets);
}
void UIButton::onPressStateChangedToNormal()
@ -348,9 +348,9 @@ void UIButton::onPressStateChangedToNormal()
_buttonNormalRenderer->stopAllActions();
_buttonClickedRenderer->stopAllActions();
_buttonDisableRenderer->stopAllActions();
Action *zoomAction = ScaleTo::create(0.05f, 1.0f);
Action *zoomAction1 = ScaleTo::create(0.05f, 1.0f);
Action *zoomAction2 = ScaleTo::create(0.05f, 1.0f);
cocos2d::Action *zoomAction = cocos2d::ScaleTo::create(0.05f, 1.0f);
cocos2d::Action *zoomAction1 = cocos2d::ScaleTo::create(0.05f, 1.0f);
cocos2d::Action *zoomAction2 = cocos2d::ScaleTo::create(0.05f, 1.0f);
_buttonNormalRenderer->runAction(zoomAction);
_buttonClickedRenderer->runAction(zoomAction1);
_buttonDisableRenderer->runAction(zoomAction2);
@ -367,9 +367,9 @@ void UIButton::onPressStateChangedToPressed()
_buttonNormalRenderer->stopAllActions();
_buttonClickedRenderer->stopAllActions();
_buttonDisableRenderer->stopAllActions();
Action *zoomAction = ScaleTo::create(0.05f, 1.1f);
Action *zoomAction1 = ScaleTo::create(0.05f, 1.1f);
Action *zoomAction2 = ScaleTo::create(0.05f, 1.1f);
cocos2d::Action *zoomAction = cocos2d::ScaleTo::create(0.05f, 1.1f);
cocos2d::Action *zoomAction1 = cocos2d::ScaleTo::create(0.05f, 1.1f);
cocos2d::Action *zoomAction2 = cocos2d::ScaleTo::create(0.05f, 1.1f);
_buttonNormalRenderer->runAction(zoomAction);
_buttonClickedRenderer->runAction(zoomAction1);
_buttonDisableRenderer->runAction(zoomAction2);
@ -390,9 +390,9 @@ void UIButton::setFlipX(bool flipX)
{
return;
}
dynamic_cast<Sprite*>(_buttonNormalRenderer)->setFlippedX(flipX);
dynamic_cast<Sprite*>(_buttonClickedRenderer)->setFlippedX(flipX);
dynamic_cast<Sprite*>(_buttonDisableRenderer)->setFlippedX(flipX);
dynamic_cast<cocos2d::Sprite*>(_buttonNormalRenderer)->setFlippedX(flipX);
dynamic_cast<cocos2d::Sprite*>(_buttonClickedRenderer)->setFlippedX(flipX);
dynamic_cast<cocos2d::Sprite*>(_buttonDisableRenderer)->setFlippedX(flipX);
}
void UIButton::setFlipY(bool flipY)
@ -402,9 +402,9 @@ void UIButton::setFlipY(bool flipY)
{
return;
}
dynamic_cast<Sprite*>(_buttonNormalRenderer)->setFlippedY(flipY);
dynamic_cast<Sprite*>(_buttonClickedRenderer)->setFlippedY(flipY);
dynamic_cast<Sprite*>(_buttonDisableRenderer)->setFlippedY(flipY);
dynamic_cast<cocos2d::Sprite*>(_buttonNormalRenderer)->setFlippedY(flipY);
dynamic_cast<cocos2d::Sprite*>(_buttonClickedRenderer)->setFlippedY(flipY);
dynamic_cast<cocos2d::Sprite*>(_buttonDisableRenderer)->setFlippedY(flipY);
}
bool UIButton::isFlipX()
@ -413,7 +413,7 @@ bool UIButton::isFlipX()
{
return false;
}
return dynamic_cast<Sprite*>(_buttonNormalRenderer)->isFlippedX();
return dynamic_cast<cocos2d::Sprite*>(_buttonNormalRenderer)->isFlippedX();
}
bool UIButton::isFlipY()
@ -422,16 +422,16 @@ bool UIButton::isFlipY()
{
return false;
}
return dynamic_cast<Sprite*>(_buttonNormalRenderer)->isFlippedY();
return dynamic_cast<cocos2d::Sprite*>(_buttonNormalRenderer)->isFlippedY();
}
void UIButton::setAnchorPoint(const Point &pt)
void UIButton::setAnchorPoint(const cocos2d::Point &pt)
{
UIWidget::setAnchorPoint(pt);
_buttonNormalRenderer->setAnchorPoint(pt);
_buttonClickedRenderer->setAnchorPoint(pt);
_buttonDisableRenderer->setAnchorPoint(pt);
_titleRenderer->setPosition(Point(_size.width*(0.5f-_anchorPoint.x), _size.height*(0.5f-_anchorPoint.y)));
_titleRenderer->setPosition(cocos2d::Point(_size.width*(0.5f-_anchorPoint.x), _size.height*(0.5f-_anchorPoint.y)));
}
void UIButton::onSizeChanged()
@ -441,12 +441,12 @@ void UIButton::onSizeChanged()
disabledTextureScaleChangedWithSize();
}
const Size& UIButton::getContentSize() const
const cocos2d::Size& UIButton::getContentSize() const
{
return _normalTextureSize;
}
Node* UIButton::getVirtualRenderer()
cocos2d::Node* UIButton::getVirtualRenderer()
{
if (_bright)
{
@ -480,11 +480,11 @@ void UIButton::normalTextureScaleChangedWithSize()
{
if (_scale9Enabled)
{
dynamic_cast<Scale9Sprite*>(_buttonNormalRenderer)->setPreferredSize(_size);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_buttonNormalRenderer)->setPreferredSize(_size);
}
else
{
Size textureSize = _normalTextureSize;
cocos2d::Size textureSize = _normalTextureSize;
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
{
_buttonNormalRenderer->setScale(1.0f);
@ -511,11 +511,11 @@ void UIButton::pressedTextureScaleChangedWithSize()
{
if (_scale9Enabled)
{
dynamic_cast<Scale9Sprite*>(_buttonClickedRenderer)->setPreferredSize(_size);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_buttonClickedRenderer)->setPreferredSize(_size);
}
else
{
Size textureSize = _pressedTextureSize;
cocos2d::Size textureSize = _pressedTextureSize;
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
{
_buttonClickedRenderer->setScale(1.0f);
@ -542,11 +542,11 @@ void UIButton::disabledTextureScaleChangedWithSize()
{
if (_scale9Enabled)
{
dynamic_cast<Scale9Sprite*>(_buttonDisableRenderer)->setPreferredSize(_size);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_buttonDisableRenderer)->setPreferredSize(_size);
}
else
{
Size textureSize = _disabledTextureSize;
cocos2d::Size textureSize = _disabledTextureSize;
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
{
_buttonDisableRenderer->setScale(1.0f);
@ -575,13 +575,13 @@ const char* UIButton::getTitleText() const
return _titleRenderer->getString();
}
void UIButton::setTitleColor(const Color3B& color)
void UIButton::setTitleColor(const cocos2d::Color3B& color)
{
_titleColor = color;
_titleRenderer->setColor(color);
}
const Color3B& UIButton::getTitleColor() const
const cocos2d::Color3B& UIButton::getTitleColor() const
{
return _titleRenderer->getColor();
}
@ -606,7 +606,7 @@ const char* UIButton::getTitleFontName() const
return _titleRenderer->getFontName();
}
void UIButton::setColor(const Color3B &color)
void UIButton::setColor(const cocos2d::Color3B &color)
{
UIWidget::setColor(color);
setTitleColor(_titleColor);
@ -617,4 +617,30 @@ const char* UIButton::getDescription() const
return "Button";
}
UIWidget* UIButton::createCloneInstance()
{
return UIButton::create();
}
void UIButton::copySpecialProperties(UIWidget *widget)
{
UIButton* button = dynamic_cast<UIButton*>(widget);
if (button)
{
_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);
setCapInsetsNormalRenderer(button->_capInsetsNormal);
setCapInsetsPressedRenderer(button->_capInsetsPressed);
setCapInsetsDisabledRenderer(button->_capInsetsDisabled);
setTitleText(button->getTitleText());
setTitleFontName(button->getTitleFontName());
setTitleFontSize(button->getTitleFontSize());
setTitleColor(button->getTitleColor());
setPressedActionEnabled(button->_pressedActionEnabled);
}
}
}

View File

@ -27,8 +27,12 @@
#include "gui/UIWidget.h"
namespace gui {
namespace gui{
/**
* @js NA
* @lua NA
*/
class UIButton : public UIWidget
{
public:
@ -162,6 +166,11 @@ public:
*/
virtual void setColor(const cocos2d::Color3B &color);
/**
* Returns the "class name" of widget.
*/
virtual const char* getDescription() const;
void setTitleText(const char* text);
const char* getTitleText() const;
void setTitleColor(const cocos2d::Color3B& color);
@ -170,11 +179,7 @@ public:
float getTitleFontSize() const;
void setTitleFontName(const char* fontName);
const char* getTitleFontName() const;
/**
* Returns the "class name" of widget.
*/
virtual const char* getDescription() const;
protected:
virtual bool init();
virtual void initRenderer();
@ -186,6 +191,8 @@ protected:
void normalTextureScaleChangedWithSize();
void pressedTextureScaleChangedWithSize();
void disabledTextureScaleChangedWithSize();
virtual UIWidget* createCloneInstance();
virtual void copySpecialProperties(UIWidget* model);
protected:
cocos2d::Node* _buttonNormalRenderer;
cocos2d::Node* _buttonClickedRenderer;

View File

@ -24,10 +24,9 @@
#include "gui/UICheckBox.h"
using namespace cocos2d;
namespace gui {
UICheckBox::UICheckBox():
_backGroundBoxRenderer(NULL),
_backGroundSelectedBoxRenderer(NULL),
@ -41,7 +40,12 @@ _backGroundTexType(UI_TEX_TYPE_LOCAL),
_backGroundSelectedTexType(UI_TEX_TYPE_LOCAL),
_frontCrossTexType(UI_TEX_TYPE_LOCAL),
_backGroundDisabledTexType(UI_TEX_TYPE_LOCAL),
_frontCrossDisabledTexType(UI_TEX_TYPE_LOCAL)
_frontCrossDisabledTexType(UI_TEX_TYPE_LOCAL),
_backGroundFileName(""),
_backGroundSelectedFileName(""),
_frontCrossFileName(""),
_backGroundDisabledFileName(""),
_frontCrossDisabledFileName("")
{
}
@ -75,11 +79,11 @@ bool UICheckBox::init()
void UICheckBox::initRenderer()
{
UIWidget::initRenderer();
_backGroundBoxRenderer = Sprite::create();
_backGroundSelectedBoxRenderer = Sprite::create();
_frontCrossRenderer = Sprite::create();
_backGroundBoxDisabledRenderer = Sprite::create();
_frontCrossDisabledRenderer = Sprite::create();
_backGroundBoxRenderer = cocos2d::Sprite::create();
_backGroundSelectedBoxRenderer = cocos2d::Sprite::create();
_frontCrossRenderer = cocos2d::Sprite::create();
_backGroundBoxDisabledRenderer = cocos2d::Sprite::create();
_frontCrossDisabledRenderer = cocos2d::Sprite::create();
_renderer->addChild(_backGroundBoxRenderer);
_renderer->addChild(_backGroundSelectedBoxRenderer);
_renderer->addChild(_frontCrossRenderer);
@ -102,6 +106,7 @@ void UICheckBox::loadTextureBackGround(const char *backGround,TextureResType tex
{
return;
}
_backGroundFileName = backGround;
_backGroundTexType = texType;
switch (_backGroundTexType)
{
@ -125,6 +130,7 @@ void UICheckBox::loadTextureBackGroundSelected(const char *backGroundSelected,Te
{
return;
}
_backGroundSelectedFileName = backGroundSelected;
_backGroundSelectedTexType = texType;
switch (_backGroundSelectedTexType)
{
@ -148,6 +154,7 @@ void UICheckBox::loadTextureFrontCross(const char *cross,TextureResType texType)
{
return;
}
_frontCrossFileName = cross;
_frontCrossTexType = texType;
switch (_frontCrossTexType)
{
@ -171,6 +178,7 @@ void UICheckBox::loadTextureBackGroundDisabled(const char *backGroundDisabled,Te
{
return;
}
_backGroundDisabledFileName = backGroundDisabled;
_backGroundDisabledTexType = texType;
switch (_backGroundDisabledTexType)
{
@ -194,6 +202,7 @@ void UICheckBox::loadTextureFrontCrossDisabled(const char *frontCrossDisabled,Te
{
return;
}
_frontCrossDisabledFileName = frontCrossDisabled;
_frontCrossDisabledTexType = texType;
switch (_frontCrossDisabledTexType)
{
@ -211,7 +220,7 @@ void UICheckBox::loadTextureFrontCrossDisabled(const char *frontCrossDisabled,Te
frontCrossDisabledTextureScaleChangedWithSize();
}
void UICheckBox::onTouchEnded(const Point &touchPoint)
void UICheckBox::onTouchEnded(const cocos2d::Point &touchPoint)
{
if (_focus)
{
@ -289,7 +298,7 @@ void UICheckBox::unSelectedEvent()
}
}
void UICheckBox::addEventListener(Object *target, SEL_SelectedStateEvent selector)
void UICheckBox::addEventListener(cocos2d::Object *target, SEL_SelectedStateEvent selector)
{
_selectedStateEventListener = target;
_selectedStateEventSelector = selector;
@ -323,7 +332,7 @@ bool UICheckBox::isFlipY()
return _backGroundBoxRenderer->isFlippedY();
}
void UICheckBox::setAnchorPoint(const Point &pt)
void UICheckBox::setAnchorPoint(const cocos2d::Point &pt)
{
UIWidget::setAnchorPoint(pt);
_backGroundBoxRenderer->setAnchorPoint(pt);
@ -342,12 +351,12 @@ void UICheckBox::onSizeChanged()
frontCrossDisabledTextureScaleChangedWithSize();
}
const Size& UICheckBox::getContentSize() const
const cocos2d::Size& UICheckBox::getContentSize() const
{
return _backGroundBoxRenderer->getContentSize();
}
Node* UICheckBox::getVirtualRenderer()
cocos2d::Node* UICheckBox::getVirtualRenderer()
{
return _backGroundBoxRenderer;
}
@ -361,7 +370,7 @@ void UICheckBox::backGroundTextureScaleChangedWithSize()
}
else
{
Size textureSize = _backGroundBoxRenderer->getContentSize();
cocos2d::Size textureSize = _backGroundBoxRenderer->getContentSize();
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
{
_backGroundBoxRenderer->setScale(1.0f);
@ -382,7 +391,7 @@ void UICheckBox::backGroundSelectedTextureScaleChangedWithSize()
}
else
{
Size textureSize = _backGroundSelectedBoxRenderer->getContentSize();
cocos2d::Size textureSize = _backGroundSelectedBoxRenderer->getContentSize();
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
{
_backGroundSelectedBoxRenderer->setScale(1.0f);
@ -403,7 +412,7 @@ void UICheckBox::frontCrossTextureScaleChangedWithSize()
}
else
{
Size textureSize = _frontCrossRenderer->getContentSize();
cocos2d::Size textureSize = _frontCrossRenderer->getContentSize();
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
{
_frontCrossRenderer->setScale(1.0f);
@ -424,7 +433,7 @@ void UICheckBox::backGroundDisabledTextureScaleChangedWithSize()
}
else
{
Size textureSize = _backGroundBoxDisabledRenderer->getContentSize();
cocos2d::Size textureSize = _backGroundBoxDisabledRenderer->getContentSize();
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
{
_backGroundBoxDisabledRenderer->setScale(1.0f);
@ -445,7 +454,7 @@ void UICheckBox::frontCrossDisabledTextureScaleChangedWithSize()
}
else
{
Size textureSize = _frontCrossDisabledRenderer->getContentSize();
cocos2d::Size textureSize = _frontCrossDisabledRenderer->getContentSize();
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
{
_frontCrossDisabledRenderer->setScale(1.0f);
@ -463,4 +472,23 @@ const char* UICheckBox::getDescription() const
return "CheckBox";
}
UIWidget* UICheckBox::createCloneInstance()
{
return UICheckBox::create();
}
void UICheckBox::copySpecialProperties(UIWidget *widget)
{
UICheckBox* checkBox = dynamic_cast<UICheckBox*>(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);
setSelectedState(checkBox->_isSelected);
}
}
}

View File

@ -35,9 +35,13 @@ typedef enum
CHECKBOX_STATE_EVENT_UNSELECTED
}CheckBoxEventType;
typedef void (cocos2d::CCObject::*SEL_SelectedStateEvent)(cocos2d::Object*,CheckBoxEventType);
typedef void (cocos2d::Object::*SEL_SelectedStateEvent)(cocos2d::Object*,CheckBoxEventType);
#define checkboxselectedeventselector(_SELECTOR) (SEL_SelectedStateEvent)(&_SELECTOR)
/**
* @js NA
* @lua NA
*/
class UICheckBox : public UIWidget
{
public:
@ -156,11 +160,12 @@ public:
//override "getVirtualRenderer" method of widget.
virtual cocos2d::Node* getVirtualRenderer();
/**
* Returns the "class name" of widget.
*/
virtual const char* getDescription() const;
protected:
virtual bool init();
virtual void initRenderer();
@ -175,6 +180,8 @@ protected:
void frontCrossTextureScaleChangedWithSize();
void backGroundDisabledTextureScaleChangedWithSize();
void frontCrossDisabledTextureScaleChangedWithSize();
virtual UIWidget* createCloneInstance();
virtual void copySpecialProperties(UIWidget* model);
protected:
cocos2d::Sprite* _backGroundBoxRenderer;
cocos2d::Sprite* _backGroundSelectedBoxRenderer;
@ -191,6 +198,12 @@ protected:
TextureResType _frontCrossTexType;
TextureResType _backGroundDisabledTexType;
TextureResType _frontCrossDisabledTexType;
std::string _backGroundFileName;
std::string _backGroundSelectedFileName;
std::string _frontCrossFileName;
std::string _backGroundDisabledFileName;
std::string _frontCrossDisabledFileName;
};
}

File diff suppressed because it is too large Load Diff

View File

@ -1,367 +0,0 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
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.
****************************************************************************/
#ifndef __UIDRAGPANEL_H__
#define __UIDRAGPANEL_H__
#include "gui/Layout.h"
#include "gui/UIScrollInterface.h"
namespace gui {
/**
* drag panel move type
*/
enum DRAGPANEL_MOVE_TYPE
{
DRAGPANEL_MOVE_TYPE_NONE,
DRAGPANEL_MOVE_TYPE_AUTOMOVE,
DRAGPANEL_MOVE_TYPE_BOUNCE,
};
/**
* dragpanel berth direction
*/
enum DRAGPANEL_BERTH_DIR
{
DRAGPANEL_BERTH_DIR_NONE,
DRAGPANEL_BERTH_DIR_LEFTBOTTOM,
DRAGPANEL_BERTH_DIR_LFETTOP,
DRAGPANEL_BERTH_DIR_RIGHTBOTTOM,
DRAGPANEL_BERTH_DIR_RIGHTTOP,
DRAGPANEL_BERTH_DIR_LEFT,
DRAGPANEL_BERTH_DIR_TOP,
DRAGPANEL_BERTH_DIR_RIGHT,
DRAGPANEL_BERTH_DIR_BOTTOM,
};
/**
* dragpanel bounce direction
*/
enum DRAGPANEL_BOUNCE_DIR
{
DRAGPANEL_BOUNCE_DIR_NONE,
DRAGPANEL_BOUNCE_DIR_LEFTBOTTOM,
DRAGPANEL_BOUNCE_DIR_LEFTTOP,
DRAGPANEL_BOUNCE_DIR_RIGHTBOTTOM,
DRAGPANEL_BOUNCE_DIR_RIGHTTOP,
DRAGPANEL_BOUNCE_DIR_LEFT,
DRAGPANEL_BOUNCE_DIR_TOP,
DRAGPANEL_BOUNCE_DIR_RIGHT,
DRAGPANEL_BOUNCE_DIR_BOTTOM,
};
typedef enum
{
DRAGPANEL_EVENT_BERTH_LEFTBOTTOM,
DRAGPANEL_EVENT_BERTH_LFETTOP,
DRAGPANEL_EVENT_BERTH_RIGHTBOTTOM,
DRAGPANEL_EVENT_BERTH_RIGHTTOP,
DRAGPANEL_EVENT_BERTH_LEFT,
DRAGPANEL_EVENT_BERTH_TOP,
DRAGPANEL_EVENT_BERTH_RIGHT,
DRAGPANEL_EVENT_BERTH_BOTTOM,
DRAGPANEL_EVENT_BOUNCE_LEFTBOTTOM,
DRAGPANEL_EVENT_BOUNCE_LEFTTOP,
DRAGPANEL_EVENT_BOUNCE_RIGHTBOTTOM,
DRAGPANEL_EVENT_BOUNCE_RIGHTTOP,
DRAGPANEL_EVENT_BOUNCE_LEFT,
DRAGPANEL_EVENT_BOUNCE_TOP,
DRAGPANEL_EVENT_BOUNCE_RIGHT,
DRAGPANEL_EVENT_BOUNCE_BOTTOM,
}DragPanelEventType;
/**
* dragpanel event
*/
typedef void (cocos2d::Object::*SEL_DragPanelEvent)(cocos2d::Object*, DragPanelEventType);
#define dragpaneleventselector(_SELECTOR)(SEL_DragPanelEvent)(&_SELECTOR)
class UIDragPanel : public Layout, public UIScrollInterface
{
public:
UIDragPanel();
virtual ~UIDragPanel();
static UIDragPanel* create();
virtual bool onTouchBegan(const cocos2d::Point &touchPoint);
virtual void onTouchMoved(const cocos2d::Point &touchPoint);
virtual void onTouchEnded(const cocos2d::Point &touchPoint);
virtual void onTouchCancelled(const cocos2d::Point &touchPoint);
virtual void onTouchLongClicked(const cocos2d::Point &touchPoint);
virtual void update(float dt);
/**
* add widget child override
*/
virtual bool addChild(UIWidget* widget);
/**
* remove widget child override
*/
virtual bool removeChild(UIWidget* child);
/**
* remove all widget children override
*/
virtual void removeAllChildren();
/**
* get widget children of inner container
*/
virtual cocos2d::Array* getChildren();
/* gui mark */
/**
* get and set inner container size
*/
const cocos2d::Size& getInnerContainerSize() const;
void setInnerContainerSize(const cocos2d::Size &size);
/**
* get and set inner container position
*/
const cocos2d::Point& getInnerContainerPosition() const;
void setInnerContainerPosition(const cocos2d::Point& point, bool animated);
/**
* set inner container offset
*/
void setInnerContainerOffset(const cocos2d::Point& offset, bool animated);
/**/
// auto move
/**
* set auto move duration
*/
void setAutoMoveDuration(float duration);
/**
* set auto move ease rate
*/
void setAutoMoveEaseRate(float rate);
// berth
/**
* get berth or not
*/
bool isBerth();
/**
* event
*/
void addEventListener(cocos2d::Object* target, SEL_DragPanelEvent selector);
/**
* get and set bounce enable
*/
bool isBounceEnable();
void setBounceEnable(bool bounce);
/**
* set bounce duration
*/
void setBounceDuratoin(float duration);
/**
* set bounce ease rate
*/
void setBounceEaseRate(float rate);
/**
* Gets inner container of dragpanel.
*
* Inner container is the container of dragpanel's children.
*
* @return inner container.
*/
Layout* getInnerContainer();
/**
* Sets LayoutType.
*
* @see LayoutType
*
* @param LayoutType
*/
virtual void setLayoutType(LayoutType type);
/**
* Gets LayoutType.
*
* @see LayoutType
*
* @return LayoutType
*/
virtual LayoutType getLayoutType() const;
virtual void doLayout();
/**
* Returns the "class name" of widget.
*/
virtual const char* getDescription() const;
protected:
virtual bool init();
virtual void initRenderer();
virtual void releaseResoures();
virtual void handlePressLogic(const cocos2d::Point &touchPoint);
virtual void handleMoveLogic(const cocos2d::Point &touchPoint);
virtual void handleReleaseLogic(const cocos2d::Point &touchPoint);
virtual void interceptTouchEvent(int handleState,UIWidget* sender, const cocos2d::Point &touchPoint);
/* gui mark */
// virtual bool isInScrollDegreeRange(UIWidget* widget);
/**/
virtual void checkChildInfo(int handleState, UIWidget *sender, const cocos2d::Point &touchPoint);
// void updateWidthAndHeight();
void recordSlidTime(float dt);
/* gui mark */
void setInnerContainerOffset(const cocos2d::Point& offset);
/**/
// check if dragpanel rect contain inner rect
bool checkContainInnerRect();
// move
void moveWithDelta(const cocos2d::Point& delta);
// auto move
void autoMove();
void autoMoveOver();
void startAutoMove();
void stopAutoMove();
// berth
// check if move to boundary with update
bool checkToBoundaryWithDeltaPosition(const cocos2d::Point& delta);
// calculate to boundary delta
cocos2d::Point calculateToBoundaryDeltaPosition(const cocos2d::Point& paramDelta);
// check berth
bool checkBerth();
// berth event
void berthEvent();
void berthToLeftEvent();
void berthToRightEvent();
void berthToTopEvent();
void berthToBottomEvent();
void berthToLeftBottomEvent();
void berthToLeftTopEvent();
void berthToRightBottomEvent();
void berthToRightTopEvent();
// bounce
bool checkNeedBounce();
void startBounce();
void stopBounce();
void bounceToCorner();
void bounceOver();
// bounce event
void bounceToLeftBottomEvent();
void bounceToRightBottomEvent();
void bounceToLeftTopEvent();
void bounceToRightTopEvent();
void bounceToLeftEvent();
void bounceToTopEvent();
void bounceToRightEvent();
void bounceToBottomEvent();
void actionWithDuration(float duration);
bool actionIsDone();
void actionStartWithWidget(UIWidget* widget);
void actionStep(float dt);
void actionUpdate(float dt);
void actionStop();
void actionDone();
void moveByWithDuration(float duration, const cocos2d::Point& deltaPosition);
void moveByInit();
void moveByUpdate(float t);
void moveToWithDuration(float duration, const cocos2d::Point& position);
void moveToInit();
void moveToUpdate(float t);
virtual void onSizeChanged();
/*compatible*/
/**
* These methods will be removed
*/
virtual void setClippingEnable(bool is){setClippingEnabled(is);};
/************/
virtual void setClippingEnabled(bool able){Layout::setClippingEnabled(able);};
protected:
Layout* _innerContainer;
/*
DRAGPANEL_DIR m_eDirection;
DRAGPANEL_MOVE_DIR m_eMoveDirection;
*/
bool _touchPressed;
bool _touchMoved;
bool _touchReleased;
bool _touchCanceld; // check touch out of drag panel boundary
cocos2d::Point _touchStartNodeSpace;
cocos2d::Point _touchStartWorldSpace;
cocos2d::Point _touchEndWorldSpace;
float _slidTime;
// move type
DRAGPANEL_MOVE_TYPE _moveType;
// auto move
float _autoMoveDuration;
float _autoMoveEaseRate;
// event
cocos2d::Object* _eventLister;
SEL_DragPanelEvent _eventSelector;
// berth
DRAGPANEL_BERTH_DIR _berthDirection;
// bounce
bool _bounceEnable;
DRAGPANEL_BOUNCE_DIR _bounceDirection;
float _bounceDuration;
float _bounceEaseRate;
float _runningAction;
int _actionType;
UIWidget* _actionWidget;
float _duration;
float _elapsed;
bool _firstTick;
cocos2d::Point _positionDelta;
cocos2d::Point _startPosition;
cocos2d::Point _previousPosition;
cocos2d::Point _endPosition;
};
}
#endif /* defined(__TestCpp__UIDragPanel__) */

View File

@ -22,111 +22,9 @@
THE SOFTWARE.
****************************************************************************/
#include "gui/UIHelper.h"
#include "cocos2d.h"
#include "cocostudio/DictionaryHelper.h"
#include "cocostudio/CCSGUIReader.h"
using namespace cocos2d;
using namespace cocostudio;
#include "CocosGUI.h"
namespace gui {
static UIHelper* helperInstance = NULL;
UIHelper* UIHelper::instance()
{
if (!helperInstance)
{
helperInstance = new UIHelper();
}
return helperInstance;
}
void UIHelper::purgeUIHelper()
{
CC_SAFE_DELETE(helperInstance);
}
UIHelper::UIHelper():
_textureFiles(NULL),
_fileDesignHeight(0.0f),
_fileDesignWidth(0.0f)
{
Size winSize = Director::getInstance()->getWinSize();
_fileDesignWidth = winSize.width;
_fileDesignHeight = winSize.height;
init();
}
UIHelper::~UIHelper()
{
cocostudio::CCSGUIReader::purgeCCSGUIReader();
}
void UIHelper::init()
{
_textureFiles = CCArray::create();
_textureFiles->retain();
}
UIWidget* UIHelper::createWidgetFromJsonFile(const char *fileName)
{
return CCSGUIReader::shareReader()->widgetFromJsonFile(fileName);
}
void UIHelper::addSpriteFrame(const char *fileName)
{
if (!fileName || strcmp(fileName, "") == 0)
{
return;
}
ccArray* arrayTextures = _textureFiles->data;
int length = arrayTextures->num;
for (int i=0;i<length;i++)
{
String* file = (String*)(arrayTextures->arr[i]);
if (strcmp(file->_string.c_str(), fileName) == 0)
{
return;
}
}
_textureFiles->addObject(CCString::create(fileName));
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(fileName);
}
void UIHelper::removeSpriteFrame(const char *fileName)
{
if (!fileName || strcmp(fileName, "") == 0)
{
return;
}
ccArray* arrayTextures = _textureFiles->data;
int length = arrayTextures->num;
for (int i=0;i<length;i++)
{
String* file = (String*)(arrayTextures->arr[i]);
if (strcmp(file->_string.c_str(), fileName) == 0)
{
SpriteFrameCache::getInstance()->removeSpriteFrameByName(fileName);
_textureFiles->removeObject(file);
return;
}
}
}
void UIHelper::removeAllSpriteFrame()
{
ccArray* arrayTextures = _textureFiles->data;
int length = arrayTextures->num;
for (int i=0;i<length;i++)
{
String* file = (String*)(arrayTextures->arr[i]);
SpriteFrameCache::getInstance()->removeSpriteFrameByName(file->_string.c_str());
}
_textureFiles->removeAllObjects();
}
UIWidget* UIHelper::seekWidgetByTag(UIWidget* root, int tag)
{
@ -138,7 +36,7 @@ UIWidget* UIHelper::seekWidgetByTag(UIWidget* root, int tag)
{
return root;
}
ccArray* arrayRootChildren = root->getChildren()->data;
cocos2d::ccArray* arrayRootChildren = root->getChildren()->data;
int length = arrayRootChildren->num;
for (int i=0;i<length;i++)
{
@ -162,7 +60,7 @@ UIWidget* UIHelper::seekWidgetByName(UIWidget* root, const char *name)
{
return root;
}
ccArray* arrayRootChildren = root->getChildren()->data;
cocos2d::ccArray* arrayRootChildren = root->getChildren()->data;
int length = arrayRootChildren->num;
for (int i=0;i<length;i++)
{
@ -182,12 +80,12 @@ UIWidget* UIHelper::seekWidgetByRelativeName(UIWidget *root, const char *name)
{
return NULL;
}
ccArray* arrayRootChildren = root->getChildren()->data;
cocos2d::ccArray* arrayRootChildren = root->getChildren()->data;
int length = arrayRootChildren->num;
for (int i=0;i<length;i++)
{
UIWidget* child = (UIWidget*)(arrayRootChildren->arr[i]);
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter());
UIRelativeLayoutParameter* layoutParameter = dynamic_cast<UIRelativeLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));
if (layoutParameter && strcmp(layoutParameter->getRelativeName(), name) == 0)
{
return child;
@ -196,26 +94,6 @@ UIWidget* UIHelper::seekWidgetByRelativeName(UIWidget *root, const char *name)
return NULL;
}
void UIHelper::setFileDesignWidth(float width)
{
_fileDesignWidth = width;
}
float UIHelper::getFileDesignWidth()
{
return _fileDesignWidth;
}
void UIHelper::setFileDesignHeight(float height)
{
_fileDesignHeight = height;
}
float UIHelper::getFileDesignHeight()
{
return _fileDesignHeight;
}
/*temp action*/
UIWidget* UIHelper::seekActionWidgetByActionTag(UIWidget* root, int tag)
{
@ -227,7 +105,7 @@ UIWidget* UIHelper::seekActionWidgetByActionTag(UIWidget* root, int tag)
{
return root;
}
ccArray* arrayRootChildren = root->getChildren()->data;
cocos2d::ccArray* arrayRootChildren = root->getChildren()->data;
int length = arrayRootChildren->num;
for (int i=0;i<length;i++)
{

View File

@ -25,52 +25,15 @@
#ifndef __UIHELPER_H__
#define __UIHELPER_H__
#include "gui/UIInputManager.h"
#include "cocostudio/CSContentJsonDictionary.h"
#define CCUIHELPER gui::UIHelper::instance()
namespace gui {
/**
* @js NA
* @lua NA
*/
class UIHelper
{
public:
/**
* Default constructor
*/
UIHelper();
/**
* Default destructor
*/
virtual ~UIHelper();
//initializes state of UIHelper.
void init();
/**
* Load a widget with json file.
*
* @return a widget created with json file.
*/
UIWidget* createWidgetFromJsonFile(const char* fileName);
//get instance
static UIHelper* instance();
//release instance
static void purgeUIHelper();
//add a plist file for loading widget's texture.
void addSpriteFrame(const char* fileName);
//remove a plist file for loading widget's texture.
void removeSpriteFrame(const char* fileName);
//remove all plist files for loading widget's texture.
void removeAllSpriteFrame();
/**
* Finds a widget whose tag equals to param tag from root widget.
*
@ -80,7 +43,7 @@ public:
*
* @return finded result.
*/
UIWidget* seekWidgetByTag(UIWidget* root, int tag);
static UIWidget* seekWidgetByTag(UIWidget* root, int tag);
/**
* Finds a widget whose name equals to param name from root widget.
@ -91,7 +54,7 @@ public:
*
* @return finded result.
*/
UIWidget* seekWidgetByName(UIWidget* root, const char* name);
static UIWidget* seekWidgetByName(UIWidget* root, const char* name);
/**
* Finds a widget whose name equals to param name from root widget.
@ -104,19 +67,10 @@ public:
*
* @return finded result.
*/
UIWidget* seekWidgetByRelativeName(UIWidget* root, const char* name);
void setFileDesignWidth(float width);
float getFileDesignWidth();
void setFileDesignHeight(float height);
float getFileDesignHeight();
/*temp action*/
UIWidget* seekActionWidgetByActionTag(UIWidget* root, int tag);
protected:
static UIWidget* seekWidgetByRelativeName(UIWidget* root, const char* name);
float _fileDesignWidth;
float _fileDesignHeight;
//texture
cocos2d::Array* _textureFiles;
/*temp action*/
static UIWidget* seekActionWidgetByActionTag(UIWidget* root, int tag);
};
}

View File

@ -25,11 +25,9 @@
#include "gui/UIImageView.h"
#include "extensions/GUI/CCControlExtension/CCScale9Sprite.h"
using namespace cocos2d;
using namespace cocos2d::extension;
namespace gui {
#define DYNAMIC_CAST_CCSPRITE dynamic_cast<cocos2d::Sprite*>(_imageRenderer)
#define DYNAMIC_CAST_SCALE9SPRITE dynamic_cast<cocos2d::extension::Scale9Sprite*>(_imageRenderer)
@ -41,7 +39,7 @@ _touchRelease(false),
_doubleClickEnabled(false),
_scale9Enabled(false),
_prevIgnoreSize(true),
_capInsets(Rect::ZERO),
_capInsets(cocos2d::Rect::ZERO),
_imageRenderer(NULL),
_textureFile(""),
_imageTexType(UI_TEX_TYPE_LOCAL),
@ -70,7 +68,7 @@ UIImageView* UIImageView::create()
void UIImageView::initRenderer()
{
UIWidget::initRenderer();
_imageRenderer = Sprite::create();
_imageRenderer = cocos2d::Sprite::create();
_renderer->addChild(_imageRenderer);
}
@ -90,6 +88,7 @@ void UIImageView::loadTexture(const char *fileName, TextureResType texType)
DYNAMIC_CAST_SCALE9SPRITE->initWithFile(fileName);
DYNAMIC_CAST_SCALE9SPRITE->setColor(getColor());
DYNAMIC_CAST_SCALE9SPRITE->setOpacity(getOpacity());
DYNAMIC_CAST_SCALE9SPRITE->setCapInsets(_capInsets);
}
else
{
@ -104,6 +103,7 @@ void UIImageView::loadTexture(const char *fileName, TextureResType texType)
DYNAMIC_CAST_SCALE9SPRITE->initWithSpriteFrameName(fileName);
DYNAMIC_CAST_SCALE9SPRITE->setColor(getColor());
DYNAMIC_CAST_SCALE9SPRITE->setOpacity(getOpacity());
DYNAMIC_CAST_SCALE9SPRITE->setCapInsets(_capInsets);
}
else
{
@ -120,7 +120,7 @@ void UIImageView::loadTexture(const char *fileName, TextureResType texType)
imageTextureScaleChangedWithSize();
}
void UIImageView::setTextureRect(const Rect &rect)
void UIImageView::setTextureRect(const cocos2d::Rect &rect)
{
if (_scale9Enabled)
{
@ -131,7 +131,7 @@ void UIImageView::setTextureRect(const Rect &rect)
}
}
bool UIImageView::onTouchBegan(const Point &touchPoint)
bool UIImageView::onTouchBegan(const cocos2d::Point &touchPoint)
{
setFocused(true);
_touchStartPos.x = touchPoint.x;
@ -149,7 +149,7 @@ bool UIImageView::onTouchBegan(const Point &touchPoint)
return _touchPassedEnabled;
}
void UIImageView::onTouchEnded(const Point &touchPoint)
void UIImageView::onTouchEnded(const cocos2d::Point &touchPoint)
{
if (_doubleClickEnabled)
{
@ -278,11 +278,11 @@ void UIImageView::setScale9Enabled(bool able)
_imageRenderer = NULL;
if (_scale9Enabled)
{
_imageRenderer = extension::Scale9Sprite::create();
_imageRenderer = cocos2d::extension::Scale9Sprite::create();
}
else
{
_imageRenderer = CCSprite::create();
_imageRenderer = cocos2d::Sprite::create();
}
loadTexture(_textureFile.c_str(),_imageTexType);
_renderer->addChild(_imageRenderer);
@ -308,7 +308,7 @@ void UIImageView::ignoreContentAdaptWithSize(bool ignore)
}
}
void UIImageView::setCapInsets(const Rect &capInsets)
void UIImageView::setCapInsets(const cocos2d::Rect &capInsets)
{
_capInsets = capInsets;
if (!_scale9Enabled)
@ -318,7 +318,7 @@ void UIImageView::setCapInsets(const Rect &capInsets)
DYNAMIC_CAST_SCALE9SPRITE->setCapInsets(capInsets);
}
void UIImageView::setAnchorPoint(const Point &pt)
void UIImageView::setAnchorPoint(const cocos2d::Point &pt)
{
UIWidget::setAnchorPoint(pt);
_imageRenderer->setAnchorPoint(pt);
@ -329,12 +329,12 @@ void UIImageView::onSizeChanged()
imageTextureScaleChangedWithSize();
}
const Size& UIImageView::getContentSize() const
const cocos2d::Size& UIImageView::getContentSize() const
{
return _imageTextureSize;
}
Node* UIImageView::getVirtualRenderer()
cocos2d::Node* UIImageView::getVirtualRenderer()
{
return _imageRenderer;
}
@ -353,11 +353,11 @@ void UIImageView::imageTextureScaleChangedWithSize()
{
if (_scale9Enabled)
{
dynamic_cast<Scale9Sprite*>(_imageRenderer)->setPreferredSize(_size);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_imageRenderer)->setPreferredSize(_size);
}
else
{
Size textureSize = _imageRenderer->getContentSize();
cocos2d::Size textureSize = _imageRenderer->getContentSize();
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
{
_imageRenderer->setScale(1.0f);
@ -376,4 +376,21 @@ const char* UIImageView::getDescription() const
return "ImageView";
}
UIWidget* UIImageView::createCloneInstance()
{
return UIImageView::create();
}
void UIImageView::copySpecialProperties(UIWidget *widget)
{
UIImageView* imageView = dynamic_cast<UIImageView*>(widget);
if (imageView)
{
_prevIgnoreSize = imageView->_prevIgnoreSize;
setScale9Enabled(imageView->_scale9Enabled);
loadTexture(imageView->_textureFile.c_str(), imageView->_imageTexType);
setCapInsets(imageView->_capInsets);
}
}
}

View File

@ -29,6 +29,10 @@
namespace gui {
/**
* @js NA
* @lua NA
*/
class UIImageView : public UIWidget
{
public:
@ -100,22 +104,22 @@ public:
//override "ignoreContentAdaptWithSize" method of widget.
virtual void ignoreContentAdaptWithSize(bool ignore);
/**
* Returns the "class name" of widget.
*/
virtual const char* getDescription() const;
void setDoubleClickEnabled(bool able);
void doubleClickEvent();
void checkDoubleClick(float dt);
virtual const cocos2d::Size& getContentSize() const;
virtual cocos2d::Node* getVirtualRenderer();
/**
* Returns the "class name" of widget.
*/
virtual const char* getDescription() const;
protected:
virtual void initRenderer();
virtual void onSizeChanged();
void imageTextureScaleChangedWithSize();
virtual UIWidget* createCloneInstance();
virtual void copySpecialProperties(UIWidget* model);
protected:
int _clickCount;
float _clickTimeInterval;

View File

@ -37,11 +37,11 @@ _longClickRecordTime(0.0),
_checkedDoubleClickWidget(NULL),
_rootWidget(NULL)
{
_manageredWidget = CCArray::create();
_manageredWidget = Array::create();
_manageredWidget->retain();
_checkedDoubleClickWidget = CCArray::create();
_checkedDoubleClickWidget = Array::create();
_checkedDoubleClickWidget->retain();
_selectedWidgets = CCArray::create();
_selectedWidgets = Array::create();
_selectedWidgets->retain();
}

View File

@ -26,7 +26,7 @@
#define __UIINPUTMANAGER_H__
#include "cocos2d.h"
#include "gui/Layout.h"
#include "gui/UILayout.h"
namespace gui {
@ -41,7 +41,7 @@ public:
/**
* Default destructor
*/
~UIInputManager();
virtual ~UIInputManager();
/**
* Regist a widget to input manager.

View File

@ -24,10 +24,9 @@
#include "gui/UILabel.h"
using namespace cocos2d;
namespace gui {
UILabel::UILabel():
_touchScaleChangeEnabled(false),
_normalScaleValue(1.0f),
@ -67,7 +66,7 @@ bool UILabel::init()
void UILabel::initRenderer()
{
UIWidget::initRenderer();
_labelRenderer = CCLabelTTF::create();
_labelRenderer = cocos2d::LabelTTF::create();
_renderer->addChild(_labelRenderer);
}
@ -95,29 +94,31 @@ int UILabel::getStringLength()
void UILabel::setFontSize(int size)
{
_fontSize = size;
_labelRenderer->setFontSize(size);
labelScaleChangedWithSize();
}
void UILabel::setFontName(const char* name)
{
_fontName = name;
_labelRenderer->setFontName(name);
labelScaleChangedWithSize();
}
void UILabel::setTextAreaSize(const Size &size)
void UILabel::setTextAreaSize(const cocos2d::Size &size)
{
_labelRenderer->setDimensions(size);
labelScaleChangedWithSize();
}
void UILabel::setTextHorizontalAlignment(TextHAlignment alignment)
void UILabel::setTextHorizontalAlignment(cocos2d::TextHAlignment alignment)
{
_labelRenderer->setHorizontalAlignment(alignment);
labelScaleChangedWithSize();
}
void UILabel::setTextVerticalAlignment(TextVAlignment alignment)
void UILabel::setTextVerticalAlignment(cocos2d::TextVAlignment alignment)
{
_labelRenderer->setVerticalAlignment(alignment);
labelScaleChangedWithSize();
@ -182,7 +183,7 @@ bool UILabel::isFlipY()
return _labelRenderer->isFlippedY();
}
void UILabel::setAnchorPoint(const Point &pt)
void UILabel::setAnchorPoint(const cocos2d::Point &pt)
{
UIWidget::setAnchorPoint(pt);
_labelRenderer->setAnchorPoint(pt);
@ -193,12 +194,12 @@ void UILabel::onSizeChanged()
labelScaleChangedWithSize();
}
const Size& UILabel::getContentSize() const
const cocos2d::Size& UILabel::getContentSize() const
{
return _labelRenderer->getContentSize();
}
Node* UILabel::getVirtualRenderer()
cocos2d::Node* UILabel::getVirtualRenderer()
{
return _labelRenderer;
}
@ -212,7 +213,7 @@ void UILabel::labelScaleChangedWithSize()
}
else
{
Size textureSize = _labelRenderer->getContentSize();
cocos2d::Size textureSize = _labelRenderer->getContentSize();
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
{
_labelRenderer->setScale(1.0f);
@ -223,6 +224,7 @@ void UILabel::labelScaleChangedWithSize()
_labelRenderer->setScaleX(scaleX);
_labelRenderer->setScaleY(scaleY);
}
}
const char* UILabel::getDescription() const
@ -230,4 +232,21 @@ const char* UILabel::getDescription() const
return "Label";
}
UIWidget* UILabel::createCloneInstance()
{
return UILabel::create();
}
void UILabel::copySpecialProperties(UIWidget *widget)
{
UILabel* label = dynamic_cast<UILabel*>(widget);
if (label)
{
setFontName(label->_fontName.c_str());
setFontSize(label->_labelRenderer->getFontSize());
setText(label->getStringValue());
setTouchScaleChangeEnabled(label->_touchScaleChangeEnabled);
}
}
}

View File

@ -27,8 +27,13 @@
#include "gui/UIWidget.h"
namespace gui {
/**
* @js NA
* @lua NA
*/
class UILabel : public UIWidget
{
public:
@ -124,11 +129,7 @@ public:
void setTextAreaSize(const cocos2d::Size &size);
void setTextHorizontalAlignment(cocos2d::TextHAlignment alignment);
void setTextVerticalAlignment(cocos2d::TextVAlignment alignment);
void setTouchScaleChangeAble(bool able){setTouchScaleChangeEnabled(able);};
bool getTouchScaleChangeAble(){return isTouchScaleChangeEnabled();};
void setTextVerticalAlignment(cocos2d::TextVAlignment alignment);
protected:
virtual bool init();
virtual void initRenderer();
@ -138,6 +139,8 @@ protected:
virtual void onSizeChanged();
void clickScale(float scale);
void labelScaleChangedWithSize();
virtual UIWidget* createCloneInstance();
virtual void copySpecialProperties(UIWidget* model);
protected:
bool _touchScaleChangeEnabled;
float _normalScaleValue;

View File

@ -24,10 +24,9 @@
#include "gui/UILabelAtlas.h"
using namespace cocos2d;
namespace gui {
UICCLabelAtlas::UICCLabelAtlas()
{
@ -56,7 +55,7 @@ void UICCLabelAtlas::setProperty(const char *string, const char *charMapFile, un
initWithString(string, charMapFile, itemWidth, itemHeight, startCharMap);
}
void UICCLabelAtlas::setProperty(const char *string, Texture2D *texture, unsigned int itemWidth, unsigned int itemHeight, unsigned int startCharMap)
void UICCLabelAtlas::setProperty(const char *string, cocos2d::Texture2D *texture, unsigned int itemWidth, unsigned int itemHeight, unsigned int startCharMap)
{
initWithString(string, texture, itemWidth, itemHeight, startCharMap);
}
@ -68,20 +67,26 @@ void UICCLabelAtlas::draw()
return;
}
CCAtlasNode::draw();
cocos2d::AtlasNode::draw();
}
void UICCLabelAtlas::updateDisplayedOpacity(GLubyte opacity)
{
CCAtlasNode::setOpacity(opacity);
cocos2d::AtlasNode::setOpacity(opacity);
}
UILabelAtlas::UILabelAtlas():
_laberAtlasRenderer(NULL)
_laberAtlasRenderer(NULL),
_stringValue(""),
_charMapFileName(""),
_itemWidth(0),
_itemHeight(0),
_startCharMap("")
{
}
UILabelAtlas::~UILabelAtlas()
@ -108,8 +113,13 @@ void UILabelAtlas::initRenderer()
_renderer->addChild(_laberAtlasRenderer);
}
void UILabelAtlas::setProperty(const char *stringValue, const char *charMapFile, int itemWidth, int itemHeight, const char *startCharMap,bool useSpriteFrame)
void UILabelAtlas::setProperty(const char *stringValue, const char *charMapFile, int itemWidth, int itemHeight, const char *startCharMap)
{
_stringValue = stringValue;
_charMapFileName = charMapFile;
_itemWidth = itemWidth;
_itemHeight = itemHeight;
_startCharMap = startCharMap;
_laberAtlasRenderer->setProperty(stringValue, charMapFile, itemWidth, itemHeight, (int)(startCharMap[0]));
updateAnchorPoint();
labelAtlasScaleChangedWithSize();
@ -117,6 +127,7 @@ void UILabelAtlas::setProperty(const char *stringValue, const char *charMapFile,
void UILabelAtlas::setStringValue(const char *value)
{
_stringValue = value;
_laberAtlasRenderer->setString(value);
labelAtlasScaleChangedWithSize();
}
@ -126,10 +137,10 @@ const char* UILabelAtlas::getStringValue()
return _laberAtlasRenderer->getString();
}
void UILabelAtlas::setAnchorPoint(const Point &pt)
void UILabelAtlas::setAnchorPoint(const cocos2d::Point &pt)
{
UIWidget::setAnchorPoint(pt);
_laberAtlasRenderer->setAnchorPoint(Point(pt.x, pt.y));
_laberAtlasRenderer->setAnchorPoint(cocos2d::Point(pt.x, pt.y));
}
void UILabelAtlas::onSizeChanged()
@ -137,12 +148,12 @@ void UILabelAtlas::onSizeChanged()
labelAtlasScaleChangedWithSize();
}
const Size& UILabelAtlas::getContentSize() const
const cocos2d::Size& UILabelAtlas::getContentSize() const
{
return _laberAtlasRenderer->getContentSize();
}
Node* UILabelAtlas::getVirtualRenderer()
cocos2d::Node* UILabelAtlas::getVirtualRenderer()
{
return _laberAtlasRenderer;
}
@ -156,7 +167,7 @@ void UILabelAtlas::labelAtlasScaleChangedWithSize()
}
else
{
Size textureSize = _laberAtlasRenderer->getContentSize();
cocos2d::Size textureSize = _laberAtlasRenderer->getContentSize();
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
{
_laberAtlasRenderer->setScale(1.0f);
@ -171,7 +182,21 @@ void UILabelAtlas::labelAtlasScaleChangedWithSize()
const char* UILabelAtlas::getDescription() const
{
return "LabelAtlase";
return "LabelAtlas";
}
UIWidget* UILabelAtlas::createCloneInstance()
{
return UILabelAtlas::create();
}
void UILabelAtlas::copySpecialProperties(UIWidget *widget)
{
UILabelAtlas* labelAtlas = dynamic_cast<UILabelAtlas*>(widget);
if (labelAtlas)
{
setProperty(labelAtlas->_stringValue.c_str(), labelAtlas->_charMapFileName.c_str(), labelAtlas->_itemWidth, labelAtlas->_itemHeight, labelAtlas->_startCharMap.c_str());
}
}
}

View File

@ -29,6 +29,10 @@
namespace gui {
/**
* @js NA
* @lua NA
*/
class UICCLabelAtlas : public cocos2d::LabelAtlas
{
public:
@ -51,7 +55,10 @@ public:
virtual void updateDisplayedOpacity(GLubyte opacity);
virtual void draw(void);
};
/**
* @js NA
* @lua NA
*/
class UILabelAtlas : public UIWidget
{
public:
@ -71,7 +78,7 @@ public:
static UILabelAtlas* create();
/** initializes the UILabelAtlas 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 char* stringValue,const char* charMapFile, int itemWidth, int itemHeight, const char* startCharMap,bool useSpriteFrame = false);
void setProperty(const char* stringValue,const char* charMapFile, int itemWidth, int itemHeight, const char* startCharMap);
//set string value for labelatlas.
void setStringValue(const char* value);
@ -92,12 +99,20 @@ public:
* Returns the "class name" of widget.
*/
virtual const char* getDescription() const;
protected:
virtual void initRenderer();
virtual void onSizeChanged();
void labelAtlasScaleChangedWithSize();
virtual UIWidget* createCloneInstance();
virtual void copySpecialProperties(UIWidget* model);
protected:
UICCLabelAtlas* _laberAtlasRenderer;
std::string _stringValue;
std::string _charMapFileName;
int _itemWidth;
int _itemHeight;
std::string _startCharMap;
};
}

View File

@ -24,13 +24,13 @@
#include "gui/UILabelBMFont.h"
using namespace cocos2d;
namespace gui {
UILabelBMFont::UILabelBMFont():
_labelBMFontRenderer(NULL),
_fntFileHasInit(false)
_fntFileHasInit(false),
_fntFileName(""),
_stringValue("")
{
}
@ -54,7 +54,7 @@ UILabelBMFont* UILabelBMFont::create()
void UILabelBMFont::initRenderer()
{
UIWidget::initRenderer();
_labelBMFontRenderer = CCLabelBMFont::create();
_labelBMFontRenderer = cocos2d::LabelBMFont::create();
_renderer->addChild(_labelBMFontRenderer);
}
@ -64,28 +64,35 @@ void UILabelBMFont::setFntFile(const char *fileName)
{
return;
}
_fntFileName = fileName;
_labelBMFontRenderer->initWithString("", fileName);
updateAnchorPoint();
labelBMFontScaleChangedWithSize();
_fntFileHasInit = true;
setText(_stringValue.c_str());
}
void UILabelBMFont::setText(const char* value)
{
if (!value || !_fntFileHasInit)
if (!value)
{
return;
}
_labelBMFontRenderer->setString(value);
_stringValue = value;
if (!_fntFileHasInit)
{
return;
}
_labelBMFontRenderer->setString(value);
labelBMFontScaleChangedWithSize();
}
const char* UILabelBMFont::getStringValue()
{
return _labelBMFontRenderer->getString();
return _stringValue.c_str();
}
void UILabelBMFont::setAnchorPoint(const Point &pt)
void UILabelBMFont::setAnchorPoint(const cocos2d::Point &pt)
{
UIWidget::setAnchorPoint(pt);
_labelBMFontRenderer->setAnchorPoint(pt);
@ -96,12 +103,12 @@ void UILabelBMFont::onSizeChanged()
labelBMFontScaleChangedWithSize();
}
const Size& UILabelBMFont::getContentSize() const
const cocos2d::Size& UILabelBMFont::getContentSize() const
{
return _labelBMFontRenderer->getContentSize();
}
Node* UILabelBMFont::getVirtualRenderer()
cocos2d::Node* UILabelBMFont::getVirtualRenderer()
{
return _labelBMFontRenderer;
}
@ -115,7 +122,7 @@ void UILabelBMFont::labelBMFontScaleChangedWithSize()
}
else
{
Size textureSize = _labelBMFontRenderer->getContentSize();
cocos2d::Size textureSize = _labelBMFontRenderer->getContentSize();
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
{
_labelBMFontRenderer->setScale(1.0f);
@ -133,5 +140,19 @@ const char* UILabelBMFont::getDescription() const
return "LabelBMFont";
}
UIWidget* UILabelBMFont::createCloneInstance()
{
return UILabelBMFont::create();
}
void UILabelBMFont::copySpecialProperties(UIWidget *widget)
{
UILabelBMFont* labelBMFont = dynamic_cast<UILabelBMFont*>(widget);
if (labelBMFont)
{
setFntFile(labelBMFont->_fntFileName.c_str());
setText(labelBMFont->_stringValue.c_str());
}
}
}

View File

@ -29,6 +29,10 @@
namespace gui {
/**
* @js NA
* @lua NA
*/
class UILabelBMFont : public UIWidget
{
public:
@ -58,7 +62,6 @@ public:
virtual void setAnchorPoint(const cocos2d::Point &pt);
virtual const cocos2d::Size& getContentSize() const;
virtual cocos2d::Node* getVirtualRenderer();
/**
* Returns the "class name" of widget.
*/
@ -67,9 +70,13 @@ protected:
virtual void initRenderer();
virtual void onSizeChanged();
void labelBMFontScaleChangedWithSize();
virtual UIWidget* createCloneInstance();
virtual void copySpecialProperties(UIWidget* model);
protected:
cocos2d::LabelBMFont* _labelBMFontRenderer;
bool _fntFileHasInit;
std::string _fntFileName;
std::string _stringValue;
};
}

View File

@ -119,7 +119,7 @@ UIWidget* UILayer::getWidgetByTag(int tag)
{
return NULL;
}
return CCUIHELPER->seekWidgetByTag(_rootWidget, tag);
return UIHelper::seekWidgetByTag(_rootWidget, tag);
}
UIWidget* UILayer::getWidgetByName(const char* name)
@ -128,7 +128,7 @@ UIWidget* UILayer::getWidgetByName(const char* name)
{
return NULL;
}
return CCUIHELPER->seekWidgetByName(_rootWidget, name);
return UIHelper::seekWidgetByName(_rootWidget, name);
}
UIRootWidget* UILayer::getRootWidget()

1010
cocos/gui/UILayout.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -44,23 +44,28 @@ typedef enum
LAYOUT_RELATIVE
}LayoutType;
class Layout : public UIWidget
/**
* @js NA
* @lua NA
*/
class UILayout : public UIWidget
{
public:
/**
* Default constructor
*/
Layout();
UILayout();
/**
* Default destructor
*/
virtual ~Layout();
virtual ~UILayout();
/**
* Allocates and initializes a layout.
*/
static Layout* create();
static UILayout* create();
//override "hitTest" method of widget.
virtual bool hitTest(const cocos2d::Point &pt);
@ -168,6 +173,11 @@ public:
*/
virtual const cocos2d::Size& getContentSize() const;
/**
* Returns the "class name" of widget.
*/
virtual const char* getDescription() const;
/**
* Sets LayoutType.
*
@ -187,11 +197,14 @@ public:
virtual LayoutType getLayoutType() const;
virtual void doLayout();
/**
* Returns the "class name" of widget.
* Adds a child to the container.
*
* @param child A child widget
*/
virtual const char* getDescription() const;
virtual bool addChild(UIWidget* child);
protected:
//override "init" method of widget.
virtual bool init();
@ -204,6 +217,11 @@ protected:
//init background image renderer.
void addBackGroundImage();
void supplyTheLayoutParameterLackToChild(UIWidget* child);
virtual UIWidget* createCloneInstance();
virtual void copySpecialProperties(UIWidget* model);
virtual void copyClonedWidgetChildren(UIWidget* model);
protected:
bool _clippingEnabled;
@ -224,23 +242,26 @@ protected:
cocos2d::Size _backGroundImageTextureSize;
LayoutType _layoutType;
};
class RectClippingNode : public cocos2d::ClippingNode
/**
* @js NA
* @lua NA
*/
class UIRectClippingNode : public cocos2d::ClippingNode
{
public:
virtual ~RectClippingNode();
virtual ~UIRectClippingNode();
virtual bool init();
static RectClippingNode* create();
static UIRectClippingNode* create();
void setClippingSize(const cocos2d::Size& size);
void setClippingEnabled(bool enabled);
virtual void visit();
void setEnabled(bool enabled);
bool isEnabled() const;
protected:
cocos2d::DrawNode* m_pInnerStencil;
cocos2d::DrawNode* _innerStencil;
bool _enabled;
private:
RectClippingNode();
UIRectClippingNode();
cocos2d::Point rect[4];
cocos2d::Size _clippingSize;
bool _clippingEnabled;

View File

@ -21,7 +21,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "gui/UILayoutDefine.h"
#include "UILayoutDefine.h"
namespace gui {

View File

@ -26,9 +26,13 @@
#define __UILAYOUTDEFINE_H__
#include "cocos2d.h"
#include "ExtensionMacros.h"
namespace gui {
/**
* @js NA
* @lua NA
*/
class UIMargin
{
public:
@ -46,6 +50,7 @@ public:
bool equals(const UIMargin& target) const;
};
const UIMargin UIMarginZero = UIMargin();
typedef enum
{
@ -61,22 +66,25 @@ typedef enum
typedef enum
{
RELATIVE_ALIGN_NONE,
RELATIVE_ALIGN_PARENT_LEFT,
RELATIVE_ALIGN_PARENT_TOP,
RELATIVE_ALIGN_PARENT_RIGHT,
RELATIVE_ALIGN_PARENT_BOTTOM,
RELATIVE_ALIGN_PARENT_TOP_LEFT,
RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL,
RELATIVE_ALIGN_PARENT_TOP_RIGHT,
RELATIVE_ALIGN_PARENT_LEFT_CENTER_VERTICAL,
RELATIVE_CENTER_IN_PARENT,
RELATIVE_CENTER_HORIZONTAL,
RELATIVE_CENTER_VERTICAL,
RELATIVE_ALIGN_PARENT_RIGHT_CENTER_VERTICAL,
RELATIVE_ALIGN_PARENT_LEFT_BOTTOM,
RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL,
RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM,
RELATIVE_LOCATION_ABOVE_LEFTALIGN,
RELATIVE_LOCATION_ABOVE_CENTER,
RELATIVE_LOCATION_ABOVE_RIGHTALIGN,
RELATIVE_LOCATION_LEFT_OF_TOPALIGN,
RELATIVE_LOCATION_LEFT_OF_CENTER,
RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN,
RELATIVE_LOCATION_RIGHT_OF_TOPALIGN,
RELATIVE_LOCATION_RIGHT_OF_CENTER,
RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN,
RELATIVE_LOCATION_ABOVE_LEFTALIGN,
RELATIVE_LOCATION_ABOVE_CENTER,
RELATIVE_LOCATION_ABOVE_RIGHTALIGN,
RELATIVE_LOCATION_BELOW_LEFTALIGN,
RELATIVE_LOCATION_BELOW_CENTER,
RELATIVE_LOCATION_BELOW_RIGHTALIGN

View File

@ -22,14 +22,15 @@
THE SOFTWARE.
****************************************************************************/
#include "gui/LayoutParameter.h"
#include "gui/Layout.h"
#include "gui/UILayoutParameter.h"
#include "gui/UILayout.h"
namespace gui {
LayoutParameter* LayoutParameter::create()
UILayoutParameter* UILayoutParameter::create()
{
LayoutParameter* parameter = new LayoutParameter();
UILayoutParameter* parameter = new UILayoutParameter();
if (parameter)
{
parameter->autorelease();
@ -39,24 +40,24 @@ LayoutParameter* LayoutParameter::create()
return NULL;
}
void LayoutParameter::setMargin(const UIMargin &margin)
void UILayoutParameter::setMargin(const UIMargin &margin)
{
_margin = margin;
}
const UIMargin& LayoutParameter::getMargin() const
const UIMargin& UILayoutParameter::getMargin() const
{
return _margin;
}
LayoutParameterType LayoutParameter::getLayoutType() const
LayoutParameterType UILayoutParameter::getLayoutType() const
{
return _layoutParameterType;
}
LinearLayoutParameter* LinearLayoutParameter::create()
UILinearLayoutParameter* UILinearLayoutParameter::create()
{
LinearLayoutParameter* parameter = new LinearLayoutParameter();
UILinearLayoutParameter* parameter = new UILinearLayoutParameter();
if (parameter)
{
parameter->autorelease();
@ -66,19 +67,19 @@ LinearLayoutParameter* LinearLayoutParameter::create()
return NULL;
}
void LinearLayoutParameter::setGravity(UILinearGravity gravity)
void UILinearLayoutParameter::setGravity(UILinearGravity gravity)
{
_linearGravity = gravity;
}
UILinearGravity LinearLayoutParameter::getGravity() const
UILinearGravity UILinearLayoutParameter::getGravity() const
{
return _linearGravity;
}
RelativeLayoutParameter* RelativeLayoutParameter::create()
UIRelativeLayoutParameter* UIRelativeLayoutParameter::create()
{
RelativeLayoutParameter* parameter = new RelativeLayoutParameter();
UIRelativeLayoutParameter* parameter = new UIRelativeLayoutParameter();
if (parameter)
{
parameter->autorelease();
@ -88,32 +89,32 @@ RelativeLayoutParameter* RelativeLayoutParameter::create()
return NULL;
}
void RelativeLayoutParameter::setAlign(UIRelativeAlign align)
void UIRelativeLayoutParameter::setAlign(UIRelativeAlign align)
{
_relativeAlign = align;
}
UIRelativeAlign RelativeLayoutParameter::getAlign() const
UIRelativeAlign UIRelativeLayoutParameter::getAlign() const
{
return _relativeAlign;
}
void RelativeLayoutParameter::setRelativeToWidgetName(const char *name)
void UIRelativeLayoutParameter::setRelativeToWidgetName(const char *name)
{
_relativeWidgetName = name;
}
const char* RelativeLayoutParameter::getRelativeToWidgetName() const
const char* UIRelativeLayoutParameter::getRelativeToWidgetName() const
{
return _relativeWidgetName.c_str();
}
void RelativeLayoutParameter::setRelativeName(const char* name)
void UIRelativeLayoutParameter::setRelativeName(const char* name)
{
_relativeLayoutName = name;
}
const char* RelativeLayoutParameter::getRelativeName() const
const char* UIRelativeLayoutParameter::getRelativeName() const
{
return _relativeLayoutName.c_str();
}

View File

@ -35,25 +35,28 @@ typedef enum
LAYOUT_PARAMETER_LINEAR,
LAYOUT_PARAMETER_RELATIVE
}LayoutParameterType;
class LayoutParameter : public cocos2d::Object
/**
* @js NA
* @lua NA
*/
class UILayoutParameter : public cocos2d::Object
{
public:
/**
* Default constructor
*/
LayoutParameter() : _margin(UIMargin()){_layoutParameterType = LAYOUT_PARAMETER_NONE;};
UILayoutParameter() : _margin(UIMargin()){_layoutParameterType = LAYOUT_PARAMETER_NONE;};
/**
* Default destructor
*/
virtual ~LayoutParameter(){};
virtual ~UILayoutParameter(){};
/**
* Allocates and initializes.
* @return A initialized LayoutParameter which is marked as "autorelease".
*/
static LayoutParameter* create();
static UILayoutParameter* create();
/**
* Sets Margin parameter for LayoutParameter.
@ -85,25 +88,28 @@ protected:
UIMargin _margin;
LayoutParameterType _layoutParameterType;
};
class LinearLayoutParameter : public LayoutParameter
/**
* @js NA
* @lua NA
*/
class UILinearLayoutParameter : public UILayoutParameter
{
public:
/**
* Default constructor
*/
LinearLayoutParameter() : _linearGravity(LINEAR_GRAVITY_NONE){_layoutParameterType = LAYOUT_PARAMETER_LINEAR;};
UILinearLayoutParameter() : _linearGravity(LINEAR_GRAVITY_NONE){_layoutParameterType = LAYOUT_PARAMETER_LINEAR;};
/**
* Default destructor
*/
virtual ~LinearLayoutParameter(){};
virtual ~UILinearLayoutParameter(){};
/**
* Allocates and initializes.
* @return A initialized LayoutParameter which is marked as "autorelease".
*/
static LinearLayoutParameter* create();
static UILinearLayoutParameter* create();
/**
* Sets UILinearGravity parameter for LayoutParameter.
@ -125,25 +131,31 @@ public:
protected:
UILinearGravity _linearGravity;
};
/**
* @js NA
* @lua NA
*/
class RelativeLayoutParameter : public LayoutParameter
class UILayout;
class UIRelativeLayoutParameter : public UILayoutParameter
{
public:
/**
* Default constructor
*/
RelativeLayoutParameter() : _relativeAlign(RELATIVE_ALIGN_NONE),_relativeWidgetName(""),_relativeLayoutName(""){_layoutParameterType = LAYOUT_PARAMETER_RELATIVE;};
UIRelativeLayoutParameter() : _relativeAlign(RELATIVE_ALIGN_NONE),_relativeWidgetName(""),_relativeLayoutName(""),_put(false){_layoutParameterType = LAYOUT_PARAMETER_RELATIVE;};
/**
* Default destructor
*/
virtual ~RelativeLayoutParameter(){};
virtual ~UIRelativeLayoutParameter(){};
/**
* Allocates and initializes.
* @return A initialized LayoutParameter which is marked as "autorelease".
*/
static RelativeLayoutParameter* create();
static UIRelativeLayoutParameter* create();
/**
* Sets UIRelativeAlign parameter for LayoutParameter.
@ -194,6 +206,8 @@ protected:
UIRelativeAlign _relativeAlign;
std::string _relativeWidgetName;
std::string _relativeLayoutName;
bool _put;
friend class UILayout;
};
}

File diff suppressed because it is too large Load Diff

View File

@ -22,226 +22,156 @@
THE SOFTWARE.
****************************************************************************/
#ifndef __UILISTVIEW_H__
#define __UILISTVIEW_H__
/* gui mark */
#include "gui/Layout.h"
/**/
#include "gui/UIScrollView.h"
namespace gui {
/**
* list view direction
*/
typedef enum LISTVIEW_DIR
{
LISTVIEW_DIR_NONE,
LISTVIEW_DIR_VERTICAL,
LISTVIEW_DIR_HORIZONTAL
}ListViewDirection;
/**
* list view scroll direction
*/
typedef enum LISTVIEW_MOVE_DIR
{
LISTVIEW_MOVE_DIR_NONE,
LISTVIEW_MOVE_DIR_UP,
LISTVIEW_MOVE_DIR_DOWN,
LISTVIEW_MOVE_DIR_LEFT,
LISTVIEW_MOVE_DIR_RIGHT,
}ListViewMoveDirection;
namespace gui{
typedef enum
{
LISTVIEW_EVENT_INIT_CHILD,
LISTVIEW_EVENT_UPDATE_CHILD,
}ListViewEventType;
LISTVIEW_GRAVITY_LEFT,
LISTVIEW_GRAVITY_RIGHT,
LISTVIEW_GRAVITY_CENTER_HORIZONTAL,
LISTVIEW_GRAVITY_TOP,
LISTVIEW_GRAVITY_BOTTOM,
LISTVIEW_GRAVITY_CENTER_VERTICAL,
}ListViewGravity;
/**
* list view event
*/
typedef void (cocos2d::Object::*SEL_ListViewEvent)(cocos2d::Object*, ListViewEventType);
#define listvieweventselector(_SELECTOR)(SEL_ListViewEvent)(&_SELECTOR)
class UIListView : public Layout
class UIListView : public UIScrollView
{
public:
/**
* Default constructor
*/
UIListView();
/**
* Default destructor
*/
virtual ~UIListView();
/**
* Allocates and initializes.
*/
static UIListView* create();
/**
* add widget child override
* Sets a item model for listview
*
* A model will be cloned for adding default item.
*
* @param model item model for listview
*/
virtual bool addChild(UIWidget* widget);
/**
* remove all widget children override
*/
virtual void removeAllChildren();
/**
* remove widget child override
*/
virtual bool removeChild(UIWidget* child);
virtual bool onTouchBegan(const cocos2d::Point &touchPoint);
virtual void onTouchMoved(const cocos2d::Point &touchPoint);
virtual void onTouchEnded(const cocos2d::Point &touchPoint);
virtual void onTouchCancelled(const cocos2d::Point &touchPoint);
virtual void onTouchLongClicked(const cocos2d::Point &touchPoint);
void setItemModel(UIWidget* model);
/**
* set and get direction
* Push back a default item(create by a cloned model) into listview.
*/
void setDirection(ListViewDirection dir);
ListViewDirection getDirection();
void pushBackDefaultItem();
/**
* initialze data length
* and create children with parameter length
* Insert a default item(create by a cloned model) into listview.
*/
void initChildWithDataLength(int length);
/**
* get data length
*/
int getDataLength();
void insertDefaultItem(int index);
/**
* update child function whetn trigger update child event
* Push back custom item into listview.
*/
/**
* get update widget child
*/
UIWidget* getUpdateChild();
/**
* get update data index
*/
int getUpdateDataIndex();
/**
* get and set update success or not
*/
bool getUpdateSuccess();
void setUpdateSuccess(bool sucess);
void pushBackCustomItem(UIWidget* item);
/**
* add event call-back function
* Insert custom item into listview.
*/
/**
* add event
*/
void addEventListenter(cocos2d::Object* target, SEL_ListViewEvent selector);
/* gui mark */
/**
* get and set degree range for checking move or not with scrolling
*/
/**/
virtual void update(float dt);
virtual void doLayout(){};
void insertCustomItem(UIWidget* item, int index);
/**
* Returns the "class name" of widget.
* Removes the last item of listview.
*/
void removeLastItem();
/**
* Removes a item whose index is same as the parameter.
*
* @param index of item.
*/
void removeItem(int index);
/**
* Returns a item whose index is same as the parameter.
*
* @param index of item.
*
* @return the item widget.
*/
UIWidget* getItem(unsigned int index);
/**
* Returns the item container.
*/
cocos2d::Array* getItems();
/**
* Returns the index of item.
*
* @param item the item which need to be checked.
*
* @return the index of item.
*/
unsigned int getIndex(UIWidget* item) const;
/**
* Changes the gravity of listview.
* @see ListViewGravity
*/
void setGravity(ListViewGravity gravity);
/**
* Changes the margin between each item.
*
* @param margin
*/
void setItemsMargin(float margin);
/**
* Refresh the view of list.
*
* If you change the data, you need to call this mathod.
*/
void refreshView();
/**
* Changes scroll direction of scrollview.
*
* @see SCROLLVIEW_DIR SCROLLVIEW_DIR_VERTICAL means vertical scroll, SCROLLVIEW_DIR_HORIZONTAL means horizontal scroll
*
* @param SCROLLVIEW_DIR
*/
virtual void setDirection(SCROLLVIEW_DIR dir);
virtual const char* getDescription() const;
protected:
virtual bool init();
void updateInnerContainerSize();
void remedyLayoutParameter(UIWidget* item);
virtual void onSizeChanged();
void setMoveDirection(ListViewMoveDirection dir);
ListViewMoveDirection getMoveDirection();
virtual void resetProperty();
virtual void handlePressLogic(const cocos2d::Point &touchPoint);
virtual void handleMoveLogic(const cocos2d::Point &touchPoint);
virtual void handleReleaseLogic(const cocos2d::Point &touchPoint);
virtual void interceptTouchEvent(int handleState,UIWidget* sender,const cocos2d::Point &touchPoint);
/* gui mark */
// virtual bool isInScrollDegreeRange(UIWidget* widget);
/**/
virtual void checkChildInfo(int handleState,UIWidget* sender,const cocos2d::Point &touchPoint);
void moveChildren(float offset);
virtual bool scrollChildren(float touchOffset);
void autoScrollChildren(float dt);
float getCurAutoScrollDistance(float time);
void startAutoScrollChildren(float v);
void stopAutoScrollChildren();
void recordSlidTime(float dt);
void startRecordSlidAction();
virtual void endRecordSlidAction();
UIWidget* getCheckPositionChild();
UIWidget* getChildFromUpdatePool();
void pushChildToPool();
void getAndCallback();
void setUpdateChild(UIWidget* child);
void setUpdateDataIndex(int index);
void clearCollectOverArray();
void collectOverTopChild();
void collectOverBottomChild();
void collectOverLeftChild();
void collectOverRightChild();
void setLoopPosition();
void updateChild();
void initChildEvent();
void updateChildEvent();
virtual void setClippingEnabled(bool able){Layout::setClippingEnabled(able);};
virtual UIWidget* createCloneInstance();
virtual void copySpecialProperties(UIWidget* model);
virtual void copyClonedWidgetChildren(UIWidget* model);
protected:
ListViewDirection _direction;
ListViewMoveDirection _moveDirection;
float _touchStartLocation;
float _touchEndLocation;
float _touchMoveStartLocation;
float _topBoundary;//test
float _bottomBoundary;//test
float _leftBoundary;
float _rightBoundary;
bool _autoScroll;
float _autoScrollOriginalSpeed;
float _autoScrollAcceleration;
bool _bePressed;
float _slidTime;
cocos2d::Point _moveChildPoint;
float _childFocusCancelOffset;
cocos2d::Object* _eventListener;
SEL_ListViewEvent _eventSelector;
cocos2d::Array* _childPool;
cocos2d::Array* _updatePool;
int _dataLength;
int _begin;
int _end;
UIWidget* _updateChild;
int _updateDataIndex;
bool _updateSuccess;
cocos2d::Array* _overTopArray;
cocos2d::Array* _overBottomArray;
cocos2d::Array* _overLeftArray;
cocos2d::Array* _overRightArray;
float _disBoundaryToChild_0;
float _disBetweenChild;
/* gui mark */
float _scrollDegreeRange;
/**/
UIWidget* _model;
cocos2d::Array* _items;
ListViewGravity _gravity;
float _itemsMargin;
};
}
#endif /* defined(__Test__UIListView__) */
#endif /* defined(__UIListView__) */

View File

@ -25,11 +25,9 @@
#include "gui/UILoadingBar.h"
#include "extensions/GUI/CCControlExtension/CCScale9Sprite.h"
using namespace cocos2d;
using namespace cocos2d::extension;
namespace gui {
#define DYNAMIC_CAST_CCSPRITE dynamic_cast<cocos2d::Sprite*>(_barRenderer)
UILoadingBar::UILoadingBar():
@ -38,10 +36,10 @@ _percent(100),
_totalLength(0),
_barRenderer(NULL),
_renderBarTexType(UI_TEX_TYPE_LOCAL),
_barRendererTextureSize(Size::ZERO),
_barRendererTextureSize(cocos2d::Size::ZERO),
_scale9Enabled(false),
_prevIgnoreSize(true),
_capInsets(Rect::ZERO),
_capInsets(cocos2d::Rect::ZERO),
_textureFile("")
{
}
@ -66,9 +64,9 @@ UILoadingBar* UILoadingBar::create()
void UILoadingBar::initRenderer()
{
UIWidget::initRenderer();
_barRenderer = CCSprite::create();
_barRenderer = cocos2d::Sprite::create();
_renderer->addChild(_barRenderer);
_barRenderer->setAnchorPoint(Point(0.0f,0.5f));
_barRenderer->setAnchorPoint(cocos2d::Point(0.0,0.5));
}
void UILoadingBar::setDirection(LoadingBarType dir)
@ -82,19 +80,19 @@ void UILoadingBar::setDirection(LoadingBarType dir)
switch (_barType)
{
case LoadingBarTypeLeft:
_barRenderer->setAnchorPoint(Point(0.0f,0.5f));
_barRenderer->setPosition(Point(-_totalLength*0.5f,0.0f));
_barRenderer->setAnchorPoint(cocos2d::Point(0.0f,0.5f));
_barRenderer->setPosition(cocos2d::Point(-_totalLength*0.5f,0.0f));
if (!_scale9Enabled)
{
dynamic_cast<Sprite*>(_barRenderer)->setFlippedX(false);
dynamic_cast<cocos2d::Sprite*>(_barRenderer)->setFlippedX(false);
}
break;
case LoadingBarTypeRight:
_barRenderer->setAnchorPoint(Point(1.0f,0.5f));
_barRenderer->setPosition(Point(_totalLength*0.5f,0.0f));
_barRenderer->setAnchorPoint(cocos2d::Point(1.0f,0.5f));
_barRenderer->setPosition(cocos2d::Point(_totalLength*0.5f,0.0f));
if (!_scale9Enabled)
{
dynamic_cast<Sprite*>(_barRenderer)->setFlippedX(true);
dynamic_cast<cocos2d::Sprite*>(_barRenderer)->setFlippedX(true);
}
break;
}
@ -118,21 +116,23 @@ void UILoadingBar::loadTexture(const char* texture,TextureResType texType)
case UI_TEX_TYPE_LOCAL:
if (_scale9Enabled)
{
dynamic_cast<Scale9Sprite*>(_barRenderer)->initWithFile(texture);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_barRenderer)->initWithFile(texture);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_barRenderer)->setCapInsets(_capInsets);
}
else
{
dynamic_cast<Sprite*>(_barRenderer)->initWithFile(texture);
dynamic_cast<cocos2d::Sprite*>(_barRenderer)->initWithFile(texture);
}
break;
case UI_TEX_TYPE_PLIST:
if (_scale9Enabled)
{
dynamic_cast<Scale9Sprite*>(_barRenderer)->initWithSpriteFrameName(texture);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_barRenderer)->initWithSpriteFrameName(texture);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_barRenderer)->setCapInsets(_capInsets);
}
else
{
dynamic_cast<Sprite*>(_barRenderer)->initWithSpriteFrameName(texture);
dynamic_cast<cocos2d::Sprite*>(_barRenderer)->initWithSpriteFrameName(texture);
}
break;
default:
@ -140,31 +140,31 @@ void UILoadingBar::loadTexture(const char* texture,TextureResType texType)
}
if (_scale9Enabled)
{
dynamic_cast<Scale9Sprite*>(_barRenderer)->setColor(getColor());
dynamic_cast<Scale9Sprite*>(_barRenderer)->setOpacity(getOpacity());
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_barRenderer)->setColor(getColor());
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_barRenderer)->setOpacity(getOpacity());
}
else
{
dynamic_cast<Sprite*>(_barRenderer)->setColor(getColor());
dynamic_cast<Sprite*>(_barRenderer)->setOpacity(getOpacity());
dynamic_cast<cocos2d::Sprite*>(_barRenderer)->setColor(getColor());
dynamic_cast<cocos2d::Sprite*>(_barRenderer)->setOpacity(getOpacity());
}
_barRendererTextureSize.width = _barRenderer->getContentSize().width;
_barRendererTextureSize.height = _barRenderer->getContentSize().height;
_barRendererTextureSize = _barRenderer->getContentSize();
switch (_barType)
{
case LoadingBarTypeLeft:
_barRenderer->setAnchorPoint(Point(0.0f,0.5f));
_barRenderer->setAnchorPoint(cocos2d::Point(0.0f,0.5f));
if (!_scale9Enabled)
{
dynamic_cast<Sprite*>(_barRenderer)->setFlippedX(false);
dynamic_cast<cocos2d::Sprite*>(_barRenderer)->setFlippedX(false);
}
break;
case LoadingBarTypeRight:
_barRenderer->setAnchorPoint(Point(1.0f,0.5f));
_barRenderer->setAnchorPoint(cocos2d::Point(1.0f,0.5f));
if (!_scale9Enabled)
{
dynamic_cast<Sprite*>(_barRenderer)->setFlippedX(true);
dynamic_cast<cocos2d::Sprite*>(_barRenderer)->setFlippedX(true);
}
break;
}
@ -182,11 +182,11 @@ void UILoadingBar::setScale9Enabled(bool enabled)
_barRenderer = NULL;
if (_scale9Enabled)
{
_barRenderer = Scale9Sprite::create();
_barRenderer = cocos2d::extension::Scale9Sprite::create();
}
else
{
_barRenderer = CCSprite::create();
_barRenderer = cocos2d::Sprite::create();
}
loadTexture(_textureFile.c_str(),_renderBarTexType);
_renderer->addChild(_barRenderer);
@ -203,14 +203,14 @@ void UILoadingBar::setScale9Enabled(bool enabled)
setCapInsets(_capInsets);
}
void UILoadingBar::setCapInsets(const Rect &capInsets)
void UILoadingBar::setCapInsets(const cocos2d::Rect &capInsets)
{
_capInsets = capInsets;
if (!_scale9Enabled)
{
return;
}
dynamic_cast<Scale9Sprite*>(_barRenderer)->setCapInsets(capInsets);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_barRenderer)->setCapInsets(capInsets);
}
void UILoadingBar::setPercent(int percent)
@ -231,10 +231,10 @@ void UILoadingBar::setPercent(int percent)
{
case UI_TEX_TYPE_PLIST:
{
Sprite* barNode = DYNAMIC_CAST_CCSPRITE;
cocos2d::Sprite* barNode = DYNAMIC_CAST_CCSPRITE;
if (barNode)
{
Point to = barNode->getTextureRect().origin;
cocos2d::Point to = barNode->getTextureRect().origin;
x = to.x;
y = to.y;
}
@ -249,7 +249,7 @@ void UILoadingBar::setPercent(int percent)
}
else
{
dynamic_cast<Sprite*>(_barRenderer)->setTextureRect(Rect(x, y, _barRendererTextureSize.width * res, _barRendererTextureSize.height));
dynamic_cast<cocos2d::Sprite*>(_barRenderer)->setTextureRect(cocos2d::Rect(x, y, _barRendererTextureSize.width * res, _barRendererTextureSize.height));
}
}
@ -272,12 +272,12 @@ void UILoadingBar::ignoreContentAdaptWithSize(bool ignore)
}
}
const Size& UILoadingBar::getContentSize() const
const cocos2d::Size& UILoadingBar::getContentSize() const
{
return _barRendererTextureSize;
}
Node* UILoadingBar::getVirtualRenderer()
cocos2d::Node* UILoadingBar::getVirtualRenderer()
{
return _barRenderer;
}
@ -303,7 +303,7 @@ void UILoadingBar::barRendererScaleChangedWithSize()
else
{
Size textureSize = _barRenderer->getContentSize();
cocos2d::Size textureSize = _barRendererTextureSize;
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
{
_barRenderer->setScale(1.0f);
@ -318,10 +318,10 @@ void UILoadingBar::barRendererScaleChangedWithSize()
switch (_barType)
{
case LoadingBarTypeLeft:
_barRenderer->setPosition(Point(-_totalLength * 0.5f, 0.0f));
_barRenderer->setPosition(cocos2d::Point(-_totalLength * 0.5f, 0.0f));
break;
case LoadingBarTypeRight:
_barRenderer->setPosition(Point(_totalLength * 0.5f, 0.0f));
_barRenderer->setPosition(cocos2d::Point(_totalLength * 0.5f, 0.0f));
break;
default:
break;
@ -331,7 +331,7 @@ void UILoadingBar::barRendererScaleChangedWithSize()
void UILoadingBar::setScale9Scale()
{
float width = (float)(_percent) / 100 * _totalLength;
dynamic_cast<Scale9Sprite*>(_barRenderer)->setPreferredSize(Size(width, _barRendererTextureSize.height));
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_barRenderer)->setPreferredSize(cocos2d::Size(width, _size.height));
}
const char* UILoadingBar::getDescription() const
@ -339,4 +339,22 @@ const char* UILoadingBar::getDescription() const
return "LoadingBar";
}
UIWidget* UILoadingBar::createCloneInstance()
{
return UILoadingBar::create();
}
void UILoadingBar::copySpecialProperties(UIWidget *widget)
{
UILoadingBar* loadingBar = dynamic_cast<UILoadingBar*>(widget);
if (loadingBar)
{
_prevIgnoreSize = loadingBar->_prevIgnoreSize;
setScale9Enabled(loadingBar->_scale9Enabled);
loadTexture(loadingBar->_textureFile.c_str(), loadingBar->_renderBarTexType);
setCapInsets(loadingBar->_capInsets);
setPercent(loadingBar->_percent);
}
}
}

View File

@ -34,7 +34,10 @@ typedef enum
LoadingBarTypeLeft,
LoadingBarTypeRight
}LoadingBarType;
/**
* @js NA
* @lua NA
*/
class UILoadingBar : public UIWidget
{
public:
@ -126,6 +129,8 @@ protected:
virtual void onSizeChanged();
void setScale9Scale();
void barRendererScaleChangedWithSize();
virtual UIWidget* createCloneInstance();
virtual void copySpecialProperties(UIWidget* model);
protected:
LoadingBarType _barType;
int _percent;

View File

@ -24,8 +24,6 @@
#include "gui/UIPageView.h"
using namespace cocos2d;
namespace gui {
UIPageView::UIPageView():
@ -33,9 +31,8 @@ _curPageIdx(0),
_pages(NULL),
_touchMoveDir(PAGEVIEW_TOUCHLEFT),
_touchStartLocation(0.0f),
_touchEndLocation(0.0f),
_touchMoveStartLocation(0.0f),
_movePagePoint(Point::ZERO),
_movePagePoint(cocos2d::Point::ZERO),
_leftChild(NULL),
_rightChild(NULL),
_leftBoundary(0.0f),
@ -52,7 +49,8 @@ _eventSelector(NULL)
UIPageView::~UIPageView()
{
_pages->release();
_pages->removeAllObjects();
CC_SAFE_RELEASE(_pages);
}
UIPageView* UIPageView::create()
@ -69,12 +67,13 @@ UIPageView* UIPageView::create()
bool UIPageView::init()
{
if (Layout::init())
if (UILayout::init())
{
_pages = CCArray::create();
_pages = cocos2d::Array::create();
_pages->retain();
setClippingEnabled(true);
setUpdateEnabled(true);
setTouchEnabled(true);
return true;
}
return false;
@ -86,6 +85,10 @@ void UIPageView::addWidgetToPage(UIWidget *widget, int pageIdx, bool forceCreate
{
return;
}
if (pageIdx < 0)
{
return;
}
int pageCount = _pages->count();
if (pageIdx < 0 || pageIdx >= pageCount)
{
@ -95,30 +98,29 @@ void UIPageView::addWidgetToPage(UIWidget *widget, int pageIdx, bool forceCreate
{
CCLOG("pageIdx is %d, it will be added as page id [%d]",pageIdx,pageCount);
}
Layout* newPage = createPage();
UILayout* newPage = createPage();
newPage->addChild(widget);
addPage(newPage);
}
}
else
{
Layout * page = dynamic_cast<Layout*>(_pages->getObjectAtIndex(pageIdx));
UILayout * page = dynamic_cast<UILayout*>(_pages->getObjectAtIndex(pageIdx));
if (page)
{
page->addChild(widget);
}
}
}
Layout* UIPageView::createPage()
UILayout* UIPageView::createPage()
{
Layout* newPage = Layout::create();
UILayout* newPage = UILayout::create();
newPage->setSize(getSize());
return newPage;
}
void UIPageView::addPage(Layout* page)
void UIPageView::addPage(UILayout* page)
{
if (!page)
{
@ -132,20 +134,20 @@ void UIPageView::addPage(Layout* page)
{
return;
}
Size pSize = page->getSize();
Size pvSize = getSize();
cocos2d::Size pSize = page->getSize();
cocos2d::Size pvSize = getSize();
if (!pSize.equals(pvSize))
{
CCLOG("page size does not match pageview size, it will be force sized!");
page->setSize(pvSize);
}
page->setPosition(Point(getPositionXByIndex(_pages->count()), 0));
page->setPosition(cocos2d::Point(getPositionXByIndex(_pages->count()), 0));
_pages->addObject(page);
addChild(page);
updateBoundaryPages();
}
void UIPageView::insertPage(Layout* page, int idx)
void UIPageView::insertPage(UILayout* page, int idx)
{
if (idx < 0)
{
@ -172,27 +174,27 @@ void UIPageView::insertPage(Layout* page, int idx)
else
{
_pages->insertObject(page, idx);
page->setPosition(Point(getPositionXByIndex(idx), 0));
page->setPosition(cocos2d::Point(getPositionXByIndex(idx), 0));
addChild(page);
Size pSize = page->getSize();
Size pvSize = getSize();
cocos2d::Size pSize = page->getSize();
cocos2d::Size pvSize = getSize();
if (!pSize.equals(pvSize))
{
CCLOG("page size does not match pageview size, it will be force sized!");
page->setSize(pvSize);
}
ccArray* arrayPages = _pages->data;
cocos2d::ccArray* arrayPages = _pages->data;
int length = arrayPages->num;
for (int i=(idx+1); i<length; i++) {
UIWidget* behindPage = dynamic_cast<UIWidget*>(arrayPages->arr[i]);
Point formerPos = behindPage->getPosition();
behindPage->setPosition(Point(formerPos.x+getSize().width, 0));
cocos2d::Point formerPos = behindPage->getPosition();
behindPage->setPosition(cocos2d::Point(formerPos.x+getSize().width, 0));
}
updateBoundaryPages();
}
}
void UIPageView::removePage(Layout* page)
void UIPageView::removePage(UILayout* page)
{
if (!page)
{
@ -209,7 +211,7 @@ void UIPageView::removePageAtIndex(int index)
{
return;
}
Layout* page = dynamic_cast<Layout*>(_pages->getObjectAtIndex(index));
UILayout* page = dynamic_cast<UILayout*>(_pages->getObjectAtIndex(index));
if (page)
{
removePage(page);
@ -222,6 +224,7 @@ void UIPageView::updateBoundaryPages()
{
_leftChild = NULL;
_rightChild = NULL;
return;
}
_leftChild = dynamic_cast<UIWidget*>(_pages->getObjectAtIndex(0));
_rightChild = dynamic_cast<UIWidget*>(_pages->getLastObject());
@ -234,7 +237,7 @@ float UIPageView::getPositionXByIndex(int idx)
bool UIPageView::addChild(UIWidget* widget)
{
return Layout::addChild(widget);
return UILayout::addChild(widget);
}
bool UIPageView::removeChild(UIWidget* widget)
@ -242,14 +245,14 @@ bool UIPageView::removeChild(UIWidget* widget)
if (_pages->containsObject(widget))
{
_pages->removeObject(widget);
return Layout::removeChild(widget);
return UILayout::removeChild(widget);
}
return false;
}
void UIPageView::onSizeChanged()
{
Layout::onSizeChanged();
UILayout::onSizeChanged();
_rightBoundary = getSize().width;
updateChildrenSize();
updateChildrenPosition();
@ -262,10 +265,10 @@ void UIPageView::updateChildrenSize()
return;
}
Size selfSize = getSize();
for (int i = 0; i < _pages->count(); i++)
cocos2d::Size selfSize = getSize();
for (unsigned int i=0; i<_pages->count(); i++)
{
Layout* page = dynamic_cast<Layout*>(_pages->getObjectAtIndex(i));
UILayout* page = dynamic_cast<UILayout*>(_pages->getObjectAtIndex(i));
page->setSize(selfSize);
}
}
@ -288,18 +291,18 @@ void UIPageView::updateChildrenPosition()
_curPageIdx = pageCount-1;
}
float pageWidth = getSize().width;
ccArray* arrayPages = _pages->data;
cocos2d::ccArray* arrayPages = _pages->data;
for (int i=0; i<pageCount; i++)
{
Layout* page = dynamic_cast<Layout*>(arrayPages->arr[i]);
page->setPosition(Point((i-_curPageIdx)*pageWidth, 0));
UILayout* page = dynamic_cast<UILayout*>(arrayPages->arr[i]);
page->setPosition(cocos2d::Point((i-_curPageIdx)*pageWidth, 0));
}
}
void UIPageView::removeAllChildren()
{
_pages->removeAllObjects();
Layout::removeAllChildren();
UILayout::removeAllChildren();
}
void UIPageView::scrollToPage(int idx)
@ -330,13 +333,16 @@ void UIPageView::update(float dt)
step = -_autoScrollDistance;
_autoScrollDistance = 0.0f;
_isAutoScrolling = false;
pageTurningEvent();
}
else
{
_autoScrollDistance += step;
}
scrollPages(-step);
if (!_isAutoScrolling)
{
pageTurningEvent();
}
break;
}
break;
@ -348,13 +354,16 @@ void UIPageView::update(float dt)
step = _autoScrollDistance;
_autoScrollDistance = 0.0f;
_isAutoScrolling = false;
pageTurningEvent();
}
else
{
_autoScrollDistance -= step;
}
scrollPages(step);
if (!_isAutoScrolling)
{
pageTurningEvent();
}
break;
}
default:
@ -363,14 +372,14 @@ void UIPageView::update(float dt)
}
}
bool UIPageView::onTouchBegan(const Point &touchPoint)
bool UIPageView::onTouchBegan(const cocos2d::Point &touchPoint)
{
bool pass = Layout::onTouchBegan(touchPoint);
bool pass = UILayout::onTouchBegan(touchPoint);
handlePressLogic(touchPoint);
return pass;
}
void UIPageView::onTouchMoved(const Point &touchPoint)
void UIPageView::onTouchMoved(const cocos2d::Point &touchPoint)
{
_touchMovePos.x = touchPoint.x;
_touchMovePos.y = touchPoint.y;
@ -387,15 +396,15 @@ void UIPageView::onTouchMoved(const Point &touchPoint)
}
}
void UIPageView::onTouchEnded(const Point &touchPoint)
void UIPageView::onTouchEnded(const cocos2d::Point &touchPoint)
{
Layout::onTouchEnded(touchPoint);
UILayout::onTouchEnded(touchPoint);
handleReleaseLogic(touchPoint);
}
void UIPageView::movePages(float offset)
{
ccArray* arrayPages = _pages->data;
cocos2d::ccArray* arrayPages = _pages->data;
int length = arrayPages->num;
for (int i = 0; i < length; i++)
{
@ -447,21 +456,21 @@ bool UIPageView::scrollPages(float touchOffset)
return true;
}
void UIPageView::onTouchCancelled(const Point &touchPoint)
void UIPageView::onTouchCancelled(const cocos2d::Point &touchPoint)
{
Layout::onTouchCancelled(touchPoint);
UILayout::onTouchCancelled(touchPoint);
}
void UIPageView::handlePressLogic(const Point &touchPoint)
void UIPageView::handlePressLogic(const cocos2d::Point &touchPoint)
{
Point nsp = _renderer->convertToNodeSpace(touchPoint);
cocos2d::Point nsp = _renderer->convertToNodeSpace(touchPoint);
_touchMoveStartLocation = nsp.x;
_touchStartLocation = nsp.x;
}
void UIPageView::handleMoveLogic(const Point &touchPoint)
void UIPageView::handleMoveLogic(const cocos2d::Point &touchPoint)
{
Point nsp = _renderer->convertToNodeSpace(touchPoint);
cocos2d::Point nsp = _renderer->convertToNodeSpace(touchPoint);
float offset = 0.0;
float moveX = nsp.x;
offset = moveX - _touchMoveStartLocation;
@ -477,12 +486,16 @@ void UIPageView::handleMoveLogic(const Point &touchPoint)
scrollPages(offset);
}
void UIPageView::handleReleaseLogic(const Point &touchPoint)
void UIPageView::handleReleaseLogic(const cocos2d::Point &touchPoint)
{
if (_pages->count() <= 0)
{
return;
}
UIWidget* curPage = dynamic_cast<UIWidget*>(_pages->getObjectAtIndex(_curPageIdx));
if (curPage)
{
Point curPagePos = curPage->getPosition();
cocos2d::Point curPagePos = curPage->getPosition();
int pageCount = _pages->count();
float curPageLocation = curPagePos.x;
float pageWidth = getSize().width;
@ -516,12 +529,12 @@ void UIPageView::handleReleaseLogic(const Point &touchPoint)
}
}
void UIPageView::checkChildInfo(int handleState,UIWidget* sender, const Point &touchPoint)
void UIPageView::checkChildInfo(int handleState,UIWidget* sender, const cocos2d::Point &touchPoint)
{
interceptTouchEvent(handleState, sender, touchPoint);
}
void UIPageView::interceptTouchEvent(int handleState, UIWidget *sender, const Point &touchPoint)
void UIPageView::interceptTouchEvent(int handleState, UIWidget *sender, const cocos2d::Point &touchPoint)
{
switch (handleState)
{
@ -556,7 +569,7 @@ void UIPageView::pageTurningEvent()
}
}
void UIPageView::addEventListener(Object *target, SEL_PageViewEvent selector)
void UIPageView::addEventListener(cocos2d::Object *target, SEL_PageViewEvent selector)
{
_eventListener = target;
_eventSelector = selector;
@ -567,9 +580,39 @@ int UIPageView::getCurPageIndex() const
return _curPageIdx;
}
cocos2d::Array* UIPageView::getPages()
{
return _pages;
}
const char* UIPageView::getDescription() const
{
return "PageView";
}
UIWidget* UIPageView::createCloneInstance()
{
return UIPageView::create();
}
void UIPageView::copyClonedWidgetChildren(UIWidget* model)
{
cocos2d::ccArray* arrayPages = dynamic_cast<UIPageView*>(model)->getPages()->data;
int length = arrayPages->num;
for (int i=0; i<length; i++)
{
UILayout* page = (UILayout*)(arrayPages->arr[i]);
addPage(dynamic_cast<UILayout*>(page->clone()));
}
}
void UIPageView::copySpecialProperties(UIWidget *widget)
{
UIPageView* pageView = dynamic_cast<UIPageView*>(widget);
if (pageView)
{
UILayout::copySpecialProperties(widget);
}
}
}

View File

@ -25,7 +25,7 @@
#ifndef __UIPAGEVIEW_H__
#define __UIPAGEVIEW_H__
#include "gui/Layout.h"
#include "gui/UILayout.h"
#include "gui/UIScrollInterface.h"
namespace gui {
@ -43,7 +43,7 @@ typedef enum {
PAGEVIEW_TOUCHRIGHT
}PVTouchDir;
class UIPageView : public Layout , public UIScrollInterface
class UIPageView : public UILayout , public UIScrollInterface
{
public:
@ -78,21 +78,21 @@ public:
*
* @param page page to be added to pageview.
*/
void addPage(Layout* page);
void addPage(UILayout* page);
/**
* Inert a page to pageview.
*
* @param page page to be added to pageview.
*/
void insertPage(Layout* page, int idx);
void insertPage(UILayout* page, int idx);
/**
* Remove a page of pageview.
*
* @param page page which will be removed.
*/
void removePage(Layout* page);
void removePage(UILayout* page);
/**
* Remove a page at index of pageview.
@ -115,8 +115,11 @@ public:
*/
int getCurPageIndex() const;
cocos2d::Array* getPages();
// event
void addEventListener(cocos2d::Object *target, SEL_PageViewEvent selector);
//override "removeChild" method of widget.
virtual bool removeChild(UIWidget* widget);
@ -140,15 +143,16 @@ public:
virtual void update(float dt);
virtual void doLayout(){};
/**
* Returns the "class name" of widget.
*/
virtual const char* getDescription() const;
protected:
virtual bool addChild(UIWidget* widget);
virtual bool init();
Layout* createPage();
UILayout* createPage();
float getPositionXByIndex(int idx);
void updateBoundaryPages();
virtual void handlePressLogic(const cocos2d::Point &touchPoint);
@ -162,14 +166,15 @@ protected:
void updateChildrenSize();
void updateChildrenPosition();
virtual void onSizeChanged();
virtual void setClippingEnabled(bool able){Layout::setClippingEnabled(able);};
virtual UIWidget* createCloneInstance();
virtual void copySpecialProperties(UIWidget* model);
virtual void copyClonedWidgetChildren(UIWidget* model);
virtual void setClippingEnabled(bool able){UILayout::setClippingEnabled(able);};
protected:
int _curPageIdx;
cocos2d::Array* _pages;
PVTouchDir _touchMoveDir;
float _touchStartLocation;
float _touchEndLocation;
float _touchMoveStartLocation;
cocos2d::Point _movePagePoint;
UIWidget* _leftChild;
@ -183,6 +188,7 @@ protected:
float _childFocusCancelOffset;
cocos2d::Object* _eventListener;
SEL_PageViewEvent _eventSelector;
};
}

View File

@ -24,8 +24,6 @@
#include "gui/UIRootWidget.h"
using namespace cocos2d;
namespace gui {
UIRootWidget::UIRootWidget()
@ -50,9 +48,9 @@ UIRootWidget* UIRootWidget::create()
bool UIRootWidget::init()
{
if (Layout::init())
if (UILayout::init())
{
setSize(Director::getInstance()->getWinSize());
setSize(cocos2d::Director::getInstance()->getWinSize());
return true;
}
return false;

View File

@ -25,11 +25,15 @@
#ifndef __UIROOTWIDGET_H__
#define __UIROOTWIDGET_H__
#include "gui/Layout.h"
#include "gui/UILayout.h"
namespace gui {
class UIRootWidget : public Layout
/**
* @js NA
* @lua NA
*/
class UIRootWidget : public UILayout
{
public:
/**

View File

@ -36,7 +36,6 @@ protected:
virtual void handleMoveLogic(const cocos2d::Point &touchPoint) = 0;
virtual void handleReleaseLogic(const cocos2d::Point &touchPoint) = 0;
virtual void interceptTouchEvent(int handleState, UIWidget* sender, const cocos2d::Point &touchPoint) = 0;
// virtual bool isInScrollDegreeRange(UIWidget* widget) = 0;
};
}

File diff suppressed because it is too large Load Diff

View File

@ -25,7 +25,7 @@
#ifndef __UISCROLLVIEW_H__
#define __UISCROLLVIEW_H__
#include "gui//Layout.h"
#include "gui/UILayout.h"
#include "gui/UIScrollInterface.h"
namespace gui {
@ -34,16 +34,8 @@ enum SCROLLVIEW_DIR
{
SCROLLVIEW_DIR_NONE,
SCROLLVIEW_DIR_VERTICAL,
SCROLLVIEW_DIR_HORIZONTAL
};
enum SCROLLVIEW_MOVE_DIR
{
SCROLLVIEW_MOVE_DIR_NONE,
SCROLLVIEW_MOVE_DIR_UP,
SCROLLVIEW_MOVE_DIR_DOWN,
SCROLLVIEW_MOVE_DIR_LEFT,
SCROLLVIEW_MOVE_DIR_RIGHT,
SCROLLVIEW_DIR_HORIZONTAL,
SCROLLVIEW_DIR_BOTH
};
typedef enum
@ -52,13 +44,18 @@ typedef enum
SCROLLVIEW_EVENT_SCROLL_TO_BOTTOM,
SCROLLVIEW_EVENT_SCROLL_TO_LEFT,
SCROLLVIEW_EVENT_SCROLL_TO_RIGHT,
SCROLLVIEW_EVENT_SCROLLING,
SCROLLVIEW_EVENT_BOUNCE_TOP,
SCROLLVIEW_EVENT_BOUNCE_BOTTOM,
SCROLLVIEW_EVENT_BOUNCE_LEFT,
SCROLLVIEW_EVENT_BOUNCE_RIGHT
}ScrollviewEventType;
typedef void (cocos2d::Object::*SEL_ScrollViewEvent)(cocos2d::Object*, ScrollviewEventType);
typedef void (cocos2d::CCObject::*SEL_ScrollViewEvent)(cocos2d::Object*, ScrollviewEventType);
#define scrollvieweventselector(_SELECTOR) (SEL_ScrollViewEvent)(&_SELECTOR)
class UIScrollView : public Layout , public UIScrollInterface
class UIScrollView : public UILayout , public UIScrollInterface
{
public:
/**
@ -83,7 +80,7 @@ public:
*
* @param SCROLLVIEW_DIR
*/
void setDirection(SCROLLVIEW_DIR dir);
virtual void setDirection(SCROLLVIEW_DIR dir);
/**
* Gets scroll direction of scrollview.
@ -101,17 +98,117 @@ public:
*
* @return inner container.
*/
Layout* getInnerContainer();
UILayout* getInnerContainer();
/**
* Scroll inner container to bottom boundary of scrollview.
*/
void scrollToBottom();
void scrollToBottom(float time, bool attenuated);
/**
* Scroll inner container to top boundary of scrollview.
*/
void scrollToTop();
void scrollToTop(float time, bool attenuated);
/**
* Scroll inner container to left boundary of scrollview.
*/
void scrollToLeft(float time, bool attenuated);
/**
* Scroll inner container to right boundary of scrollview.
*/
void scrollToRight(float time, bool attenuated);
/**
* Scroll inner container to top and left boundary of scrollview.
*/
void scrollToTopLeft(float time, bool attenuated);
/**
* Scroll inner container to top and right boundary of scrollview.
*/
void scrollToTopRight(float time, bool attenuated);
/**
* Scroll inner container to bottom and left boundary of scrollview.
*/
void scrollToBottomLeft(float time, bool attenuated);
/**
* Scroll inner container to bottom and right boundary of scrollview.
*/
void scrollToBottomRight(float time, bool attenuated);
/**
* Scroll inner container to vertical percent position of scrollview.
*/
void scrollToPercentVertical(float percent, float time, bool attenuated);
/**
* Scroll inner container to horizontal percent position of scrollview.
*/
void scrollToPercentHorizontal(float percent, float time, bool attenuated);
/**
* Scroll inner container to both direction percent position of scrollview.
*/
void scrollToPercentBothDirection(const cocos2d::Point& percent, float time, bool attenuated);
/**
* Move inner container to bottom boundary of scrollview.
*/
void jumpToBottom();
/**
* Move inner container to top boundary of scrollview.
*/
void jumpToTop();
/**
* Move inner container to left boundary of scrollview.
*/
void jumpToLeft();
/**
* Move inner container to right boundary of scrollview.
*/
void jumpToRight();
/**
* Move inner container to top and left boundary of scrollview.
*/
void jumpToTopLeft();
/**
* Move inner container to top and right boundary of scrollview.
*/
void jumpToTopRight();
/**
* Move inner container to bottom and left boundary of scrollview.
*/
void jumpToBottomLeft();
/**
* Move inner container to bottom and right boundary of scrollview.
*/
void jumpToBottomRight();
/**
* Move inner container to vertical percent position of scrollview.
*/
void jumpToPercentVertical(float percent);
/**
* Move inner container to horizontal percent position of scrollview.
*/
void jumpToPercentHorizontal(float percent);
/**
* Move inner container to both direction percent position of scrollview.
*/
void jumpToPercentBothDirection(const cocos2d::Point& percent);
/**
* Changes inner container size of scrollview.
@ -134,7 +231,7 @@ public:
/**
* Add call back function called scrollview event triggered
*/
void addEventListener(cocos2d::Object* target, SEL_ScrollViewEvent selector);
void addEventListener(cocos2d::Object* target, SEL_ScrollViewEvent selector);
//override "addChild" method of widget.
virtual bool addChild(UIWidget* widget);
@ -165,6 +262,14 @@ public:
virtual void update(float dt);
void setBounceEnabled(bool enabled);
bool isBounceEnabled() const;
void setInertiaScrollEnabled(bool enabled);
bool isInertiaScrollEnabled() const;
/**
* Sets LayoutType.
*
@ -192,12 +297,20 @@ public:
protected:
virtual bool init();
virtual void initRenderer();
void moveChildren(float offset);
void moveChildren(float offsetX, float offsetY);
void autoScrollChildren(float dt);
void startAutoScrollChildren(float v);
void bounceChildren(float dt);
void checkBounceBoundary();
bool checkNeedBounce();
void startAutoScrollChildrenWithOriginalSpeed(const cocos2d::Point& dir, float v, bool attenuated, float acceleration);
void startAutoScrollChildrenWithDestination(const cocos2d::Point& des, float time, bool attenuated);
void jumpToDestination(const cocos2d::Point& des);
void stopAutoScrollChildren();
float getCurAutoScrollDistance(float time);
virtual bool scrollChildren(float touchOffset);
void startBounceChildren(float v);
void stopBounceChildren();
bool checkCustomScrollDestination(float* touchOffsetX, float* touchOffsetY);
virtual bool scrollChildren(float touchOffsetX, float touchOffsetY);
bool bounceScrollChildren(float touchOffsetX, float touchOffsetY);
void startRecordSlidAction();
virtual void endRecordSlidAction();
virtual void handlePressLogic(const cocos2d::Point &touchPoint);
@ -206,48 +319,71 @@ protected:
virtual void interceptTouchEvent(int handleState,UIWidget* sender,const cocos2d::Point &touchPoint);
virtual void checkChildInfo(int handleState,UIWidget* sender,const cocos2d::Point &touchPoint);
void recordSlidTime(float dt);
//override "releaseResoures" method of widget.
virtual void releaseResoures();
void scrollToTopEvent();
void scrollToBottomEvent();
void scrollToLeftEvent();
void scrollToRightEvent();
void setMoveDirection(SCROLLVIEW_MOVE_DIR dir);
SCROLLVIEW_MOVE_DIR getMoveDirection();
void scrollingEvent();
void bounceTopEvent();
void bounceBottomEvent();
void bounceLeftEvent();
void bounceRightEvent();
virtual void onSizeChanged();
virtual void setClippingEnabled(bool able){Layout::setClippingEnabled(able);};
virtual UIWidget* createCloneInstance();
virtual void copySpecialProperties(UIWidget* model);
virtual void copyClonedWidgetChildren(UIWidget* model);
virtual void setClippingEnabled(bool able){UILayout::setClippingEnabled(able);};
protected:
Layout* _innerContainer;
UILayout* _innerContainer;
SCROLLVIEW_DIR _direction;
SCROLLVIEW_MOVE_DIR _moveDirection;
float _touchStartLocation;
float _touchEndLocation;
float _touchMoveStartLocation;
float _topBoundary;//test
float _bottomBoundary;//test
cocos2d::Point _touchBeganPoint;
cocos2d::Point _touchMovedPoint;
cocos2d::Point _touchEndedPoint;
cocos2d::Point _touchMovingPoint;
cocos2d::Point _autoScrollDir;
float _topBoundary;
float _bottomBoundary;
float _leftBoundary;
float _rightBoundary;
bool _topEnd;
bool _bottomEnd;
bool _leftEnd;
bool _rightEnd;
float _bounceTopBoundary;
float _bounceBottomBoundary;
float _bounceLeftBoundary;
float _bounceRightBoundary;
bool _autoScroll;
float _autoScrollAddUpTime;
float _autoScrollOriginalSpeed;
float _autoScrollAcceleration;
bool _isAutoScrollSpeedAttenuated;
bool _needCheckAutoScrollDestination;
cocos2d::Point _autoScrollDestination;
bool _bePressed;
float _slidTime;
cocos2d::Point _moveChildPoint;
float _childFocusCancelOffset;
bool _leftBounceNeeded;
bool _topBounceNeeded;
bool _rightBounceNeeded;
bool _bottomBounceNeeded;
bool _bounceEnabled;
bool _bouncing;
cocos2d::Point _bounceDir;
float _bounceOriginalSpeed;
bool _inertiaScrollEnabled;
cocos2d::Object* _eventListener;
SEL_ScrollViewEvent _eventSelector;
};
}

View File

@ -25,15 +25,12 @@
#include "gui/UISlider.h"
#include "extensions/GUI/CCControlExtension/CCScale9Sprite.h"
using namespace cocos2d;
using namespace cocos2d::extension;
namespace gui {
UISlider::UISlider():
_barRenderer(NULL),
_progressBarRenderer(NULL),
_progressBarTextureSize(Size::ZERO),
_progressBarTextureSize(cocos2d::Size::ZERO),
_slidBallNormalRenderer(NULL),
_slidBallPressedRenderer(NULL),
_slidBallDisabledRenderer(NULL),
@ -47,8 +44,8 @@ _progressBarTextureFile(""),
_slidBallNormalTextureFile(""),
_slidBallPressedTextureFile(""),
_slidBallDisabledTextureFile(""),
_capInsetsBarRenderer(Rect::ZERO),
_capInsetsProgressBarRenderer(Rect::ZERO),
_capInsetsBarRenderer(cocos2d::Rect::ZERO),
_capInsetsProgressBarRenderer(cocos2d::Rect::ZERO),
_slidPercentListener(NULL),
_slidPercentSelector(NULL),
_barTexType(UI_TEX_TYPE_LOCAL),
@ -79,17 +76,17 @@ UISlider* UISlider::create()
void UISlider::initRenderer()
{
UIWidget::initRenderer();
_barRenderer = CCSprite::create();
_progressBarRenderer = CCSprite::create();
_progressBarRenderer->setAnchorPoint(Point(0.0f, 0.5f));
_barRenderer = cocos2d::Sprite::create();
_progressBarRenderer = cocos2d::Sprite::create();
_progressBarRenderer->setAnchorPoint(cocos2d::Point(0.0f, 0.5f));
_renderer->addChild(_barRenderer, -1);
_renderer->addChild(_progressBarRenderer, -1);
_slidBallNormalRenderer = CCSprite::create();
_slidBallPressedRenderer = CCSprite::create();
_slidBallNormalRenderer = cocos2d::Sprite::create();
_slidBallPressedRenderer = cocos2d::Sprite::create();
_slidBallPressedRenderer->setVisible(false);
_slidBallDisabledRenderer = CCSprite::create();
_slidBallDisabledRenderer = cocos2d::Sprite::create();
_slidBallDisabledRenderer->setVisible(false);
_slidBallRenderer = CCNode::create();
_slidBallRenderer = cocos2d::Node::create();
_slidBallRenderer->addChild(_slidBallNormalRenderer);
_slidBallRenderer->addChild(_slidBallPressedRenderer);
_slidBallRenderer->addChild(_slidBallDisabledRenderer);
@ -109,21 +106,21 @@ void UISlider::loadBarTexture(const char* fileName, TextureResType texType)
case UI_TEX_TYPE_LOCAL:
if (_scale9Enabled)
{
dynamic_cast<Scale9Sprite*>(_barRenderer)->initWithFile(fileName);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_barRenderer)->initWithFile(fileName);
}
else
{
dynamic_cast<Sprite*>(_barRenderer)->initWithFile(fileName);
dynamic_cast<cocos2d::Sprite*>(_barRenderer)->initWithFile(fileName);
}
break;
case UI_TEX_TYPE_PLIST:
if (_scale9Enabled)
{
dynamic_cast<Scale9Sprite*>(_barRenderer)->initWithSpriteFrameName(fileName);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_barRenderer)->initWithSpriteFrameName(fileName);
}
else
{
dynamic_cast<Sprite*>(_barRenderer)->initWithSpriteFrameName(fileName);
dynamic_cast<cocos2d::Sprite*>(_barRenderer)->initWithSpriteFrameName(fileName);
}
break;
default:
@ -131,13 +128,13 @@ void UISlider::loadBarTexture(const char* fileName, TextureResType texType)
}
if (_scale9Enabled)
{
dynamic_cast<Scale9Sprite*>(_barRenderer)->setColor(getColor());
dynamic_cast<Scale9Sprite*>(_barRenderer)->setOpacity(getOpacity());
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_barRenderer)->setColor(getColor());
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_barRenderer)->setOpacity(getOpacity());
}
else
{
dynamic_cast<Sprite*>(_barRenderer)->setColor(getColor());
dynamic_cast<Sprite*>(_barRenderer)->setOpacity(getOpacity());
dynamic_cast<cocos2d::Sprite*>(_barRenderer)->setColor(getColor());
dynamic_cast<cocos2d::Sprite*>(_barRenderer)->setOpacity(getOpacity());
}
barRendererScaleChangedWithSize();
}
@ -155,21 +152,21 @@ void UISlider::loadProgressBarTexture(const char *fileName, TextureResType texTy
case UI_TEX_TYPE_LOCAL:
if (_scale9Enabled)
{
dynamic_cast<Scale9Sprite*>(_progressBarRenderer)->initWithFile(fileName);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_progressBarRenderer)->initWithFile(fileName);
}
else
{
dynamic_cast<Sprite*>(_progressBarRenderer)->initWithFile(fileName);
dynamic_cast<cocos2d::Sprite*>(_progressBarRenderer)->initWithFile(fileName);
}
break;
case UI_TEX_TYPE_PLIST:
if (_scale9Enabled)
{
dynamic_cast<Scale9Sprite*>(_progressBarRenderer)->initWithSpriteFrameName(fileName);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_progressBarRenderer)->initWithSpriteFrameName(fileName);
}
else
{
dynamic_cast<Sprite*>(_progressBarRenderer)->initWithSpriteFrameName(fileName);
dynamic_cast<cocos2d::Sprite*>(_progressBarRenderer)->initWithSpriteFrameName(fileName);
}
break;
default:
@ -177,15 +174,15 @@ void UISlider::loadProgressBarTexture(const char *fileName, TextureResType texTy
}
if (_scale9Enabled)
{
dynamic_cast<Scale9Sprite*>(_progressBarRenderer)->setColor(getColor());
dynamic_cast<Scale9Sprite*>(_progressBarRenderer)->setOpacity(getOpacity());
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_progressBarRenderer)->setColor(getColor());
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_progressBarRenderer)->setOpacity(getOpacity());
}
else
{
dynamic_cast<Sprite*>(_progressBarRenderer)->setColor(getColor());
dynamic_cast<Sprite*>(_progressBarRenderer)->setOpacity(getOpacity());
dynamic_cast<cocos2d::Sprite*>(_progressBarRenderer)->setColor(getColor());
dynamic_cast<cocos2d::Sprite*>(_progressBarRenderer)->setOpacity(getOpacity());
}
_progressBarRenderer->setAnchorPoint(Point(0.0f, 0.5f));
_progressBarRenderer->setAnchorPoint(cocos2d::Point(0.0f, 0.5f));
_progressBarTextureSize = _progressBarRenderer->getContentSize();
progressBarRendererScaleChangedWithSize();
}
@ -204,13 +201,13 @@ void UISlider::setScale9Enabled(bool able)
_progressBarRenderer = NULL;
if (_scale9Enabled)
{
_barRenderer = Scale9Sprite::create();
_progressBarRenderer = Scale9Sprite::create();
_barRenderer = cocos2d::extension::Scale9Sprite::create();
_progressBarRenderer = cocos2d::extension::Scale9Sprite::create();
}
else
{
_barRenderer = CCSprite::create();
_progressBarRenderer = CCSprite::create();
_barRenderer = cocos2d::Sprite::create();
_progressBarRenderer = cocos2d::Sprite::create();
}
loadBarTexture(_textureFile.c_str(), _barTexType);
loadProgressBarTexture(_progressBarTextureFile.c_str(), _progressBarTexType);
@ -239,30 +236,30 @@ void UISlider::ignoreContentAdaptWithSize(bool ignore)
}
}
void UISlider::setCapInsets(const Rect &capInsets)
void UISlider::setCapInsets(const cocos2d::Rect &capInsets)
{
setCapInsetsBarRenderer(capInsets);
setCapInsetProgressBarRebderer(capInsets);
}
void UISlider::setCapInsetsBarRenderer(const Rect &capInsets)
void UISlider::setCapInsetsBarRenderer(const cocos2d::Rect &capInsets)
{
_capInsetsBarRenderer = capInsets;
if (!_scale9Enabled)
{
return;
}
dynamic_cast<Scale9Sprite*>(_barRenderer)->setCapInsets(capInsets);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_barRenderer)->setCapInsets(capInsets);
}
void UISlider::setCapInsetProgressBarRebderer(const Rect &capInsets)
void UISlider::setCapInsetProgressBarRebderer(const cocos2d::Rect &capInsets)
{
_capInsetsProgressBarRenderer = capInsets;
if (!_scale9Enabled)
{
return;
}
dynamic_cast<Scale9Sprite*>(_progressBarRenderer)->setCapInsets(capInsets);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_progressBarRenderer)->setCapInsets(capInsets);
}
void UISlider::loadSlidBallTextures(const char* normal,const char* pressed,const char* disabled,TextureResType texType)
@ -353,10 +350,10 @@ void UISlider::setPercent(int percent)
}
_percent = percent;
float dis = _barLength*(percent/100.0f);
_slidBallRenderer->setPosition(Point(-_barLength/2.0f + dis, 0.0f));
_slidBallRenderer->setPosition(cocos2d::Point(-_barLength/2.0f + dis, 0.0f));
if (_scale9Enabled)
{
dynamic_cast<Scale9Sprite*>(_progressBarRenderer)->setPreferredSize(Size(dis,_progressBarTextureSize.height));
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_progressBarRenderer)->setPreferredSize(cocos2d::Size(dis,_progressBarTextureSize.height));
}
else
{
@ -365,10 +362,10 @@ void UISlider::setPercent(int percent)
{
case UI_TEX_TYPE_PLIST:
{
Sprite* barNode = dynamic_cast<Sprite*>(_progressBarRenderer);
cocos2d::Sprite* barNode = dynamic_cast<cocos2d::Sprite*>(_progressBarRenderer);
if (barNode)
{
Point to = barNode->getTextureRect().origin;
cocos2d::Point to = barNode->getTextureRect().origin;
x = to.x;
y = to.y;
}
@ -377,33 +374,33 @@ void UISlider::setPercent(int percent)
default:
break;
}
dynamic_cast<Sprite*>(_progressBarRenderer)->setTextureRect(Rect(x, y, _progressBarTextureSize.width * (percent/100.0f), _progressBarTextureSize.height));
dynamic_cast<cocos2d::Sprite*>(_progressBarRenderer)->setTextureRect(cocos2d::Rect(x, y, _progressBarTextureSize.width * (percent/100.0f), _progressBarTextureSize.height));
}
}
bool UISlider::onTouchBegan(const Point &touchPoint)
bool UISlider::onTouchBegan(const cocos2d::Point &touchPoint)
{
bool pass = UIWidget::onTouchBegan(touchPoint);
Point nsp = _renderer->convertToNodeSpace(touchPoint);
cocos2d::Point nsp = _renderer->convertToNodeSpace(touchPoint);
setPercent(getPercentWithBallPos(nsp.x));
percentChangedEvent();
return pass;
}
void UISlider::onTouchMoved(const Point &touchPoint)
void UISlider::onTouchMoved(const cocos2d::Point &touchPoint)
{
Point nsp = _renderer->convertToNodeSpace(touchPoint);
_slidBallRenderer->setPosition(Point(nsp.x,0));
cocos2d::Point nsp = _renderer->convertToNodeSpace(touchPoint);
_slidBallRenderer->setPosition(cocos2d::Point(nsp.x,0));
setPercent(getPercentWithBallPos(nsp.x));
percentChangedEvent();
}
void UISlider::onTouchEnded(const Point &touchPoint)
void UISlider::onTouchEnded(const cocos2d::Point &touchPoint)
{
UIWidget::onTouchEnded(touchPoint);
}
void UISlider::onTouchCancelled(const Point &touchPoint)
void UISlider::onTouchCancelled(const cocos2d::Point &touchPoint)
{
UIWidget::onTouchCancelled(touchPoint);
}
@ -413,7 +410,7 @@ float UISlider::getPercentWithBallPos(float px)
return (((px-(-_barLength/2.0f))/_barLength)*100.0f);
}
void UISlider::addEventListener(Object *target, SEL_SlidPercentChangedEvent selector)
void UISlider::addEventListener(cocos2d::Object *target, SEL_SlidPercentChangedEvent selector)
{
_slidPercentListener = target;
_slidPercentSelector = selector;
@ -438,12 +435,12 @@ void UISlider::onSizeChanged()
progressBarRendererScaleChangedWithSize();
}
const Size& UISlider::getContentSize() const
const cocos2d::Size& UISlider::getContentSize() const
{
return _barRenderer->getContentSize();
}
Node* UISlider::getVirtualRenderer()
cocos2d::Node* UISlider::getVirtualRenderer()
{
return _barRenderer;
}
@ -462,11 +459,11 @@ void UISlider::barRendererScaleChangedWithSize()
_barLength = _size.width;
if (_scale9Enabled)
{
dynamic_cast<Scale9Sprite*>(_barRenderer)->setPreferredSize(_size);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_barRenderer)->setPreferredSize(_size);
}
else
{
Size btextureSize = _barRenderer->getContentSize();
cocos2d::Size btextureSize = _barRenderer->getContentSize();
if (btextureSize.width <= 0.0f || btextureSize.height <= 0.0f)
{
_barRenderer->setScale(1.0f);
@ -487,7 +484,7 @@ void UISlider::progressBarRendererScaleChangedWithSize()
{
if (!_scale9Enabled)
{
Size ptextureSize = _progressBarTextureSize;
cocos2d::Size ptextureSize = _progressBarTextureSize;
float pscaleX = _size.width / ptextureSize.width;
float pscaleY = _size.height / ptextureSize.height;
_progressBarRenderer->setScaleX(pscaleX);
@ -498,11 +495,11 @@ void UISlider::progressBarRendererScaleChangedWithSize()
{
if (_scale9Enabled)
{
dynamic_cast<Scale9Sprite*>(_progressBarRenderer)->setPreferredSize(_size);
dynamic_cast<cocos2d::extension::Scale9Sprite*>(_progressBarRenderer)->setPreferredSize(_size);
}
else
{
Size ptextureSize = _progressBarTextureSize;
cocos2d::Size ptextureSize = _progressBarTextureSize;
if (ptextureSize.width <= 0.0f || ptextureSize.height <= 0.0f)
{
_progressBarRenderer->setScale(1.0f);
@ -514,7 +511,7 @@ void UISlider::progressBarRendererScaleChangedWithSize()
_progressBarRenderer->setScaleY(pscaleY);
}
}
_progressBarRenderer->setPosition(Point(-_barLength * 0.5f, 0.0f));
_progressBarRenderer->setPosition(cocos2d::Point(-_barLength * 0.5f, 0.0f));
setPercent(_percent);
}
@ -544,4 +541,25 @@ const char* UISlider::getDescription() const
return "Slider";
}
UIWidget* UISlider::createCloneInstance()
{
return UISlider::create();
}
void UISlider::copySpecialProperties(UIWidget *widget)
{
UISlider* slider = dynamic_cast<UISlider*>(widget);
if (slider)
{
_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);
setPercent(slider->getPercent());
}
}
}

View File

@ -34,9 +34,13 @@ typedef enum
SLIDER_PERCENTCHANGED
}SliderEventType;
typedef void (cocos2d::CCObject::*SEL_SlidPercentChangedEvent)(cocos2d::Object*,SliderEventType);
typedef void (cocos2d::Object::*SEL_SlidPercentChangedEvent)(cocos2d::Object*,SliderEventType);
#define sliderpercentchangedselector(_SELECTOR) (SEL_SlidPercentChangedEvent)(&_SELECTOR)
/**
* @js NA
* @lua NA
*/
class UISlider : public UIWidget
{
public:
@ -185,6 +189,7 @@ public:
* Returns the "class name" of widget.
*/
virtual const char* getDescription() const;
protected:
virtual void initRenderer();
float getPercentWithBallPos(float location);
@ -195,6 +200,8 @@ protected:
virtual void onSizeChanged();
void barRendererScaleChangedWithSize();
void progressBarRendererScaleChangedWithSize();
virtual UIWidget* createCloneInstance();
virtual void copySpecialProperties(UIWidget* model);
protected:
cocos2d::Node* _barRenderer;
cocos2d::Node* _progressBarRenderer;

View File

@ -24,19 +24,17 @@
#include "gui/UITextField.h"
using namespace cocos2d;
namespace gui {
UICCTextField::UICCTextField()
: m_bMaxLengthEnabled(false)
, m_nMaxLength(0)
, m_bPasswordEnabled(false)
, m_strPasswordStyleText("*")
, m_bAttachWithIME(false)
, m_bDetachWithIME(false)
, m_bInsertText(false)
, m_bDeleteBackward(false)
: _maxLengthEnabled(false)
, _maxLength(0)
, _passwordEnabled(false)
, _passwordStyleText("*")
, _attachWithIME(false)
, _detachWithIME(false)
, _insertText(false)
, _deleteBackward(false)
{
}
@ -64,26 +62,26 @@ UICCTextField * UICCTextField::create(const char *placeholder, const char *fontN
void UICCTextField::onEnter()
{
CCTextFieldTTF::setDelegate(this);
cocos2d::TextFieldTTF::setDelegate(this);
}
bool UICCTextField::onTextFieldAttachWithIME(TextFieldTTF *pSender)
bool UICCTextField::onTextFieldAttachWithIME(cocos2d::TextFieldTTF *pSender)
{
setAttachWithIME(true);
return false;
}
bool UICCTextField::onTextFieldInsertText(TextFieldTTF *pSender, const char *text, int nLen)
bool UICCTextField::onTextFieldInsertText(cocos2d::TextFieldTTF *pSender, const char *text, int nLen)
{
if (nLen == 1 && strcmp(text, "\n") == 0)
{
return false;
}
setInsertText(true);
if (m_bMaxLengthEnabled)
if (_maxLengthEnabled)
{
if (CCTextFieldTTF::getCharCount() >= m_nMaxLength)
if (cocos2d::TextFieldTTF::getCharCount() >= _maxLength)
{
return true;
}
@ -92,13 +90,13 @@ bool UICCTextField::onTextFieldInsertText(TextFieldTTF *pSender, const char *tex
return false;
}
bool UICCTextField::onTextFieldDeleteBackward(TextFieldTTF *pSender, const char *delText, int nLen)
bool UICCTextField::onTextFieldDeleteBackward(cocos2d::TextFieldTTF *pSender, const char *delText, int nLen)
{
setDeleteBackward(true);
return false;
}
bool UICCTextField::onTextFieldDetachWithIME(TextFieldTTF *pSender)
bool UICCTextField::onTextFieldDetachWithIME(cocos2d::TextFieldTTF *pSender)
{
setDetachWithIME(true);
return false;
@ -107,11 +105,11 @@ bool UICCTextField::onTextFieldDetachWithIME(TextFieldTTF *pSender)
void UICCTextField::insertText(const char * text, int len)
{
std::string str_text = text;
int str_len = strlen(CCTextFieldTTF::getString());
int str_len = strlen(cocos2d::TextFieldTTF::getString());
if (strcmp(text, "\n") != 0)
{
if (m_bMaxLengthEnabled)
if (_maxLengthEnabled)
{
int multiple = 1;
char value = text[0];
@ -120,26 +118,26 @@ void UICCTextField::insertText(const char * text, int len)
multiple = 3;
}
if (str_len + len > m_nMaxLength * multiple)
if (str_len + len > _maxLength * multiple)
{
str_text = str_text.substr(0, m_nMaxLength * multiple);
len = m_nMaxLength * multiple;
str_text = str_text.substr(0, _maxLength * multiple);
len = _maxLength * multiple;
/*
int mod = str_len % 3;
int offset = (mod == 0) ? 0 : (3 - mod);
int amount = str_len + offset;
str_text = str_text.substr(0, m_nMaxLength - amount);
str_text = str_text.substr(0, _maxLength - amount);
// CCLOG("str_test = %s", str_text.c_str());
*/
}
}
}
CCTextFieldTTF::insertText(str_text.c_str(), len);
cocos2d::TextFieldTTF::insertText(str_text.c_str(), len);
// password
if (m_bPasswordEnabled)
if (_passwordEnabled)
{
if (CCTextFieldTTF::getCharCount() > 0)
if (cocos2d::TextFieldTTF::getCharCount() > 0)
{
setPasswordText(_inputText->c_str());
}
@ -148,12 +146,12 @@ void UICCTextField::insertText(const char * text, int len)
void UICCTextField::deleteBackward()
{
CCTextFieldTTF::deleteBackward();
cocos2d::TextFieldTTF::deleteBackward();
if (CCTextFieldTTF::getCharCount() > 0)
if (cocos2d::TextFieldTTF::getCharCount() > 0)
{
// password
if (m_bPasswordEnabled)
if (_passwordEnabled)
{
setPasswordText(_inputText->c_str());
}
@ -162,47 +160,47 @@ void UICCTextField::deleteBackward()
void UICCTextField::openIME()
{
CCTextFieldTTF::attachWithIME();
cocos2d::TextFieldTTF::attachWithIME();
}
void UICCTextField::closeIME()
{
CCTextFieldTTF::detachWithIME();
cocos2d::TextFieldTTF::detachWithIME();
}
void UICCTextField::setMaxLengthEnabled(bool enable)
{
m_bMaxLengthEnabled = enable;
_maxLengthEnabled = enable;
}
bool UICCTextField::isMaxLengthEnabled()
{
return m_bMaxLengthEnabled;
return _maxLengthEnabled;
}
void UICCTextField::setMaxLength(int length)
{
m_nMaxLength = length;
_maxLength = length;
}
int UICCTextField::getMaxLength()
{
return m_nMaxLength;
return _maxLength;
}
int UICCTextField::getCharCount()
{
return CCTextFieldTTF::getCharCount();
return cocos2d::TextFieldTTF::getCharCount();
}
void UICCTextField::setPasswordEnabled(bool enable)
{
m_bPasswordEnabled = enable;
_passwordEnabled = enable;
}
bool UICCTextField::isPasswordEnabled()
{
return m_bPasswordEnabled;
return _passwordEnabled;
}
void UICCTextField::setPasswordStyleText(const char* styleText)
@ -216,7 +214,7 @@ void UICCTextField::setPasswordStyleText(const char* styleText)
{
return;
}
m_strPasswordStyleText = styleText;
_passwordStyleText = styleText;
}
void UICCTextField::setPasswordText(const char *text)
@ -224,49 +222,49 @@ void UICCTextField::setPasswordText(const char *text)
std::string tempStr;
for (size_t i = 0; i < strlen(text); ++i)
{
tempStr.append(m_strPasswordStyleText);
tempStr.append(_passwordStyleText);
}
CCLabelTTF::setString(tempStr.c_str());
cocos2d::LabelTTF::setString(tempStr.c_str());
}
void UICCTextField::setAttachWithIME(bool attach)
{
m_bAttachWithIME = attach;
_attachWithIME = attach;
}
bool UICCTextField::getAttachWithIME()
{
return m_bAttachWithIME;
return _attachWithIME;
}
void UICCTextField::setDetachWithIME(bool detach)
{
m_bDetachWithIME = detach;
_detachWithIME = detach;
}
bool UICCTextField::getDetachWithIME()
{
return m_bDetachWithIME;
return _detachWithIME;
}
void UICCTextField::setInsertText(bool insert)
{
m_bInsertText = insert;
_insertText = insert;
}
bool UICCTextField::getInsertText()
{
return m_bInsertText;
return _insertText;
}
void UICCTextField::setDeleteBackward(bool deleteBackward)
{
m_bDeleteBackward = deleteBackward;
_deleteBackward = deleteBackward;
}
bool UICCTextField::getDeleteBackward()
{
return m_bDeleteBackward;
return _deleteBackward;
}
@ -278,7 +276,8 @@ _touchWidth(0.0f),
_touchHeight(0.0f),
_useTouchArea(false),
_eventListener(NULL),
_eventSelector(NULL)
_eventSelector(NULL),
_passwordStyleText("")
{
}
@ -315,7 +314,7 @@ void UITextField::initRenderer()
_renderer->addChild(_textFieldRenderer);
}
void UITextField::setTouchSize(const Size &size)
void UITextField::setTouchSize(const cocos2d::Size &size)
{
_useTouchArea = true;
_touchWidth = size.width;
@ -361,7 +360,7 @@ const char* UITextField::getStringValue()
return _textFieldRenderer->getString();
}
bool UITextField::onTouchBegan(const Point &touchPoint)
bool UITextField::onTouchBegan(const cocos2d::Point &touchPoint)
{
bool pass = UIWidget::onTouchBegan(touchPoint);
_textFieldRenderer->attachWithIME();
@ -401,6 +400,8 @@ bool UITextField::isPasswordEnabled()
void UITextField::setPasswordStyleText(const char *styleText)
{
_textFieldRenderer->setPasswordStyleText(styleText);
_passwordStyleText = styleText;
}
void UITextField::update(float dt)
@ -489,7 +490,7 @@ void UITextField::insertTextEvent()
{
if (_eventListener && _eventSelector)
{
(_eventListener->*_eventSelector)(this, TEXTFIELD_EVENT_INDERT_TEXT);
(_eventListener->*_eventSelector)(this, TEXTFIELD_EVENT_INSERT_TEXT);
}
}
@ -501,19 +502,19 @@ void UITextField::deleteBackwardEvent()
}
}
void UITextField::addEventListener(Object *target, SEL_TextFieldEvent selecor)
void UITextField::addEventListener(cocos2d::Object *target, SEL_TextFieldEvent selecor)
{
_eventListener = target;
_eventSelector = selecor;
}
void UITextField::setAnchorPoint(const Point &pt)
void UITextField::setAnchorPoint(const cocos2d::Point &pt)
{
UIWidget::setAnchorPoint(pt);
_textFieldRenderer->setAnchorPoint(pt);
}
void UITextField::setColor(const Color3B &color)
void UITextField::setColor(const cocos2d::Color3B &color)
{
UIWidget::setColor(color);
_textFieldRenderer->setColor(color);
@ -539,7 +540,7 @@ void UITextField::textfieldRendererScaleChangedWithSize()
}
else
{
Size textureSize = getContentSize();
cocos2d::Size textureSize = getContentSize();
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
{
_textFieldRenderer->setScale(1.0f);
@ -552,12 +553,12 @@ void UITextField::textfieldRendererScaleChangedWithSize()
}
}
const Size& UITextField::getContentSize() const
const cocos2d::Size& UITextField::getContentSize() const
{
return _textFieldRenderer->getContentSize();
}
Node* UITextField::getVirtualRenderer()
cocos2d::Node* UITextField::getVirtualRenderer()
{
return _textFieldRenderer;
}
@ -567,4 +568,34 @@ const char* UITextField::getDescription() const
return "TextField";
}
void UITextField::attachWithIME()
{
_textFieldRenderer->attachWithIME();
}
UIWidget* UITextField::createCloneInstance()
{
return UITextField::create();
}
void UITextField::copySpecialProperties(UIWidget *widget)
{
UITextField* textField = dynamic_cast<UITextField*>(widget);
if (textField)
{
setText(textField->_textFieldRenderer->getString());
setPlaceHolder(textField->getStringValue());
setFontSize(textField->_textFieldRenderer->getFontSize());
setFontName(textField->_textFieldRenderer->getFontName());
setMaxLengthEnabled(textField->isMaxLengthEnabled());
setMaxLength(textField->getMaxLength());
setPasswordEnabled(textField->isPasswordEnabled());
setPasswordStyleText(textField->_passwordStyleText.c_str());
setAttachWithIME(textField->getAttachWithIME());
setDetachWithIME(textField->getDetachWithIME());
setInsertText(textField->getInsertText());
setDeleteBackward(textField->getDeleteBackward());
}
}
}

View File

@ -30,6 +30,10 @@
namespace gui {
/**
* @js NA
* @lua NA
*/
class UICCTextField: public cocos2d::TextFieldTTF, public cocos2d::TextFieldDelegate
{
public:
@ -70,32 +74,32 @@ public:
bool getInsertText();
void setDeleteBackward(bool deleteBackward);
bool getDeleteBackward();
protected:
bool m_bMaxLengthEnabled;
int m_nMaxLength;
bool m_bPasswordEnabled;
std::string m_strPasswordStyleText;
bool m_bAttachWithIME;
bool m_bDetachWithIME;
bool m_bInsertText;
bool m_bDeleteBackward;
bool _maxLengthEnabled;
int _maxLength;
bool _passwordEnabled;
std::string _passwordStyleText;
bool _attachWithIME;
bool _detachWithIME;
bool _insertText;
bool _deleteBackward;
};
typedef enum
{
TEXTFIELD_EVENT_ATTACH_WITH_IME,
TEXTFIELD_EVENT_DETACH_WITH_IME,
TEXTFIELD_EVENT_INDERT_TEXT,
TEXTFIELD_EVENT_INSERT_TEXT,
TEXTFIELD_EVENT_DELETE_BACKWARD,
}TextFiledEventType;
typedef void (cocos2d::Object::*SEL_TextFieldEvent)(cocos2d::Object*, TextFiledEventType);
#define textfieldeventselector(_SELECTOR) (SEL_TextFieldEvent)(&_SELECTOR)
//class UITextField : public UIWidget
/** class UITextField : public UIWidget
* @js NA
* @lua NA
*/
class UITextField : public UIWidget
{
public:
@ -129,22 +133,19 @@ public:
bool getDeleteBackward();
void setDeleteBackward(bool deleteBackward);
void addEventListener(cocos2d::Object* target, SEL_TextFieldEvent selecor);
virtual void setAnchorPoint(const cocos2d::Point &pt);
virtual void setColor(const cocos2d::Color3B &color);
virtual void setOpacity(int opacity);
/**
* Returns the "class name" of widget.
*/
virtual const char* getDescription() const;
/*compatibel*/
/**
* These methods will be removed
*/
void setMaxLengthEnable(bool is){setMaxLengthEnabled(is);};
void setPasswordEnable(bool is){setPasswordEnabled(is);};
/************/
virtual const cocos2d::Size& getContentSize() const;
virtual cocos2d::Node* getVirtualRenderer();
void attachWithIME();
protected:
// event
void attachWithIMEEvent();
@ -153,9 +154,11 @@ protected:
void deleteBackwardEvent();
virtual void onSizeChanged();
void textfieldRendererScaleChangedWithSize();
virtual UIWidget* createCloneInstance();
virtual void copySpecialProperties(UIWidget* model);
protected:
UICCTextField* _textFieldRenderer;
float _touchWidth;
float _touchHeight;
bool _useTouchArea;
@ -163,6 +166,7 @@ protected:
cocos2d::Object* _eventListener;
SEL_TextFieldEvent _eventSelector;
std::string _passwordStyleText;
};
}

View File

@ -24,11 +24,9 @@
#include "gui/UIWidget.h"
#include "gui/UILayer.h"
#include "gui/Layout.h"
#include "gui/UILayout.h"
#include "gui/UIHelper.h"
using namespace cocos2d;
namespace gui {
#define DYNAMIC_CAST_CCBLENDPROTOCOL dynamic_cast<cocos2d::BlendProtocol*>(_renderer)
@ -45,31 +43,31 @@ _touchEnabled(false),
_touchPassedEnabled(false),
_focus(false),
_widgetZOrder(0),
_anchorPoint(Point(0.5f, 0.5f)),
_anchorPoint(cocos2d::Point(0.5f, 0.5f)),
_widgetParent(NULL),
_brightStyle(BRIGHT_NONE),
_updateEnabled(false),
_renderer(NULL),
_touchStartPos(Point::ZERO),
_touchMovePos(Point::ZERO),
_touchEndPos(Point::ZERO),
_touchStartPos(cocos2d::Point::ZERO),
_touchMovePos(cocos2d::Point::ZERO),
_touchEndPos(cocos2d::Point::ZERO),
_touchEventListener(NULL),
_touchEventSelector(NULL),
_widgetTag(-1),
_name("default"),
_widgetType(WidgetTypeWidget),
_actionTag(0),
_size(Size::ZERO),
_customSize(Size::ZERO),
_layoutParameter(NULL),
_size(cocos2d::Size::ZERO),
_customSize(cocos2d::Size::ZERO),
_layoutParameterDictionary(NULL),
_ignoreSize(false),
_children(NULL),
_affectByClipping(false),
_scheduler(NULL),
_sizeType(SIZE_ABSOLUTE),
_sizePercent(Point::ZERO),
_sizePercent(cocos2d::Point::ZERO),
_positionType(POSITION_ABSOLUTE),
_positionPercent(Point::ZERO),
_positionPercent(cocos2d::Point::ZERO),
_isRunning(false)
{
@ -79,7 +77,8 @@ UIWidget::~UIWidget()
{
releaseResoures();
setParent(NULL);
CC_SAFE_RELEASE_NULL(_layoutParameter);
_layoutParameterDictionary->removeAllObjects();
CC_SAFE_RELEASE(_layoutParameterDictionary);
CC_SAFE_RELEASE(_scheduler);
}
@ -97,12 +96,14 @@ UIWidget* UIWidget::create()
bool UIWidget::init()
{
_children = Array::create();
_children = cocos2d::Array::create();
_children->retain();
_layoutParameterDictionary = cocos2d::Dictionary::create();
CC_SAFE_RETAIN(_layoutParameterDictionary);
initRenderer();
_renderer->retain();
_renderer->setZOrder(_widgetZOrder);
RGBAProtocol* renderRGBA = DYNAMIC_CAST_CCRGBAPROTOCOL;
cocos2d::RGBAProtocol* renderRGBA = DYNAMIC_CAST_CCRGBAPROTOCOL;
if (renderRGBA)
{
renderRGBA->setCascadeColorEnabled(true);
@ -110,14 +111,13 @@ bool UIWidget::init()
}
setBright(true);
ignoreContentAdaptWithSize(true);
_scheduler = Director::getInstance()->getScheduler();
_scheduler = cocos2d::Director::getInstance()->getScheduler();
CC_SAFE_RETAIN(_scheduler);
return true;
}
void UIWidget::releaseResoures()
{
setUpdateEnabled(false);
removeAllChildren();
_children->release();
_renderer->removeAllChildrenWithCleanup(true);
@ -157,7 +157,7 @@ bool UIWidget::addChild(UIWidget *child)
else
{
bool seekSucceed = false;
ccArray* arrayChildren = _children->data;
cocos2d::ccArray* arrayChildren = _children->data;
for (int i=childrenCount-1; i>=0; --i)
{
UIWidget* widget = (UIWidget*)(arrayChildren->arr[i]);
@ -203,7 +203,7 @@ bool UIWidget::removeChild(UIWidget *child)
{
child->onExit();
}
child->disableUpdate();
child->setUpdateEnabled(false);
child->setParent(NULL);
_renderer->removeChild(child->getRenderer());
_children->removeObject(child);
@ -246,7 +246,7 @@ void UIWidget::reorderChild(UIWidget* child)
else
{
bool seekSucceed = false;
ccArray* arrayChildren = _children->data;
cocos2d::ccArray* arrayChildren = _children->data;
for (int i=childrenCount-1; i>=0; --i)
{
UIWidget* widget = (UIWidget*)(arrayChildren->arr[i]);
@ -274,21 +274,6 @@ void UIWidget::reorderChild(UIWidget* child)
CC_SAFE_RELEASE(child);
}
void UIWidget::disableUpdate()
{
if (_scheduler)
{
_scheduler->unscheduleUpdateForTarget(this);
}
int childrenCount = _children->data->num;
ccArray* arrayChildren = _children->data;
for (int i=0; i<childrenCount; i++)
{
UIWidget* child = (UIWidget*)(arrayChildren->arr[i]);
child->disableUpdate();
}
}
void UIWidget::setEnabled(bool enabled)
{
_enabled = enabled;
@ -299,9 +284,9 @@ void UIWidget::setEnabled(bool enabled)
}
else
{
dynamic_cast<RectClippingNode*>(_renderer)->setEnabled(enabled);
dynamic_cast<UIRectClippingNode*>(_renderer)->setEnabled(enabled);
}
ccArray* arrayChildren = _children->data;
cocos2d::ccArray* arrayChildren = _children->data;
int childrenCount = arrayChildren->num;
for (int i = 0; i < childrenCount; i++)
{
@ -312,15 +297,15 @@ void UIWidget::setEnabled(bool enabled)
UIWidget* UIWidget::getChildByName(const char *name)
{
return CCUIHELPER->seekWidgetByName(this, name);
return UIHelper::seekWidgetByName(this, name);
}
UIWidget* UIWidget::getChildByTag(int tag)
{
return CCUIHELPER->seekWidgetByTag(this, tag);
return UIHelper::seekWidgetByTag(this, tag);
}
Array* UIWidget::getChildren()
cocos2d::Array* UIWidget::getChildren()
{
return _children;
}
@ -330,7 +315,7 @@ void UIWidget::initRenderer()
_renderer = GUIRenderer::create();
}
void UIWidget::setSize(const Size &size)
void UIWidget::setSize(const cocos2d::Size &size)
{
_customSize = size;
if (_ignoreSize)
@ -343,19 +328,19 @@ void UIWidget::setSize(const Size &size)
}
if (_isRunning)
{
_sizePercent = (_widgetParent == NULL) ? Point::ZERO : Point(_customSize.width / _widgetParent->getSize().width, _customSize.height / _widgetParent->getSize().height);
_sizePercent = (_widgetParent == NULL) ? cocos2d::Point::ZERO : cocos2d::Point(_customSize.width / _widgetParent->getSize().width, _customSize.height / _widgetParent->getSize().height);
}
onSizeChanged();
}
void UIWidget::setSizePercent(const Point &percent)
void UIWidget::setSizePercent(const cocos2d::Point &percent)
{
_sizePercent = percent;
if (!_isRunning)
{
return;
}
Size cSize = (_widgetParent == NULL) ? Size::ZERO : Size(_widgetParent->getSize().width * percent.x , _widgetParent->getSize().height * percent.y);
cocos2d::Size cSize = (_widgetParent == NULL) ? cocos2d::Size::ZERO : cocos2d::Size(_widgetParent->getSize().width * percent.x , _widgetParent->getSize().height * percent.y);
if (_ignoreSize)
{
_size = getContentSize();
@ -381,11 +366,11 @@ void UIWidget::updateSizeAndPosition()
{
_size = _customSize;
}
_sizePercent = (_widgetParent == NULL) ? Point::ZERO : Point(_customSize.width / _widgetParent->getSize().width, _customSize.height / _widgetParent->getSize().height);
_sizePercent = (_widgetParent == NULL) ? cocos2d::Point::ZERO : cocos2d::Point(_customSize.width / _widgetParent->getSize().width, _customSize.height / _widgetParent->getSize().height);
break;
case SIZE_PERCENT:
{
Size cSize = (_widgetParent == NULL) ? Size::ZERO : Size(_widgetParent->getSize().width * _sizePercent.x , _widgetParent->getSize().height * _sizePercent.y);
cocos2d::Size cSize = (_widgetParent == NULL) ? cocos2d::Size::ZERO : cocos2d::Size(_widgetParent->getSize().width * _sizePercent.x , _widgetParent->getSize().height * _sizePercent.y);
if (_ignoreSize)
{
_size = getContentSize();
@ -401,16 +386,16 @@ void UIWidget::updateSizeAndPosition()
break;
}
onSizeChanged();
Point absPos = getPosition();
cocos2d::Point absPos = getPosition();
switch (_positionType)
{
case POSITION_ABSOLUTE:
_positionPercent = (_widgetParent == NULL) ? Point::ZERO : Point(absPos.x / _widgetParent->getSize().width, absPos.y / _widgetParent->getSize().height);
_positionPercent = (_widgetParent == NULL) ? cocos2d::Point::ZERO : cocos2d::Point(absPos.x / _widgetParent->getSize().width, absPos.y / _widgetParent->getSize().height);
break;
case POSITION_PERCENT:
{
Size parentSize = _widgetParent->getSize();
absPos = Point(parentSize.width * _positionPercent.x, parentSize.height * _positionPercent.y);
cocos2d::Size parentSize = _widgetParent->getSize();
absPos = cocos2d::Point(parentSize.width * _positionPercent.x, parentSize.height * _positionPercent.y);
}
break;
default:
@ -434,7 +419,7 @@ void UIWidget::ignoreContentAdaptWithSize(bool ignore)
_ignoreSize = ignore;
if (_ignoreSize)
{
Size s = getContentSize();
cocos2d::Size s = getContentSize();
_size = s;
}
else
@ -449,27 +434,27 @@ bool UIWidget::isIgnoreContentAdaptWithSize() const
return _ignoreSize;
}
const Size& UIWidget::getSize() const
const cocos2d::Size& UIWidget::getSize() const
{
return _size;
}
const Point& UIWidget::getSizePercent() const
const cocos2d::Point& UIWidget::getSizePercent() const
{
return _sizePercent;
}
Point UIWidget::getWorldPosition()
cocos2d::Point UIWidget::getWorldPosition()
{
return _renderer->convertToWorldSpace(Point::ZERO);
return _renderer->convertToWorldSpace(cocos2d::Point::ZERO);
}
Point UIWidget::convertToWorldSpace(const Point& pt)
cocos2d::Point UIWidget::convertToWorldSpace(const cocos2d::Point& pt)
{
return _renderer->convertToWorldSpace(pt);
}
Node* UIWidget::getVirtualRenderer()
cocos2d::Node* UIWidget::getVirtualRenderer()
{
return _renderer;
}
@ -479,7 +464,7 @@ void UIWidget::onSizeChanged()
}
const Size& UIWidget::getContentSize() const
const cocos2d::Size& UIWidget::getContentSize() const
{
return _size;
}
@ -511,6 +496,10 @@ bool UIWidget::isTouchEnabled() const
void UIWidget::setUpdateEnabled(bool enable)
{
if (enable == _updateEnabled)
{
return;
}
_updateEnabled = enable;
if (enable)
{
@ -616,7 +605,7 @@ void UIWidget::didNotSelectSelf()
}
bool UIWidget::onTouchBegan(const Point &touchPoint)
bool UIWidget::onTouchBegan(const cocos2d::Point &touchPoint)
{
setFocused(true);
_touchStartPos.x = touchPoint.x;
@ -629,7 +618,7 @@ bool UIWidget::onTouchBegan(const Point &touchPoint)
return _touchPassedEnabled;
}
void UIWidget::onTouchMoved(const Point &touchPoint)
void UIWidget::onTouchMoved(const cocos2d::Point &touchPoint)
{
_touchMovePos.x = touchPoint.x;
_touchMovePos.y = touchPoint.y;
@ -641,7 +630,7 @@ void UIWidget::onTouchMoved(const Point &touchPoint)
moveEvent();
}
void UIWidget::onTouchEnded(const Point &touchPoint)
void UIWidget::onTouchEnded(const cocos2d::Point &touchPoint)
{
_touchEndPos.x = touchPoint.x;
_touchEndPos.y = touchPoint.y;
@ -661,13 +650,13 @@ void UIWidget::onTouchEnded(const Point &touchPoint)
}
}
void UIWidget::onTouchCancelled(const Point &touchPoint)
void UIWidget::onTouchCancelled(const cocos2d::Point &touchPoint)
{
setFocused(false);
cancelUpEvent();
}
void UIWidget::onTouchLongClicked(const Point &touchPoint)
void UIWidget::onTouchLongClicked(const cocos2d::Point &touchPoint)
{
longClickEvent();
}
@ -709,31 +698,31 @@ void UIWidget::longClickEvent()
}
void UIWidget::addTouchEventListener(Object *target, SEL_TouchEvent selector)
void UIWidget::addTouchEventListener(cocos2d::Object *target, SEL_TouchEvent selector)
{
_touchEventListener = target;
_touchEventSelector = selector;
}
Node* UIWidget::getRenderer()
cocos2d::Node* UIWidget::getRenderer()
{
return _renderer;
}
void UIWidget::addRenderer(Node* renderer, int zOrder)
void UIWidget::addRenderer(cocos2d::Node* renderer, int zOrder)
{
_renderer->addChild(renderer, zOrder);
}
void UIWidget::removeRenderer(Node* renderer, bool cleanup)
void UIWidget::removeRenderer(cocos2d::Node* renderer, bool cleanup)
{
_renderer->removeChild(renderer,cleanup);
}
bool UIWidget::hitTest(const Point &pt)
bool UIWidget::hitTest(const cocos2d::Point &pt)
{
Point nsp = _renderer->convertToNodeSpace(pt);
Rect bb = Rect(-_size.width * _anchorPoint.x, -_size.height * _anchorPoint.y, _size.width, _size.height);
cocos2d::Point nsp = _renderer->convertToNodeSpace(pt);
cocos2d::Rect bb = cocos2d::Rect(-_size.width * _anchorPoint.x, -_size.height * _anchorPoint.y, _size.width, _size.height);
if (nsp.x >= bb.origin.x && nsp.x <= bb.origin.x + bb.size.width && nsp.y >= bb.origin.y && nsp.y <= bb.origin.y + bb.size.height)
{
return true;
@ -741,14 +730,14 @@ bool UIWidget::hitTest(const Point &pt)
return false;
}
bool UIWidget::clippingParentAreaContainPoint(const Point &pt)
bool UIWidget::clippingParentAreaContainPoint(const cocos2d::Point &pt)
{
_affectByClipping = false;
UIWidget* parent = getParent();
UIWidget* clippingParent = NULL;
while (parent)
{
Layout* layoutParent = dynamic_cast<Layout*>(parent);
UILayout* layoutParent = dynamic_cast<UILayout*>(parent);
if (layoutParent)
{
if (layoutParent->isClippingEnabled())
@ -783,7 +772,7 @@ bool UIWidget::clippingParentAreaContainPoint(const Point &pt)
return true;
}
void UIWidget::checkChildInfo(int handleState, UIWidget *sender, const Point &touchPoint)
void UIWidget::checkChildInfo(int handleState, UIWidget *sender, const cocos2d::Point &touchPoint)
{
if (_widgetParent)
{
@ -791,27 +780,27 @@ void UIWidget::checkChildInfo(int handleState, UIWidget *sender, const Point &to
}
}
void UIWidget::setPosition(const Point &pos)
void UIWidget::setPosition(const cocos2d::Point &pos)
{
if (_isRunning)
{
_positionPercent = (_widgetParent == NULL) ? Point::ZERO : Point(pos.x / _widgetParent->getSize().width, pos.y / _widgetParent->getSize().height);
_positionPercent = (_widgetParent == NULL) ? cocos2d::Point::ZERO : cocos2d::Point(pos.x / _widgetParent->getSize().width, pos.y / _widgetParent->getSize().height);
}
_renderer->setPosition(pos);
}
void UIWidget::setPositionPercent(const Point &percent)
void UIWidget::setPositionPercent(const cocos2d::Point &percent)
{
_positionPercent = percent;
if (_isRunning)
{
Size parentSize = _widgetParent->getSize();
Point absPos = Point(parentSize.width * _positionPercent.x, parentSize.height * _positionPercent.y);
cocos2d::Size parentSize = _widgetParent->getSize();
cocos2d::Point absPos = cocos2d::Point(parentSize.width * _positionPercent.x, parentSize.height * _positionPercent.y);
_renderer->setPosition(absPos);
}
}
void UIWidget::setAnchorPoint(const Point &pt)
void UIWidget::setAnchorPoint(const cocos2d::Point &pt)
{
_anchorPoint = pt;
_renderer->setAnchorPoint(pt);
@ -822,12 +811,12 @@ void UIWidget::updateAnchorPoint()
setAnchorPoint(_anchorPoint);
}
const Point& UIWidget::getPosition()
const cocos2d::Point& UIWidget::getPosition()
{
return _renderer->getPosition();
}
const Point& UIWidget::getPositionPercent()
const cocos2d::Point& UIWidget::getPositionPercent()
{
return _positionPercent;
}
@ -842,7 +831,7 @@ PositionType UIWidget::getPositionType() const
return _positionType;
}
const Point& UIWidget::getAnchorPoint()
const cocos2d::Point& UIWidget::getAnchorPoint()
{
return _anchorPoint;
}
@ -930,36 +919,12 @@ bool UIWidget::isEnabled() const
float UIWidget::getLeftInParent()
{
float leftPos = 0.0f;
switch (_widgetType)
{
case WidgetTypeWidget:
leftPos = getPosition().x - getAnchorPoint().x * _size.width;
break;
case WidgetTypeContainer:
leftPos = getPosition().x;
break;
default:
break;
}
return leftPos;
return getPosition().x - getAnchorPoint().x * _size.width;;
}
float UIWidget::getBottomInParent()
{
float bottomPos = 0.0f;
switch (_widgetType)
{
case WidgetTypeWidget:
bottomPos = getPosition().y - getAnchorPoint().y * _size.height;
break;
case WidgetTypeContainer:
bottomPos = getPosition().y;
break;
default:
break;
}
return bottomPos;
return getPosition().y - getAnchorPoint().y * _size.height;;
}
float UIWidget::getRightInParent()
@ -982,17 +947,17 @@ void UIWidget::setParent(UIWidget* parent)
_widgetParent = parent;
}
Action* UIWidget::runAction(Action *action)
cocos2d::Action* UIWidget::runAction(cocos2d::Action *action)
{
return _renderer->runAction(action);
}
void UIWidget::setActionManager(ActionManager *actionManager)
void UIWidget::setActionManager(cocos2d::ActionManager *actionManager)
{
_renderer->setActionManager(actionManager);
}
ActionManager* UIWidget::getActionManager()
cocos2d::ActionManager* UIWidget::getActionManager()
{
return _renderer->getActionManager();
}
@ -1002,7 +967,7 @@ void UIWidget::stopAllActions()
_renderer->stopAllActions();
}
void UIWidget::stopAction(Action *action)
void UIWidget::stopAction(cocos2d::Action *action)
{
_renderer->stopAction(action);
}
@ -1012,33 +977,33 @@ void UIWidget::stopActionByTag(int tag)
_renderer->stopActionByTag(tag);
}
Action* UIWidget::getActionByTag(int tag)
cocos2d::Action* UIWidget::getActionByTag(int tag)
{
return _renderer->getActionByTag(tag);
}
void UIWidget::setColor(const Color3B &color)
void UIWidget::setColor(const cocos2d::Color3B &color)
{
RGBAProtocol* rgbap = DYNAMIC_CAST_CCRGBAPROTOCOL;
cocos2d::RGBAProtocol* rgbap = DYNAMIC_CAST_CCRGBAPROTOCOL;
if (rgbap)
{
rgbap->setColor(color);
}
}
const Color3B& UIWidget::getColor()
const cocos2d::Color3B& UIWidget::getColor()
{
RGBAProtocol* rgbap = DYNAMIC_CAST_CCRGBAPROTOCOL;
cocos2d::RGBAProtocol* rgbap = DYNAMIC_CAST_CCRGBAPROTOCOL;
if (rgbap)
{
return rgbap->getColor();
}
return Color3B::WHITE;
return cocos2d::Color3B::WHITE;
}
void UIWidget::setOpacity(int opacity)
{
RGBAProtocol* rgbap = DYNAMIC_CAST_CCRGBAPROTOCOL;
cocos2d::RGBAProtocol* rgbap = DYNAMIC_CAST_CCRGBAPROTOCOL;
if (rgbap)
{
rgbap->setOpacity(opacity);
@ -1047,7 +1012,7 @@ void UIWidget::setOpacity(int opacity)
int UIWidget::getOpacity()
{
RGBAProtocol* rgbap = DYNAMIC_CAST_CCRGBAPROTOCOL;
cocos2d::RGBAProtocol* rgbap = DYNAMIC_CAST_CCRGBAPROTOCOL;
if (rgbap)
{
return rgbap->getOpacity();
@ -1057,7 +1022,7 @@ int UIWidget::getOpacity()
bool UIWidget::isCascadeOpacityEnabled()
{
RGBAProtocol* rgbap = DYNAMIC_CAST_CCRGBAPROTOCOL;
cocos2d::RGBAProtocol* rgbap = DYNAMIC_CAST_CCRGBAPROTOCOL;
if (rgbap)
{
return rgbap->isCascadeOpacityEnabled();
@ -1067,7 +1032,7 @@ bool UIWidget::isCascadeOpacityEnabled()
void UIWidget::setCascadeOpacityEnabled(bool cascadeOpacityEnabled)
{
RGBAProtocol* rgbap = DYNAMIC_CAST_CCRGBAPROTOCOL;
cocos2d::RGBAProtocol* rgbap = DYNAMIC_CAST_CCRGBAPROTOCOL;
if (rgbap)
{
rgbap->setCascadeOpacityEnabled(cascadeOpacityEnabled);
@ -1076,7 +1041,7 @@ void UIWidget::setCascadeOpacityEnabled(bool cascadeOpacityEnabled)
bool UIWidget::isCascadeColorEnabled()
{
RGBAProtocol* rgbap = DYNAMIC_CAST_CCRGBAPROTOCOL;
cocos2d::RGBAProtocol* rgbap = DYNAMIC_CAST_CCRGBAPROTOCOL;
if (rgbap)
{
return rgbap->isCascadeColorEnabled();
@ -1086,33 +1051,33 @@ bool UIWidget::isCascadeColorEnabled()
void UIWidget::setCascadeColorEnabled(bool cascadeColorEnabled)
{
RGBAProtocol* rgbap = DYNAMIC_CAST_CCRGBAPROTOCOL;
cocos2d::RGBAProtocol* rgbap = DYNAMIC_CAST_CCRGBAPROTOCOL;
if (rgbap)
{
rgbap->setCascadeColorEnabled(cascadeColorEnabled);
}
}
void UIWidget::setBlendFunc(BlendFunc blendFunc)
void UIWidget::setBlendFunc(cocos2d::BlendFunc blendFunc)
{
BlendProtocol * blendNode = DYNAMIC_CAST_CCBLENDPROTOCOL;
cocos2d::BlendProtocol * blendNode = DYNAMIC_CAST_CCBLENDPROTOCOL;
if (blendNode)
{
blendNode->setBlendFunc(blendFunc);
}
}
const Point& UIWidget::getTouchStartPos()
const cocos2d::Point& UIWidget::getTouchStartPos()
{
return _touchStartPos;
}
const Point& UIWidget::getTouchMovePos()
const cocos2d::Point& UIWidget::getTouchMovePos()
{
return _touchMovePos;
}
const Point& UIWidget::getTouchEndPos()
const cocos2d::Point& UIWidget::getTouchEndPos()
{
return _touchEndPos;
}
@ -1142,19 +1107,14 @@ WidgetType UIWidget::getWidgetType() const
return _widgetType;
}
void UIWidget::setLayoutParameter(LayoutParameter *parameter)
void UIWidget::setLayoutParameter(UILayoutParameter *parameter)
{
if (_layoutParameter)
{
CC_SAFE_RELEASE_NULL(_layoutParameter);
}
_layoutParameter = parameter;
CC_SAFE_RETAIN(_layoutParameter);
_layoutParameterDictionary->setObject(parameter, parameter->getLayoutType());
}
LayoutParameter* UIWidget::getLayoutParameter()
UILayoutParameter* UIWidget::getLayoutParameter(LayoutParameterType type)
{
return _layoutParameter;
return dynamic_cast<UILayoutParameter*>(_layoutParameterDictionary->objectForKey(type));
}
const char* UIWidget::getDescription() const
@ -1162,6 +1122,71 @@ const char* UIWidget::getDescription() const
return "Widget";
}
UIWidget* UIWidget::clone()
{
UIWidget* clonedWidget = createCloneInstance();
clonedWidget->copyProperties(this);
clonedWidget->copyClonedWidgetChildren(this);
return clonedWidget;
}
UIWidget* UIWidget::createCloneInstance()
{
return UIWidget::create();
}
void UIWidget::copyClonedWidgetChildren(UIWidget* model)
{
cocos2d::ccArray* arrayWidgetChildren = model->getChildren()->data;
int length = arrayWidgetChildren->num;
for (int i=0; i<length; i++)
{
UIWidget* child = (UIWidget*)(arrayWidgetChildren->arr[i]);
addChild(child->clone());
}
}
void UIWidget::copySpecialProperties(UIWidget* model)
{
}
void UIWidget::copyProperties(UIWidget *widget)
{
setEnabled(widget->isEnabled());
setVisible(widget->isVisible());
setBright(widget->isBright());
setTouchEnabled(widget->isTouchEnabled());
_touchPassedEnabled = false;
setZOrder(widget->getZOrder());
setUpdateEnabled(widget->isUpdateEnabled());
setTag(widget->getTag());
setName(widget->getName());
setActionTag(widget->getActionTag());
_ignoreSize = widget->_ignoreSize;
_size = widget->_size;
_customSize = widget->_customSize;
copySpecialProperties(widget);
_sizeType = widget->getSizeType();
_sizePercent = widget->_sizePercent;
_positionType = widget->_positionType;
_positionPercent = widget->_positionPercent;
setPosition(widget->getPosition());
setAnchorPoint(widget->getAnchorPoint());
setScaleX(widget->getScaleX());
setScaleY(widget->getScaleY());
setRotation(widget->getRotation());
setRotationX(widget->getRotationX());
setRotationY(widget->getRotationY());
setFlipX(widget->isFlipX());
setFlipY(widget->isFlipY());
setColor(widget->getColor());
setOpacity(widget->getOpacity());
setCascadeOpacityEnabled(widget->isCascadeOpacityEnabled());
setCascadeColorEnabled(widget->isCascadeColorEnabled());
onSizeChanged();
}
/*temp action*/
void UIWidget::setActionTag(int tag)
{
@ -1214,7 +1239,7 @@ void GUIRenderer::visit()
{
return;
}
NodeRGBA::visit();
cocos2d::NodeRGBA::visit();
}
}

View File

@ -27,9 +27,9 @@
#include "cocos2d.h"
#include "gui/UILayoutDefine.h"
#include "gui/LayoutParameter.h"
namespace gui {
#include "gui/UILayoutParameter.h"
namespace gui {
typedef enum
{
@ -72,11 +72,10 @@ typedef enum
typedef void (cocos2d::Object::*SEL_TouchEvent)(cocos2d::Object*,TouchEventType);
#define toucheventselector(_SELECTOR) (SEL_TouchEvent)(&_SELECTOR)
//class UILayer;
/*temp action*/
class UIActionNode;
/**
* @js NA
* @lua NA
*/
class UIWidget : public cocos2d::Object
{
public:
@ -260,12 +259,7 @@ public:
* Removes all children from the container, and do a cleanup to all running actions depending on the cleanup parameter.
*/
virtual void removeAllChildren();
/**
* Unschedules the "update" method.
*/
void disableUpdate();
/**
* Reorders a child according to a new z value.
*
@ -304,27 +298,27 @@ public:
/**
* Gets the renderer of widget
*
* renderer is a CCNode, it's for drawing
* renderer is a Node, it's for drawing
*
* @return a CCNode object
* @return a Node object
*/
cocos2d::Node* getRenderer();
/**
* Add a CCNode for rendering.
* Add a Node for rendering.
*
* renderer is a CCNode, it's for drawing
* renderer is a Node, it's for drawing
*
* @param renderer A render node
*
* @param zOrder Z order for drawing priority. Please refer to CCNode::setZOrder(int)
* @param zOrder Z order for drawing priority. Please refer to Node::setZOrder(int)
*/
void addRenderer(cocos2d::Node* renderer, int zOrder);
/**
* Remove a CCNode from widget.
* Remove a Node from widget.
*
* renderer is a CCNode, it's for drawing
* renderer is a Node, it's for drawing
*
* @param renderer A render node which needs to be removed
*
@ -359,7 +353,7 @@ public:
/**
* Changes the position (x,y) of the widget in OpenGL coordinates
*
* Usually we use ccp(x,y) to compose Point object.
* Usually we use p(x,y) to compose Point object.
* The original point (0,0) is at the left-bottom corner of screen.
*
* @param position The position (x,y) of the widget in OpenGL coordinates
@ -369,7 +363,7 @@ public:
/**
* Changes the position (x,y) of the widget in OpenGL coordinates
*
* Usually we use ccp(x,y) to compose Point object.
* Usually we use p(x,y) to compose Point object.
* The original point (0,0) is at the left-bottom corner of screen.
*
* @param percent The percent (x,y) of the widget in OpenGL coordinates
@ -809,15 +803,21 @@ public:
* @see LayoutParameter
*
* @param LayoutParameter pointer
*
* @param type Relative or Linear
*/
void setLayoutParameter(LayoutParameter* parameter);
void setLayoutParameter(UILayoutParameter* parameter);
/**
* Gets LayoutParameter of widget.
*
* @see LayoutParameter
*
* @param type Relative or Linear
*
* @return LayoutParameter
*/
LayoutParameter* getLayoutParameter();
UILayoutParameter* getLayoutParameter(LayoutParameterType type);
/**
* Ignore the widget size
@ -850,7 +850,7 @@ public:
*
* For example, a button's Virtual Renderer is it's texture renderer.
*
* @return CCNode pointer.
* @return Node pointer.
*/
virtual cocos2d::Node* getVirtualRenderer();
@ -871,14 +871,15 @@ public:
*/
virtual const cocos2d::Size& getContentSize() const;
virtual void onEnter();
virtual void onExit();
/**
* Returns the "class name" of widget.
*/
virtual const char* getDescription() const;
UIWidget* clone();
virtual void onEnter();
virtual void onExit();
/*temp action*/
void setActionTag(int tag);
int getActionTag();
@ -913,6 +914,10 @@ protected:
*/
virtual void releaseResoures();
void updateSizeAndPosition();
void copyProperties(UIWidget* model);
virtual UIWidget* createCloneInstance();
virtual void copySpecialProperties(UIWidget* model);
virtual void copyClonedWidgetChildren(UIWidget* model);
protected:
bool _enabled; ///< Highest control of widget
bool _visible; ///< is this widget visible
@ -930,7 +935,7 @@ protected:
cocos2d::Point _touchMovePos; ///< touch moved point
cocos2d::Point _touchEndPos; ///< touch ended point
cocos2d::Object* _touchEventListener;
Object* _touchEventListener;
SEL_TouchEvent _touchEventSelector;
@ -941,7 +946,7 @@ protected:
int _actionTag;
cocos2d::Size _size;
cocos2d::Size _customSize;
LayoutParameter* _layoutParameter;
cocos2d::Dictionary* _layoutParameterDictionary;
bool _ignoreSize;
cocos2d::Array* _children;
bool _affectByClipping;
@ -954,7 +959,10 @@ protected:
cocos2d::Point _positionPercent;
bool _isRunning;
};
/**
* @js NA
* @lua NA
*/
class GUIRenderer : public cocos2d::NodeRGBA
{
public:
@ -969,5 +977,4 @@ protected:
};
}
#endif /* defined(__UIWidget__) */

View File

@ -19,7 +19,6 @@ CocosGUITestScene::~CocosGUITestScene()
{
cocostudio::SceneReader::getInstance()->purgeSceneReader();
cocostudio::ActionManagerEx::purgeActionManager();
gui::UIHelper::purgeUIHelper();
}
void CocosGUITestScene::runThisTest()

View File

@ -44,78 +44,25 @@ bool UIDragPanelTest::init()
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.925));
m_pUiLayer->addWidget(alert);
Layout *background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
// Create the dragpanel
UIDragPanel* dragPanel = UIDragPanel::create();
dragPanel->setTouchEnabled(true);
dragPanel->setBackGroundImageScale9Enabled(true);
dragPanel->setBackGroundImage("cocosgui/scrollviewbg.png");
dragPanel->setSize(Size(210, 122.5));
Size backgroundSize = background->getContentSize();
dragPanel->setPosition(Point((widgetSize.width - backgroundSize.width) / 2 +
(backgroundSize.width - dragPanel->getSize().width) / 2,
(widgetSize.height - backgroundSize.height) / 2 +
(backgroundSize.height - dragPanel->getSize().height) / 2));
dragPanel->addEventListener(this, dragpaneleventselector(UIDragPanelTest::dragPanelEvent));
UIImageView* imageView = UIImageView::create();
imageView->setTouchEnabled(true);
imageView->loadTexture("cocosgui/b11.png");
dragPanel->addChild(imageView);
dragPanel->setInnerContainerSize(imageView->getContentSize());
Size innerSize = dragPanel->getInnerContainerSize();
imageView->setPosition(Point(innerSize.width / 2, innerSize.height / 2));
m_pUiLayer->addWidget(dragPanel);
UIScrollView* sc = UIScrollView::create();
sc->setBackGroundColor(Color3B::GREEN);
sc->setBackGroundColorType(LAYOUT_COLOR_SOLID);
sc->setDirection(SCROLLVIEW_DIR_BOTH);
sc->setInnerContainerSize(Size(480, 320));
sc->setSize(Size(100,100));
sc->setPosition(Point(100,100));
sc->scrollToPercentBothDirection(Point(50, 50), 1, true);
UIImageView* iv = UIImageView::create();
iv->loadTexture("cocosgui/Hello.png");
iv->setPosition(Point(240, 160));
sc->addChild(iv);
m_pUiLayer->addWidget(sc);
return true;
}
return false;
}
void UIDragPanelTest::dragPanelEvent(Object *pSender, DragPanelEventType type)
{
switch (type)
{
case DRAGPANEL_EVENT_BERTH_LEFTBOTTOM:
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Left Bottom")->getCString());
break;
case DRAGPANEL_EVENT_BERTH_LFETTOP:
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Left Top")->getCString());
break;
case DRAGPANEL_EVENT_BERTH_RIGHTBOTTOM:
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Right Bottom")->getCString());
break;
case DRAGPANEL_EVENT_BERTH_RIGHTTOP:
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Right Top")->getCString());
break;
case DRAGPANEL_EVENT_BERTH_LEFT:
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Left")->getCString());
break;
case DRAGPANEL_EVENT_BERTH_TOP:
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Top")->getCString());
break;
case DRAGPANEL_EVENT_BERTH_RIGHT:
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Right")->getCString());
break;
case DRAGPANEL_EVENT_BERTH_BOTTOM:
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Bottom")->getCString());
break;
default:
break;
}
}
// UIDragPanelTest_Bounce
UIDragPanelTest_Bounce::UIDragPanelTest_Bounce()
: m_pDisplayValueLabel(NULL)
@ -151,76 +98,23 @@ bool UIDragPanelTest_Bounce::init()
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.925));
m_pUiLayer->addWidget(alert);
Layout *background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
// Create the dragpanel
UIDragPanel* dragPanel = UIDragPanel::create();
dragPanel->setTouchEnabled(true);
dragPanel->setBounceEnable(true);
dragPanel->setBackGroundImageScale9Enabled(true);
dragPanel->setBackGroundImage("cocosgui/green_edit.png");
dragPanel->setSize(Size(210, 122.5));
Size backgroundSize = background->getContentSize();
dragPanel->setPosition(Point((widgetSize.width - backgroundSize.width) / 2 +
(backgroundSize.width - dragPanel->getSize().width) / 2,
(widgetSize.height - backgroundSize.height) / 2 +
(backgroundSize.height - dragPanel->getSize().height) / 2));
dragPanel->addEventListener(this, dragpaneleventselector(UIDragPanelTest_Bounce::dragPanelEvent));
UIImageView* imageView = UIImageView::create();
imageView->setTouchEnabled(true);
imageView->loadTexture("cocosgui/b11.png");
dragPanel->addChild(imageView);
dragPanel->setInnerContainerSize(imageView->getContentSize());
Size innerSize = dragPanel->getInnerContainerSize();
imageView->setPosition(Point(innerSize.width / 2, innerSize.height / 2));
m_pUiLayer->addWidget(dragPanel);
UIScrollView* sc = UIScrollView::create();
sc->setBackGroundColor(Color3B::GREEN);
sc->setBackGroundColorType(LAYOUT_COLOR_SOLID);
sc->setBounceEnabled(true);
sc->setDirection(SCROLLVIEW_DIR_BOTH);
sc->setInnerContainerSize(Size(480, 320));
sc->setSize(Size(100,100));
sc->setPosition(Point(100,100));
sc->scrollToPercentBothDirection(Point(50, 50), 1, true);
UIImageView* iv = UIImageView::create();
iv->loadTexture("cocosgui/Hello.png");
iv->setPosition(Point(240, 160));
sc->addChild(iv);
m_pUiLayer->addWidget(sc);
return true;
}
return false;
}
void UIDragPanelTest_Bounce::dragPanelEvent(Object *pSender, DragPanelEventType type)
{
switch (type)
{
case DRAGPANEL_EVENT_BOUNCE_LEFTBOTTOM:
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Left Bottom")->getCString());
break;
case DRAGPANEL_EVENT_BOUNCE_LEFTTOP:
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Left Top")->getCString());
break;
case DRAGPANEL_EVENT_BOUNCE_RIGHTBOTTOM:
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Right Bottom")->getCString());
break;
case DRAGPANEL_EVENT_BOUNCE_RIGHTTOP:
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Right Top")->getCString());
break;
case DRAGPANEL_EVENT_BOUNCE_LEFT:
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Left")->getCString());
break;
case DRAGPANEL_EVENT_BOUNCE_TOP:
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Top")->getCString());
break;
case DRAGPANEL_EVENT_BOUNCE_RIGHT:
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Right")->getCString());
break;
case DRAGPANEL_EVENT_BOUNCE_BOTTOM:
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Bottom")->getCString());
break;
default:
break;
}
}

View File

@ -33,7 +33,6 @@ public:
UIDragPanelTest();
~UIDragPanelTest();
bool init();
void dragPanelEvent(Object* pSender, DragPanelEventType type);
protected:
UI_SCENE_CREATE_FUNC(UIDragPanelTest)
@ -46,7 +45,6 @@ public:
UIDragPanelTest_Bounce();
~UIDragPanelTest_Bounce();
bool init();
void dragPanelEvent(Object* pSender, DragPanelEventType type);
protected:
UI_SCENE_CREATE_FUNC(UIDragPanelTest_Bounce)

View File

@ -45,54 +45,23 @@ bool UIListViewTest_Vertical::init()
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.925));
m_pUiLayer->addWidget(alert);
Layout *background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
// Create the list view
m_nCount = 0;
m_array = CCArray::create();
m_array->retain();
for (int i = 0; i < 20; ++i)
UIListView* lv = UIListView::create();
UIButton* model = UIButton::create();
model->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
lv->setItemModel(model);
for (int i=0; i<20; i++)
{
String* ccstr = String::createWithFormat("object_%d", i);
m_array->addObject(ccstr);
lv->pushBackDefaultItem();
}
UIListView *listView = UIListView::create();
listView->setTouchEnabled(true);
listView->setBackGroundImageScale9Enabled(true);
listView->setBackGroundImage("cocosgui/green_edit.png");
listView->setSize(Size(240, 130));
Size backgroundSize = background->getContentSize();
listView->setPosition(Point((widgetSize.width - backgroundSize.width) / 2 +
(backgroundSize.width - listView->getSize().width) / 2,
(widgetSize.height - backgroundSize.height) / 2 +
(backgroundSize.height - listView->getSize().height) / 2));
float listWidth = listView->getSize().width;
float listHeight = listView->getSize().height;
for (int i = 0; i < 5; ++i)
{
UIButton* textButton = UIButton::create();
textButton->setName("TextButton");
textButton->setTouchEnabled(true);
textButton->loadTextures("cocosgui/backtotoppressed.png", "cocosgui/backtotopnormal.png", "");
Layout *layout = Layout::create();
layout->setName(String::createWithFormat("panel_%i", i)->getCString());
layout->setSize(Size(textButton->getSize().width, textButton->getSize().height));
textButton->setPosition(Point(layout->getSize().width / 2, layout->getSize().height / 2));
layout->addChild(textButton);
Size panel_size = layout->getSize();
layout->setPosition(Point((listWidth - panel_size.width) / 2,
(listHeight - (panel_size.height + panel_size.height * 0.25)) - i * (panel_size.height + panel_size.height * 0.25)));
listView->addChild(layout);
}
listView->addEventListenter(this, listvieweventselector(UIListViewTest_Vertical::listViewEvent));
listView->initChildWithDataLength(m_array->count());
m_pUiLayer->addWidget(listView);
lv->setItemsMargin(10);
lv->setGravity(LISTVIEW_GRAVITY_CENTER_HORIZONTAL);
lv->setSize(Size(100, 100));
lv->setBackGroundColorType(LAYOUT_COLOR_SOLID);
lv->setBackGroundColor(Color3B::GREEN);
lv->setPosition(Point(100, 100));
m_pUiLayer->addWidget(lv);
return true;
}
@ -100,46 +69,6 @@ bool UIListViewTest_Vertical::init()
return false;
}
void UIListViewTest_Vertical::listViewEvent(Object *pSender, ListViewEventType type)
{
switch (type)
{
case LISTVIEW_EVENT_INIT_CHILD:
{
String* ccstr = static_cast<String*>(m_array->getObjectAtIndex(m_nCount));
UIListView* list = dynamic_cast<UIListView*>(pSender);
Layout* layout = dynamic_cast<Layout*>(list->getUpdateChild());
UIButton* textButton = dynamic_cast<UIButton*>(layout->getChildByName("TextButton"));
textButton->setTitleText(ccstr->getCString());
m_nCount++;
}
break;
case LISTVIEW_EVENT_UPDATE_CHILD:
{
UIListView* list = dynamic_cast<UIListView*>(pSender);
int index = list->getUpdateDataIndex();
if (index < 0 || index >= list->getDataLength())
{
list->setUpdateSuccess(false);
}
String* ccstr = static_cast<String*>(m_array->getObjectAtIndex(index));
Layout* layout = dynamic_cast<Layout*>(list->getUpdateChild());
UIButton* textButton = dynamic_cast<UIButton*>(layout->getChildByName("TextButton"));
textButton->setTitleText(ccstr->getCString());
list->setUpdateSuccess(true);
}
break;
default:
break;
}
}
// UIListViewTest_Horizontal
UIListViewTest_Horizontal::UIListViewTest_Horizontal()
@ -176,97 +105,26 @@ bool UIListViewTest_Horizontal::init()
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.925));
m_pUiLayer->addWidget(alert);
Layout *background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
UIListView* lv = UIListView::create();
lv->setDirection(SCROLLVIEW_DIR_HORIZONTAL);
UIButton* model = UIButton::create();
model->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
lv->setItemModel(model);
// Create the list view
m_nCount = 0;
m_array = CCArray::create();
m_array->retain();
for (int i = 0; i < 20; ++i)
for (int i=0; i<20; i++)
{
String* ccstr = String::createWithFormat("object_%d", i);
m_array->addObject(ccstr);
lv->pushBackDefaultItem();
}
UIListView *listView = UIListView::create();
listView->setDirection(LISTVIEW_DIR_HORIZONTAL);
listView->setTouchEnabled(true);
listView->setBackGroundImageScale9Enabled(true);
listView->setBackGroundImage("cocosgui/green_edit.png");
listView->setSize(Size(240, 130));
Size backgroundSize = background->getContentSize();
listView->setPosition(Point((widgetSize.width - backgroundSize.width) / 2 +
(backgroundSize.width - listView->getSize().width) / 2,
(widgetSize.height - backgroundSize.height) / 2 +
(backgroundSize.height - listView->getSize().height) / 2));
float listHeight = listView->getSize().height;
for (int i = 0; i < 3; ++i)
{
UIButton* textButton = UIButton::create();
textButton->setName("TextButton");
textButton->setTouchEnabled(true);
textButton->loadTextures("cocosgui/backtotoppressed.png", "cocosgui/backtotopnormal.png", "");
Layout *layout = Layout::create();
layout->setName(String::createWithFormat("panel_%i", i)->getCString());
layout->setSize(Size(textButton->getSize().width, textButton->getSize().height));
textButton->setPosition(Point(layout->getSize().width / 2, layout->getSize().height / 2));
layout->addChild(textButton);
Size layout_size = layout->getSize();
layout->setPosition(Point(0 + (layout_size.width * 0.2) + i * (layout_size.width + layout_size.width * 0.2),
(listHeight - layout_size.height) / 2));
listView->addChild(layout);
}
listView->addEventListenter(this, listvieweventselector(UIListViewTest_Horizontal::listViewEvent));
listView->initChildWithDataLength(m_array->count());
m_pUiLayer->addWidget(listView);
lv->setItemsMargin(10);
lv->setGravity(LISTVIEW_GRAVITY_CENTER_VERTICAL);
lv->setSize(Size(100, 100));
lv->setBackGroundColorType(LAYOUT_COLOR_SOLID);
lv->setBackGroundColor(Color3B::GREEN);
lv->setPosition(Point(100, 100));
m_pUiLayer->addWidget(lv);
return true;
}
return false;
}
void UIListViewTest_Horizontal::listViewEvent(Object *pSender, ListViewEventType type)
{
switch (type)
{
case LISTVIEW_EVENT_INIT_CHILD:
{
String* ccstr = static_cast<String*>(m_array->getObjectAtIndex(m_nCount));
UIListView* list = dynamic_cast<UIListView*>(pSender);
Layout* layout = dynamic_cast<Layout*>(list->getUpdateChild());
UIButton* textButton = dynamic_cast<UIButton*>(layout->getChildByName("TextButton"));
textButton->setTitleText(ccstr->getCString());
m_nCount++;
}
break;
case LISTVIEW_EVENT_UPDATE_CHILD:
{
UIListView* list = dynamic_cast<UIListView*>(pSender);
int index = list->getUpdateDataIndex();
if (index < 0 || index >= list->getDataLength())
{
list->setUpdateSuccess(false);
}
String* ccstr = static_cast<String*>(m_array->getObjectAtIndex(index));
Layout* layout = dynamic_cast<Layout*>(list->getUpdateChild());
UIButton* textButton = dynamic_cast<UIButton*>(layout->getChildByName("TextButton"));
textButton->setTitleText(ccstr->getCString());
list->setUpdateSuccess(true);
}
break;
default:
break;
}
}
}

View File

@ -33,7 +33,6 @@ public:
UIListViewTest_Vertical();
~UIListViewTest_Vertical();
bool init();
void listViewEvent(Object* pSender, ListViewEventType type);
protected:
UI_SCENE_CREATE_FUNC(UIListViewTest_Vertical)
@ -49,7 +48,6 @@ public:
UIListViewTest_Horizontal();
~UIListViewTest_Horizontal();
bool init();
void listViewEvent(Object* pSender, ListViewEventType type);
protected:
UI_SCENE_CREATE_FUNC(UIListViewTest_Horizontal)

View File

@ -44,7 +44,7 @@ bool UIPageViewTest::init()
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.925));
m_pUiLayer->addWidget(alert);
Layout *background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
// Create the page view
UIPageView* pageView = UIPageView::create();
@ -58,7 +58,7 @@ bool UIPageViewTest::init()
for (int i = 0; i < 3; ++i)
{
Layout* layout = Layout::create();
UILayout* layout = UILayout::create();
layout->setSize(Size(240, 130));
UIImageView* imageView = UIImageView::create();

View File

@ -34,10 +34,10 @@ bool UIPanelTest::init()
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.925));
m_pUiLayer->addWidget(alert);
Layout *background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
// Create the layout
Layout* layout = Layout::create();
UILayout* layout = UILayout::create();
layout->setSize(Size(280, 150));
Size backgroundSize = background->getSize();
layout->setPosition(Point((widgetSize.width - backgroundSize.width) / 2 +
@ -98,10 +98,10 @@ bool UIPanelTest_Color::init()
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.925));
m_pUiLayer->addWidget(alert);
Layout *background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
// Create the layout with color render
Layout* layout = Layout::create();
UILayout* layout = UILayout::create();
layout->setBackGroundColorType(LAYOUT_COLOR_SOLID);
layout->setBackGroundColor(Color3B(128, 128, 128));
layout->setSize(Size(280, 150));
@ -163,10 +163,10 @@ bool UIPanelTest_Gradient::init()
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.925));
m_pUiLayer->addWidget(alert);
Layout *background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
// Create the layout with gradient render
Layout* layout = Layout::create();
UILayout* layout = UILayout::create();
layout->setBackGroundColorType(LAYOUT_COLOR_GRADIENT);
layout->setBackGroundColor(Color3B(64, 64, 64), Color3B(192, 192, 192));
layout->setSize(Size(280, 150));
@ -228,10 +228,10 @@ bool UIPanelTest_BackGroundImage::init()
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.925));
m_pUiLayer->addWidget(alert);
Layout *background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
// Create the layout with background image
Layout* layout = Layout::create();
UILayout* layout = UILayout::create();
layout->setClippingEnabled(true);
layout->setBackGroundImage("cocosgui/Hello.png");
layout->setSize(Size(280, 150));
@ -293,10 +293,10 @@ bool UIPanelTest_BackGroundImage_Scale9::init()
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.925));
m_pUiLayer->addWidget(alert);
Layout *background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
// Create the layout with background image
Layout* layout = Layout::create();
UILayout* layout = UILayout::create();
layout->setBackGroundImageScale9Enabled(true);
layout->setBackGroundImage("cocosgui/green_edit.png");
layout->setSize(Size(280, 150));
@ -358,10 +358,10 @@ bool UIPanelTest_Layout_Linear_Vertical::init()
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.925));
m_pUiLayer->addWidget(alert);
Layout *background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
// Create the layout
Layout* layout = Layout::create();
UILayout* layout = UILayout::create();
layout->setLayoutType(LAYOUT_LINEAR_VERTICAL);
layout->setSize(Size(280, 150));
Size backgroundSize = background->getSize();
@ -377,7 +377,7 @@ bool UIPanelTest_Layout_Linear_Vertical::init()
button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
layout->addChild(button);
LinearLayoutParameter* lp1 = LinearLayoutParameter::create();
UILinearLayoutParameter* lp1 = UILinearLayoutParameter::create();
button->setLayoutParameter(lp1);
lp1->setGravity(LINEAR_GRAVITY_CENTER_HORIZONTAL);
lp1->setMargin(UIMargin(0, 5, 0, 10));
@ -389,7 +389,7 @@ bool UIPanelTest_Layout_Linear_Vertical::init()
textButton->setTitleText("Text Button");
layout->addChild(textButton);
LinearLayoutParameter* lp2 = LinearLayoutParameter::create();
UILinearLayoutParameter* lp2 = UILinearLayoutParameter::create();
textButton->setLayoutParameter(lp2);
lp2->setGravity(LINEAR_GRAVITY_CENTER_HORIZONTAL);
lp2->setMargin(UIMargin(0, 10, 0, 10));
@ -402,7 +402,7 @@ bool UIPanelTest_Layout_Linear_Vertical::init()
button_scale9->setSize(Size(100, button_scale9->getContentSize().height));
layout->addChild(button_scale9);
LinearLayoutParameter* lp3 = LinearLayoutParameter::create();
UILinearLayoutParameter* lp3 = UILinearLayoutParameter::create();
button_scale9->setLayoutParameter(lp3);
lp3->setGravity(LINEAR_GRAVITY_CENTER_HORIZONTAL);
lp3->setMargin(UIMargin(0, 10, 0, 10));
@ -441,10 +441,10 @@ bool UIPanelTest_Layout_Linear_Horizontal::init()
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.925));
m_pUiLayer->addWidget(alert);
Layout *background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
// Create the layout
Layout* layout = Layout::create();
UILayout* layout = UILayout::create();
layout->setLayoutType(LAYOUT_LINEAR_HORIZONTAL);
layout->setClippingEnabled(true);
layout->setSize(Size(280, 150));
@ -460,7 +460,7 @@ bool UIPanelTest_Layout_Linear_Horizontal::init()
button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
layout->addChild(button);
LinearLayoutParameter* lp1 = LinearLayoutParameter::create();
UILinearLayoutParameter* lp1 = UILinearLayoutParameter::create();
button->setLayoutParameter(lp1);
lp1->setGravity(LINEAR_GRAVITY_CENTER_VERTICAL);
lp1->setMargin(UIMargin(0, 10, 0, 10));
@ -472,7 +472,7 @@ bool UIPanelTest_Layout_Linear_Horizontal::init()
textButton->setTitleText("Text Button");
layout->addChild(textButton);
LinearLayoutParameter* lp2 = LinearLayoutParameter::create();
UILinearLayoutParameter* lp2 = UILinearLayoutParameter::create();
textButton->setLayoutParameter(lp2);
lp2->setGravity(LINEAR_GRAVITY_CENTER_VERTICAL);
lp2->setMargin(UIMargin(0, 10, 0, 10));
@ -485,7 +485,7 @@ bool UIPanelTest_Layout_Linear_Horizontal::init()
button_scale9->setSize(Size(100, button_scale9->getContentSize().height));
layout->addChild(button_scale9);
LinearLayoutParameter* lp3 = LinearLayoutParameter::create();
UILinearLayoutParameter* lp3 = UILinearLayoutParameter::create();
button_scale9->setLayoutParameter(lp3);
lp3->setGravity(LINEAR_GRAVITY_CENTER_VERTICAL);
lp3->setMargin(UIMargin(0, 10, 0, 10));
@ -524,10 +524,10 @@ bool UIPanelTest_Layout_Relative::init()
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.925));
m_pUiLayer->addWidget(alert);
Layout *background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
// Create the layout
Layout* layout = Layout::create();
UILayout* layout = UILayout::create();
layout->setLayoutType(LAYOUT_RELATIVE);
layout->setSize(Size(280, 150));
layout->setBackGroundColorType(LAYOUT_COLOR_SOLID);
@ -544,9 +544,9 @@ bool UIPanelTest_Layout_Relative::init()
button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
layout->addChild(button);
RelativeLayoutParameter* rp1 = RelativeLayoutParameter::create();
UIRelativeLayoutParameter* rp1 = UIRelativeLayoutParameter::create();
button->setLayoutParameter(rp1);
rp1->setAlign(RELATIVE_ALIGN_PARENT_BOTTOM);
rp1->setAlign(RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL);
// rp1->setMargin(UIMargin(0, 10, 0, 10));
@ -556,9 +556,9 @@ bool UIPanelTest_Layout_Relative::init()
textButton->setTitleText("Text Button");
layout->addChild(textButton);
RelativeLayoutParameter* rp2 = RelativeLayoutParameter::create();
UIRelativeLayoutParameter* rp2 = UIRelativeLayoutParameter::create();
textButton->setLayoutParameter(rp2);
rp2->setAlign(RELATIVE_ALIGN_PARENT_LEFT);
rp2->setAlign(RELATIVE_ALIGN_PARENT_LEFT_BOTTOM);
UIButton* button_scale9 = UIButton::create();
@ -568,9 +568,9 @@ bool UIPanelTest_Layout_Relative::init()
button_scale9->setSize(Size(100, button_scale9->getContentSize().height));
layout->addChild(button_scale9);
RelativeLayoutParameter* rp3 = RelativeLayoutParameter::create();
UIRelativeLayoutParameter* rp3 = UIRelativeLayoutParameter::create();
textButton->setLayoutParameter(rp3);
rp3->setAlign(RELATIVE_ALIGN_PARENT_RIGHT);
rp3->setAlign(RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM);
layout->doLayout();

View File

@ -3,6 +3,7 @@
#include "UIScene.h"
#include "UISceneManager.h"
#include "../ExtensionsTest.h"
#include "editor-support/cocostudio/CCSGUIReader.h"
using namespace gui;
@ -25,7 +26,7 @@ bool UIScene::init()
m_pUiLayer = UILayer::create();
addChild(m_pUiLayer);
m_pWidget = dynamic_cast<Layout*>(CCUIHELPER->createWidgetFromJsonFile("cocosgui/UITest/UITest.json"));
m_pWidget = dynamic_cast<UILayout*>(cocostudio::CCSGUIReader::shareReader()->widgetFromJsonFile("cocosgui/UITest/UITest.json"));
m_pUiLayer->addWidget(m_pWidget);
m_pSceneTitle = dynamic_cast<UILabel*>(m_pUiLayer->getWidgetByName("UItest"));

View File

@ -95,7 +95,7 @@ protected:
protected:
UILayer *m_pUiLayer;
Layout *m_pWidget;
UILayout *m_pWidget;
};
#endif /* defined(__TestCpp__UIScene__) */

View File

@ -44,7 +44,7 @@ bool UIScrollViewTest_Vertical::init()
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.925));
m_pUiLayer->addWidget(alert);
Layout *background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
// Create the scrollview by vertical
UIScrollView* scrollView = UIScrollView::create();
@ -129,10 +129,11 @@ bool UIScrollViewTest_Horizontal::init()
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.925));
m_pUiLayer->addWidget(alert);
Layout *background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
// Create the scrollview by horizontal
UIScrollView* scrollView = UIScrollView::create();
UIScrollView* scrollView = UIScrollView::create();
scrollView->setBounceEnabled(true);
scrollView->setDirection(SCROLLVIEW_DIR_HORIZONTAL);
scrollView->setTouchEnabled(true);
scrollView->setSize(Size(280, 150));

View File

@ -82,7 +82,7 @@ void UITextFieldTest::textFieldEvent(Object *pSender, TextFiledEventType type)
}
break;
case TEXTFIELD_EVENT_INDERT_TEXT:
case TEXTFIELD_EVENT_INSERT_TEXT:
m_pDisplayValueLabel->setText(CCString::createWithFormat("insert words")->getCString());
break;
@ -132,7 +132,7 @@ bool UITextFieldTest_MaxLength::init()
// Create the textfield
UITextField* textField = UITextField::create();
textField->setMaxLengthEnable(true);
textField->setMaxLengthEnabled(true);
textField->setMaxLength(3);
textField->setTouchEnabled(true);
textField->setFontName(font_UITextFieldTest);
@ -170,7 +170,7 @@ void UITextFieldTest_MaxLength::textFieldEvent(Object *pSender, TextFiledEventTy
}
break;
case TEXTFIELD_EVENT_INDERT_TEXT:
case TEXTFIELD_EVENT_INSERT_TEXT:
{
UITextField* textField = dynamic_cast<UITextField*>(pSender);
m_pDisplayValueLabel->setText(CCString::createWithFormat("insert words max length %d", textField->getMaxLength())->getCString());
@ -226,7 +226,7 @@ bool UITextFieldTest_Password::init()
// Create the textfield
UITextField* textField = UITextField::create();
textField->setPasswordEnable(true);
textField->setPasswordEnabled(true);
textField->setPasswordStyleText("*");
textField->setTouchEnabled(true);
textField->setFontName(font_UITextFieldTest);
@ -264,7 +264,7 @@ void UITextFieldTest_Password::textFieldEvent(Object *pSender, TextFiledEventTyp
}
break;
case TEXTFIELD_EVENT_INDERT_TEXT:
case TEXTFIELD_EVENT_INSERT_TEXT:
m_pDisplayValueLabel->setText(CCString::createWithFormat("insert words password")->getCString());
break;

View File

@ -14,7 +14,6 @@ SceneEditorTestLayer::~SceneEditorTestLayer()
ArmatureDataManager::getInstance()->destoryInstance();
SceneReader::getInstance()->purgeSceneReader();
ActionManagerEx::shareManager()->purgeActionManager();
UIHelper::instance()->purgeUIHelper();
}
SceneEditorTestLayer::SceneEditorTestLayer()

View File

@ -1 +0,0 @@
3275ac270645139eb273b2a47c215f39bcb0e0d5