Merge remote-tracking branch 'upstream/develop' into develop

* upstream/develop:
  modify autotest.py in tools/jenkins-scripts
  Adjust layout
  [EventDispatcher] Adds 'pauseEventListenersForTarget', 'resumeEventListenersForTarget' and 'removeEventListenersForTarget'.
  Add method for editor
  fixed incorrect effect of Gaussian Blur.
  Add "override"
  optimize scissor clipping
  Fixed bug of label
  Add clone method to LayoutParameter
  Fixed bug of reader.
  Fixed bugs.
  Fixed bug of reader
  Fixed bugs
This commit is contained in:
bmanGH 2014-03-03 19:12:34 +08:00
commit 95208d7543
29 changed files with 805 additions and 275 deletions

View File

@ -267,9 +267,9 @@ void EventDispatcher::visitTarget(Node* node, bool isRootNode)
}
}
void EventDispatcher::pauseTarget(Node* node)
void EventDispatcher::pauseEventListenersForTarget(Node* target, bool recursive/* = false */)
{
auto listenerIter = _nodeListenersMap.find(node);
auto listenerIter = _nodeListenersMap.find(target);
if (listenerIter != _nodeListenersMap.end())
{
auto listeners = listenerIter->second;
@ -278,11 +278,20 @@ void EventDispatcher::pauseTarget(Node* node)
l->setPaused(true);
}
}
if (recursive)
{
const auto& children = target->getChildren();
for (const auto& child : children)
{
pauseEventListenersForTarget(child, true);
}
}
}
void EventDispatcher::resumeTarget(Node* node)
void EventDispatcher::resumeEventListenersForTarget(Node* target, bool recursive/* = false */)
{
auto listenerIter = _nodeListenersMap.find(node);
auto listenerIter = _nodeListenersMap.find(target);
if (listenerIter != _nodeListenersMap.end())
{
auto listeners = listenerIter->second;
@ -291,12 +300,21 @@ void EventDispatcher::resumeTarget(Node* node)
l->setPaused(false);
}
}
setDirtyForNode(node);
setDirtyForNode(target);
if (recursive)
{
const auto& children = target->getChildren();
for (const auto& child : children)
{
resumeEventListenersForTarget(child, true);
}
}
}
void EventDispatcher::cleanTarget(Node* node)
void EventDispatcher::removeEventListenersForTarget(Node* target, bool recursive/* = false */)
{
auto listenerIter = _nodeListenersMap.find(node);
auto listenerIter = _nodeListenersMap.find(target);
if (listenerIter != _nodeListenersMap.end())
{
auto listeners = listenerIter->second;
@ -306,6 +324,15 @@ void EventDispatcher::cleanTarget(Node* node)
removeEventListener(l);
}
}
if (recursive)
{
const auto& children = target->getChildren();
for (const auto& child : children)
{
removeEventListenersForTarget(child, true);
}
}
}
void EventDispatcher::associateNodeAndEventListener(Node* node, EventListener* listener)
@ -389,7 +416,7 @@ void EventDispatcher::forceAddEventListener(EventListener* listener)
if (node->isRunning())
{
resumeTarget(node);
resumeEventListenersForTarget(node);
}
}
else
@ -430,7 +457,7 @@ void EventDispatcher::addEventListenerWithFixedPriority(EventListener* listener,
addEventListener(listener);
}
EventListenerCustom* EventDispatcher::addCustomEventListener(const std::string &eventName, std::function<void(EventCustom*)> callback)
EventListenerCustom* EventDispatcher::addCustomEventListener(const std::string &eventName, const std::function<void(EventCustom*)>& callback)
{
EventListenerCustom *listener = EventListenerCustom::create(eventName, callback);
addEventListenerWithFixedPriority(listener, 1);
@ -443,7 +470,7 @@ void EventDispatcher::removeEventListener(EventListener* listener)
return;
bool isFound = false;
auto removeListenerInVector = [&](std::vector<EventListener*>* listeners){
if (listeners == nullptr)
return;
@ -553,7 +580,7 @@ void EventDispatcher::setPriority(EventListener* listener, int fixedPriority)
}
}
void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, std::function<bool(EventListener*)> onEvent)
void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, const std::function<bool(EventListener*)>& onEvent)
{
bool shouldStopPropagation = false;
auto fixedPriorityListeners = listeners->getFixedPriorityListeners();
@ -1121,7 +1148,7 @@ void EventDispatcher::removeEventListenersForListenerID(const EventListener::Lis
}
}
void EventDispatcher::removeEventListeners(EventListener::Type listenerType)
void EventDispatcher::removeEventListenersForType(EventListener::Type listenerType)
{
if (listenerType == EventListener::Type::TOUCH_ONE_BY_ONE)
{

View File

@ -56,6 +56,8 @@ dispatched.
class EventDispatcher : public Ref
{
public:
// Adds event listener
/** Adds a event listener for a specified event with the priority of scene graph.
* @param listener The listener of a specified event.
* @param node The priority of the listener is based on the draw order of this node.
@ -76,22 +78,41 @@ public:
It will use a fixed priority of 1.
@return the generated event. Needed in order to remove the event from the dispather
*/
EventListenerCustom* addCustomEventListener(const std::string &eventName, std::function<void(EventCustom*)> callback);
EventListenerCustom* addCustomEventListener(const std::string &eventName, const std::function<void(EventCustom*)>& callback);
/////////////////////////////////////////////
// Removes event listener
/** Remove a listener
* @param listener The specified event listener which needs to be removed.
*/
void removeEventListener(EventListener* listener);
/** Removes all listeners with the same event listener type */
void removeEventListeners(EventListener::Type listenerType);
void removeEventListenersForType(EventListener::Type listenerType);
/** Removes all listeners which are associated with the specified target. */
void removeEventListenersForTarget(Node* target, bool recursive = false);
/** Removes all custom listeners with the same event name */
void removeCustomEventListeners(const std::string& customEventName);
/** Removes all listeners */
void removeAllEventListeners();
/////////////////////////////////////////////
// Pauses / Resumes event listener
/** Pauses all listeners which are associated the specified target. */
void pauseEventListenersForTarget(Node* target, bool recursive = false);
/** Resumes all listeners which are associated the specified target. */
void resumeEventListenersForTarget(Node* target, bool recursive = false);
/////////////////////////////////////////////
/** Sets listener's priority with fixed value. */
void setPriority(EventListener* listener, int fixedPriority);
@ -101,6 +122,8 @@ public:
/** Checks whether dispatching events is enabled */
bool isEnabled() const;
/////////////////////////////////////////////
/** Dispatches the event
* Also removes all EventListeners marked for deletion from the
* event dispatcher list.
@ -110,6 +133,8 @@ public:
/** Dispatches a Custom Event with a event name an optional user data */
void dispatchCustomEvent(const std::string &eventName, void *optionalUserData = nullptr);
/////////////////////////////////////////////
/** Constructor of EventDispatcher */
EventDispatcher();
/** Destructor of EventDispatcher */
@ -121,15 +146,6 @@ protected:
/** Sets the dirty flag for a node. */
void setDirtyForNode(Node* node);
/** Notifys event dispatcher that the node has been paused. */
void pauseTarget(Node* node);
/** Notifys event dispatcher that the node has been resumed. */
void resumeTarget(Node* node);
/** Notifys event dispatcher that the node has been deleted. */
void cleanTarget(Node* node);
/**
* The vector to store event listeners with scene graph based priority and fixed priority.
*/
@ -202,7 +218,7 @@ protected:
void dissociateNodeAndEventListener(Node* node, EventListener* listener);
/** Dispatches event to listeners with a specified listener type */
void dispatchEventToListeners(EventListenerVector* listeners, std::function<bool(EventListener*)> onEvent);
void dispatchEventToListeners(EventListenerVector* listeners, const std::function<bool(EventListener*)>& onEvent);
/// Priority dirty flag
enum class DirtyFlag

View File

@ -156,7 +156,7 @@ Node::~Node()
CC_SAFE_RELEASE(_actionManager);
CC_SAFE_RELEASE(_scheduler);
_eventDispatcher->cleanTarget(this);
_eventDispatcher->removeEventListenersForTarget(this);
CC_SAFE_RELEASE(_eventDispatcher);
// attributes
@ -1065,7 +1065,7 @@ void Node::setEventDispatcher(EventDispatcher* dispatcher)
{
if (dispatcher != _eventDispatcher)
{
_eventDispatcher->cleanTarget(this);
_eventDispatcher->removeEventListenersForTarget(this);
CC_SAFE_RETAIN(dispatcher);
CC_SAFE_RELEASE(_eventDispatcher);
_eventDispatcher = dispatcher;
@ -1208,14 +1208,14 @@ void Node::resume()
{
_scheduler->resumeTarget(this);
_actionManager->resumeTarget(this);
_eventDispatcher->resumeTarget(this);
_eventDispatcher->resumeEventListenersForTarget(this);
}
void Node::pause()
{
_scheduler->pauseTarget(this);
_actionManager->pauseTarget(this);
_eventDispatcher->pauseTarget(this);
_eventDispatcher->pauseEventListenersForTarget(this);
}
void Node::resumeSchedulerAndActions()

View File

@ -474,7 +474,7 @@ void WidgetPropertiesReader0250::setPropsForCheckBoxFromJsonDictionary(Widget*wi
{
checkBox->loadTextures(backGroundFileName_tp, backGroundSelectedFileName_tp, frontCrossFileName_tp,backGroundDisabledFileName_tp,frontCrossDisabledFileName_tp);
}
checkBox->setSelectedState(DICTOOL->getBooleanValue_json(options, "selectedState"));
setColorPropsForWidgetFromJsonDictionary(widget,options);
}
@ -1364,7 +1364,7 @@ void WidgetPropertiesReader0300::setPropsForCheckBoxFromJsonDictionary(Widget*wi
default:
break;
}
checkBox->setSelectedState(DICTOOL->getBooleanValue_json(options, "selectedState"));
setColorPropsForWidgetFromJsonDictionary(widget,options);
}

View File

@ -152,6 +152,11 @@ void Button::setScale9Enabled(bool able)
setCapInsetsDisabledRenderer(_capInsetsDisabled);
setBright(_bright);
}
bool Button::isScale9Enabled()
{
return _scale9Enabled;
}
void Button::ignoreContentAdaptWithSize(bool ignore)
{
@ -326,6 +331,11 @@ void Button::setCapInsetsNormalRenderer(const Rect &capInsets)
}
static_cast<extension::Scale9Sprite*>(_buttonNormalRenderer)->setCapInsets(capInsets);
}
const Rect& Button::getCapInsetsNormalRenderer()
{
return _capInsetsNormal;
}
void Button::setCapInsetsPressedRenderer(const Rect &capInsets)
{
@ -336,6 +346,11 @@ void Button::setCapInsetsPressedRenderer(const Rect &capInsets)
}
static_cast<extension::Scale9Sprite*>(_buttonClickedRenderer)->setCapInsets(capInsets);
}
const Rect& Button::getCapInsetsPressedRenderer()
{
return _capInsetsPressed;
}
void Button::setCapInsetsDisabledRenderer(const Rect &capInsets)
{
@ -346,6 +361,11 @@ void Button::setCapInsetsDisabledRenderer(const Rect &capInsets)
}
static_cast<extension::Scale9Sprite*>(_buttonDisableRenderer)->setCapInsets(capInsets);
}
const Rect& Button::getCapInsetsDisabledRenderer()
{
return _capInsetsDisabled;
}
void Button::onPressStateChangedToNormal()
{
@ -366,8 +386,7 @@ void Button::onPressStateChangedToNormal()
else
{
_buttonNormalRenderer->stopAllActions();
Action *zoomAction = ScaleTo::create(0.05f, _normalTextureScaleXInSize, _normalTextureScaleYInSize);
_buttonNormalRenderer->runAction(zoomAction);
_buttonNormalRenderer->setScale(_normalTextureScaleXInSize, _normalTextureScaleYInSize);
}
}
@ -393,8 +412,7 @@ void Button::onPressStateChangedToPressed()
_buttonClickedRenderer->setVisible(true);
_buttonDisableRenderer->setVisible(false);
_buttonNormalRenderer->stopAllActions();
Action *zoomAction = ScaleTo::create(0.05f, _pressedTextureScaleXInSize + 0.1f, _pressedTextureScaleYInSize + 0.1f);
_buttonNormalRenderer->runAction(zoomAction);
_buttonNormalRenderer->setScale(_normalTextureScaleXInSize + 0.1f, _normalTextureScaleYInSize + 0.1f);
}
}

