CCScrollView display area and touch area bug

I found 2 bugs of CCScrollView.

  1. CCScrollView disaplay area bug:
    In function void CCScrollView::beforeDraw(),
    CCPoint screenPos = this->convertToWorldSpace(this->getParent()->getPosition());
    I think it should be:
    CCPoint screenPos = this->getParent()->convertToWorldSpace(getPosition());

  2. Touch area bug:
    In function bool CCScrollView::ccTouchBegan(CCTouch* touch, CCEvent* event) and void CCScrollView::ccTouchMoved(CCTouch* touch, CCEvent* event)
    There is something wrong in calculating the frame of scrollview in world space.

CCRect frame; frame = CCRectMake(this->getPosition().x, this->getPosition().y, m_tViewSize.width, m_tViewSize.height);
I think it should be:
CCRect frame; CCPoint frameOriginal = this->getParent()->convertToWorldSpace(this->getPosition()); frame = CCRectMake(frameOriginal.x, frameOriginal.y, m_tViewSize.width, m_tViewSize.height);

Garfield Kwong wrote:

I found 2 bugs of CCScrollView.
>

  1. CCScrollView disaplay area bug:
    In function void CCScrollView::beforeDraw(),
    CCPoint screenPos = this->convertToWorldSpace(this->getParent()->getPosition());
    I think it should be:
    CCPoint screenPos = this->getParent()->convertToWorldSpace(getPosition());
    >
  2. Touch area bug:
    In function bool CCScrollView::ccTouchBegan(CCTouch* touch, CCEvent* event) and void CCScrollView::ccTouchMoved(CCTouch* touch, CCEvent* event)
    There is something wrong in calculating the frame of scrollview in world space.
    >
    CCRect frame; frame = CCRectMake(this->getPosition().x, this->getPosition().y, m_tViewSize.width, m_tViewSize.height);
    I think it should be:
    CCRect frame; CCPoint frameOriginal = this->getParent()->convertToWorldSpace(this->getPosition()); frame = CCRectMake(frameOriginal.x, frameOriginal.y, m_tViewSize.width, m_tViewSize.height);

Is this right? I try it, but there are still some problem

Seongkue Kang wrote:

Garfield Kwong wrote:
> I found 2 bugs of CCScrollView.
>
> 1. CCScrollView disaplay area bug:
> In function void CCScrollView::beforeDraw(),
> CCPoint screenPos = this->convertToWorldSpace(this->getParent()->getPosition());
> I think it should be:
> CCPoint screenPos = this->getParent()->convertToWorldSpace(getPosition());
>
> 2. Touch area bug:
> In function bool CCScrollView::ccTouchBegan(CCTouch* touch, CCEvent* event) and void CCScrollView::ccTouchMoved(CCTouch* touch, CCEvent* event)
> There is something wrong in calculating the frame of scrollview in world space.
>
> `CCRect frame;

frame = CCRectMake(this->getPosition().x, this->getPosition().y, m_tViewSize.width, m_tViewSize.height);`

> I think it should be:
> `CCRect frame;

CCPoint frameOriginal = this->getParent()->convertToWorldSpace(this->getPosition()); 
frame = CCRectMake(frameOriginal.x, frameOriginal.y, m_tViewSize.width, m_tViewSize.height);`

>

Is this right? I try it, but there are still some problem

I found same CCScrollView disaplay area bug

My solution is a bit different, but I think the result should be same.

I changed
CCPoint screenPos = this->convertToWorldSpace(this->getParent()>getPosition);
to
CCPoint screenPos = this
>convertToWorldSpace(CCPointZero);

Also, it has a bug for Retina display.

Shouldn’t it be

@
glScissor((GLint)screenPos.x, (GLint)screenPos.y, (GLsizei)(m_tViewSize.width*s), (GLsizei)(m_tViewSize.height*s));
->
glScissor((GLint)screenPos.x*s, (GLint)screenPos.y*s, (GLsizei)(m_tViewSize.width*s), (GLsizei)(m_tViewSize.height*s));
@

???

Garfield Kwong’s Answer is right.

And, Add some code in beforeDraw() for retina.

CCPoint screenPos = this->getParent()->convertToWorldSpace(getPosition());
screenPos = CC_POINT_POINTS_TO_PIXELS(screenPos); // Add this code for Retina

Seongkue Kang wrote:

Garfield Kwong’s Answer is right.
>
And, Add some code in beforeDraw() for retina.
>
CCPoint screenPos = this->getParent()->convertToWorldSpace(getPosition());
screenPos = CC_POINT_POINTS_TO_PIXELS(screenPos); // Add this code for Retina

In Cocos2d-x 2.0.2 you should use

CCEGLView::sharedOpenGLView()->setScissorInPoints()

and not glScissor directly.

It is a great extension. Thank you all.

eh, I found that there is another bug:

void CCScrollView::ccTouchMoved(CCTouch* touch, CCEvent* event)

not all the touch area can move. I modified some lines.

The modified code is:

CCPoint moveDistance, newPoint, maxInset, minInset;
//CCRect frame;
float newX, newY;

CCRect frame;
CCPoint frameOriginal = this->getParent()>convertToWorldSpace);
frame = CCRectMake;
m_bTouchMoved = true;
//frame = CCRectMake.x, this
>getPosition().y, m_tViewSize.width, m_tViewSize.height);

You’re right, issue #1495 was created for this issue. Thanks. :slight_smile:
Garfield Kwong wrote:

I found 2 bugs of CCScrollView.
>

  1. CCScrollView disaplay area bug:
    In function void CCScrollView::beforeDraw(),
    CCPoint screenPos = this->convertToWorldSpace(this->getParent()->getPosition());
    I think it should be:
    CCPoint screenPos = this->getParent()->convertToWorldSpace(getPosition());
    >
  2. Touch area bug:
    In function bool CCScrollView::ccTouchBegan(CCTouch* touch, CCEvent* event) and void CCScrollView::ccTouchMoved(CCTouch* touch, CCEvent* event)
    There is something wrong in calculating the frame of scrollview in world space.
    >
    CCRect frame; frame = CCRectMake(this->getPosition().x, this->getPosition().y, m_tViewSize.width, m_tViewSize.height);
    I think it should be:
    CCRect frame; CCPoint frameOriginal = this->getParent()->convertToWorldSpace(this->getPosition()); frame = CCRectMake(frameOriginal.x, frameOriginal.y, m_tViewSize.width, m_tViewSize.height);