void markupEllipse::drawMarkup( QPainter& p )
{
    // Scale markup
    QRect scaledRect = rect;
    double scale = getZoomScale();
    scaledRect.moveTo( rect.x() * scale, rect.y() * scale );

    scaledRect.setWidth( rect.width() * scale );
    scaledRect.setHeight( rect.height() * scale );

    // Draw markup
    p.drawEllipse( scaledRect );

    // Draw markup legend
    drawLegend( p, scaledRect.topLeft() );
}
Example #2
0
GridViewCell* GridView::cellForTouch(Touch *touch)
{
    Vec2 offset = getContentOffset();
    const Size size = getViewSize();
    const float scale = getZoomScale();
    
    Rect viewRect = Rect::ZERO;
    
    if (Direction::Horizontal == _direction)
    {
        if (0 <= offset.x) // right
        {
            offset.x = offset.x + _cellSize.width;
            
        } else // left
        {
            offset.x = offset.x - _cellSize.width;
        }
    } else if (Direction::Vertical == _direction)
    {
        if (0 <= offset.y) // down
        {
            offset.y = offset.y + _cellSize.height;
            
        } else // up
        {
            offset.y = offset.y - _cellSize.height;
        }
    }
    viewRect = Rect(-offset.x/scale, -offset.y/scale, size.width/scale, size.height/scale);
    
    for (int i = 0; i < _container->getChildrenCount(); i++)
    {
        GridViewCell* pCell = dynamic_cast<GridViewCell*>(_container->getChildren().at(i));
        if (!pCell) continue;
        
        if (viewRect.intersectsRect(pCell->boundingBox()))
        {
            if (pCell->boundingBox().containsPoint(_container->convertTouchToNodeSpace(touch)))
            {
                return pCell;
            }
        }
    }
    return nullptr;
}
CCPoint CCScrollView::getNodeFullyVisibleOffset(CCNode* node) {
    // get node bound in container
    CCRect nodeBound = CCRectMake(0, 0, node->getContentSize().width, node->getContentSize().height);
    CCAffineTransform t = node->nodeToAncestorTransform(getContainer());
    nodeBound = CCRectApplyAffineTransform(nodeBound, t);
    
    // get offset
    float scale = getZoomScale();
    CCPoint offset = ccp(-nodeBound.origin.x / scale, -nodeBound.origin.y / scale);
    
    // clamp offset
    const CCPoint minOffset = minContainerOffset();
    const CCPoint maxOffset = maxContainerOffset();
    offset.x = MAX(minOffset.x, MIN(maxOffset.x, offset.x));
    offset.y = MAX(minOffset.y, MIN(maxOffset.y, offset.y));
    
    // return
    return offset;
}
void WHScrollView::onTouchMoved(cocos2d::Touch *pTouch, cocos2d::Event *pEvent)
{
	if (m_PointerId != pTouch->getID())
		return;

	if (m_MoveCount < 8)
		m_MoveCount++;

	//CCScrollView::ccTouchMoved(pTouch, pEvent);
	if (!isVisible())
		return;

	if (m_bScroll)
	{
		//if (_touches->containsObject(pTouch))
		if (std::find(_touches.begin(), _touches.end(), pTouch) != _touches.end())
		{
			if (_touches.size() == 1 && _dragging)
			{ // scrolling
				CCPoint moveDistance, newPoint, maxInset, minInset;
				CCRect  frame;
				float newX, newY;

				_touchMoved = true;
				CCPoint frameOriginal = getParent()->convertToWorldSpace(getPosition());
				//frame = CCRectMake(frameOriginal.x, frameOriginal.y, m_tViewSize.width, m_tViewSize.height);
				frame = CCRectMake(0, 0, _viewSize.width, _viewSize.height);

				newPoint = convertTouchToNodeSpace((CCTouch*)_touches[0]);
				moveDistance = ccpSub(newPoint, _touchPoint);
				_touchPoint = newPoint;
				CCSize contentsize = getContentSize();
				CCPoint offset = getContentOffset();
				if (offset.y <= _viewSize.height - contentsize.height)
				{
					moveDistance.y = moveDistance.y / m_MoveCount;
				}
				//if (frame.containsPoint(convertToWorldSpace(newPoint)))
				if (frame.containsPoint(newPoint))
				{
					switch (_direction)
					{
					case ScrollView::Direction::VERTICAL:
						moveDistance = ccp(0.0f, moveDistance.y);
						break;
					case ScrollView::Direction::HORIZONTAL:
						moveDistance = ccp(moveDistance.x, 0.0f);
						break;
					default:
						break;
					}

					_container->setPosition(ccpAdd(_container->getPosition(), moveDistance));

					maxInset = _maxInset;
					minInset = _minInset;


					//check to see if offset lies within the inset bounds
					newX = MIN(_container->getPosition().x, maxInset.x);
					newX = MAX(newX, minInset.x);
					newY = MIN(_container->getPosition().y, maxInset.y);
					newY = MAX(newY, minInset.y);

					_scrollDistance = ccpSub(moveDistance, ccp(newX - _container->getPosition().x, newY - _container->getPosition().y));
					setContentOffset(ccp(newX, newY));
				}
			}
			else if (_touches.size() == 2 && !_dragging)
			{
				const float len = ccpDistance(_container->convertTouchToNodeSpace((CCTouch*)_touches[0]),_container->convertTouchToNodeSpace((CCTouch*)_touches[1]));
				setZoomScale(getZoomScale()*len / _touchLength);
			}
		}
	}

	for (int i = 0; i < m_TouchLayer.size(); i++)
	{
		if (m_TouchLayerTouched[i])
		{
			CCLayer* pTouchLayer = m_TouchLayer[i];
			pTouchLayer->ccTouchMoved(pTouch, pEvent);
		}
	}
	//CCScrollView::ccTouchMoved(pTouch, pEvent);

}