2012-09-10 14:13:55 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2010 Sangwoo Im
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2012-09-10 14:13:55 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2012-06-18 18:30:07 +08:00
|
|
|
|
|
|
|
#include "CCScrollView.h"
|
2014-05-17 05:36:00 +08:00
|
|
|
#include "platform/CCDevice.h"
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCActionInstant.h"
|
|
|
|
#include "2d/CCActionInterval.h"
|
|
|
|
#include "2d/CCActionTween.h"
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "base/CCDirector.h"
|
2014-08-26 18:19:28 +08:00
|
|
|
#include "base/CCEventDispatcher.h"
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "renderer/CCRenderer.h"
|
2012-06-18 18:30:07 +08:00
|
|
|
|
2013-09-12 20:47:15 +08:00
|
|
|
#include <algorithm>
|
|
|
|
|
2012-06-18 18:30:07 +08:00
|
|
|
NS_CC_EXT_BEGIN
|
|
|
|
|
|
|
|
#define SCROLL_DEACCEL_RATE 0.95f
|
|
|
|
#define SCROLL_DEACCEL_DIST 1.0f
|
|
|
|
#define BOUNCE_DURATION 0.15f
|
|
|
|
#define INSET_RATIO 0.2f
|
2013-02-16 19:36:21 +08:00
|
|
|
#define MOVE_INCH 7.0f/160.0f
|
2014-03-19 17:01:38 +08:00
|
|
|
#define BOUNCE_BACK_FACTOR 0.35f
|
2013-02-16 19:36:21 +08:00
|
|
|
|
|
|
|
static float convertDistanceFromPointToInch(float pointDis)
|
|
|
|
{
|
2014-01-24 07:36:55 +08:00
|
|
|
auto glview = Director::getInstance()->getOpenGLView();
|
|
|
|
float factor = ( glview->getScaleX() + glview->getScaleY() ) / 2;
|
2013-06-20 14:15:53 +08:00
|
|
|
return pointDis * factor / Device::getDPI();
|
2013-02-16 19:36:21 +08:00
|
|
|
}
|
2012-06-18 18:30:07 +08:00
|
|
|
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
ScrollView::ScrollView()
|
2014-08-03 20:22:16 +08:00
|
|
|
: _delegate(nullptr)
|
2013-07-26 22:55:41 +08:00
|
|
|
, _direction(Direction::BOTH)
|
2013-06-15 14:03:30 +08:00
|
|
|
, _dragging(false)
|
2014-01-07 22:16:24 +08:00
|
|
|
, _container(nullptr)
|
2013-06-15 14:03:30 +08:00
|
|
|
, _touchMoved(false)
|
|
|
|
, _bounceable(false)
|
|
|
|
, _clippingToBounds(false)
|
|
|
|
, _touchLength(0.0f)
|
|
|
|
, _minScale(0.0f)
|
|
|
|
, _maxScale(0.0f)
|
2014-08-03 20:22:16 +08:00
|
|
|
, _scissorRestored(false)
|
2014-10-30 22:25:46 +08:00
|
|
|
, _touchListener(nullptr)
|
2016-01-22 01:33:47 +08:00
|
|
|
, _animatedScrollAction(nullptr)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
ScrollView::~ScrollView()
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-09-12 14:42:56 +08:00
|
|
|
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
ScrollView* ScrollView::create(Size size, Node* container/* = nullptr*/)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
ScrollView* pRet = new (std::nothrow) ScrollView();
|
2012-06-18 18:30:07 +08:00
|
|
|
if (pRet && pRet->initWithViewSize(size, container))
|
|
|
|
{
|
|
|
|
pRet->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
}
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
ScrollView* ScrollView::create()
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
ScrollView* pRet = new (std::nothrow) ScrollView();
|
2012-06-18 18:30:07 +08:00
|
|
|
if (pRet && pRet->init())
|
|
|
|
{
|
|
|
|
pRet->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
}
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
bool ScrollView::initWithViewSize(Size size, Node *container/* = nullptr*/)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
if (Layer::init())
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_container = container;
|
2012-06-18 18:30:07 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (!this->_container)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
_container = Layer::create();
|
2016-04-22 20:36:02 +08:00
|
|
|
_container->setIgnoreAnchorPointForPosition(false);
|
2014-05-15 01:07:09 +08:00
|
|
|
_container->setAnchorPoint(Vec2(0.0f, 0.0f));
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
this->setViewSize(size);
|
|
|
|
|
2013-10-25 16:06:52 +08:00
|
|
|
setTouchEnabled(true);
|
2013-09-03 18:22:03 +08:00
|
|
|
|
2013-09-20 19:19:31 +08:00
|
|
|
_touches.reserve(EventTouch::MAX_TOUCHES);
|
2013-08-22 10:15:47 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
_delegate = nullptr;
|
2013-06-15 14:03:30 +08:00
|
|
|
_bounceable = true;
|
|
|
|
_clippingToBounds = true;
|
2013-07-12 14:47:36 +08:00
|
|
|
//_container->setContentSize(Size::ZERO);
|
2013-07-26 22:55:41 +08:00
|
|
|
_direction = Direction::BOTH;
|
2014-08-28 11:41:18 +08:00
|
|
|
_container->setPosition(0.0f, 0.0f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_touchLength = 0.0f;
|
2012-06-18 18:30:07 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
this->addChild(_container);
|
|
|
|
_minScale = _maxScale = 1.0f;
|
2013-09-03 18:22:03 +08:00
|
|
|
|
|
|
|
|
2012-06-18 18:30:07 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
bool ScrollView::init()
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2014-07-10 00:45:27 +08:00
|
|
|
return this->initWithViewSize(Size(200, 200), nullptr);
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
bool ScrollView::isNodeVisible(Node* node)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
const Vec2 offset = this->getContentOffset();
|
2013-06-20 14:15:53 +08:00
|
|
|
const Size size = this->getViewSize();
|
2012-06-18 18:30:07 +08:00
|
|
|
const float scale = this->getZoomScale();
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Rect viewRect;
|
2012-06-18 18:30:07 +08:00
|
|
|
|
2013-07-12 14:30:26 +08:00
|
|
|
viewRect = Rect(-offset.x/scale, -offset.y/scale, size.width/scale, size.height/scale);
|
2012-06-18 18:30:07 +08:00
|
|
|
|
2013-07-17 09:16:04 +08:00
|
|
|
return viewRect.intersectsRect(node->getBoundingBox());
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void ScrollView::pause(Ref* /*sender*/)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-10-26 15:04:01 +08:00
|
|
|
_container->pause();
|
2012-06-18 18:30:07 +08:00
|
|
|
|
2013-12-17 17:45:29 +08:00
|
|
|
auto& children = _container->getChildren();
|
2013-12-20 05:34:41 +08:00
|
|
|
for(const auto &child : children) {
|
2013-11-28 18:23:06 +08:00
|
|
|
child->pause();
|
2013-12-20 05:34:41 +08:00
|
|
|
}
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void ScrollView::resume(Ref* /*sender*/)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-12-17 17:45:29 +08:00
|
|
|
auto& children = _container->getChildren();
|
2013-12-20 05:34:41 +08:00
|
|
|
for(const auto &child : children) {
|
2013-11-28 18:23:06 +08:00
|
|
|
child->resume();
|
2013-12-20 05:34:41 +08:00
|
|
|
}
|
2012-06-18 18:30:07 +08:00
|
|
|
|
2013-10-26 15:04:01 +08:00
|
|
|
_container->resume();
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
2013-11-20 11:35:04 +08:00
|
|
|
bool ScrollView::isTouchEnabled() const
|
|
|
|
{
|
|
|
|
return _touchListener != nullptr;
|
|
|
|
}
|
|
|
|
|
2013-10-25 16:06:52 +08:00
|
|
|
void ScrollView::setTouchEnabled(bool enabled)
|
|
|
|
{
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher->removeEventListener(_touchListener);
|
2013-11-20 11:35:04 +08:00
|
|
|
_touchListener = nullptr;
|
|
|
|
|
2013-10-25 16:06:52 +08:00
|
|
|
if (enabled)
|
|
|
|
{
|
|
|
|
_touchListener = EventListenerTouchOneByOne::create();
|
2016-02-12 21:21:57 +08:00
|
|
|
_touchListener->setSwallowTouches(true);
|
2013-10-25 16:06:52 +08:00
|
|
|
_touchListener->onTouchBegan = CC_CALLBACK_2(ScrollView::onTouchBegan, this);
|
|
|
|
_touchListener->onTouchMoved = CC_CALLBACK_2(ScrollView::onTouchMoved, this);
|
|
|
|
_touchListener->onTouchEnded = CC_CALLBACK_2(ScrollView::onTouchEnded, this);
|
|
|
|
_touchListener->onTouchCancelled = CC_CALLBACK_2(ScrollView::onTouchCancelled, this);
|
|
|
|
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(_touchListener, this);
|
2013-10-25 16:06:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_dragging = false;
|
|
|
|
_touchMoved = false;
|
|
|
|
_touches.clear();
|
|
|
|
}
|
|
|
|
}
|
2012-06-18 18:30:07 +08:00
|
|
|
|
2017-08-07 11:20:35 +08:00
|
|
|
void ScrollView::setSwallowTouches(bool needSwallow)
|
|
|
|
{
|
|
|
|
if (_touchListener != nullptr)
|
|
|
|
{
|
|
|
|
_touchListener->setSwallowTouches(needSwallow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ScrollView::setContentOffset(Vec2 offset, bool animated/* = false*/)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
|
|
|
if (animated)
|
|
|
|
{ //animate scrolling
|
|
|
|
this->setContentOffsetInDuration(offset, BOUNCE_DURATION);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ //set the container position directly
|
2013-06-15 14:03:30 +08:00
|
|
|
if (!_bounceable)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
const Vec2 minOffset = this->minContainerOffset();
|
|
|
|
const Vec2 maxOffset = this->maxContainerOffset();
|
2012-06-18 18:30:07 +08:00
|
|
|
|
|
|
|
offset.x = MAX(minOffset.x, MIN(maxOffset.x, offset.x));
|
|
|
|
offset.y = MAX(minOffset.y, MIN(maxOffset.y, offset.y));
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_container->setPosition(offset);
|
2012-06-18 18:30:07 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
if (_delegate != nullptr)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_delegate->scrollViewDidScroll(this);
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ScrollView::setContentOffsetInDuration(Vec2 offset, float dt)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
FiniteTimeAction *scroll, *expire;
|
2012-06-18 18:30:07 +08:00
|
|
|
|
2016-01-22 01:33:47 +08:00
|
|
|
if (_animatedScrollAction) {
|
|
|
|
stopAnimatedContentOffset();
|
|
|
|
}
|
2013-06-20 14:15:53 +08:00
|
|
|
scroll = MoveTo::create(dt, offset);
|
2013-07-16 03:43:22 +08:00
|
|
|
expire = CallFuncN::create(CC_CALLBACK_1(ScrollView::stoppedAnimatedScroll,this));
|
2016-01-22 01:33:47 +08:00
|
|
|
_animatedScrollAction = _container->runAction(Sequence::create(scroll, expire, nullptr));
|
2016-12-01 17:10:20 +08:00
|
|
|
_animatedScrollAction->retain();
|
2014-10-04 00:38:36 +08:00
|
|
|
this->schedule(CC_SCHEDULE_SELECTOR(ScrollView::performedAnimatedScroll));
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
2016-01-22 01:33:47 +08:00
|
|
|
void ScrollView::stopAnimatedContentOffset() {
|
|
|
|
stopAction(_animatedScrollAction);
|
2016-12-01 17:10:20 +08:00
|
|
|
_animatedScrollAction->release();
|
2016-01-22 01:33:47 +08:00
|
|
|
_animatedScrollAction = nullptr;
|
|
|
|
stoppedAnimatedScroll(this);
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 ScrollView::getContentOffset()
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _container->getPosition();
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void ScrollView::setZoomScale(float s)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_container->getScale() != s)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 oldCenter, newCenter;
|
|
|
|
Vec2 center;
|
2012-06-18 18:30:07 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_touchLength == 0.0f)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2015-04-20 01:40:52 +08:00
|
|
|
center.set(_viewSize.width*0.5f, _viewSize.height*0.5f);
|
2012-06-18 18:30:07 +08:00
|
|
|
center = this->convertToWorldSpace(center);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
center = _touchPoint;
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
oldCenter = _container->convertToNodeSpace(center);
|
|
|
|
_container->setScale(MAX(_minScale, MIN(_maxScale, s)));
|
|
|
|
newCenter = _container->convertToWorldSpace(oldCenter);
|
2012-06-18 18:30:07 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
const Vec2 offset = center - newCenter;
|
2014-07-10 00:45:27 +08:00
|
|
|
if (_delegate != nullptr)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_delegate->scrollViewDidZoom(this);
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
2013-07-11 16:38:58 +08:00
|
|
|
this->setContentOffset(_container->getPosition() + offset);
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
float ScrollView::getZoomScale()
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _container->getScale();
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void ScrollView::setZoomScale(float s, bool animated)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
|
|
|
if (animated)
|
|
|
|
{
|
|
|
|
this->setZoomScaleInDuration(s, BOUNCE_DURATION);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->setZoomScale(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void ScrollView::setZoomScaleInDuration(float s, float dt)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
|
|
|
if (dt > 0)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_container->getScale() != s)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
ActionTween *scaleAction;
|
|
|
|
scaleAction = ActionTween::create(dt, "zoomScale", _container->getScale(), s);
|
2012-06-18 18:30:07 +08:00
|
|
|
this->runAction(scaleAction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->setZoomScale(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void ScrollView::updateTweenAction(float value, const std::string& /*key*/)
|
2014-01-14 20:03:12 +08:00
|
|
|
{
|
2014-01-14 20:33:02 +08:00
|
|
|
this->setZoomScale(value);
|
2014-01-14 20:03:12 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void ScrollView::setViewSize(Size size)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_viewSize = size;
|
2013-06-20 14:15:53 +08:00
|
|
|
Layer::setContentSize(size);
|
2012-06-19 09:43:53 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Node * ScrollView::getContainer()
|
2012-06-19 09:43:53 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return this->_container;
|
2012-06-19 09:43:53 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void ScrollView::setContainer(Node * pContainer)
|
2012-06-19 09:43:53 +08:00
|
|
|
{
|
2014-07-10 00:45:27 +08:00
|
|
|
// Make sure that '_container' has a non-nullptr value since there are
|
2013-06-15 14:03:30 +08:00
|
|
|
// lots of logic that use '_container'.
|
2014-07-10 00:45:27 +08:00
|
|
|
if (nullptr == pContainer)
|
2013-04-15 09:52:46 +08:00
|
|
|
return;
|
2012-06-19 09:43:53 +08:00
|
|
|
|
2013-04-15 09:52:46 +08:00
|
|
|
this->removeAllChildrenWithCleanup(true);
|
2013-06-15 14:03:30 +08:00
|
|
|
this->_container = pContainer;
|
2012-06-19 09:43:53 +08:00
|
|
|
|
2016-04-22 20:36:02 +08:00
|
|
|
this->_container->setIgnoreAnchorPointForPosition(false);
|
2014-05-15 01:07:09 +08:00
|
|
|
this->_container->setAnchorPoint(Vec2(0.0f, 0.0f));
|
2012-06-19 09:43:53 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
this->addChild(this->_container);
|
2012-06-19 09:43:53 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
this->setViewSize(this->_viewSize);
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
2014-09-05 19:49:15 +08:00
|
|
|
bool ScrollView::hasVisibleParents() const
|
|
|
|
{
|
|
|
|
auto parent = this->getParent();
|
|
|
|
for( auto c = parent; c != nullptr; c = c->getParent() )
|
|
|
|
{
|
|
|
|
if( !c->isVisible() )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void ScrollView::relocateContainer(bool animated)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 oldPoint, min, max;
|
2012-08-01 15:30:12 +08:00
|
|
|
float newX, newY;
|
2012-06-18 18:30:07 +08:00
|
|
|
|
|
|
|
min = this->minContainerOffset();
|
|
|
|
max = this->maxContainerOffset();
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
oldPoint = _container->getPosition();
|
2012-06-18 18:30:07 +08:00
|
|
|
|
|
|
|
newX = oldPoint.x;
|
|
|
|
newY = oldPoint.y;
|
2013-07-26 22:55:41 +08:00
|
|
|
if (_direction == Direction::BOTH || _direction == Direction::HORIZONTAL)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
|
|
|
newX = MAX(newX, min.x);
|
2012-12-05 22:55:06 +08:00
|
|
|
newX = MIN(newX, max.x);
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
2013-07-26 22:55:41 +08:00
|
|
|
if (_direction == Direction::BOTH || _direction == Direction::VERTICAL)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
|
|
|
newY = MIN(newY, max.y);
|
|
|
|
newY = MAX(newY, min.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newY != oldPoint.y || newX != oldPoint.x)
|
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
this->setContentOffset(Vec2(newX, newY), animated);
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 ScrollView::maxContainerOffset()
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2015-03-14 18:06:49 +08:00
|
|
|
Point anchorPoint = _container->isIgnoreAnchorPointForPosition()?Point::ZERO:_container->getAnchorPoint();
|
|
|
|
float contW = _container->getContentSize().width * _container->getScaleX();
|
|
|
|
float contH = _container->getContentSize().height * _container->getScaleY();
|
|
|
|
|
|
|
|
return Vec2(anchorPoint.x * contW, anchorPoint.y * contH);
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 ScrollView::minContainerOffset()
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2015-03-14 18:06:49 +08:00
|
|
|
Point anchorPoint = _container->isIgnoreAnchorPointForPosition()?Point::ZERO:_container->getAnchorPoint();
|
|
|
|
float contW = _container->getContentSize().width * _container->getScaleX();
|
|
|
|
float contH = _container->getContentSize().height * _container->getScaleY();
|
|
|
|
|
|
|
|
return Vec2(_viewSize.width - (1 - anchorPoint.x) * contW, _viewSize.height - (1 - anchorPoint.y) * contH);
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void ScrollView::deaccelerateScrolling(float /*dt*/)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_dragging)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2014-10-04 00:38:36 +08:00
|
|
|
this->unschedule(CC_SCHEDULE_SELECTOR(ScrollView::deaccelerateScrolling));
|
2012-06-18 18:30:07 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-01 15:30:12 +08:00
|
|
|
float newX, newY;
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 maxInset, minInset;
|
2012-06-18 18:30:07 +08:00
|
|
|
|
2013-07-11 16:38:58 +08:00
|
|
|
_container->setPosition(_container->getPosition() + _scrollDistance);
|
2012-06-18 18:30:07 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_bounceable)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
maxInset = _maxInset;
|
|
|
|
minInset = _minInset;
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
maxInset = this->maxContainerOffset();
|
|
|
|
minInset = this->minContainerOffset();
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
newX = _container->getPosition().x;
|
|
|
|
newY = _container->getPosition().y;
|
2012-12-05 04:32:13 +08:00
|
|
|
|
2013-07-11 16:38:58 +08:00
|
|
|
_scrollDistance = _scrollDistance * SCROLL_DEACCEL_RATE;
|
2014-05-15 01:07:09 +08:00
|
|
|
this->setContentOffset(Vec2(newX,newY));
|
2012-06-18 18:30:07 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if ((fabsf(_scrollDistance.x) <= SCROLL_DEACCEL_DIST &&
|
|
|
|
fabsf(_scrollDistance.y) <= SCROLL_DEACCEL_DIST) ||
|
2015-07-08 16:03:03 +08:00
|
|
|
((_direction == Direction::BOTH || _direction == Direction::VERTICAL) && (newY >= maxInset.y || newY <= minInset.y)) ||
|
|
|
|
((_direction == Direction::BOTH || _direction == Direction::HORIZONTAL) && (newX >= maxInset.x || newX <= minInset.x)))
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2014-10-04 00:38:36 +08:00
|
|
|
this->unschedule(CC_SCHEDULE_SELECTOR(ScrollView::deaccelerateScrolling));
|
2012-06-18 18:30:07 +08:00
|
|
|
this->relocateContainer(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void ScrollView::stoppedAnimatedScroll(Node * /*node*/)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2014-10-04 00:38:36 +08:00
|
|
|
this->unschedule(CC_SCHEDULE_SELECTOR(ScrollView::performedAnimatedScroll));
|
2013-02-18 09:45:01 +08:00
|
|
|
// After the animation stopped, "scrollViewDidScroll" should be invoked, this could fix the bug of lack of tableview cells.
|
2014-07-10 00:45:27 +08:00
|
|
|
if (_delegate != nullptr)
|
2013-02-18 09:45:01 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_delegate->scrollViewDidScroll(this);
|
2013-02-18 09:45:01 +08:00
|
|
|
}
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void ScrollView::performedAnimatedScroll(float /*dt*/)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_dragging)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2014-10-04 00:38:36 +08:00
|
|
|
this->unschedule(CC_SCHEDULE_SELECTOR(ScrollView::performedAnimatedScroll));
|
2012-06-18 18:30:07 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
if (_delegate != nullptr)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_delegate->scrollViewDidScroll(this);
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
const Size& ScrollView::getContentSize() const
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _container->getContentSize();
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void ScrollView::setContentSize(const Size & size)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2014-07-10 00:45:27 +08:00
|
|
|
if (this->getContainer() != nullptr)
|
2012-09-09 22:34:32 +08:00
|
|
|
{
|
|
|
|
this->getContainer()->setContentSize(size);
|
2012-09-09 22:46:31 +08:00
|
|
|
this->updateInset();
|
|
|
|
}
|
|
|
|
}
|
2012-09-09 22:34:32 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void ScrollView::updateInset()
|
2012-09-09 22:46:31 +08:00
|
|
|
{
|
2014-07-10 00:45:27 +08:00
|
|
|
if (this->getContainer() != nullptr)
|
2012-09-09 22:46:31 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_maxInset = this->maxContainerOffset();
|
2015-04-20 01:40:52 +08:00
|
|
|
_maxInset.set(_maxInset.x + _viewSize.width * INSET_RATIO,
|
2013-06-15 14:03:30 +08:00
|
|
|
_maxInset.y + _viewSize.height * INSET_RATIO);
|
|
|
|
_minInset = this->minContainerOffset();
|
2015-04-20 01:40:52 +08:00
|
|
|
_minInset.set(_minInset.x - _viewSize.width * INSET_RATIO,
|
2013-06-15 14:03:30 +08:00
|
|
|
_minInset.y - _viewSize.height * INSET_RATIO);
|
2012-09-09 22:46:31 +08:00
|
|
|
}
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
2012-09-09 22:46:31 +08:00
|
|
|
|
2012-06-18 18:30:07 +08:00
|
|
|
/**
|
|
|
|
* make sure all children go to the container
|
|
|
|
*/
|
2013-06-20 14:15:53 +08:00
|
|
|
void ScrollView::addChild(Node * child, int zOrder, int tag)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_container != child) {
|
|
|
|
_container->addChild(child, zOrder, tag);
|
2012-06-18 18:30:07 +08:00
|
|
|
} else {
|
2013-06-20 14:15:53 +08:00
|
|
|
Layer::addChild(child, zOrder, tag);
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-21 11:35:11 +08:00
|
|
|
void ScrollView::removeChild(Node* node, bool cleanup)
|
|
|
|
{
|
|
|
|
if(_container != node)
|
|
|
|
{
|
|
|
|
_container->removeChild(node, cleanup);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Layer::removeChild(node, cleanup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::removeAllChildrenWithCleanup(bool cleanup)
|
|
|
|
{
|
|
|
|
_container->removeAllChildrenWithCleanup(cleanup);
|
|
|
|
Layer::removeAllChildrenWithCleanup(cleanup);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::removeAllChildren()
|
|
|
|
{
|
|
|
|
removeAllChildrenWithCleanup(true);
|
|
|
|
}
|
|
|
|
|
2014-06-25 11:27:48 +08:00
|
|
|
void ScrollView::addChild(Node * child, int zOrder, const std::string &name)
|
|
|
|
{
|
|
|
|
if (_container != child)
|
|
|
|
{
|
|
|
|
_container->addChild(child, zOrder, name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Layer::addChild(child, zOrder, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-07 17:46:24 +08:00
|
|
|
void ScrollView::beforeDraw()
|
|
|
|
{
|
metal support for cocos2d-x (#19305)
* remove deprecated files
* remove some deprecated codes
* remove more deprecated codes
* remove ui deprecated codes
* remove more deprecated codes
* remove deprecated codes in ccmenuitem
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes
* remove more deprecated codes
* remove more deprecated codes
* remove vr related codes and ignore some modules
* remove allocator
* remove some config
* 【Feature】add back-end project file
* [Feature] add back-end file
* add pipeline descriptor and shader cache
* [Feature] support sprite for backend
* [Feature] remove unneeded code
* [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture
* [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture
* [Feature] remove macro define to .cpp file
* [Feature] add log info
* [Feature] add PipelineDescriptor for TriangleCommand
* [Feature] add PipelineDescriptor object as member of TriangleCommand
* [Feature] add getPipelineDescriptor method
* add renderbackend
* complete pipeline descriptor
* [Feature] add viewport in RenderCommand
* set viewport when rendrering
* [Feature] occur error when using RendererBackend, to be fixed.
* a workaround to fix black screen on macOS 10.14 (#19090)
* add rendererbackend init function
* fix typo
* [Feature] modify testFile
* [BugFix] modify shader path
* [Feature] set default viewport
* fix projection
* [Feature] modify log info
* [BugFix] change viewport data type to int
* [BugFix] add BindGroup to PipelienDescriptor
* [BugFix] change a_position to vec3 in sprite.vert
* [BugFix] set vertexLayout according to V3F_C4B_T2F structure
* [Feature] revert a_position to vec4
* [Feature] renderer should not use gl codes directly
* [Feature] it's better not use default value parameter
* fix depth test setting
* rendererbackend -> renderer
* clear color and depth at begin
* add metal backend
* metal support normalized attribute
* simplify codes
* update external
* add render pass desctriptor in pipeline descriptor
* fix warnings
* fix crash and memeory leak
* refactor Texture2D
* put pipeline descriptor into render command
* simplify codes
* [Feature] update Sprite
* fix crash when closing app
* [Feature] update SpriteBatchNode and TextureAtlas
* support render texture(not finish)
* [Feature] remove unused code
* make tests work on mac
* fix download-deps path error
* make tests work on iOS
* [Feature] support ttf under normal label effect
* refactor triangle command processing
* let renderer handle more common commands
* refactor backend
* make render texture work
* [Feature] refactor backend for GL
* [Feature]Renaming to make it easy to understand
* [Feature] change warp mode to CLAMP_TO_EDGE
* fix ghost
* simplify visit render queue logic
* support progress timer without rial mode
* support partcile system
* Feature/update label (#149)
* [BugFix] fix compile error
* [Feature] support outline effect in ios
* [Feature] add shader file
* [BugFix] fix begin and end RenderPass
* [Feature] update CustomCommand
* [Feature] revert project.pbxproj
* [Feature] simplify codes
* [BugFix] pack AI88 to RGBA8888 only when outline enable
* [Feature] support shadow effect in Label
* [Feature] support BMFont
* [Feature] support glow effect
* [Feature] simplify shader files
* LabelAtlas work
* handle blend function correctly
* support tile map
* don't share buffer in metal
* alloc buffer size as needed
* support more tilemap
* Merge branch 'minggo/metal-support' into feature/updateLabel
* minggo/metal-support:
support tile map
handle blend function correctly
LabelAtlas work
Feature/update label (#149)
support partcile system
# Conflicts:
# cocos/2d/CCLabel.cpp
# cocos/2d/CCSprite.cpp
# cocos/2d/CCSpriteBatchNode.cpp
# cocos/renderer/CCQuadCommand.cpp
# cocos/renderer/CCQuadCommand.h
* render texture work without saving file
* use global viewport
* grid3d works
* remove grabber
* tiled3d works
* [BugFix] fix label bug
* [Feature] add updateSubData for buffer
* [Feature] remove setVertexCount
* support depth test
* add callback command
* [Feature] add UITest
* [Feature] update UITest
* [Feature] remove unneeded codes
* fix custom command issue
* fix layer color blend issue
* [BugFix] fix iOS compile error
* [Feature] remove unneeded codes
* [Feature] fix updateVertexBuffer
* layerradial works
* add draw test back
* fix batch issue
* fix compiling error
* [BugFix] support ETC1
* [BugFix] get the correct pipelineDescriptor
* [BugFix] skip draw when backendTexture nullptr
* clipping node support
* [Feature] add shader files
* fix stencil issue in metal
* [Feature] update UILayoutTest
* [BugFix] skip drawing when vertexCount is zero
* refactor renderer
* add set global z order for stencil manager commands
* fix warnings caused by type
* remove viewport in render command
* [Feature] fix warnings caused by type
* [BugFix] clear vertexCount and indexCount for CustomComand when needed
* [Feature] update clear for CustomCommand
* ios use metal
* fix viewport issue
* fix LayerColorGradient crash
* [cmake] transport to android and windows (#160)
* save point 1
* compile on windows
* run on android
* revert useless change
* android set CC_ENABLE_CACHE_TEXTURE_DATA to 1
* add initGlew
* fix android crash
* add TODO new-renderer
* review update
* revert onGLFWWindowPosCallback
* fix android compiling error
* Impl progress radial (#162)
* progresstimer add radial impl
* default drawType to element
* dec invoke times of createVertexBuffer (#163)
* support depth/stencil format for gl backend
* simplify progress timer codes
* support motionstreak, effect is wrong
* fix motionstreak issue
* [Feature] update Scissor Test (#161)
* [Feature] update Scissor Test
* [Feature] update ScissorTest
* [Feature] rename function
* [Feature] get constant reference if needed
* [Feature] show render status (#164)
* improve performance
* fix depth state
* fill error that triangle vertex/index number bigger than buffer
* fix compiline error in release mode
* fix buffer conflict between CPU and GPU on iOS/macOS
* Renderer refactor (#165)
* use one vertes/index buffer with opengl
* fix error on windows
* custom command support index format config
* CCLayer: compact vertex data structure
* update comment
* fix doc
* support fast tilemap
* pass index format instead
* fix some wrong effect
* fix render texture error
* fix texture per-element size
* fix texture format error
* BlendFunc type refactor, GLenum -> backend::BlendFactor (#167)
* BlendFunc use backend::BlendFactor as inner field
* update comments
* use int to replace GLenum
* update xcode project fiel
* rename to GLBlendConst
* add ccConstants.h
* update xcode project file
* update copyright
* remove primitive command
* remove CCPrimitive.cpp/.h
* remove deprecated files
* remove unneeded files
* remove multiple view support
* remove multiple view support
* remove the usage of frame buffer in camera
* director don't use frame buffer
* remove FrameBuffer
* remove BatchCommand
* add some api reference
* add physics2d back
* fix crash when close app on mac
* improve render texture
* fix rendertexture issue
* fix rendertexture issue
* simplify codes
* CMake support for mac & ios (#169)
* update cmake
* fix compile error
* update 3rd libs version
* remove CCThread.h/.cpp
* remove ccthread
* use audio engine to implement simple audio engine
* remove unneeded codes
* remove deprecated codes
* remove winrt macro
* remove CC_USE_WIC
* set partcile blend function in more elegant way
* remove unneeded codes
* remove unneeded codes
* cmake works on windows
* update project setting
* improve performance
* GLFloat -> float
* sync v3 cmake improvements into metal-support (#172)
* pick: modern cmake, compile definitions improvement (#19139)
* modern cmake, use target_compile_definitions partly
* simplify macro define, remove USE_*
* modern cmake, macro define
* add physics 2d macro define into ccConfig.h
* remove USE_CHIPMUNK macro in build.gradle
* remove CocosSelectModule.cmake
* shrink useless define
* simplify compile options config, re-add if necessary
* update external for tmp CI test
* un-quote target_compile_options value
* add "-g" parameter only when debug mode
* keep single build type when generator Xcode & VS projecy
* update external for tmp CI tes
* add static_cast<char>(-1), fix -Wc++11-narrowing
* simplify win32 compile define
* not modify code, only improve compile options
# Conflicts:
# .gitignore
# cmake/Modules/CocosConfigDepend.cmake
# cocos/CMakeLists.txt
# external/config.json
# tests/cpp-tests/CMakeLists.txt
* modern cmake, improve cmake_compiler_flags (#19145)
* cmake_compiler_flags
* Fix typo
* Fix typo2
* Remove chanages from Android.mk
* correct lua template cmake build (#19149)
* don't add -Wno-deprecated into jsb target
* correct lua template cmake build
* fix win32 lua template compile error
* prevent cmake in-source-build friendly (#19151)
* pick: Copy resources to "Resources/" on win32 like in linux configuration
* add "/Z7" for cpp-tests on windows
* [cmake] fix iOS xcode property setting failed (#19208)
* fix iOS xcode property setting failed
* use search_depend_libs_recursive at dlls collect
* fix typo
* [cmake] add find_host_library into iOS toolchain file (#19230)
* pick: [lua android] use luajit & template cmake update (#19239)
* increase cmake stability , remove tests/CMakeLists.txt (#19261)
* cmake win32 Precompiled header (#19273)
* Precompiled header
* Fix
* Precompiled header for cocos
* Precompiled header jscocos2d
* Fix for COCOS2D_DEBUG is always 1 on Android (#19291)
Related #19289
* little build fix, tests cpp-tests works on mac
* sync v3 build related codes into metal-support (#173)
* strict initialization for std::array
* remove proj.win32 project configs
* modern cmake, cmake_cleanup_remove_unused_variables (#19146)
* Switch travis CI to xenial (#19207)
* Switch travis CI to xenial
* Remove language: android
* Set language: cpp
* Fix java problem
* Update sdkmanager
* Fix sdkmanger
* next sdkmanager fix
* Remove xenial from android
* revert to sdk-tools-{system}-3859397
* Remove linux cmake install
* Update before-install.sh
* Update .travis.yml
* Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212)
* Simplify install-deps-linux.sh
* Cleanup
* pick: install ninja
* update cocos2d-console submodule
* for metal-support alpha release, we only test cpp
* add HelloCpp into project(Cocos2d-x) for tmp test
* update extenal metal-support-4
* update uniform setting
* [Feature] update BindGroup
* [Feature] empty-test
* [Feature] cpp-test
* [Feature] fix GL compiler error
* [Feature] fix GL crash
* [Feature] empty-test
* [Feature] cpp-tests
* [feature] improve frameRate
* [feature] fix opengl compile error
* [feature] fix opengl compile error
* [BugFix] fix compute maxLocation error
* [Feature] update setting unifrom
* [Feature] fix namespace
* [Feature] remove unneeded code
* [Bugfix] fix project file
* [Feature] update review
* [texture2d] impl texture format support (#175)
* texture update
* update
* update texture
* commit
* compile on windows
* ddd
* rename
* rename methods
* no crash
* save gl
* save
* save
* rename
* move out pixel format convert functions
* metal crash
* update
* update android
* support gles compressed texture format
* support more compress format
* add more conversion methods
* ss
* save
* update conversion methods
* add PVRTC format support
* reformat
* add marco linux
* fix GL marcro
* pvrtc supported only by ios 8.0+
* remove unused cmake
* revert change
* refactor Texture2D::initWithData
* fix conversion log
* refactor Texture2D::initWithData
* remove some OpenGL constants for PVRTC
* add todo
* fix typo
* AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174)
* review cpp-tests, and fix part issues on start auto test
* sync png format fix: Node:Particle3D abnormal texture effects #19204
* fix cpp-tests SpritePolygon crash, wrong png format (#19170)
* fix wrong png convert format from sRGB to Gray
* erase plist index if all frames was erased
* test_A8.png have I8 format, fix it
* [CCSpriteCache] allow re-add plist & add testcase (#19175)
* allow re-add plist & add testcase
* remove comments/rename method/update testcase
* fix isSpriteFramesWithFileLoaded & add testcase
* remove used variable
* remove unused variable
* fix double free issues when js/lua-tests exit on iOS (#19236)
* disable part cases, AutoTest works without crash on mac
* update cocos2dx files json, to test cocos new next
* fix spritecache plist parsing issue (#19269)
* [linux] Fix FileUtils::getContents with folder (#19157)
* fix FileUtils::getContents on linux/mac
* use stat.st_mode
* simplify
* [CCFileUtils] win32 getFileSize (#19176)
* win32 getFileSize
* fix stat
* [cpp test-Android]20:FileUtils/2 change title (#19197)
* sync #19200
* sync #19231
* [android lua] improve performance of lua loader (#19234)
* [lua] improve performance of lua loader
* remove cache fix
* Revert "fix spritecache plist parsing issue (#19269)"
This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf.
* remove win32 project files ref in template.json
* add metal framework lnk ref into cpp template
* test on iOS, and disable part cases
* alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227)
* changes AudioCache to use alBufferData instead of alBufferDataStatic
(also makes test 19 faster to trigger openal bugs faster)
The original problem: CrashIfClientProvidedBogusAudioBufferList
https://github.com/cocos2d/cocos2d-x/issues/18948
is not happening anymore, but there's still a not very frequent issue
that makes OpenAL crash with a call stack like this.
AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList
It happes more frequently when the device is "cold", which means after
half an hour of not using the device (locked).
I could not find the actual source code for iOS OpenAL, so I used the
macOS versions:
https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html
They seem to use CAGuard.h to make sure the dead buffer list
has no threading issues. I'm worried because the CAGuard code I found
has macos and win32 define but no iOS, so I'm not sure. I guess the
iOS version is different and has the guard.
I could not find a place in the code that's unprotected by the locks
except the InitializeBufferMap() which should not be called more than
once from cocos, and there's a workaround in AudioEngine-impl for it.
I reduced the occurence of the CleanUpDeadBufferList crash by moving
the guard in ~AudioCache to cover the alDeleteBuffers call.
* remove hack method "setTimeout" on audio
* AutoTest works on iOS
* support set ios deployment target for root project
* enable all texture2d cases, since Jiang have fixed
* add CCTextureUtils to xcode project file (#176)
* add leak cases for SpriteFrameCache (#177)
* re-add SpriteFrameCache cases
* update template file json
* Update SpriteFrameCacheTest.cpp
* fix compiling error
2019-01-18 15:08:25 +08:00
|
|
|
//TODO: minggo
|
2015-01-16 06:00:49 +08:00
|
|
|
//ScrollView don't support drawing in 3D space
|
metal support for cocos2d-x (#19305)
* remove deprecated files
* remove some deprecated codes
* remove more deprecated codes
* remove ui deprecated codes
* remove more deprecated codes
* remove deprecated codes in ccmenuitem
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes
* remove more deprecated codes
* remove more deprecated codes
* remove vr related codes and ignore some modules
* remove allocator
* remove some config
* 【Feature】add back-end project file
* [Feature] add back-end file
* add pipeline descriptor and shader cache
* [Feature] support sprite for backend
* [Feature] remove unneeded code
* [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture
* [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture
* [Feature] remove macro define to .cpp file
* [Feature] add log info
* [Feature] add PipelineDescriptor for TriangleCommand
* [Feature] add PipelineDescriptor object as member of TriangleCommand
* [Feature] add getPipelineDescriptor method
* add renderbackend
* complete pipeline descriptor
* [Feature] add viewport in RenderCommand
* set viewport when rendrering
* [Feature] occur error when using RendererBackend, to be fixed.
* a workaround to fix black screen on macOS 10.14 (#19090)
* add rendererbackend init function
* fix typo
* [Feature] modify testFile
* [BugFix] modify shader path
* [Feature] set default viewport
* fix projection
* [Feature] modify log info
* [BugFix] change viewport data type to int
* [BugFix] add BindGroup to PipelienDescriptor
* [BugFix] change a_position to vec3 in sprite.vert
* [BugFix] set vertexLayout according to V3F_C4B_T2F structure
* [Feature] revert a_position to vec4
* [Feature] renderer should not use gl codes directly
* [Feature] it's better not use default value parameter
* fix depth test setting
* rendererbackend -> renderer
* clear color and depth at begin
* add metal backend
* metal support normalized attribute
* simplify codes
* update external
* add render pass desctriptor in pipeline descriptor
* fix warnings
* fix crash and memeory leak
* refactor Texture2D
* put pipeline descriptor into render command
* simplify codes
* [Feature] update Sprite
* fix crash when closing app
* [Feature] update SpriteBatchNode and TextureAtlas
* support render texture(not finish)
* [Feature] remove unused code
* make tests work on mac
* fix download-deps path error
* make tests work on iOS
* [Feature] support ttf under normal label effect
* refactor triangle command processing
* let renderer handle more common commands
* refactor backend
* make render texture work
* [Feature] refactor backend for GL
* [Feature]Renaming to make it easy to understand
* [Feature] change warp mode to CLAMP_TO_EDGE
* fix ghost
* simplify visit render queue logic
* support progress timer without rial mode
* support partcile system
* Feature/update label (#149)
* [BugFix] fix compile error
* [Feature] support outline effect in ios
* [Feature] add shader file
* [BugFix] fix begin and end RenderPass
* [Feature] update CustomCommand
* [Feature] revert project.pbxproj
* [Feature] simplify codes
* [BugFix] pack AI88 to RGBA8888 only when outline enable
* [Feature] support shadow effect in Label
* [Feature] support BMFont
* [Feature] support glow effect
* [Feature] simplify shader files
* LabelAtlas work
* handle blend function correctly
* support tile map
* don't share buffer in metal
* alloc buffer size as needed
* support more tilemap
* Merge branch 'minggo/metal-support' into feature/updateLabel
* minggo/metal-support:
support tile map
handle blend function correctly
LabelAtlas work
Feature/update label (#149)
support partcile system
# Conflicts:
# cocos/2d/CCLabel.cpp
# cocos/2d/CCSprite.cpp
# cocos/2d/CCSpriteBatchNode.cpp
# cocos/renderer/CCQuadCommand.cpp
# cocos/renderer/CCQuadCommand.h
* render texture work without saving file
* use global viewport
* grid3d works
* remove grabber
* tiled3d works
* [BugFix] fix label bug
* [Feature] add updateSubData for buffer
* [Feature] remove setVertexCount
* support depth test
* add callback command
* [Feature] add UITest
* [Feature] update UITest
* [Feature] remove unneeded codes
* fix custom command issue
* fix layer color blend issue
* [BugFix] fix iOS compile error
* [Feature] remove unneeded codes
* [Feature] fix updateVertexBuffer
* layerradial works
* add draw test back
* fix batch issue
* fix compiling error
* [BugFix] support ETC1
* [BugFix] get the correct pipelineDescriptor
* [BugFix] skip draw when backendTexture nullptr
* clipping node support
* [Feature] add shader files
* fix stencil issue in metal
* [Feature] update UILayoutTest
* [BugFix] skip drawing when vertexCount is zero
* refactor renderer
* add set global z order for stencil manager commands
* fix warnings caused by type
* remove viewport in render command
* [Feature] fix warnings caused by type
* [BugFix] clear vertexCount and indexCount for CustomComand when needed
* [Feature] update clear for CustomCommand
* ios use metal
* fix viewport issue
* fix LayerColorGradient crash
* [cmake] transport to android and windows (#160)
* save point 1
* compile on windows
* run on android
* revert useless change
* android set CC_ENABLE_CACHE_TEXTURE_DATA to 1
* add initGlew
* fix android crash
* add TODO new-renderer
* review update
* revert onGLFWWindowPosCallback
* fix android compiling error
* Impl progress radial (#162)
* progresstimer add radial impl
* default drawType to element
* dec invoke times of createVertexBuffer (#163)
* support depth/stencil format for gl backend
* simplify progress timer codes
* support motionstreak, effect is wrong
* fix motionstreak issue
* [Feature] update Scissor Test (#161)
* [Feature] update Scissor Test
* [Feature] update ScissorTest
* [Feature] rename function
* [Feature] get constant reference if needed
* [Feature] show render status (#164)
* improve performance
* fix depth state
* fill error that triangle vertex/index number bigger than buffer
* fix compiline error in release mode
* fix buffer conflict between CPU and GPU on iOS/macOS
* Renderer refactor (#165)
* use one vertes/index buffer with opengl
* fix error on windows
* custom command support index format config
* CCLayer: compact vertex data structure
* update comment
* fix doc
* support fast tilemap
* pass index format instead
* fix some wrong effect
* fix render texture error
* fix texture per-element size
* fix texture format error
* BlendFunc type refactor, GLenum -> backend::BlendFactor (#167)
* BlendFunc use backend::BlendFactor as inner field
* update comments
* use int to replace GLenum
* update xcode project fiel
* rename to GLBlendConst
* add ccConstants.h
* update xcode project file
* update copyright
* remove primitive command
* remove CCPrimitive.cpp/.h
* remove deprecated files
* remove unneeded files
* remove multiple view support
* remove multiple view support
* remove the usage of frame buffer in camera
* director don't use frame buffer
* remove FrameBuffer
* remove BatchCommand
* add some api reference
* add physics2d back
* fix crash when close app on mac
* improve render texture
* fix rendertexture issue
* fix rendertexture issue
* simplify codes
* CMake support for mac & ios (#169)
* update cmake
* fix compile error
* update 3rd libs version
* remove CCThread.h/.cpp
* remove ccthread
* use audio engine to implement simple audio engine
* remove unneeded codes
* remove deprecated codes
* remove winrt macro
* remove CC_USE_WIC
* set partcile blend function in more elegant way
* remove unneeded codes
* remove unneeded codes
* cmake works on windows
* update project setting
* improve performance
* GLFloat -> float
* sync v3 cmake improvements into metal-support (#172)
* pick: modern cmake, compile definitions improvement (#19139)
* modern cmake, use target_compile_definitions partly
* simplify macro define, remove USE_*
* modern cmake, macro define
* add physics 2d macro define into ccConfig.h
* remove USE_CHIPMUNK macro in build.gradle
* remove CocosSelectModule.cmake
* shrink useless define
* simplify compile options config, re-add if necessary
* update external for tmp CI test
* un-quote target_compile_options value
* add "-g" parameter only when debug mode
* keep single build type when generator Xcode & VS projecy
* update external for tmp CI tes
* add static_cast<char>(-1), fix -Wc++11-narrowing
* simplify win32 compile define
* not modify code, only improve compile options
# Conflicts:
# .gitignore
# cmake/Modules/CocosConfigDepend.cmake
# cocos/CMakeLists.txt
# external/config.json
# tests/cpp-tests/CMakeLists.txt
* modern cmake, improve cmake_compiler_flags (#19145)
* cmake_compiler_flags
* Fix typo
* Fix typo2
* Remove chanages from Android.mk
* correct lua template cmake build (#19149)
* don't add -Wno-deprecated into jsb target
* correct lua template cmake build
* fix win32 lua template compile error
* prevent cmake in-source-build friendly (#19151)
* pick: Copy resources to "Resources/" on win32 like in linux configuration
* add "/Z7" for cpp-tests on windows
* [cmake] fix iOS xcode property setting failed (#19208)
* fix iOS xcode property setting failed
* use search_depend_libs_recursive at dlls collect
* fix typo
* [cmake] add find_host_library into iOS toolchain file (#19230)
* pick: [lua android] use luajit & template cmake update (#19239)
* increase cmake stability , remove tests/CMakeLists.txt (#19261)
* cmake win32 Precompiled header (#19273)
* Precompiled header
* Fix
* Precompiled header for cocos
* Precompiled header jscocos2d
* Fix for COCOS2D_DEBUG is always 1 on Android (#19291)
Related #19289
* little build fix, tests cpp-tests works on mac
* sync v3 build related codes into metal-support (#173)
* strict initialization for std::array
* remove proj.win32 project configs
* modern cmake, cmake_cleanup_remove_unused_variables (#19146)
* Switch travis CI to xenial (#19207)
* Switch travis CI to xenial
* Remove language: android
* Set language: cpp
* Fix java problem
* Update sdkmanager
* Fix sdkmanger
* next sdkmanager fix
* Remove xenial from android
* revert to sdk-tools-{system}-3859397
* Remove linux cmake install
* Update before-install.sh
* Update .travis.yml
* Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212)
* Simplify install-deps-linux.sh
* Cleanup
* pick: install ninja
* update cocos2d-console submodule
* for metal-support alpha release, we only test cpp
* add HelloCpp into project(Cocos2d-x) for tmp test
* update extenal metal-support-4
* update uniform setting
* [Feature] update BindGroup
* [Feature] empty-test
* [Feature] cpp-test
* [Feature] fix GL compiler error
* [Feature] fix GL crash
* [Feature] empty-test
* [Feature] cpp-tests
* [feature] improve frameRate
* [feature] fix opengl compile error
* [feature] fix opengl compile error
* [BugFix] fix compute maxLocation error
* [Feature] update setting unifrom
* [Feature] fix namespace
* [Feature] remove unneeded code
* [Bugfix] fix project file
* [Feature] update review
* [texture2d] impl texture format support (#175)
* texture update
* update
* update texture
* commit
* compile on windows
* ddd
* rename
* rename methods
* no crash
* save gl
* save
* save
* rename
* move out pixel format convert functions
* metal crash
* update
* update android
* support gles compressed texture format
* support more compress format
* add more conversion methods
* ss
* save
* update conversion methods
* add PVRTC format support
* reformat
* add marco linux
* fix GL marcro
* pvrtc supported only by ios 8.0+
* remove unused cmake
* revert change
* refactor Texture2D::initWithData
* fix conversion log
* refactor Texture2D::initWithData
* remove some OpenGL constants for PVRTC
* add todo
* fix typo
* AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174)
* review cpp-tests, and fix part issues on start auto test
* sync png format fix: Node:Particle3D abnormal texture effects #19204
* fix cpp-tests SpritePolygon crash, wrong png format (#19170)
* fix wrong png convert format from sRGB to Gray
* erase plist index if all frames was erased
* test_A8.png have I8 format, fix it
* [CCSpriteCache] allow re-add plist & add testcase (#19175)
* allow re-add plist & add testcase
* remove comments/rename method/update testcase
* fix isSpriteFramesWithFileLoaded & add testcase
* remove used variable
* remove unused variable
* fix double free issues when js/lua-tests exit on iOS (#19236)
* disable part cases, AutoTest works without crash on mac
* update cocos2dx files json, to test cocos new next
* fix spritecache plist parsing issue (#19269)
* [linux] Fix FileUtils::getContents with folder (#19157)
* fix FileUtils::getContents on linux/mac
* use stat.st_mode
* simplify
* [CCFileUtils] win32 getFileSize (#19176)
* win32 getFileSize
* fix stat
* [cpp test-Android]20:FileUtils/2 change title (#19197)
* sync #19200
* sync #19231
* [android lua] improve performance of lua loader (#19234)
* [lua] improve performance of lua loader
* remove cache fix
* Revert "fix spritecache plist parsing issue (#19269)"
This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf.
* remove win32 project files ref in template.json
* add metal framework lnk ref into cpp template
* test on iOS, and disable part cases
* alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227)
* changes AudioCache to use alBufferData instead of alBufferDataStatic
(also makes test 19 faster to trigger openal bugs faster)
The original problem: CrashIfClientProvidedBogusAudioBufferList
https://github.com/cocos2d/cocos2d-x/issues/18948
is not happening anymore, but there's still a not very frequent issue
that makes OpenAL crash with a call stack like this.
AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList
It happes more frequently when the device is "cold", which means after
half an hour of not using the device (locked).
I could not find the actual source code for iOS OpenAL, so I used the
macOS versions:
https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html
They seem to use CAGuard.h to make sure the dead buffer list
has no threading issues. I'm worried because the CAGuard code I found
has macos and win32 define but no iOS, so I'm not sure. I guess the
iOS version is different and has the guard.
I could not find a place in the code that's unprotected by the locks
except the InitializeBufferMap() which should not be called more than
once from cocos, and there's a workaround in AudioEngine-impl for it.
I reduced the occurence of the CleanUpDeadBufferList crash by moving
the guard in ~AudioCache to cover the alDeleteBuffers call.
* remove hack method "setTimeout" on audio
* AutoTest works on iOS
* support set ios deployment target for root project
* enable all texture2d cases, since Jiang have fixed
* add CCTextureUtils to xcode project file (#176)
* add leak cases for SpriteFrameCache (#177)
* re-add SpriteFrameCache cases
* update template file json
* Update SpriteFrameCacheTest.cpp
* fix compiling error
2019-01-18 15:08:25 +08:00
|
|
|
// _beforeDrawCommand.init(_globalZOrder);
|
|
|
|
// _beforeDrawCommand.func = CC_CALLBACK_0(ScrollView::onBeforeDraw, this);
|
|
|
|
// Director::getInstance()->getRenderer()->addCommand(&_beforeDrawCommand);
|
|
|
|
}
|
2014-01-07 17:46:24 +08:00
|
|
|
|
2012-06-18 18:30:07 +08:00
|
|
|
/**
|
|
|
|
* clip this view so that outside of the visible bounds can be hidden.
|
|
|
|
*/
|
2014-01-07 17:46:24 +08:00
|
|
|
void ScrollView::onBeforeDraw()
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
metal support for cocos2d-x (#19305)
* remove deprecated files
* remove some deprecated codes
* remove more deprecated codes
* remove ui deprecated codes
* remove more deprecated codes
* remove deprecated codes in ccmenuitem
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes
* remove more deprecated codes
* remove more deprecated codes
* remove vr related codes and ignore some modules
* remove allocator
* remove some config
* 【Feature】add back-end project file
* [Feature] add back-end file
* add pipeline descriptor and shader cache
* [Feature] support sprite for backend
* [Feature] remove unneeded code
* [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture
* [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture
* [Feature] remove macro define to .cpp file
* [Feature] add log info
* [Feature] add PipelineDescriptor for TriangleCommand
* [Feature] add PipelineDescriptor object as member of TriangleCommand
* [Feature] add getPipelineDescriptor method
* add renderbackend
* complete pipeline descriptor
* [Feature] add viewport in RenderCommand
* set viewport when rendrering
* [Feature] occur error when using RendererBackend, to be fixed.
* a workaround to fix black screen on macOS 10.14 (#19090)
* add rendererbackend init function
* fix typo
* [Feature] modify testFile
* [BugFix] modify shader path
* [Feature] set default viewport
* fix projection
* [Feature] modify log info
* [BugFix] change viewport data type to int
* [BugFix] add BindGroup to PipelienDescriptor
* [BugFix] change a_position to vec3 in sprite.vert
* [BugFix] set vertexLayout according to V3F_C4B_T2F structure
* [Feature] revert a_position to vec4
* [Feature] renderer should not use gl codes directly
* [Feature] it's better not use default value parameter
* fix depth test setting
* rendererbackend -> renderer
* clear color and depth at begin
* add metal backend
* metal support normalized attribute
* simplify codes
* update external
* add render pass desctriptor in pipeline descriptor
* fix warnings
* fix crash and memeory leak
* refactor Texture2D
* put pipeline descriptor into render command
* simplify codes
* [Feature] update Sprite
* fix crash when closing app
* [Feature] update SpriteBatchNode and TextureAtlas
* support render texture(not finish)
* [Feature] remove unused code
* make tests work on mac
* fix download-deps path error
* make tests work on iOS
* [Feature] support ttf under normal label effect
* refactor triangle command processing
* let renderer handle more common commands
* refactor backend
* make render texture work
* [Feature] refactor backend for GL
* [Feature]Renaming to make it easy to understand
* [Feature] change warp mode to CLAMP_TO_EDGE
* fix ghost
* simplify visit render queue logic
* support progress timer without rial mode
* support partcile system
* Feature/update label (#149)
* [BugFix] fix compile error
* [Feature] support outline effect in ios
* [Feature] add shader file
* [BugFix] fix begin and end RenderPass
* [Feature] update CustomCommand
* [Feature] revert project.pbxproj
* [Feature] simplify codes
* [BugFix] pack AI88 to RGBA8888 only when outline enable
* [Feature] support shadow effect in Label
* [Feature] support BMFont
* [Feature] support glow effect
* [Feature] simplify shader files
* LabelAtlas work
* handle blend function correctly
* support tile map
* don't share buffer in metal
* alloc buffer size as needed
* support more tilemap
* Merge branch 'minggo/metal-support' into feature/updateLabel
* minggo/metal-support:
support tile map
handle blend function correctly
LabelAtlas work
Feature/update label (#149)
support partcile system
# Conflicts:
# cocos/2d/CCLabel.cpp
# cocos/2d/CCSprite.cpp
# cocos/2d/CCSpriteBatchNode.cpp
# cocos/renderer/CCQuadCommand.cpp
# cocos/renderer/CCQuadCommand.h
* render texture work without saving file
* use global viewport
* grid3d works
* remove grabber
* tiled3d works
* [BugFix] fix label bug
* [Feature] add updateSubData for buffer
* [Feature] remove setVertexCount
* support depth test
* add callback command
* [Feature] add UITest
* [Feature] update UITest
* [Feature] remove unneeded codes
* fix custom command issue
* fix layer color blend issue
* [BugFix] fix iOS compile error
* [Feature] remove unneeded codes
* [Feature] fix updateVertexBuffer
* layerradial works
* add draw test back
* fix batch issue
* fix compiling error
* [BugFix] support ETC1
* [BugFix] get the correct pipelineDescriptor
* [BugFix] skip draw when backendTexture nullptr
* clipping node support
* [Feature] add shader files
* fix stencil issue in metal
* [Feature] update UILayoutTest
* [BugFix] skip drawing when vertexCount is zero
* refactor renderer
* add set global z order for stencil manager commands
* fix warnings caused by type
* remove viewport in render command
* [Feature] fix warnings caused by type
* [BugFix] clear vertexCount and indexCount for CustomComand when needed
* [Feature] update clear for CustomCommand
* ios use metal
* fix viewport issue
* fix LayerColorGradient crash
* [cmake] transport to android and windows (#160)
* save point 1
* compile on windows
* run on android
* revert useless change
* android set CC_ENABLE_CACHE_TEXTURE_DATA to 1
* add initGlew
* fix android crash
* add TODO new-renderer
* review update
* revert onGLFWWindowPosCallback
* fix android compiling error
* Impl progress radial (#162)
* progresstimer add radial impl
* default drawType to element
* dec invoke times of createVertexBuffer (#163)
* support depth/stencil format for gl backend
* simplify progress timer codes
* support motionstreak, effect is wrong
* fix motionstreak issue
* [Feature] update Scissor Test (#161)
* [Feature] update Scissor Test
* [Feature] update ScissorTest
* [Feature] rename function
* [Feature] get constant reference if needed
* [Feature] show render status (#164)
* improve performance
* fix depth state
* fill error that triangle vertex/index number bigger than buffer
* fix compiline error in release mode
* fix buffer conflict between CPU and GPU on iOS/macOS
* Renderer refactor (#165)
* use one vertes/index buffer with opengl
* fix error on windows
* custom command support index format config
* CCLayer: compact vertex data structure
* update comment
* fix doc
* support fast tilemap
* pass index format instead
* fix some wrong effect
* fix render texture error
* fix texture per-element size
* fix texture format error
* BlendFunc type refactor, GLenum -> backend::BlendFactor (#167)
* BlendFunc use backend::BlendFactor as inner field
* update comments
* use int to replace GLenum
* update xcode project fiel
* rename to GLBlendConst
* add ccConstants.h
* update xcode project file
* update copyright
* remove primitive command
* remove CCPrimitive.cpp/.h
* remove deprecated files
* remove unneeded files
* remove multiple view support
* remove multiple view support
* remove the usage of frame buffer in camera
* director don't use frame buffer
* remove FrameBuffer
* remove BatchCommand
* add some api reference
* add physics2d back
* fix crash when close app on mac
* improve render texture
* fix rendertexture issue
* fix rendertexture issue
* simplify codes
* CMake support for mac & ios (#169)
* update cmake
* fix compile error
* update 3rd libs version
* remove CCThread.h/.cpp
* remove ccthread
* use audio engine to implement simple audio engine
* remove unneeded codes
* remove deprecated codes
* remove winrt macro
* remove CC_USE_WIC
* set partcile blend function in more elegant way
* remove unneeded codes
* remove unneeded codes
* cmake works on windows
* update project setting
* improve performance
* GLFloat -> float
* sync v3 cmake improvements into metal-support (#172)
* pick: modern cmake, compile definitions improvement (#19139)
* modern cmake, use target_compile_definitions partly
* simplify macro define, remove USE_*
* modern cmake, macro define
* add physics 2d macro define into ccConfig.h
* remove USE_CHIPMUNK macro in build.gradle
* remove CocosSelectModule.cmake
* shrink useless define
* simplify compile options config, re-add if necessary
* update external for tmp CI test
* un-quote target_compile_options value
* add "-g" parameter only when debug mode
* keep single build type when generator Xcode & VS projecy
* update external for tmp CI tes
* add static_cast<char>(-1), fix -Wc++11-narrowing
* simplify win32 compile define
* not modify code, only improve compile options
# Conflicts:
# .gitignore
# cmake/Modules/CocosConfigDepend.cmake
# cocos/CMakeLists.txt
# external/config.json
# tests/cpp-tests/CMakeLists.txt
* modern cmake, improve cmake_compiler_flags (#19145)
* cmake_compiler_flags
* Fix typo
* Fix typo2
* Remove chanages from Android.mk
* correct lua template cmake build (#19149)
* don't add -Wno-deprecated into jsb target
* correct lua template cmake build
* fix win32 lua template compile error
* prevent cmake in-source-build friendly (#19151)
* pick: Copy resources to "Resources/" on win32 like in linux configuration
* add "/Z7" for cpp-tests on windows
* [cmake] fix iOS xcode property setting failed (#19208)
* fix iOS xcode property setting failed
* use search_depend_libs_recursive at dlls collect
* fix typo
* [cmake] add find_host_library into iOS toolchain file (#19230)
* pick: [lua android] use luajit & template cmake update (#19239)
* increase cmake stability , remove tests/CMakeLists.txt (#19261)
* cmake win32 Precompiled header (#19273)
* Precompiled header
* Fix
* Precompiled header for cocos
* Precompiled header jscocos2d
* Fix for COCOS2D_DEBUG is always 1 on Android (#19291)
Related #19289
* little build fix, tests cpp-tests works on mac
* sync v3 build related codes into metal-support (#173)
* strict initialization for std::array
* remove proj.win32 project configs
* modern cmake, cmake_cleanup_remove_unused_variables (#19146)
* Switch travis CI to xenial (#19207)
* Switch travis CI to xenial
* Remove language: android
* Set language: cpp
* Fix java problem
* Update sdkmanager
* Fix sdkmanger
* next sdkmanager fix
* Remove xenial from android
* revert to sdk-tools-{system}-3859397
* Remove linux cmake install
* Update before-install.sh
* Update .travis.yml
* Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212)
* Simplify install-deps-linux.sh
* Cleanup
* pick: install ninja
* update cocos2d-console submodule
* for metal-support alpha release, we only test cpp
* add HelloCpp into project(Cocos2d-x) for tmp test
* update extenal metal-support-4
* update uniform setting
* [Feature] update BindGroup
* [Feature] empty-test
* [Feature] cpp-test
* [Feature] fix GL compiler error
* [Feature] fix GL crash
* [Feature] empty-test
* [Feature] cpp-tests
* [feature] improve frameRate
* [feature] fix opengl compile error
* [feature] fix opengl compile error
* [BugFix] fix compute maxLocation error
* [Feature] update setting unifrom
* [Feature] fix namespace
* [Feature] remove unneeded code
* [Bugfix] fix project file
* [Feature] update review
* [texture2d] impl texture format support (#175)
* texture update
* update
* update texture
* commit
* compile on windows
* ddd
* rename
* rename methods
* no crash
* save gl
* save
* save
* rename
* move out pixel format convert functions
* metal crash
* update
* update android
* support gles compressed texture format
* support more compress format
* add more conversion methods
* ss
* save
* update conversion methods
* add PVRTC format support
* reformat
* add marco linux
* fix GL marcro
* pvrtc supported only by ios 8.0+
* remove unused cmake
* revert change
* refactor Texture2D::initWithData
* fix conversion log
* refactor Texture2D::initWithData
* remove some OpenGL constants for PVRTC
* add todo
* fix typo
* AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174)
* review cpp-tests, and fix part issues on start auto test
* sync png format fix: Node:Particle3D abnormal texture effects #19204
* fix cpp-tests SpritePolygon crash, wrong png format (#19170)
* fix wrong png convert format from sRGB to Gray
* erase plist index if all frames was erased
* test_A8.png have I8 format, fix it
* [CCSpriteCache] allow re-add plist & add testcase (#19175)
* allow re-add plist & add testcase
* remove comments/rename method/update testcase
* fix isSpriteFramesWithFileLoaded & add testcase
* remove used variable
* remove unused variable
* fix double free issues when js/lua-tests exit on iOS (#19236)
* disable part cases, AutoTest works without crash on mac
* update cocos2dx files json, to test cocos new next
* fix spritecache plist parsing issue (#19269)
* [linux] Fix FileUtils::getContents with folder (#19157)
* fix FileUtils::getContents on linux/mac
* use stat.st_mode
* simplify
* [CCFileUtils] win32 getFileSize (#19176)
* win32 getFileSize
* fix stat
* [cpp test-Android]20:FileUtils/2 change title (#19197)
* sync #19200
* sync #19231
* [android lua] improve performance of lua loader (#19234)
* [lua] improve performance of lua loader
* remove cache fix
* Revert "fix spritecache plist parsing issue (#19269)"
This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf.
* remove win32 project files ref in template.json
* add metal framework lnk ref into cpp template
* test on iOS, and disable part cases
* alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227)
* changes AudioCache to use alBufferData instead of alBufferDataStatic
(also makes test 19 faster to trigger openal bugs faster)
The original problem: CrashIfClientProvidedBogusAudioBufferList
https://github.com/cocos2d/cocos2d-x/issues/18948
is not happening anymore, but there's still a not very frequent issue
that makes OpenAL crash with a call stack like this.
AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList
It happes more frequently when the device is "cold", which means after
half an hour of not using the device (locked).
I could not find the actual source code for iOS OpenAL, so I used the
macOS versions:
https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html
They seem to use CAGuard.h to make sure the dead buffer list
has no threading issues. I'm worried because the CAGuard code I found
has macos and win32 define but no iOS, so I'm not sure. I guess the
iOS version is different and has the guard.
I could not find a place in the code that's unprotected by the locks
except the InitializeBufferMap() which should not be called more than
once from cocos, and there's a workaround in AudioEngine-impl for it.
I reduced the occurence of the CleanUpDeadBufferList crash by moving
the guard in ~AudioCache to cover the alDeleteBuffers call.
* remove hack method "setTimeout" on audio
* AutoTest works on iOS
* support set ios deployment target for root project
* enable all texture2d cases, since Jiang have fixed
* add CCTextureUtils to xcode project file (#176)
* add leak cases for SpriteFrameCache (#177)
* re-add SpriteFrameCache cases
* update template file json
* Update SpriteFrameCacheTest.cpp
* fix compiling error
2019-01-18 15:08:25 +08:00
|
|
|
//TODO: minggo
|
|
|
|
// if (_clippingToBounds)
|
|
|
|
// {
|
|
|
|
// _scissorRestored = false;
|
|
|
|
// Rect frame = getViewRect();
|
|
|
|
// auto glview = Director::getInstance()->getOpenGLView();
|
|
|
|
//
|
|
|
|
// if (glview->getVR() == nullptr) {
|
|
|
|
// if (glview->isScissorEnabled()) {
|
|
|
|
// _scissorRestored = true;
|
|
|
|
// _parentScissorRect = glview->getScissorRect();
|
|
|
|
// //set the intersection of _parentScissorRect and frame as the new scissor rect
|
|
|
|
// if (frame.intersectsRect(_parentScissorRect)) {
|
|
|
|
// float x = MAX(frame.origin.x, _parentScissorRect.origin.x);
|
|
|
|
// float y = MAX(frame.origin.y, _parentScissorRect.origin.y);
|
|
|
|
// float xx = MIN(frame.origin.x + frame.size.width, _parentScissorRect.origin.x + _parentScissorRect.size.width);
|
|
|
|
// float yy = MIN(frame.origin.y + frame.size.height, _parentScissorRect.origin.y + _parentScissorRect.size.height);
|
|
|
|
// glview->setScissorInPoints(x, y, xx - x, yy - y);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// else {
|
|
|
|
// glEnable(GL_SCISSOR_TEST);
|
|
|
|
// glview->setScissorInPoints(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
2014-01-07 17:46:24 +08:00
|
|
|
void ScrollView::afterDraw()
|
|
|
|
{
|
metal support for cocos2d-x (#19305)
* remove deprecated files
* remove some deprecated codes
* remove more deprecated codes
* remove ui deprecated codes
* remove more deprecated codes
* remove deprecated codes in ccmenuitem
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes
* remove more deprecated codes
* remove more deprecated codes
* remove vr related codes and ignore some modules
* remove allocator
* remove some config
* 【Feature】add back-end project file
* [Feature] add back-end file
* add pipeline descriptor and shader cache
* [Feature] support sprite for backend
* [Feature] remove unneeded code
* [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture
* [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture
* [Feature] remove macro define to .cpp file
* [Feature] add log info
* [Feature] add PipelineDescriptor for TriangleCommand
* [Feature] add PipelineDescriptor object as member of TriangleCommand
* [Feature] add getPipelineDescriptor method
* add renderbackend
* complete pipeline descriptor
* [Feature] add viewport in RenderCommand
* set viewport when rendrering
* [Feature] occur error when using RendererBackend, to be fixed.
* a workaround to fix black screen on macOS 10.14 (#19090)
* add rendererbackend init function
* fix typo
* [Feature] modify testFile
* [BugFix] modify shader path
* [Feature] set default viewport
* fix projection
* [Feature] modify log info
* [BugFix] change viewport data type to int
* [BugFix] add BindGroup to PipelienDescriptor
* [BugFix] change a_position to vec3 in sprite.vert
* [BugFix] set vertexLayout according to V3F_C4B_T2F structure
* [Feature] revert a_position to vec4
* [Feature] renderer should not use gl codes directly
* [Feature] it's better not use default value parameter
* fix depth test setting
* rendererbackend -> renderer
* clear color and depth at begin
* add metal backend
* metal support normalized attribute
* simplify codes
* update external
* add render pass desctriptor in pipeline descriptor
* fix warnings
* fix crash and memeory leak
* refactor Texture2D
* put pipeline descriptor into render command
* simplify codes
* [Feature] update Sprite
* fix crash when closing app
* [Feature] update SpriteBatchNode and TextureAtlas
* support render texture(not finish)
* [Feature] remove unused code
* make tests work on mac
* fix download-deps path error
* make tests work on iOS
* [Feature] support ttf under normal label effect
* refactor triangle command processing
* let renderer handle more common commands
* refactor backend
* make render texture work
* [Feature] refactor backend for GL
* [Feature]Renaming to make it easy to understand
* [Feature] change warp mode to CLAMP_TO_EDGE
* fix ghost
* simplify visit render queue logic
* support progress timer without rial mode
* support partcile system
* Feature/update label (#149)
* [BugFix] fix compile error
* [Feature] support outline effect in ios
* [Feature] add shader file
* [BugFix] fix begin and end RenderPass
* [Feature] update CustomCommand
* [Feature] revert project.pbxproj
* [Feature] simplify codes
* [BugFix] pack AI88 to RGBA8888 only when outline enable
* [Feature] support shadow effect in Label
* [Feature] support BMFont
* [Feature] support glow effect
* [Feature] simplify shader files
* LabelAtlas work
* handle blend function correctly
* support tile map
* don't share buffer in metal
* alloc buffer size as needed
* support more tilemap
* Merge branch 'minggo/metal-support' into feature/updateLabel
* minggo/metal-support:
support tile map
handle blend function correctly
LabelAtlas work
Feature/update label (#149)
support partcile system
# Conflicts:
# cocos/2d/CCLabel.cpp
# cocos/2d/CCSprite.cpp
# cocos/2d/CCSpriteBatchNode.cpp
# cocos/renderer/CCQuadCommand.cpp
# cocos/renderer/CCQuadCommand.h
* render texture work without saving file
* use global viewport
* grid3d works
* remove grabber
* tiled3d works
* [BugFix] fix label bug
* [Feature] add updateSubData for buffer
* [Feature] remove setVertexCount
* support depth test
* add callback command
* [Feature] add UITest
* [Feature] update UITest
* [Feature] remove unneeded codes
* fix custom command issue
* fix layer color blend issue
* [BugFix] fix iOS compile error
* [Feature] remove unneeded codes
* [Feature] fix updateVertexBuffer
* layerradial works
* add draw test back
* fix batch issue
* fix compiling error
* [BugFix] support ETC1
* [BugFix] get the correct pipelineDescriptor
* [BugFix] skip draw when backendTexture nullptr
* clipping node support
* [Feature] add shader files
* fix stencil issue in metal
* [Feature] update UILayoutTest
* [BugFix] skip drawing when vertexCount is zero
* refactor renderer
* add set global z order for stencil manager commands
* fix warnings caused by type
* remove viewport in render command
* [Feature] fix warnings caused by type
* [BugFix] clear vertexCount and indexCount for CustomComand when needed
* [Feature] update clear for CustomCommand
* ios use metal
* fix viewport issue
* fix LayerColorGradient crash
* [cmake] transport to android and windows (#160)
* save point 1
* compile on windows
* run on android
* revert useless change
* android set CC_ENABLE_CACHE_TEXTURE_DATA to 1
* add initGlew
* fix android crash
* add TODO new-renderer
* review update
* revert onGLFWWindowPosCallback
* fix android compiling error
* Impl progress radial (#162)
* progresstimer add radial impl
* default drawType to element
* dec invoke times of createVertexBuffer (#163)
* support depth/stencil format for gl backend
* simplify progress timer codes
* support motionstreak, effect is wrong
* fix motionstreak issue
* [Feature] update Scissor Test (#161)
* [Feature] update Scissor Test
* [Feature] update ScissorTest
* [Feature] rename function
* [Feature] get constant reference if needed
* [Feature] show render status (#164)
* improve performance
* fix depth state
* fill error that triangle vertex/index number bigger than buffer
* fix compiline error in release mode
* fix buffer conflict between CPU and GPU on iOS/macOS
* Renderer refactor (#165)
* use one vertes/index buffer with opengl
* fix error on windows
* custom command support index format config
* CCLayer: compact vertex data structure
* update comment
* fix doc
* support fast tilemap
* pass index format instead
* fix some wrong effect
* fix render texture error
* fix texture per-element size
* fix texture format error
* BlendFunc type refactor, GLenum -> backend::BlendFactor (#167)
* BlendFunc use backend::BlendFactor as inner field
* update comments
* use int to replace GLenum
* update xcode project fiel
* rename to GLBlendConst
* add ccConstants.h
* update xcode project file
* update copyright
* remove primitive command
* remove CCPrimitive.cpp/.h
* remove deprecated files
* remove unneeded files
* remove multiple view support
* remove multiple view support
* remove the usage of frame buffer in camera
* director don't use frame buffer
* remove FrameBuffer
* remove BatchCommand
* add some api reference
* add physics2d back
* fix crash when close app on mac
* improve render texture
* fix rendertexture issue
* fix rendertexture issue
* simplify codes
* CMake support for mac & ios (#169)
* update cmake
* fix compile error
* update 3rd libs version
* remove CCThread.h/.cpp
* remove ccthread
* use audio engine to implement simple audio engine
* remove unneeded codes
* remove deprecated codes
* remove winrt macro
* remove CC_USE_WIC
* set partcile blend function in more elegant way
* remove unneeded codes
* remove unneeded codes
* cmake works on windows
* update project setting
* improve performance
* GLFloat -> float
* sync v3 cmake improvements into metal-support (#172)
* pick: modern cmake, compile definitions improvement (#19139)
* modern cmake, use target_compile_definitions partly
* simplify macro define, remove USE_*
* modern cmake, macro define
* add physics 2d macro define into ccConfig.h
* remove USE_CHIPMUNK macro in build.gradle
* remove CocosSelectModule.cmake
* shrink useless define
* simplify compile options config, re-add if necessary
* update external for tmp CI test
* un-quote target_compile_options value
* add "-g" parameter only when debug mode
* keep single build type when generator Xcode & VS projecy
* update external for tmp CI tes
* add static_cast<char>(-1), fix -Wc++11-narrowing
* simplify win32 compile define
* not modify code, only improve compile options
# Conflicts:
# .gitignore
# cmake/Modules/CocosConfigDepend.cmake
# cocos/CMakeLists.txt
# external/config.json
# tests/cpp-tests/CMakeLists.txt
* modern cmake, improve cmake_compiler_flags (#19145)
* cmake_compiler_flags
* Fix typo
* Fix typo2
* Remove chanages from Android.mk
* correct lua template cmake build (#19149)
* don't add -Wno-deprecated into jsb target
* correct lua template cmake build
* fix win32 lua template compile error
* prevent cmake in-source-build friendly (#19151)
* pick: Copy resources to "Resources/" on win32 like in linux configuration
* add "/Z7" for cpp-tests on windows
* [cmake] fix iOS xcode property setting failed (#19208)
* fix iOS xcode property setting failed
* use search_depend_libs_recursive at dlls collect
* fix typo
* [cmake] add find_host_library into iOS toolchain file (#19230)
* pick: [lua android] use luajit & template cmake update (#19239)
* increase cmake stability , remove tests/CMakeLists.txt (#19261)
* cmake win32 Precompiled header (#19273)
* Precompiled header
* Fix
* Precompiled header for cocos
* Precompiled header jscocos2d
* Fix for COCOS2D_DEBUG is always 1 on Android (#19291)
Related #19289
* little build fix, tests cpp-tests works on mac
* sync v3 build related codes into metal-support (#173)
* strict initialization for std::array
* remove proj.win32 project configs
* modern cmake, cmake_cleanup_remove_unused_variables (#19146)
* Switch travis CI to xenial (#19207)
* Switch travis CI to xenial
* Remove language: android
* Set language: cpp
* Fix java problem
* Update sdkmanager
* Fix sdkmanger
* next sdkmanager fix
* Remove xenial from android
* revert to sdk-tools-{system}-3859397
* Remove linux cmake install
* Update before-install.sh
* Update .travis.yml
* Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212)
* Simplify install-deps-linux.sh
* Cleanup
* pick: install ninja
* update cocos2d-console submodule
* for metal-support alpha release, we only test cpp
* add HelloCpp into project(Cocos2d-x) for tmp test
* update extenal metal-support-4
* update uniform setting
* [Feature] update BindGroup
* [Feature] empty-test
* [Feature] cpp-test
* [Feature] fix GL compiler error
* [Feature] fix GL crash
* [Feature] empty-test
* [Feature] cpp-tests
* [feature] improve frameRate
* [feature] fix opengl compile error
* [feature] fix opengl compile error
* [BugFix] fix compute maxLocation error
* [Feature] update setting unifrom
* [Feature] fix namespace
* [Feature] remove unneeded code
* [Bugfix] fix project file
* [Feature] update review
* [texture2d] impl texture format support (#175)
* texture update
* update
* update texture
* commit
* compile on windows
* ddd
* rename
* rename methods
* no crash
* save gl
* save
* save
* rename
* move out pixel format convert functions
* metal crash
* update
* update android
* support gles compressed texture format
* support more compress format
* add more conversion methods
* ss
* save
* update conversion methods
* add PVRTC format support
* reformat
* add marco linux
* fix GL marcro
* pvrtc supported only by ios 8.0+
* remove unused cmake
* revert change
* refactor Texture2D::initWithData
* fix conversion log
* refactor Texture2D::initWithData
* remove some OpenGL constants for PVRTC
* add todo
* fix typo
* AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174)
* review cpp-tests, and fix part issues on start auto test
* sync png format fix: Node:Particle3D abnormal texture effects #19204
* fix cpp-tests SpritePolygon crash, wrong png format (#19170)
* fix wrong png convert format from sRGB to Gray
* erase plist index if all frames was erased
* test_A8.png have I8 format, fix it
* [CCSpriteCache] allow re-add plist & add testcase (#19175)
* allow re-add plist & add testcase
* remove comments/rename method/update testcase
* fix isSpriteFramesWithFileLoaded & add testcase
* remove used variable
* remove unused variable
* fix double free issues when js/lua-tests exit on iOS (#19236)
* disable part cases, AutoTest works without crash on mac
* update cocos2dx files json, to test cocos new next
* fix spritecache plist parsing issue (#19269)
* [linux] Fix FileUtils::getContents with folder (#19157)
* fix FileUtils::getContents on linux/mac
* use stat.st_mode
* simplify
* [CCFileUtils] win32 getFileSize (#19176)
* win32 getFileSize
* fix stat
* [cpp test-Android]20:FileUtils/2 change title (#19197)
* sync #19200
* sync #19231
* [android lua] improve performance of lua loader (#19234)
* [lua] improve performance of lua loader
* remove cache fix
* Revert "fix spritecache plist parsing issue (#19269)"
This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf.
* remove win32 project files ref in template.json
* add metal framework lnk ref into cpp template
* test on iOS, and disable part cases
* alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227)
* changes AudioCache to use alBufferData instead of alBufferDataStatic
(also makes test 19 faster to trigger openal bugs faster)
The original problem: CrashIfClientProvidedBogusAudioBufferList
https://github.com/cocos2d/cocos2d-x/issues/18948
is not happening anymore, but there's still a not very frequent issue
that makes OpenAL crash with a call stack like this.
AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList
It happes more frequently when the device is "cold", which means after
half an hour of not using the device (locked).
I could not find the actual source code for iOS OpenAL, so I used the
macOS versions:
https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html
They seem to use CAGuard.h to make sure the dead buffer list
has no threading issues. I'm worried because the CAGuard code I found
has macos and win32 define but no iOS, so I'm not sure. I guess the
iOS version is different and has the guard.
I could not find a place in the code that's unprotected by the locks
except the InitializeBufferMap() which should not be called more than
once from cocos, and there's a workaround in AudioEngine-impl for it.
I reduced the occurence of the CleanUpDeadBufferList crash by moving
the guard in ~AudioCache to cover the alDeleteBuffers call.
* remove hack method "setTimeout" on audio
* AutoTest works on iOS
* support set ios deployment target for root project
* enable all texture2d cases, since Jiang have fixed
* add CCTextureUtils to xcode project file (#176)
* add leak cases for SpriteFrameCache (#177)
* re-add SpriteFrameCache cases
* update template file json
* Update SpriteFrameCacheTest.cpp
* fix compiling error
2019-01-18 15:08:25 +08:00
|
|
|
//TODO: minggo
|
|
|
|
// _afterDrawCommand.init(_globalZOrder);
|
|
|
|
// _afterDrawCommand.func = CC_CALLBACK_0(ScrollView::onAfterDraw, this);
|
|
|
|
// Director::getInstance()->getRenderer()->addCommand(&_afterDrawCommand);
|
2014-01-07 17:46:24 +08:00
|
|
|
}
|
|
|
|
|
2012-06-18 18:30:07 +08:00
|
|
|
/**
|
|
|
|
* retract what's done in beforeDraw so that there's no side effect to
|
|
|
|
* other nodes.
|
|
|
|
*/
|
2014-01-07 17:46:24 +08:00
|
|
|
void ScrollView::onAfterDraw()
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
metal support for cocos2d-x (#19305)
* remove deprecated files
* remove some deprecated codes
* remove more deprecated codes
* remove ui deprecated codes
* remove more deprecated codes
* remove deprecated codes in ccmenuitem
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes
* remove more deprecated codes
* remove more deprecated codes
* remove vr related codes and ignore some modules
* remove allocator
* remove some config
* 【Feature】add back-end project file
* [Feature] add back-end file
* add pipeline descriptor and shader cache
* [Feature] support sprite for backend
* [Feature] remove unneeded code
* [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture
* [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture
* [Feature] remove macro define to .cpp file
* [Feature] add log info
* [Feature] add PipelineDescriptor for TriangleCommand
* [Feature] add PipelineDescriptor object as member of TriangleCommand
* [Feature] add getPipelineDescriptor method
* add renderbackend
* complete pipeline descriptor
* [Feature] add viewport in RenderCommand
* set viewport when rendrering
* [Feature] occur error when using RendererBackend, to be fixed.
* a workaround to fix black screen on macOS 10.14 (#19090)
* add rendererbackend init function
* fix typo
* [Feature] modify testFile
* [BugFix] modify shader path
* [Feature] set default viewport
* fix projection
* [Feature] modify log info
* [BugFix] change viewport data type to int
* [BugFix] add BindGroup to PipelienDescriptor
* [BugFix] change a_position to vec3 in sprite.vert
* [BugFix] set vertexLayout according to V3F_C4B_T2F structure
* [Feature] revert a_position to vec4
* [Feature] renderer should not use gl codes directly
* [Feature] it's better not use default value parameter
* fix depth test setting
* rendererbackend -> renderer
* clear color and depth at begin
* add metal backend
* metal support normalized attribute
* simplify codes
* update external
* add render pass desctriptor in pipeline descriptor
* fix warnings
* fix crash and memeory leak
* refactor Texture2D
* put pipeline descriptor into render command
* simplify codes
* [Feature] update Sprite
* fix crash when closing app
* [Feature] update SpriteBatchNode and TextureAtlas
* support render texture(not finish)
* [Feature] remove unused code
* make tests work on mac
* fix download-deps path error
* make tests work on iOS
* [Feature] support ttf under normal label effect
* refactor triangle command processing
* let renderer handle more common commands
* refactor backend
* make render texture work
* [Feature] refactor backend for GL
* [Feature]Renaming to make it easy to understand
* [Feature] change warp mode to CLAMP_TO_EDGE
* fix ghost
* simplify visit render queue logic
* support progress timer without rial mode
* support partcile system
* Feature/update label (#149)
* [BugFix] fix compile error
* [Feature] support outline effect in ios
* [Feature] add shader file
* [BugFix] fix begin and end RenderPass
* [Feature] update CustomCommand
* [Feature] revert project.pbxproj
* [Feature] simplify codes
* [BugFix] pack AI88 to RGBA8888 only when outline enable
* [Feature] support shadow effect in Label
* [Feature] support BMFont
* [Feature] support glow effect
* [Feature] simplify shader files
* LabelAtlas work
* handle blend function correctly
* support tile map
* don't share buffer in metal
* alloc buffer size as needed
* support more tilemap
* Merge branch 'minggo/metal-support' into feature/updateLabel
* minggo/metal-support:
support tile map
handle blend function correctly
LabelAtlas work
Feature/update label (#149)
support partcile system
# Conflicts:
# cocos/2d/CCLabel.cpp
# cocos/2d/CCSprite.cpp
# cocos/2d/CCSpriteBatchNode.cpp
# cocos/renderer/CCQuadCommand.cpp
# cocos/renderer/CCQuadCommand.h
* render texture work without saving file
* use global viewport
* grid3d works
* remove grabber
* tiled3d works
* [BugFix] fix label bug
* [Feature] add updateSubData for buffer
* [Feature] remove setVertexCount
* support depth test
* add callback command
* [Feature] add UITest
* [Feature] update UITest
* [Feature] remove unneeded codes
* fix custom command issue
* fix layer color blend issue
* [BugFix] fix iOS compile error
* [Feature] remove unneeded codes
* [Feature] fix updateVertexBuffer
* layerradial works
* add draw test back
* fix batch issue
* fix compiling error
* [BugFix] support ETC1
* [BugFix] get the correct pipelineDescriptor
* [BugFix] skip draw when backendTexture nullptr
* clipping node support
* [Feature] add shader files
* fix stencil issue in metal
* [Feature] update UILayoutTest
* [BugFix] skip drawing when vertexCount is zero
* refactor renderer
* add set global z order for stencil manager commands
* fix warnings caused by type
* remove viewport in render command
* [Feature] fix warnings caused by type
* [BugFix] clear vertexCount and indexCount for CustomComand when needed
* [Feature] update clear for CustomCommand
* ios use metal
* fix viewport issue
* fix LayerColorGradient crash
* [cmake] transport to android and windows (#160)
* save point 1
* compile on windows
* run on android
* revert useless change
* android set CC_ENABLE_CACHE_TEXTURE_DATA to 1
* add initGlew
* fix android crash
* add TODO new-renderer
* review update
* revert onGLFWWindowPosCallback
* fix android compiling error
* Impl progress radial (#162)
* progresstimer add radial impl
* default drawType to element
* dec invoke times of createVertexBuffer (#163)
* support depth/stencil format for gl backend
* simplify progress timer codes
* support motionstreak, effect is wrong
* fix motionstreak issue
* [Feature] update Scissor Test (#161)
* [Feature] update Scissor Test
* [Feature] update ScissorTest
* [Feature] rename function
* [Feature] get constant reference if needed
* [Feature] show render status (#164)
* improve performance
* fix depth state
* fill error that triangle vertex/index number bigger than buffer
* fix compiline error in release mode
* fix buffer conflict between CPU and GPU on iOS/macOS
* Renderer refactor (#165)
* use one vertes/index buffer with opengl
* fix error on windows
* custom command support index format config
* CCLayer: compact vertex data structure
* update comment
* fix doc
* support fast tilemap
* pass index format instead
* fix some wrong effect
* fix render texture error
* fix texture per-element size
* fix texture format error
* BlendFunc type refactor, GLenum -> backend::BlendFactor (#167)
* BlendFunc use backend::BlendFactor as inner field
* update comments
* use int to replace GLenum
* update xcode project fiel
* rename to GLBlendConst
* add ccConstants.h
* update xcode project file
* update copyright
* remove primitive command
* remove CCPrimitive.cpp/.h
* remove deprecated files
* remove unneeded files
* remove multiple view support
* remove multiple view support
* remove the usage of frame buffer in camera
* director don't use frame buffer
* remove FrameBuffer
* remove BatchCommand
* add some api reference
* add physics2d back
* fix crash when close app on mac
* improve render texture
* fix rendertexture issue
* fix rendertexture issue
* simplify codes
* CMake support for mac & ios (#169)
* update cmake
* fix compile error
* update 3rd libs version
* remove CCThread.h/.cpp
* remove ccthread
* use audio engine to implement simple audio engine
* remove unneeded codes
* remove deprecated codes
* remove winrt macro
* remove CC_USE_WIC
* set partcile blend function in more elegant way
* remove unneeded codes
* remove unneeded codes
* cmake works on windows
* update project setting
* improve performance
* GLFloat -> float
* sync v3 cmake improvements into metal-support (#172)
* pick: modern cmake, compile definitions improvement (#19139)
* modern cmake, use target_compile_definitions partly
* simplify macro define, remove USE_*
* modern cmake, macro define
* add physics 2d macro define into ccConfig.h
* remove USE_CHIPMUNK macro in build.gradle
* remove CocosSelectModule.cmake
* shrink useless define
* simplify compile options config, re-add if necessary
* update external for tmp CI test
* un-quote target_compile_options value
* add "-g" parameter only when debug mode
* keep single build type when generator Xcode & VS projecy
* update external for tmp CI tes
* add static_cast<char>(-1), fix -Wc++11-narrowing
* simplify win32 compile define
* not modify code, only improve compile options
# Conflicts:
# .gitignore
# cmake/Modules/CocosConfigDepend.cmake
# cocos/CMakeLists.txt
# external/config.json
# tests/cpp-tests/CMakeLists.txt
* modern cmake, improve cmake_compiler_flags (#19145)
* cmake_compiler_flags
* Fix typo
* Fix typo2
* Remove chanages from Android.mk
* correct lua template cmake build (#19149)
* don't add -Wno-deprecated into jsb target
* correct lua template cmake build
* fix win32 lua template compile error
* prevent cmake in-source-build friendly (#19151)
* pick: Copy resources to "Resources/" on win32 like in linux configuration
* add "/Z7" for cpp-tests on windows
* [cmake] fix iOS xcode property setting failed (#19208)
* fix iOS xcode property setting failed
* use search_depend_libs_recursive at dlls collect
* fix typo
* [cmake] add find_host_library into iOS toolchain file (#19230)
* pick: [lua android] use luajit & template cmake update (#19239)
* increase cmake stability , remove tests/CMakeLists.txt (#19261)
* cmake win32 Precompiled header (#19273)
* Precompiled header
* Fix
* Precompiled header for cocos
* Precompiled header jscocos2d
* Fix for COCOS2D_DEBUG is always 1 on Android (#19291)
Related #19289
* little build fix, tests cpp-tests works on mac
* sync v3 build related codes into metal-support (#173)
* strict initialization for std::array
* remove proj.win32 project configs
* modern cmake, cmake_cleanup_remove_unused_variables (#19146)
* Switch travis CI to xenial (#19207)
* Switch travis CI to xenial
* Remove language: android
* Set language: cpp
* Fix java problem
* Update sdkmanager
* Fix sdkmanger
* next sdkmanager fix
* Remove xenial from android
* revert to sdk-tools-{system}-3859397
* Remove linux cmake install
* Update before-install.sh
* Update .travis.yml
* Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212)
* Simplify install-deps-linux.sh
* Cleanup
* pick: install ninja
* update cocos2d-console submodule
* for metal-support alpha release, we only test cpp
* add HelloCpp into project(Cocos2d-x) for tmp test
* update extenal metal-support-4
* update uniform setting
* [Feature] update BindGroup
* [Feature] empty-test
* [Feature] cpp-test
* [Feature] fix GL compiler error
* [Feature] fix GL crash
* [Feature] empty-test
* [Feature] cpp-tests
* [feature] improve frameRate
* [feature] fix opengl compile error
* [feature] fix opengl compile error
* [BugFix] fix compute maxLocation error
* [Feature] update setting unifrom
* [Feature] fix namespace
* [Feature] remove unneeded code
* [Bugfix] fix project file
* [Feature] update review
* [texture2d] impl texture format support (#175)
* texture update
* update
* update texture
* commit
* compile on windows
* ddd
* rename
* rename methods
* no crash
* save gl
* save
* save
* rename
* move out pixel format convert functions
* metal crash
* update
* update android
* support gles compressed texture format
* support more compress format
* add more conversion methods
* ss
* save
* update conversion methods
* add PVRTC format support
* reformat
* add marco linux
* fix GL marcro
* pvrtc supported only by ios 8.0+
* remove unused cmake
* revert change
* refactor Texture2D::initWithData
* fix conversion log
* refactor Texture2D::initWithData
* remove some OpenGL constants for PVRTC
* add todo
* fix typo
* AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174)
* review cpp-tests, and fix part issues on start auto test
* sync png format fix: Node:Particle3D abnormal texture effects #19204
* fix cpp-tests SpritePolygon crash, wrong png format (#19170)
* fix wrong png convert format from sRGB to Gray
* erase plist index if all frames was erased
* test_A8.png have I8 format, fix it
* [CCSpriteCache] allow re-add plist & add testcase (#19175)
* allow re-add plist & add testcase
* remove comments/rename method/update testcase
* fix isSpriteFramesWithFileLoaded & add testcase
* remove used variable
* remove unused variable
* fix double free issues when js/lua-tests exit on iOS (#19236)
* disable part cases, AutoTest works without crash on mac
* update cocos2dx files json, to test cocos new next
* fix spritecache plist parsing issue (#19269)
* [linux] Fix FileUtils::getContents with folder (#19157)
* fix FileUtils::getContents on linux/mac
* use stat.st_mode
* simplify
* [CCFileUtils] win32 getFileSize (#19176)
* win32 getFileSize
* fix stat
* [cpp test-Android]20:FileUtils/2 change title (#19197)
* sync #19200
* sync #19231
* [android lua] improve performance of lua loader (#19234)
* [lua] improve performance of lua loader
* remove cache fix
* Revert "fix spritecache plist parsing issue (#19269)"
This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf.
* remove win32 project files ref in template.json
* add metal framework lnk ref into cpp template
* test on iOS, and disable part cases
* alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227)
* changes AudioCache to use alBufferData instead of alBufferDataStatic
(also makes test 19 faster to trigger openal bugs faster)
The original problem: CrashIfClientProvidedBogusAudioBufferList
https://github.com/cocos2d/cocos2d-x/issues/18948
is not happening anymore, but there's still a not very frequent issue
that makes OpenAL crash with a call stack like this.
AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList
It happes more frequently when the device is "cold", which means after
half an hour of not using the device (locked).
I could not find the actual source code for iOS OpenAL, so I used the
macOS versions:
https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html
They seem to use CAGuard.h to make sure the dead buffer list
has no threading issues. I'm worried because the CAGuard code I found
has macos and win32 define but no iOS, so I'm not sure. I guess the
iOS version is different and has the guard.
I could not find a place in the code that's unprotected by the locks
except the InitializeBufferMap() which should not be called more than
once from cocos, and there's a workaround in AudioEngine-impl for it.
I reduced the occurence of the CleanUpDeadBufferList crash by moving
the guard in ~AudioCache to cover the alDeleteBuffers call.
* remove hack method "setTimeout" on audio
* AutoTest works on iOS
* support set ios deployment target for root project
* enable all texture2d cases, since Jiang have fixed
* add CCTextureUtils to xcode project file (#176)
* add leak cases for SpriteFrameCache (#177)
* re-add SpriteFrameCache cases
* update template file json
* Update SpriteFrameCacheTest.cpp
* fix compiling error
2019-01-18 15:08:25 +08:00
|
|
|
//TODO:minggo
|
|
|
|
// if (_clippingToBounds)
|
|
|
|
// {
|
|
|
|
// auto glview = Director::getInstance()->getOpenGLView();
|
|
|
|
// if (glview->getVR() == nullptr) {
|
|
|
|
// if (_scissorRestored) {//restore the parent's scissor rect
|
|
|
|
// glview->setScissorInPoints(_parentScissorRect.origin.x, _parentScissorRect.origin.y, _parentScissorRect.size.width, _parentScissorRect.size.height);
|
|
|
|
// }
|
|
|
|
// else {
|
|
|
|
// glDisable(GL_SCISSOR_TEST);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
void ScrollView::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2014-08-14 14:15:16 +08:00
|
|
|
// quick return if not visible
|
2015-06-18 10:32:30 +08:00
|
|
|
if (!isVisible())
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2014-08-14 14:14:25 +08:00
|
|
|
return;
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
uint32_t flags = processParentFlags(parentTransform, parentFlags);
|
2014-03-01 03:20:53 +08:00
|
|
|
|
|
|
|
// IMPORTANT:
|
2014-05-15 01:07:09 +08:00
|
|
|
// To ease the migration to v3.0, we still support the Mat4 stack,
|
2014-03-01 03:20:53 +08:00
|
|
|
// but it is deprecated and your code should not rely on it
|
2014-04-03 15:55:37 +08:00
|
|
|
Director* director = Director::getInstance();
|
2015-10-09 16:59:11 +08:00
|
|
|
CCASSERT(nullptr != director, "Director is null when setting matrix stack");
|
2014-04-03 15:55:37 +08:00
|
|
|
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
|
|
|
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
|
2014-02-28 13:43:54 +08:00
|
|
|
|
2012-06-18 18:30:07 +08:00
|
|
|
this->beforeDraw();
|
2014-08-14 10:26:37 +08:00
|
|
|
bool visibleByCamera = isVisitableByVisitingCamera();
|
2012-06-18 18:30:07 +08:00
|
|
|
|
2014-08-14 14:14:25 +08:00
|
|
|
if (!_children.empty())
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2014-08-14 14:14:25 +08:00
|
|
|
int i=0;
|
2012-06-18 18:30:07 +08:00
|
|
|
|
|
|
|
// draw children zOrder < 0
|
2014-08-14 14:14:25 +08:00
|
|
|
for( ; i < _children.size(); i++ )
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2014-08-14 14:14:25 +08:00
|
|
|
Node *child = _children.at(i);
|
|
|
|
if ( child->getLocalZOrder() < 0 )
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2014-08-14 14:14:25 +08:00
|
|
|
child->visit(renderer, _modelViewTransform, flags);
|
|
|
|
}
|
2012-06-18 18:30:07 +08:00
|
|
|
else
|
|
|
|
{
|
2014-08-14 14:14:25 +08:00
|
|
|
break;
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
2014-08-14 14:14:25 +08:00
|
|
|
}
|
2012-06-18 18:30:07 +08:00
|
|
|
|
|
|
|
// this draw
|
2014-08-13 12:06:51 +08:00
|
|
|
if (visibleByCamera)
|
2014-08-14 14:11:00 +08:00
|
|
|
this->draw(renderer, _modelViewTransform, flags);
|
2013-09-12 20:47:15 +08:00
|
|
|
|
2014-08-14 14:11:00 +08:00
|
|
|
// draw children zOrder >= 0
|
|
|
|
for( ; i < _children.size(); i++ )
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-12-05 10:35:10 +08:00
|
|
|
Node *child = _children.at(i);
|
2014-05-31 07:42:05 +08:00
|
|
|
child->visit(renderer, _modelViewTransform, flags);
|
2014-08-14 14:11:00 +08:00
|
|
|
}
|
|
|
|
}
|
2014-08-13 12:06:51 +08:00
|
|
|
else if (visibleByCamera)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2014-08-14 14:11:00 +08:00
|
|
|
this->draw(renderer, _modelViewTransform, flags);
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
this->afterDraw();
|
|
|
|
|
2014-08-14 14:14:25 +08:00
|
|
|
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
bool ScrollView::onTouchBegan(Touch* touch, Event* /*event*/)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2014-09-05 19:49:15 +08:00
|
|
|
if (!this->isVisible() || !this->hasVisibleParents())
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Rect frame = getViewRect();
|
2013-02-16 14:18:13 +08:00
|
|
|
|
2012-06-18 18:30:07 +08:00
|
|
|
//dispatcher does not know about clipping. reject touches outside visible bounds.
|
2013-09-12 14:42:56 +08:00
|
|
|
if (_touches.size() > 2 ||
|
2013-06-15 14:03:30 +08:00
|
|
|
_touchMoved ||
|
2013-12-16 18:20:10 +08:00
|
|
|
!frame.containsPoint(touch->getLocation()))
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-12 16:03:03 +08:00
|
|
|
if (std::find(_touches.begin(), _touches.end(), touch) == _touches.end())
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-09-12 14:42:56 +08:00
|
|
|
_touches.push_back(touch);
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
2013-09-12 14:42:56 +08:00
|
|
|
if (_touches.size() == 1)
|
2012-06-18 18:30:07 +08:00
|
|
|
{ // scrolling
|
2013-06-15 14:03:30 +08:00
|
|
|
_touchPoint = this->convertTouchToNodeSpace(touch);
|
|
|
|
_touchMoved = false;
|
|
|
|
_dragging = true; //dragging started
|
2015-04-20 01:40:52 +08:00
|
|
|
_scrollDistance.setZero();
|
2013-06-15 14:03:30 +08:00
|
|
|
_touchLength = 0.0f;
|
|
|
|
}
|
2013-09-12 14:42:56 +08:00
|
|
|
else if (_touches.size() == 2)
|
2013-06-15 14:03:30 +08:00
|
|
|
{
|
2013-09-12 14:42:56 +08:00
|
|
|
_touchPoint = (this->convertTouchToNodeSpace(_touches[0]).getMidpoint(
|
|
|
|
this->convertTouchToNodeSpace(_touches[1])));
|
2013-07-11 16:38:58 +08:00
|
|
|
|
2013-09-12 14:42:56 +08:00
|
|
|
_touchLength = _container->convertTouchToNodeSpace(_touches[0]).getDistance(
|
|
|
|
_container->convertTouchToNodeSpace(_touches[1]));
|
2013-07-11 16:38:58 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_dragging = false;
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void ScrollView::onTouchMoved(Touch* touch, Event* /*event*/)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
|
|
|
if (!this->isVisible())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-12 14:42:56 +08:00
|
|
|
if (std::find(_touches.begin(), _touches.end(), touch) != _touches.end())
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-09-12 14:42:56 +08:00
|
|
|
if (_touches.size() == 1 && _dragging)
|
2012-06-18 18:30:07 +08:00
|
|
|
{ // scrolling
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 moveDistance, newPoint;
|
2013-06-20 14:15:53 +08:00
|
|
|
Rect frame;
|
2012-08-01 15:30:12 +08:00
|
|
|
float newX, newY;
|
2012-06-18 18:30:07 +08:00
|
|
|
|
2013-02-16 14:18:13 +08:00
|
|
|
frame = getViewRect();
|
2012-10-08 14:12:34 +08:00
|
|
|
|
2013-09-12 14:42:56 +08:00
|
|
|
newPoint = this->convertTouchToNodeSpace(_touches[0]);
|
2013-07-11 16:38:58 +08:00
|
|
|
moveDistance = newPoint - _touchPoint;
|
2013-02-16 19:36:21 +08:00
|
|
|
|
|
|
|
float dis = 0.0f;
|
2013-07-26 22:55:41 +08:00
|
|
|
if (_direction == Direction::VERTICAL)
|
2013-02-16 19:36:21 +08:00
|
|
|
{
|
|
|
|
dis = moveDistance.y;
|
2014-03-18 17:51:07 +08:00
|
|
|
float pos = _container->getPosition().y;
|
|
|
|
if (!(minContainerOffset().y <= pos && pos <= maxContainerOffset().y)) {
|
2014-03-19 17:01:38 +08:00
|
|
|
moveDistance.y *= BOUNCE_BACK_FACTOR;
|
2014-03-18 17:51:07 +08:00
|
|
|
}
|
2013-02-16 19:36:21 +08:00
|
|
|
}
|
2013-07-26 22:55:41 +08:00
|
|
|
else if (_direction == Direction::HORIZONTAL)
|
2013-02-16 19:36:21 +08:00
|
|
|
{
|
|
|
|
dis = moveDistance.x;
|
2014-03-18 17:51:07 +08:00
|
|
|
float pos = _container->getPosition().x;
|
|
|
|
if (!(minContainerOffset().x <= pos && pos <= maxContainerOffset().x)) {
|
2014-03-19 17:01:38 +08:00
|
|
|
moveDistance.x *= BOUNCE_BACK_FACTOR;
|
2014-03-18 17:51:07 +08:00
|
|
|
}
|
2013-02-16 19:36:21 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dis = sqrtf(moveDistance.x*moveDistance.x + moveDistance.y*moveDistance.y);
|
2014-03-19 17:01:38 +08:00
|
|
|
|
|
|
|
float pos = _container->getPosition().y;
|
|
|
|
if (!(minContainerOffset().y <= pos && pos <= maxContainerOffset().y)) {
|
|
|
|
moveDistance.y *= BOUNCE_BACK_FACTOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = _container->getPosition().x;
|
|
|
|
if (!(minContainerOffset().x <= pos && pos <= maxContainerOffset().x)) {
|
|
|
|
moveDistance.x *= BOUNCE_BACK_FACTOR;
|
|
|
|
}
|
2013-02-16 19:36:21 +08:00
|
|
|
}
|
2013-02-17 17:13:06 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (!_touchMoved && fabs(convertDistanceFromPointToInch(dis)) < MOVE_INCH )
|
2013-02-16 19:36:21 +08:00
|
|
|
{
|
2013-02-17 17:13:06 +08:00
|
|
|
//CCLOG("Invalid movement, distance = [%f, %f], disInch = %f", moveDistance.x, moveDistance.y);
|
2013-02-16 19:36:21 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (!_touchMoved)
|
2013-02-16 19:36:21 +08:00
|
|
|
{
|
2015-04-20 01:40:52 +08:00
|
|
|
moveDistance.setZero();
|
2013-02-16 19:36:21 +08:00
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_touchPoint = newPoint;
|
|
|
|
_touchMoved = true;
|
2012-06-18 18:30:07 +08:00
|
|
|
|
2014-03-19 17:08:28 +08:00
|
|
|
if (_dragging)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
switch (_direction)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-07-26 22:55:41 +08:00
|
|
|
case Direction::VERTICAL:
|
2015-04-20 01:40:52 +08:00
|
|
|
moveDistance.set(0.0f, moveDistance.y);
|
2012-06-18 18:30:07 +08:00
|
|
|
break;
|
2013-07-26 22:55:41 +08:00
|
|
|
case Direction::HORIZONTAL:
|
2015-04-20 01:40:52 +08:00
|
|
|
moveDistance.set(moveDistance.x, 0.0f);
|
2012-06-18 18:30:07 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-12-05 04:32:13 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
newX = _container->getPosition().x + moveDistance.x;
|
|
|
|
newY = _container->getPosition().y + moveDistance.y;
|
2012-12-05 04:32:13 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_scrollDistance = moveDistance;
|
2014-05-15 01:07:09 +08:00
|
|
|
this->setContentOffset(Vec2(newX, newY));
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
}
|
2013-09-12 14:42:56 +08:00
|
|
|
else if (_touches.size() == 2 && !_dragging)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-09-12 14:42:56 +08:00
|
|
|
const float len = _container->convertTouchToNodeSpace(_touches[0]).getDistance(
|
|
|
|
_container->convertTouchToNodeSpace(_touches[1]));
|
2013-06-15 14:03:30 +08:00
|
|
|
this->setZoomScale(this->getZoomScale()*len/_touchLength);
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void ScrollView::onTouchEnded(Touch* touch, Event* /*event*/)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
|
|
|
if (!this->isVisible())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-09-12 14:42:56 +08:00
|
|
|
|
|
|
|
auto touchIter = std::find(_touches.begin(), _touches.end(), touch);
|
|
|
|
|
|
|
|
if (touchIter != _touches.end())
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-09-12 14:42:56 +08:00
|
|
|
if (_touches.size() == 1 && _touchMoved)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2014-10-04 00:38:36 +08:00
|
|
|
this->schedule(CC_SCHEDULE_SELECTOR(ScrollView::deaccelerateScrolling));
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
2013-09-12 14:42:56 +08:00
|
|
|
_touches.erase(touchIter);
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
|
2013-09-12 14:42:56 +08:00
|
|
|
if (_touches.size() == 0)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_dragging = false;
|
|
|
|
_touchMoved = false;
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void ScrollView::onTouchCancelled(Touch* touch, Event* /*event*/)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
|
|
|
if (!this->isVisible())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-09-12 14:42:56 +08:00
|
|
|
|
|
|
|
auto touchIter = std::find(_touches.begin(), _touches.end(), touch);
|
2017-02-04 10:39:08 +08:00
|
|
|
|
|
|
|
if ( touchIter == _touches.end() )
|
|
|
|
return;
|
|
|
|
|
2013-09-12 14:42:56 +08:00
|
|
|
_touches.erase(touchIter);
|
|
|
|
|
|
|
|
if (_touches.size() == 0)
|
2012-06-18 18:30:07 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_dragging = false;
|
|
|
|
_touchMoved = false;
|
2012-06-18 18:30:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Rect ScrollView::getViewRect()
|
2013-02-16 14:18:13 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 screenPos = this->convertToWorldSpace(Vec2::ZERO);
|
2013-02-16 14:18:13 +08:00
|
|
|
|
|
|
|
float scaleX = this->getScaleX();
|
|
|
|
float scaleY = this->getScaleY();
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
for (Node *p = _parent; p != nullptr; p = p->getParent()) {
|
2013-02-16 14:18:13 +08:00
|
|
|
scaleX *= p->getScaleX();
|
|
|
|
scaleY *= p->getScaleY();
|
|
|
|
}
|
2013-04-30 23:17:38 +08:00
|
|
|
|
|
|
|
// Support negative scaling. Not doing so causes intersectsRect calls
|
|
|
|
// (eg: to check if the touch was within the bounds) to return false.
|
2013-06-20 14:15:53 +08:00
|
|
|
// Note, Node::getScale will assert if X and Y scales are different.
|
2013-04-30 23:17:38 +08:00
|
|
|
if(scaleX<0.f) {
|
2013-06-15 14:03:30 +08:00
|
|
|
screenPos.x += _viewSize.width*scaleX;
|
2013-04-30 23:17:38 +08:00
|
|
|
scaleX = -scaleX;
|
|
|
|
}
|
|
|
|
if(scaleY<0.f) {
|
2013-06-15 14:03:30 +08:00
|
|
|
screenPos.y += _viewSize.height*scaleY;
|
2013-04-30 23:17:38 +08:00
|
|
|
scaleY = -scaleY;
|
|
|
|
}
|
|
|
|
|
2013-07-12 14:30:26 +08:00
|
|
|
return Rect(screenPos.x, screenPos.y, _viewSize.width*scaleX, _viewSize.height*scaleY);
|
2013-02-16 14:18:13 +08:00
|
|
|
}
|
2012-06-18 18:30:07 +08:00
|
|
|
NS_CC_EXT_END
|