View File

@ -107,6 +107,8 @@ public:
*/
void setCapInsetsNormalRenderer(const Rect &capInsets);
const Rect& getCapInsetsNormalRenderer();
/**
* Sets capinsets for button, if button is using scale9 renderer.
*
@ -114,6 +116,8 @@ public:
*/
void setCapInsetsPressedRenderer(const Rect &capInsets);
const Rect& getCapInsetsPressedRenderer();
/**
* Sets capinsets for button, if button is using scale9 renderer.
*
@ -121,6 +125,8 @@ public:
*/
void setCapInsetsDisabledRenderer(const Rect &capInsets);
const Rect& getCapInsetsDisabledRenderer();
//override "setAnchorPoint" of widget.
virtual void setAnchorPoint(const Point &pt) override;
@ -131,6 +137,8 @@ public:
*/
virtual void setScale9Enabled(bool able);
bool isScale9Enabled();
//override "setFlipX" of widget.
virtual void setFlipX(bool flipX) override;

View File

@ -206,6 +206,11 @@ void ImageView::setScale9Enabled(bool able)
}
setCapInsets(_capInsets);
}
bool ImageView::isScale9Enabled()
{
return _scale9Enabled;
}
void ImageView::ignoreContentAdaptWithSize(bool ignore)
{
@ -226,6 +231,11 @@ void ImageView::setCapInsets(const Rect &capInsets)
STATIC_CAST_SCALE9SPRITE->setCapInsets(capInsets);
}
const Rect& ImageView::getCapInsets()
{
return _capInsets;
}
void ImageView::setAnchorPoint(const Point &pt)
{
Widget::setAnchorPoint(pt);

View File

@ -75,6 +75,8 @@ public:
*/
void setScale9Enabled(bool able);
bool isScale9Enabled();
/**
* Sets capinsets for imageview, if imageview is using scale9 renderer.
*
@ -82,6 +84,8 @@ public:
*/
void setCapInsets(const Rect &capInsets);
const Rect& getCapInsets();
//override "setFlipX" method of widget.
virtual void setFlipX(bool flipX) override;

View File

@ -67,6 +67,7 @@ _scissorRectDirty(false),
_clippingRect(Rect::ZERO),
_clippingParent(nullptr),
_doLayoutDirty(true),
_clippingRectDirty(true),
_currentStencilEnabled(GL_FALSE),
_currentStencilWriteMask(~0),
_currentStencilFunc(GL_ALWAYS),
@ -95,6 +96,8 @@ void Layout::onEnter()
{
_clippingStencil->onEnter();
}
_doLayoutDirty = true;
_clippingRectDirty = true;
}
void Layout::onExit()
@ -150,6 +153,23 @@ void Layout::addChild(Node *child, int zOrder, int tag)
Widget::addChild(child, zOrder, tag);
_doLayoutDirty = true;
}
void Layout::removeChild(Node *child, bool cleanup)
{
Widget::removeChild(child, cleanup);
_doLayoutDirty = true;
}
void Layout::removeAllChildren()
{
Widget::removeAllChildren();
}
void Layout::removeAllChildrenWithCleanup(bool cleanup)
{
Widget::removeAllChildrenWithCleanup(cleanup);
_doLayoutDirty = true;
}
bool Layout::isClippingEnabled()
{
@ -405,6 +425,11 @@ void Layout::setClippingType(LayoutClippingType type)
setClippingEnabled(clippingEnabled);
}
LayoutClippingType Layout::getClippingType()
{
return _clippingType;
}
void Layout::setStencilClippingSize(const Size &size)
{
if (_clippingEnabled && _clippingType == LAYOUT_CLIPPING_STENCIL)
@ -422,79 +447,83 @@ void Layout::setStencilClippingSize(const Size &size)
const Rect& Layout::getClippingRect()
{
Point worldPos = convertToWorldSpace(Point::ZERO);
AffineTransform t = getNodeToWorldAffineTransform();
float scissorWidth = _size.width*t.a;
float scissorHeight = _size.height*t.d;
Rect parentClippingRect;
Layout* parent = this;
bool firstClippingParentFounded = false;
while (parent)
if (_clippingRectDirty)
{
parent = dynamic_cast<Layout*>(parent->getParent());
if(parent)
Point worldPos = convertToWorldSpace(Point::ZERO);
AffineTransform t = getNodeToWorldAffineTransform();
float scissorWidth = _size.width*t.a;
float scissorHeight = _size.height*t.d;
Rect parentClippingRect;
Layout* parent = this;
bool firstClippingParentFounded = false;
while (parent)
{
if (parent->isClippingEnabled())
parent = dynamic_cast<Layout*>(parent->getParent());
if(parent)
{
if (!firstClippingParentFounded)
if (parent->isClippingEnabled())
{
_clippingParent = parent;
firstClippingParentFounded = true;
break;
if (!firstClippingParentFounded)
{
_clippingParent = parent;
firstClippingParentFounded = true;
break;
}
}
}
}
}
if (_clippingParent)
{
parentClippingRect = _clippingParent->getClippingRect();
float finalX = worldPos.x - (scissorWidth * _anchorPoint.x);
float finalY = worldPos.y - (scissorHeight * _anchorPoint.y);
float finalWidth = scissorWidth;
float finalHeight = scissorHeight;
float leftOffset = worldPos.x - parentClippingRect.origin.x;
if (leftOffset < 0.0f)
if (_clippingParent)
{
finalX = parentClippingRect.origin.x;
finalWidth += leftOffset;
parentClippingRect = _clippingParent->getClippingRect();
float finalX = worldPos.x - (scissorWidth * _anchorPoint.x);
float finalY = worldPos.y - (scissorHeight * _anchorPoint.y);
float finalWidth = scissorWidth;
float finalHeight = scissorHeight;
float leftOffset = worldPos.x - parentClippingRect.origin.x;
if (leftOffset < 0.0f)
{
finalX = parentClippingRect.origin.x;
finalWidth += leftOffset;
}
float rightOffset = (worldPos.x + scissorWidth) - (parentClippingRect.origin.x + parentClippingRect.size.width);
if (rightOffset > 0.0f)
{
finalWidth -= rightOffset;
}
float topOffset = (worldPos.y + scissorHeight) - (parentClippingRect.origin.y + parentClippingRect.size.height);
if (topOffset > 0.0f)
{
finalHeight -= topOffset;
}
float bottomOffset = worldPos.y - parentClippingRect.origin.y;
if (bottomOffset < 0.0f)
{
finalY = parentClippingRect.origin.x;
finalHeight += bottomOffset;
}
if (finalWidth < 0.0f)
{
finalWidth = 0.0f;
}
if (finalHeight < 0.0f)
{
finalHeight = 0.0f;
}
_clippingRect.origin.x = finalX;
_clippingRect.origin.y = finalY;
_clippingRect.size.width = finalWidth;
_clippingRect.size.height = finalHeight;
}
float rightOffset = (worldPos.x + scissorWidth) - (parentClippingRect.origin.x + parentClippingRect.size.width);
if (rightOffset > 0.0f)
else
{
finalWidth -= rightOffset;
_clippingRect.origin.x = worldPos.x - (scissorWidth * _anchorPoint.x);
_clippingRect.origin.y = worldPos.y - (scissorHeight * _anchorPoint.y);
_clippingRect.size.width = scissorWidth;
_clippingRect.size.height = scissorHeight;
}
float topOffset = (worldPos.y + scissorHeight) - (parentClippingRect.origin.y + parentClippingRect.size.height);
if (topOffset > 0.0f)
{
finalHeight -= topOffset;
}
float bottomOffset = worldPos.y - parentClippingRect.origin.y;
if (bottomOffset < 0.0f)
{
finalY = parentClippingRect.origin.x;
finalHeight += bottomOffset;
}
if (finalWidth < 0.0f)
{
finalWidth = 0.0f;
}
if (finalHeight < 0.0f)
{
finalHeight = 0.0f;
}
_clippingRect.origin.x = finalX;
_clippingRect.origin.y = finalY;
_clippingRect.size.width = finalWidth;
_clippingRect.size.height = finalHeight;
}
else
{
_clippingRect.origin.x = worldPos.x - (scissorWidth * _anchorPoint.x);
_clippingRect.origin.y = worldPos.y - (scissorHeight * _anchorPoint.y);
_clippingRect.size.width = scissorWidth;
_clippingRect.size.height = scissorHeight;
_clippingRectDirty = false;
}
return _clippingRect;
}
@ -505,6 +534,7 @@ void Layout::onSizeChanged()
setContentSize(_size);
setStencilClippingSize(_size);
_doLayoutDirty = true;
_clippingRectDirty = true;
if (_backGroundImage)
{
_backGroundImage->setPosition(Point(_size.width/2.0f, _size.height/2.0f));
@ -612,6 +642,11 @@ void Layout::setBackGroundImageCapInsets(const Rect &capInsets)
static_cast<extension::Scale9Sprite*>(_backGroundImage)->setCapInsets(capInsets);
}
}
const Rect& Layout::getBackGroundImageCapInsets()
{
return _backGroundImageCapInsets;
}
void Layout::supplyTheLayoutParameterLackToChild(Widget *child)
{
@ -739,6 +774,11 @@ void Layout::setBackGroundColorType(LayoutBackGroundColorType type)
break;
}
}
LayoutBackGroundColorType Layout::getBackGroundColorType()
{
return _colorType;
}
void Layout::setBackGroundColor(const Color3B &color)
{
@ -748,6 +788,11 @@ void Layout::setBackGroundColor(const Color3B &color)
_colorRender->setColor(color);
}
}
const Color3B& Layout::getBackGroundColor()
{
return _cColor;
}
void Layout::setBackGroundColor(const Color3B &startColor, const Color3B &endColor)
{
@ -762,6 +807,16 @@ void Layout::setBackGroundColor(const Color3B &startColor, const Color3B &endCol
_gradientRender->setEndColor(endColor);
}
}
const Color3B& Layout::getBackGroundStartColor()
{
return _gStartColor;
}
const Color3B& Layout::getBackGroundEndColor()
{
return _gEndColor;
}
void Layout::setBackGroundColorOpacity(int opacity)
{
@ -780,6 +835,11 @@ void Layout::setBackGroundColorOpacity(int opacity)
break;
}
}
int Layout::getBackGroundColorOpacity()
{
return _cOpacity;
}
void Layout::setBackGroundColorVector(const Point &vector)
{
@ -789,6 +849,11 @@ void Layout::setBackGroundColorVector(const Point &vector)
_gradientRender->setVector(vector);
}
}
const Point& Layout::getBackGroundColorVector()
{
return _alongVector;
}
const Size& Layout::getBackGroundImageTextureSize() const
{
@ -1192,128 +1257,50 @@ void Layout::doLayout()
case RELATIVE_LOCATION_ABOVE_LEFTALIGN:
finalPosY += mg.bottom;
if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_LEFT
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_NONE
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_RIGHT)
{
finalPosY += relativeWidgetMargin.top;
}
finalPosX += mg.left;
break;
case RELATIVE_LOCATION_ABOVE_RIGHTALIGN:
finalPosY += mg.bottom;
if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_LEFT
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_NONE
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_RIGHT)
{
finalPosY += relativeWidgetMargin.top;
}
finalPosX -= mg.right;
break;
case RELATIVE_LOCATION_ABOVE_CENTER:
finalPosY += mg.bottom;
if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_LEFT
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_NONE
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_RIGHT)
{
finalPosY += relativeWidgetMargin.top;
}
break;
case RELATIVE_LOCATION_LEFT_OF_TOPALIGN:
finalPosX -= mg.right;
if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_LEFT
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_NONE
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_LEFT_BOTTOM
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_LEFT_CENTER_VERTICAL)
{
finalPosX -= relativeWidgetMargin.left;
}
finalPosY -= mg.top;
break;
case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN:
finalPosX -= mg.right;
if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_LEFT
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_NONE
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_LEFT_BOTTOM
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_LEFT_CENTER_VERTICAL)
{
finalPosX -= relativeWidgetMargin.left;
}
finalPosY += mg.bottom;
break;
case RELATIVE_LOCATION_LEFT_OF_CENTER:
finalPosX -= mg.right;
if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_LEFT
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_NONE
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_LEFT_BOTTOM
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_LEFT_CENTER_VERTICAL)
{
finalPosX -= relativeWidgetMargin.left;
}
break;
case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN:
finalPosX += mg.left;
if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_RIGHT
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_RIGHT_CENTER_VERTICAL)
{
finalPosX += relativeWidgetMargin.right;
}
finalPosY -= mg.top;
break;
case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN:
finalPosX += mg.left;
if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_RIGHT
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_RIGHT_CENTER_VERTICAL)
{
finalPosX += relativeWidgetMargin.right;
}
finalPosY += mg.bottom;
break;
case RELATIVE_LOCATION_RIGHT_OF_CENTER:
finalPosX += mg.left;
if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_RIGHT
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_RIGHT_CENTER_VERTICAL)
{
finalPosX += relativeWidgetMargin.right;
}
break;
case RELATIVE_LOCATION_BELOW_LEFTALIGN:
finalPosY -= mg.top;
if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_LEFT_BOTTOM
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL)
{
finalPosY -= relativeWidgetMargin.bottom;
}
finalPosX += mg.left;
break;
case RELATIVE_LOCATION_BELOW_RIGHTALIGN:
finalPosY -= mg.top;
if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_LEFT_BOTTOM
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL)
{
finalPosY -= relativeWidgetMargin.bottom;
}
finalPosX -= mg.right;
break;
case RELATIVE_LOCATION_BELOW_CENTER:
finalPosY -= mg.top;
if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_LEFT_BOTTOM
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM
&& relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL)
{
finalPosY -= relativeWidgetMargin.bottom;
}
break;
default:
break;

