Set scale cctableview's parent node

In my CCLayer,I inherit cctableview widgets,
but now i have a problem that i touch the cell but tableCellTouched() does not respond when i set its parent node scale(1.3f);

like this:
table_view_ = CCTableView::create(this, CCSizeMake(243, 487)); table_view_->setDirection(kCCScrollViewDirectionVertical); table_view_->setPosition(CCPointZero); table_view_->setDelegate(this); table_view_->setVerticalFillOrder(kCCTableViewFillTopDown); view_panel_->addChild(table_view_); table_view_->reloadData(); view_panel_->setScale(1.3f);

How to deal with this case?

Yes, I have the same problem. It seems there is a bug in CCTableView.cpp (ver. 2.1.4). In ccTouchEnded():

if (m_pTouchedCell){
CCRect bb = this~~>boundingBox;
bb.origin = m_pParent~~>convertToWorldSpace(bb.origin);

if (bb.containsPoint(pTouch~~>getLocation) && m_pTableViewDelegate != NULL)
{
m_pTableViewDelegate~~>tableCellUnhighlight(this, m_pTouchedCell);
m_pTableViewDelegate~~>tableCellTouched;
}
m_pTouchedCell = NULL;
}
boundingBox returns the original size, let’s say it’s 960x640.
Now you scale your tableview either by attaching your tableview to a scaled node or manually scaling it, but boundingbox still returns the same size 960x640.
and pTouch~~>getLocation() returns the world position (relative to screen), thus
bb.containsPoint(pTouch->getLocation()) will not work.

This is a stupid bug which means CCTableview simply won’t work properly when attaching to scaled node. Hope this can be fixed soon.

超 杨 wrote:

In my CCLayer,I inherit cctableview widgets,
but now i have a problem that i touch the cell but tableCellTouched() does not respond when i set its parent node scale(1.3f);
>
like this:
table_view_ = CCTableView::create(this, CCSizeMake(243, 487)); table_view_->setDirection(kCCScrollViewDirectionVertical); table_view_->setPosition(CCPointZero); table_view_->setDelegate(this); table_view_->setVerticalFillOrder(kCCTableViewFillTopDown); view_panel_->addChild(table_view_); table_view_->reloadData(); view_panel_->setScale(1.3f);
>
How to deal with this case?

Thank U. I have finded this problem some day ago.
I delete this redundant codes.

if(m_pTouchedCell){ //CCRect bb = this->boundingBox(); //bb.origin = m_pParent->convertToWorldSpace(bb.origin); //if (bb.containsPoint(pTouch->getLocation()) && m_pTableViewDelegate != NULL) if (m_pTableViewDelegate != NULL) { m_pTableViewDelegate->tableCellUnhighlight(this, m_pTouchedCell); m_pTableViewDelegate->tableCellTouched(this, m_pTouchedCell); }

and it returned to normal.

Hope this can be fixed soon too. Thanks again.

Like Zhang wrote:

Yes, I have the same problem. It seems there is a bug in CCTableView.cpp (ver. 2.1.4). In ccTouchEnded():
>
if (m_pTouchedCell){
CCRect bb = this~~>boundingBox;
bb.origin = m_pParent~~>convertToWorldSpace(bb.origin);
>
if (bb.containsPoint(pTouch~~>getLocation) && m_pTableViewDelegate != NULL)
{
m_pTableViewDelegate~~>tableCellUnhighlight(this, m_pTouchedCell);
m_pTableViewDelegate~~>tableCellTouched;
}
>
m_pTouchedCell = NULL;
}
>
boundingBox returns the original size, let’s say it’s 960x640.
>
Now you scale your tableview either by attaching your tableview to a scaled node or manually scaling it, but boundingbox still returns the same size 960x640.
>
and pTouch~~>getLocation() returns the world position (relative to screen), thus
bb.containsPoint(pTouch->getLocation()) will not work.
>
>
This is a stupid bug which means CCTableview simply won’t work properly when attaching to scaled node. Hope this can be fixed soon.
>
>
超 杨 wrote:
> In my CCLayer,I inherit cctableview widgets,
> but now i have a problem that i touch the cell but tableCellTouched() does not respond when i set its parent node scale(1.3f);
>
> like this:
> `table_view_ = CCTableView::create(this, CCSizeMake(243, 487));

table_view_->setDirection(kCCScrollViewDirectionVertical);
table_view_->setPosition(CCPointZero);
table_view_->setDelegate(this);
table_view_->setVerticalFillOrder(kCCTableViewFillTopDown);
view_panel_->addChild(table_view_);
table_view_->reloadData();
view_panel_->setScale(1.3f);`
>
> How to deal with this case?

IF someone is still looking for a solution to this problem, then here is how you fix it:

In CCTableView.cpp:

in:
void TableView::onTouchEnded(Touch *pTouch, Event *pEvent)

change this:

	Rect bb = this->getBoundingBox();
	bb.origin = _parent->convertToWorldSpace(bb.origin);

to this:

	Rect bb = this->getBoundingBox();
	auto Orig = this->convertToWorldSpace(cocos2d::Vec2(0.0f, 0.0f));
	auto X = this->convertToWorldSpace(cocos2d::Vec2(bb.size.width, 0.0f));
	auto Y = this->convertToWorldSpace(cocos2d::Vec2(0.0f, bb.size.height));
	auto Width = Orig.distance(X);
	auto Height = Orig.distance(Y);
	bb.size = cocos2d::Vec2(Width, Height);
	bb.origin = _parent->convertToWorldSpace(bb.origin);

Hope that helps someone.