View File

@ -91,6 +91,8 @@ public:
*/
void setBackGroundImageCapInsets(const Rect& capInsets);
const Rect& getBackGroundImageCapInsets();
/**
* Sets Color Type for layout.
*
@ -98,6 +100,8 @@ public:
*/
void setBackGroundColorType(LayoutBackGroundColorType type);
LayoutBackGroundColorType getBackGroundColorType();
/**
* Sets background iamge use scale9 renderer.
*
@ -105,6 +109,8 @@ public:
*/
void setBackGroundImageScale9Enabled(bool enabled);
bool isBackGroundImageScale9Enabled();
/**
* Sets background color for layout, if color type is LAYOUT_COLOR_SOLID
*
@ -112,6 +118,8 @@ public:
*/
void setBackGroundColor(const Color3B &color);
const Color3B& getBackGroundColor();
/**
* Sets background color for layout, if color type is LAYOUT_COLOR_GRADIENT
*
@ -121,6 +129,10 @@ public:
*/
void setBackGroundColor(const Color3B &startColor, const Color3B &endColor);
const Color3B& getBackGroundStartColor();
const Color3B& getBackGroundEndColor();
/**
* Sets background opacity layout.
*
@ -128,6 +140,8 @@ public:
*/
void setBackGroundColorOpacity(int opacity);
int getBackGroundColorOpacity();
/**
* Sets background color vector for layout, if color type is LAYOUT_COLOR_GRADIENT
*
@ -135,6 +149,8 @@ public:
*/
void setBackGroundColorVector(const Point &vector);
const Point& getBackGroundColorVector();
/**
* Remove the background image of layout.
*/
@ -158,6 +174,8 @@ public:
void setClippingType(LayoutClippingType type);
LayoutClippingType getClippingType();
/**
* Gets if layout is clipping enabled.
*
@ -209,6 +227,24 @@ public:
*/
virtual void addChild(Node* child, int zOrder, int tag) override;
virtual void removeChild(Node* child, bool cleanup = true) override;
/**
* Removes all children from the container with a cleanup.
*
* @see `removeAllChildrenWithCleanup(bool)`
*/
virtual void removeAllChildren() override;
/**
* Removes all children from the container, and do a cleanup to all running actions depending on the cleanup parameter.
*
* @param cleanup true if all running actions on all children nodes should be cleanup, false oterwise.
* @js removeAllChildren
* @lua removeAllChildren
*/
virtual void removeAllChildrenWithCleanup(bool cleanup) override;
virtual void visit();
virtual void sortAllChildren() override;
@ -273,6 +309,7 @@ protected:
Rect _clippingRect;
Layout* _clippingParent;
bool _doLayoutDirty;
bool _clippingRectDirty;
//clipping

View File

@ -1,26 +1,26 @@
/****************************************************************************
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "gui/UILayoutParameter.h"
#include "gui/UILayout.h"
@ -56,6 +56,23 @@ LayoutParameterType LayoutParameter::getLayoutType() const
{
return _layoutParameterType;
}
LayoutParameter* LayoutParameter::clone()
{
LayoutParameter* clonedParameter = createCloneInstance();
clonedParameter->copyProperties(this);
return clonedParameter;
}
LayoutParameter* LayoutParameter::createCloneInstance()
{
return LayoutParameter::create();
}
void LayoutParameter::copyProperties(LayoutParameter *model)
{
_margin = model->_margin;
}
LinearLayoutParameter* LinearLayoutParameter::create()
{
@ -78,6 +95,21 @@ LinearGravity LinearLayoutParameter::getGravity() const
{
return _linearGravity;
}
LayoutParameter* LinearLayoutParameter::createCloneInstance()
{
return LinearLayoutParameter::create();
}
void LinearLayoutParameter::copyProperties(LayoutParameter *model)
{
LayoutParameter::copyProperties(model);
LinearLayoutParameter* parameter = dynamic_cast<LinearLayoutParameter*>(model);
if (parameter)
{
setGravity(parameter->_linearGravity);
}
}
RelativeLayoutParameter* RelativeLayoutParameter::create()
{
@ -120,6 +152,23 @@ const char* RelativeLayoutParameter::getRelativeName() const
{
return _relativeLayoutName.c_str();
}
LayoutParameter* RelativeLayoutParameter::createCloneInstance()
{
return RelativeLayoutParameter::create();
}
void RelativeLayoutParameter::copyProperties(LayoutParameter *model)
{
LayoutParameter::copyProperties(model);
RelativeLayoutParameter* parameter = dynamic_cast<RelativeLayoutParameter*>(model);
if (parameter)
{
setAlign(parameter->_relativeAlign);
setRelativeName(parameter->_relativeLayoutName.c_str());
setRelativeToWidgetName(parameter->_relativeWidgetName.c_str());
}
}
}

View File

@ -1,26 +1,26 @@
/****************************************************************************
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __LAYOUTPARMETER_H__
#define __LAYOUTPARMETER_H__
@ -86,6 +86,10 @@ public:
* @return LayoutParameterType
*/
LayoutParameterType getLayoutType() const;
LayoutParameter* clone();
virtual LayoutParameter* createCloneInstance();
virtual void copyProperties(LayoutParameter* model);
protected:
Margin _margin;
LayoutParameterType _layoutParameterType;
@ -130,6 +134,8 @@ public:
* @return LinearGravity
*/
LinearGravity getGravity() const;
virtual LayoutParameter* createCloneInstance() override;
virtual void copyProperties(LayoutParameter* model) override;
protected:
LinearGravity _linearGravity;
};
@ -202,6 +208,9 @@ public:
* @return name
*/
const char* getRelativeName() const;
virtual LayoutParameter* createCloneInstance() override;
virtual void copyProperties(LayoutParameter* model) override;
protected:
RelativeAlign _relativeAlign;
std::string _relativeWidgetName;

View File

@ -347,6 +347,11 @@ void ListView::setItemsMargin(float margin)
_itemsMargin = margin;
_refreshViewDirty = true;
}
float ListView::getItemsMargin()
{
return _itemsMargin;
}
void ListView::setDirection(SCROLLVIEW_DIR dir)
{

View File

@ -150,6 +150,8 @@ public:
*/
void setItemsMargin(float margin);
float getItemsMargin();
virtual void sortAllChildren() override;
ssize_t getCurSelectedIndex() const;

View File

@ -196,6 +196,11 @@ void LoadingBar::setScale9Enabled(bool enabled)
setCapInsets(_capInsets);
}
bool LoadingBar::isScale9Enabled()
{
return _scale9Enabled;
}
void LoadingBar::setCapInsets(const Rect &capInsets)
{
_capInsets = capInsets;
@ -206,6 +211,11 @@ void LoadingBar::setCapInsets(const Rect &capInsets)
static_cast<extension::Scale9Sprite*>(_barRenderer)->setCapInsets(capInsets);
}
const Rect& LoadingBar::getCapInsets()
{
return _capInsets;
}
void LoadingBar::setPercent(int percent)
{
if ( percent < 0 || percent > 100)
@ -334,6 +344,7 @@ void LoadingBar::copySpecialProperties(Widget *widget)
loadTexture(loadingBar->_textureFile.c_str(), loadingBar->_renderBarTexType);
setCapInsets(loadingBar->_capInsets);
setPercent(loadingBar->_percent);
setDirection(loadingBar->_barType);
}
}

View File

@ -106,6 +106,8 @@ public:
*/
void setScale9Enabled(bool enabled);
bool isScale9Enabled();
/**
* Sets capinsets for loadingbar, if loadingbar is using scale9 renderer.
*
@ -113,6 +115,8 @@ public:
*/
void setCapInsets(const Rect &capInsets);
const Rect& getCapInsets();
//override "ignoreContentAdaptWithSize" method of widget.
virtual void ignoreContentAdaptWithSize(bool ignore) override;

View File

@ -273,6 +273,46 @@ Widget* ScrollView::getChildByName(const char *name)
{
return _innerContainer->getChildByName(name);
}
void ScrollView::addNode(Node* node)
{
Layout::addNode(node);
}
void ScrollView::addNode(Node * node, int zOrder)
{
Layout::addNode(node, zOrder);
}
void ScrollView::addNode(Node* node, int zOrder, int tag)
{
_innerContainer->addNode(node, zOrder, tag);
}
Node* ScrollView::getNodeByTag(int tag)
{
return _innerContainer->getNodeByTag(tag);
}
Vector<Node*>& ScrollView::getNodes()
{
return _innerContainer->getNodes();
}
void ScrollView::removeNode(Node* node)
{
_innerContainer->removeNode(node);
}
void ScrollView::removeNodeByTag(int tag)
{
_innerContainer->removeNodeByTag(tag);
}
void ScrollView::removeAllNodes()
{
_innerContainer->removeAllNodes();
}
void ScrollView::moveChildren(float offsetX, float offsetY)
{

View File

@ -274,6 +274,22 @@ public:
virtual Widget* getChildByName(const char* name) override;
virtual void addNode(Node* node) override;
virtual void addNode(Node * node, int zOrder) override;
virtual void addNode(Node* node, int zOrder, int tag) override;
virtual Node * getNodeByTag(int tag) override;
virtual Vector<Node*>& getNodes() override;
virtual void removeNode(Node* node) override;
virtual void removeNodeByTag(int tag) override;
virtual void removeAllNodes() override;
virtual bool onTouchBegan(Touch *touch, Event *unusedEvent) override;
virtual void onTouchMoved(Touch *touch, Event *unusedEvent) override;
virtual void onTouchEnded(Touch *touch, Event *unusedEvent) override;

View File

@ -216,6 +216,11 @@ void Slider::setScale9Enabled(bool able)
setCapInsetsBarRenderer(_capInsetsBarRenderer);
setCapInsetProgressBarRebderer(_capInsetsProgressBarRenderer);
}
bool Slider::isScale9Enabled()
{
return _scale9Enabled;
}
void Slider::ignoreContentAdaptWithSize(bool ignore)
{
@ -241,6 +246,11 @@ void Slider::setCapInsetsBarRenderer(const Rect &capInsets)
}
static_cast<extension::Scale9Sprite*>(_barRenderer)->setCapInsets(capInsets);
}
const Rect& Slider::getCapInsetsBarRenderer()
{
return _capInsetsBarRenderer;
}
void Slider::setCapInsetProgressBarRebderer(const Rect &capInsets)
{
@ -251,6 +261,11 @@ void Slider::setCapInsetProgressBarRebderer(const Rect &capInsets)
}
static_cast<extension::Scale9Sprite*>(_progressBarRenderer)->setCapInsets(capInsets);
}
const Rect& Slider::getCapInsetsProgressBarRebderer()
{
return _capInsetsProgressBarRenderer;
}
void Slider::loadSlidBallTextures(const char* normal,const char* pressed,const char* disabled,TextureResType texType)
{

View File

@ -77,6 +77,8 @@ public:
*/
void setScale9Enabled(bool able);
bool isScale9Enabled();
/**
* Sets capinsets for slider, if slider is using scale9 renderer.
*
@ -91,6 +93,8 @@ public:
*/
void setCapInsetsBarRenderer(const Rect &capInsets);
const Rect& getCapInsetsBarRenderer();
/**
* Sets capinsets for slider, if slider is using scale9 renderer.
*
@ -98,6 +102,8 @@ public:
*/
void setCapInsetProgressBarRebderer(const Rect &capInsets);
const Rect& getCapInsetsProgressBarRebderer();
/**
* Load textures for slider ball.
*

View File

@ -98,6 +98,11 @@ void Text::setFontSize(int size)
_labelRenderer->setFontSize(size);
labelScaleChangedWithSize();
}
int Text::getFontSize()
{
return _fontSize;
}
void Text::setFontName(const std::string& name)
{
@ -105,36 +110,53 @@ void Text::setFontName(const std::string& name)
_labelRenderer->setFontName(name);
labelScaleChangedWithSize();
}
const std::string& Text::getFontName()
{
return _fontName;
}
void Text::setTextAreaSize(const Size &size)
{
_labelRenderer->setDimensions(size);
labelScaleChangedWithSize();
}
const Size& Text::getTextAreaSize()
{
return _labelRenderer->getDimensions();
}
void Text::setTextHorizontalAlignment(TextHAlignment alignment)
{
_labelRenderer->setHorizontalAlignment(alignment);
labelScaleChangedWithSize();
}
TextHAlignment Text::getTextHorizontalAlignment()
{
return _labelRenderer->getHorizontalAlignment();
}
void Text::setTextVerticalAlignment(TextVAlignment alignment)
{
_labelRenderer->setVerticalAlignment(alignment);
labelScaleChangedWithSize();
}
TextVAlignment Text::getTextVerticalAlignment()
{
return _labelRenderer->getVerticalAlignment();
}
void Text::setTouchScaleChangeEnabled(bool enable)
{
_touchScaleChangeEnabled = enable;
_normalScaleValueX = getScaleX();
_normalScaleValueY = getScaleY();
}
void Text::setScale(float fScale)
{
Widget::setScale(fScale);
_normalScaleValueX = _normalScaleValueY = fScale;
}
void Text::setScaleX(float fScaleX)
@ -158,7 +180,7 @@ void Text::onPressStateChangedToNormal()
{
return;
}
clickScale(_normalScaleValueX, _normalScaleValueY);
_labelRenderer->setScale(_normalScaleValueX, _normalScaleValueY);
}
void Text::onPressStateChangedToPressed()
@ -167,9 +189,7 @@ void Text::onPressStateChangedToPressed()
{
return;
}
_normalScaleValueX = getScaleX();
_normalScaleValueY = getScaleY();
clickScale(_normalScaleValueX + _onSelectedScaleOffset, _normalScaleValueY + _onSelectedScaleOffset);
_labelRenderer->setScale(_normalScaleValueX + _onSelectedScaleOffset, _normalScaleValueY + _onSelectedScaleOffset);
}
void Text::onPressStateChangedToDisabled()
@ -177,12 +197,6 @@ void Text::onPressStateChangedToDisabled()
}
void Text::clickScale(float scaleX, float scaleY)
{
setScaleX(scaleX);
setScaleY(scaleY);
}
void Text::setFlipX(bool flipX)
{
_labelRenderer->setFlippedX(flipX);
@ -231,6 +245,7 @@ void Text::labelScaleChangedWithSize()
{
_labelRenderer->setScale(1.0f);
_size = _labelRenderer->getContentSize();
_normalScaleValueX = _normalScaleValueY = 1.0f;
}
else
{
@ -244,6 +259,8 @@ void Text::labelScaleChangedWithSize()
float scaleY = _size.height / textureSize.height;
_labelRenderer->setScaleX(scaleX);
_labelRenderer->setScaleY(scaleY);
_normalScaleValueX = scaleX;
_normalScaleValueY = scaleY;
}
}

View File

@ -81,6 +81,8 @@ public:
*/
void setFontSize(int size);
int getFontSize();
/**
* Sets the font name of label.
*
@ -88,6 +90,8 @@ public:
*/
void setFontName(const std::string& name);
const std::string& getFontName();
/**
* Sets the touch scale enabled of label.
*
@ -157,8 +161,17 @@ public:
virtual std::string getDescription() const override;
void setTextAreaSize(const Size &size);
const Size& getTextAreaSize();
void setTextHorizontalAlignment(TextHAlignment alignment);
void setTextVerticalAlignment(TextVAlignment alignment);
TextHAlignment getTextHorizontalAlignment();
void setTextVerticalAlignment(TextVAlignment alignment);
TextVAlignment getTextVerticalAlignment();
protected:
virtual bool init() override;
virtual void initRenderer() override;
@ -166,7 +179,6 @@ protected:
virtual void onPressStateChangedToPressed() override;
virtual void onPressStateChangedToDisabled() override;
virtual void onSizeChanged() override;
void clickScale(float scaleX, float scaleY);
void labelScaleChangedWithSize();
virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override;

View File

@ -319,6 +319,11 @@ void TextField::setTouchSize(const Size &size)
_touchWidth = size.width;
_touchHeight = size.height;
}
Size TextField::getTouchSize()
{
return Size(_touchWidth, _touchHeight);
}
void TextField::setText(const std::string& text)
{
@ -345,18 +350,33 @@ void TextField::setPlaceHolder(const std::string& value)
_textFieldRenderer->setPlaceHolder(value);
textfieldRendererScaleChangedWithSize();
}
const std::string& TextField::getPlaceHolder()
{
return _textFieldRenderer->getPlaceHolder();
}
void TextField::setFontSize(int size)
{
_textFieldRenderer->setFontSize(size);
textfieldRendererScaleChangedWithSize();
}
int TextField::getFontSize()
{
return _textFieldRenderer->getFontSize();
}
void TextField::setFontName(const std::string& name)
{
_textFieldRenderer->setFontName(name);
textfieldRendererScaleChangedWithSize();
}
const std::string& TextField::getFontName()
{
return _textFieldRenderer->getFontName();
}
void TextField::didNotSelectSelf()
{
@ -414,6 +434,11 @@ void TextField::setPasswordStyleText(const char *styleText)
_passwordStyleText = styleText;
}
const char* TextField::getPasswordStyleText()
{
return _passwordStyleText.c_str();
}
void TextField::update(float dt)
{

View File

@ -108,10 +108,14 @@ public:
virtual ~TextField();
static TextField* create();
void setTouchSize(const Size &size);
Size getTouchSize();
void setText(const std::string& text);
void setPlaceHolder(const std::string& value);
const std::string& getPlaceHolder();
void setFontSize(int size);
int getFontSize();
void setFontName(const std::string& name);
const std::string& getFontName();
virtual void didNotSelectSelf();
const std::string& getStringValue();
virtual bool onTouchBegan(Touch *touch, Event *unusedEvent) override;
@ -122,6 +126,7 @@ public:
void setPasswordEnabled(bool enable);
bool isPasswordEnabled();
void setPasswordStyleText(const char* styleText);
const char* getPasswordStyleText();
virtual void update(float dt) override;
bool getAttachWithIME();
void setAttachWithIME(bool attach);

View File

@ -1065,6 +1065,11 @@ void Widget::copyProperties(Widget *widget)
setOpacity(widget->getOpacity());
setCascadeOpacityEnabled(widget->isCascadeOpacityEnabled());
setCascadeColorEnabled(widget->isCascadeColorEnabled());
Map<int, LayoutParameter*>& layoutParameterDic = widget->_layoutParameterDictionary;
for (auto iter = layoutParameterDic.begin(); iter != layoutParameterDic.end(); ++iter)
{
setLayoutParameter(iter->second->clone());
}
onSizeChanged();
}

View File

@ -24,6 +24,7 @@ std::function<Layer*()> createFunctions[] =
CL(DirectorEventTest),
CL(GlobalZTouchTest),
CL(StopPropagationTest),
CL(PauseResumeTargetTest),
CL(Issue4129),
CL(Issue4160)
};
@ -187,7 +188,7 @@ void TouchableSpriteTest::onEnter()
auto senderItem = static_cast<MenuItemFont*>(sender);
senderItem->setString("Only Next item could be clicked");
_eventDispatcher->removeEventListeners(EventListener::Type::TOUCH_ONE_BY_ONE);
_eventDispatcher->removeEventListenersForType(EventListener::Type::TOUCH_ONE_BY_ONE);
auto nextItem = MenuItemFont::create("Next", [=](Ref* sender){
nextCallback(nullptr);
@ -223,21 +224,32 @@ std::string TouchableSpriteTest::subtitle() const
// FixedPriorityChangedTest
class TouchableSpriteWithFixedPriority : public Sprite
class TouchableSprite : public Sprite
{
public:
static TouchableSprite* create(int priority = 0)
{
auto ret = new TouchableSprite(priority);
if (ret && ret->init())
{
ret->autorelease();
}
else
{
CC_SAFE_DELETE(ret);
}
return ret;
}
CREATE_FUNC(TouchableSpriteWithFixedPriority);
TouchableSpriteWithFixedPriority()
protected:
TouchableSprite(int priority)
: _listener(nullptr)
, _fixedPriority(0)
, _fixedPriority(priority)
, _removeListenerOnTouchEnded(false)
{
}
void setPriority(int fixedPriority) { _fixedPriority = fixedPriority; };
public:
void onEnter() override
{
Sprite::onEnter();
@ -268,7 +280,14 @@ public:
}
};
_eventDispatcher->addEventListenerWithFixedPriority(listener, _fixedPriority);
if (_fixedPriority != 0)
{
_eventDispatcher->addEventListenerWithFixedPriority(listener, _fixedPriority);
}
else
{
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}
_listener = listener;
}
@ -295,21 +314,18 @@ void FixedPriorityTest::onEnter()
Point origin = Director::getInstance()->getVisibleOrigin();
Size size = Director::getInstance()->getVisibleSize();
auto sprite1 = TouchableSpriteWithFixedPriority::create();
auto sprite1 = TouchableSprite::create(30);
sprite1->setTexture("Images/CyanSquare.png");
sprite1->setPriority(30);
sprite1->setPosition(origin+Point(size.width/2, size.height/2) + Point(-80, 40));
addChild(sprite1, 10);
auto sprite2 = TouchableSpriteWithFixedPriority::create();
auto sprite2 = TouchableSprite::create(20);
sprite2->setTexture("Images/MagentaSquare.png");
sprite2->setPriority(20);
sprite2->setPosition(origin+Point(size.width/2, size.height/2));
addChild(sprite2, 20);
auto sprite3 = TouchableSpriteWithFixedPriority::create();
auto sprite3 = TouchableSprite::create(10);
sprite3->setTexture("Images/YellowSquare.png");
sprite3->setPriority(10);
sprite3->setPosition(Point(0, 0));
sprite2->addChild(sprite3, 1);
@ -701,7 +717,7 @@ void RemoveListenerAfterAddingTest::onEnter()
};
_eventDispatcher->addEventListenerWithFixedPriority(listener, -1);
_eventDispatcher->removeEventListeners(EventListener::Type::TOUCH_ONE_BY_ONE);
_eventDispatcher->removeEventListenersForType(EventListener::Type::TOUCH_ONE_BY_ONE);
addNextButton();
});
@ -1087,6 +1103,72 @@ std::string StopPropagationTest::subtitle() const
return "Shouldn't crash and only blue block could be clicked";
}
// PauseResumeTargetTest
PauseResumeTargetTest::PauseResumeTargetTest()
{
Point origin = Director::getInstance()->getVisibleOrigin();
Size size = Director::getInstance()->getVisibleSize();
auto sprite1 = TouchableSprite::create();
sprite1->setTexture("Images/CyanSquare.png");
sprite1->setPosition(origin+Point(size.width/2, size.height/2) + Point(-80, 40));
addChild(sprite1, -10);
auto sprite2 = TouchableSprite::create();
sprite2->setTexture("Images/MagentaSquare.png");
sprite2->setPosition(origin+Point(size.width/2, size.height/2));
addChild(sprite2, -20);
auto sprite3 = TouchableSprite::create();
sprite3->setTexture("Images/YellowSquare.png");
sprite3->setPosition(Point(0, 0));
sprite2->addChild(sprite3, -1);
auto popup = MenuItemFont::create("Popup", [this](Ref* sender){
_eventDispatcher->pauseEventListenersForTarget(this, true);
auto colorLayer = LayerColor::create(Color4B(0, 0, 255, 100));
this->addChild(colorLayer, 99999);
auto closeItem = MenuItemFont::create("close", [this, colorLayer](Ref* sender){
colorLayer->removeFromParent();
_eventDispatcher->resumeEventListenersForTarget(this, true);
});
closeItem->setPosition(VisibleRect::center());
auto closeMenu = Menu::create(closeItem, NULL);
closeMenu->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT);
closeMenu->setPosition(Point::ZERO);
colorLayer->addChild(closeMenu);
});
popup->setAnchorPoint(Point::ANCHOR_MIDDLE_RIGHT);
popup->setPosition(VisibleRect::right());
auto menu = Menu::create(popup, nullptr);
menu->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT);
menu->setPosition(Point::ZERO);
addChild(menu);
}
PauseResumeTargetTest::~PauseResumeTargetTest()
{
}
std::string PauseResumeTargetTest::title() const
{
return "PauseResumeTargetTest";
}
std::string PauseResumeTargetTest::subtitle() const
{
return "";
}
// Issue4129
Issue4129::Issue4129()
: _bugFixed(false)
@ -1157,22 +1239,19 @@ Issue4160::Issue4160()
Point origin = Director::getInstance()->getVisibleOrigin();
Size size = Director::getInstance()->getVisibleSize();
auto sprite1 = TouchableSpriteWithFixedPriority::create();
auto sprite1 = TouchableSprite::create(-30);
sprite1->setTexture("Images/CyanSquare.png");
sprite1->setPriority(-30);
sprite1->setPosition(origin+Point(size.width/2, size.height/2) + Point(-80, 40));
addChild(sprite1, -10);
auto sprite2 = TouchableSpriteWithFixedPriority::create();
auto sprite2 = TouchableSprite::create(-20);
sprite2->setTexture("Images/MagentaSquare.png");
sprite2->setPriority(-20);
sprite2->removeListenerOnTouchEnded(true);
sprite2->setPosition(origin+Point(size.width/2, size.height/2));
addChild(sprite2, -20);
auto sprite3 = TouchableSpriteWithFixedPriority::create();
auto sprite3 = TouchableSprite::create(-10);
sprite3->setTexture("Images/YellowSquare.png");
sprite3->setPriority(-10);
sprite3->setPosition(Point(0, 0));
sprite2->addChild(sprite3, -1);
}

View File

@ -165,6 +165,19 @@ protected:
bool isPointInTopHalfAreaOfScreen(Point pt);
};
class PauseResumeTargetTest : public EventDispatcherTestDemo
{
public:
CREATE_FUNC(PauseResumeTargetTest);
PauseResumeTargetTest();
virtual ~PauseResumeTargetTest();
virtual std::string title() const override;
virtual std::string subtitle() const override;
private:
};
class Issue4129 : public EventDispatcherTestDemo
{
public:

View File

@ -438,14 +438,21 @@ public:
static SpriteBlur* create(const char *pszFileName);
Point blur_;
GLfloat sub_[4];
GLuint blurLocation;
GLuint subLocation;
protected:
void onDraw();
private:
int _blurRadius;
Point _pixelSize;
int _samplingRadius;
//gaussian = cons * exp( (dx*dx + dy*dy) * scale);
float _scale;
float _cons;
float _weightSum;
GLuint pixelSizeLocation;
GLuint coefficientLocation;
CustomCommand _customCommand;
};
@ -470,6 +477,7 @@ SpriteBlur* SpriteBlur::create(const char *pszFileName)
bool SpriteBlur::initWithTexture(Texture2D* texture, const Rect& rect)
{
_blurRadius = 0;
if( Sprite::initWithTexture(texture, rect) )
{
#if CC_ENABLE_CACHE_TEXTURE_DATA
@ -483,11 +491,10 @@ bool SpriteBlur::initWithTexture(Texture2D* texture, const Rect& rect)
auto s = getTexture()->getContentSizeInPixels();
blur_ = Point(1/s.width, 1/s.height);
sub_[0] = sub_[1] = sub_[2] = sub_[3] = 0;
_pixelSize = Point(1/s.width, 1/s.height);
_samplingRadius = 0;
this->initProgram();
return true;
}
@ -497,7 +504,7 @@ bool SpriteBlur::initWithTexture(Texture2D* texture, const Rect& rect)
void SpriteBlur::initProgram()
{
GLchar * fragSource = (GLchar*) String::createWithContentsOfFile(
FileUtils::getInstance()->fullPathForFilename("Shaders/example_Blur.fsh").c_str())->getCString();
FileUtils::getInstance()->fullPathForFilename("Shaders/example_Blur.fsh").c_str())->getCString();
auto pProgram = new GLProgram();
pProgram->initWithVertexShaderByteArray(ccPositionTextureColor_vert, fragSource);
setShaderProgram(pProgram);
@ -519,9 +526,9 @@ void SpriteBlur::initProgram()
CHECK_GL_ERROR_DEBUG();
subLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "substract");
blurLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "blurSize");
pixelSizeLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "onePixelSize");
coefficientLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "gaussianCoefficient");
CHECK_GL_ERROR_DEBUG();
}
@ -540,8 +547,8 @@ void SpriteBlur::onDraw()
getShaderProgram()->use();
getShaderProgram()->setUniformsForBuiltins();
getShaderProgram()->setUniformLocationWith2f(blurLocation, blur_.x, blur_.y);
getShaderProgram()->setUniformLocationWith4fv(subLocation, sub_, 1);
getShaderProgram()->setUniformLocationWith2f(pixelSizeLocation, _pixelSize.x, _pixelSize.y);
getShaderProgram()->setUniformLocationWith4f(coefficientLocation, _samplingRadius, _scale,_cons,_weightSum);
GL::bindTexture2D( getTexture()->getName());
@ -571,10 +578,37 @@ void SpriteBlur::onDraw()
void SpriteBlur::setBlurSize(float f)
{
auto s = getTexture()->getContentSizeInPixels();
if(_blurRadius == (int)f)
return;
_blurRadius = (int)f;
blur_ = Point(1/s.width, 1/s.height);
blur_ = blur_ * f;
_samplingRadius = _blurRadius;
if (_samplingRadius > 10)
{
_samplingRadius = 10;
}
if (_blurRadius > 0)
{
float sigma = _blurRadius / 2.0f;
_scale = -0.5f / (sigma * sigma);
_cons = -1.0f * _scale / 3.141592f;
_weightSum = -_cons;
float weight;
int squareX;
for(int dx = 0; dx <= _samplingRadius; ++dx)
{
squareX = dx * dx;
weight = _cons * exp(squareX * _scale);
_weightSum += 2.0 * weight;
for (int dy = 1; dy <= _samplingRadius; ++dy)
{
weight = _cons * exp((squareX + dy * dy) * _scale);
_weightSum += 4.0 * weight;
}
}
}
log("_blurRadius:%d",_blurRadius);
}
// ShaderBlur
@ -597,16 +631,17 @@ std::string ShaderBlur::subtitle() const
ControlSlider* ShaderBlur::createSliderCtl()
{
auto screenSize = Director::getInstance()->getWinSize();
ControlSlider *slider = ControlSlider::create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png");
slider->setAnchorPoint(Point(0.5f, 1.0f));
slider->setMinimumValue(0.0f); // Sets the min value of range
slider->setMaximumValue(3.0f); // Sets the max value of range
slider->setValue(1.0f);
slider->setMaximumValue(25.0f); // Sets the max value of range
slider->setPosition(Point(screenSize.width / 2.0f, screenSize.height / 3.0f));
// When the value of the slider will change, the given selector will be call
slider->addTargetWithActionForControlEvents(this, cccontrol_selector(ShaderBlur::sliderAction), Control::EventType::VALUE_CHANGED);
slider->setValue(2.0f);
return slider;

View File

@ -0,0 +1,75 @@
import os
import sys
import subprocess
import socket
import time
HOST = 'localhost'
PORT = 5678
def autotest():
soc = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
soc.connect((HOST, PORT))
time.sleep(3)
print 'autotest run:'
soc.send('autotest run\r\n')
while True:
buf = soc.recv(64)
print buf
print 'test end and close socket.'
soc.close()
#----------------autotest build and run----------------#
sleep_time = 1.5
def cleanProj():
infoClean = os.system('xcodebuild -project ./build/cocos2d_tests.xcodeproj -target Test\ cpp\ Mac clean')
print 'infoClean: ', infoClean
if infoClean != 0:
print 'clean **CLEAN FAILED**'
time.sleep(sleep_time)
def buildProj():
infoBuild = os.system('xcodebuild -project ./build/cocos2d_tests.xcodeproj -target Test\ cpp\ Mac')
print 'infoBuild: ', infoBuild
if infoBuild != 0:
print 'build **BUILD FAILED**'
time.sleep(sleep_time)
return infoBuild
def openProj():
cmd = 'open ./build/build/Debug/Test\ cpp\ Mac.app'
print 'cmd: ', cmd
infoOpen = os.system(cmd)
print 'infoOpen: ', infoOpen
if infoOpen != 0:
print 'open **OPEN FAILED**'
time.sleep(sleep_time)
def buildAndRun():
# cleanProj()
if buildProj() != 0:
cleanProj()
buildProj()
openProj()
time.sleep(sleep_time)
#----------------autotest build and run end----------------#
def main():
try:
buildAndRun()
except Exception, e:
print 'BUILD FAILED!'
else:
autotest()
# -------------- main --------------
if __name__ == '__main__':
sys_ret = 0
try:
sys_ret = main()
except:
traceback.print_exc()
sys_ret = 1
finally:
sys.exit(sys_ret)