Exemple #1
0
bool InteractScene::penUp( const OFX::PenArgs& args )
{
	//TUTTLE_LOG_TRACE("penUp");
	bool result = false;

	if( _creatingSelection )
	{
		_selectionRect.x2 = args.penPosition.x;
		_selectionRect.y2 = args.penPosition.y;

		_selected.clear();
		//TUTTLE_LOG_VAR4( TUTTLE_TRACE, _selectionRect.x1, _selectionRect.y1, _selectionRect.x2, _selectionRect.y2 );
		IsActiveFunctorVector::iterator itActive = _isActive.begin();
		for( InteractObjectsVector::iterator it = _objects.begin(), itEnd = _objects.end();
			 it != itEnd;
			 ++it, ++itActive )
		{
			if( ! itActive->active() )
				continue;
			if( it->isIn( _selectionRect ) )
			{
				it->setSelected(true);
				_selected.push_back( SelectedObject( &(*it), it->getPosition() ) );
				_hasSelection = true;
				result = true;
			}
			else
			{
				it->setSelected(false);
			}
		}
		//TUTTLE_LOG_VAR( TUTTLE_TRACE, _selected.size() );
		_creatingSelection = false;
	}

	_mouseDown = false;
	_creatingSelection = false;
	
	_params.endEditBlock();

	return result;
}
Exemple #2
0
bool InteractScene::penMotion(const OFX::PenArgs& args)
{
    if(!_mouseDown)
        return false;

    if(_creatingSelection)
    {
        // create selection

        TUTTLE_LOG_TRACE("create a selection");
        _selectionRect.x2 = args.penPosition.x;
        _selectionRect.y2 = args.penPosition.y;
        _hasSelection = false;

        IsActiveFunctorVector::iterator itActive = _isActive.begin();
        for(InteractObjectsVector::iterator it = _objects.begin(), itEnd = _objects.end(); it != itEnd; ++it, ++itActive)
        {
            if(!itActive->active())
                continue;
            if(it->isIn(_selectionRect))
            {
                it->setSelected(true);
                _hasSelection = true;
            }
            else
            {
                it->setSelected(false);
            }
        }
        return true;
    }

    if(_selected.size() == 0)
    {
        TUTTLE_LOG_INFOS;
        return false;
    }

    const Point2 penPosition = ofxToGil(args.penPosition);
    switch(_motionType._mode)
    {
        case eMotionTranslate:
        {
            translate(penPosition - _beginPenPosition);
            break;
        }
        case eMotionRotate:
        {
            if(_manipulator)
            {
                rotate(_manipulator->getPosition(), penPosition, penPosition - _beginPenPosition);
            }
            break;
        }
        case eMotionScale:
        {
            if(_manipulator)
                scale(_manipulator->getPosition(), penPosition - _beginPenPosition);
            break;
        }
        case eMotionNone:
        {
            TUTTLE_LOG_INFOS;
            break;
        }
    }
    return true;
}
Exemple #3
0
bool InteractScene::penDown(const OFX::PenArgs& args)
{
    // TUTTLE_LOG_TRACE("penDown");
    const Point2 penPosition = ofxToGil(args.penPosition);
    _mouseDown = true;
    _beginPenPosition = penPosition;
    _selectionRect.x1 = args.penPosition.x;
    _selectionRect.y1 = args.penPosition.y;
    _selectionRect.x2 = args.penPosition.x;
    _selectionRect.y2 = args.penPosition.y;
    _motionType._mode = eMotionNone;
    _motionType._axis = eAxisNone;

    bool result = false;
    SelectedObject oneSelectedObj;

    if(_hasSelection && _manipulator)
    {
        _motionType = _manipulator->intersect(args);
        if(_motionType._mode != eMotionNone)
        {
            result = true;
        }
    }
    if(!result)
    {
        IsActiveFunctorVector::iterator itActive = _isActive.begin();
        for(InteractObjectsVector::iterator it = _objects.begin(), itEnd = _objects.end(); it != itEnd; ++it, ++itActive)
        {
            if(!itActive->active())
                continue;
            MotionType m = it->intersect(args);
            if(m._axis != eAxisNone)
            {
                // first time
                if(_motionType._axis == eAxisNone)
                {
                    oneSelectedObj = SelectedObject(&(*it), it->getPosition());
                    _motionType = m;
                }
                else if(m._axis == eAxisXY) // if we already register an object X or Y and we found an XY intersection
                {
                    oneSelectedObj = SelectedObject(&(*it), it->getPosition());
                    _motionType = m;
                }
                result = true;
                if(m._axis == eAxisXY)
                    break;
            }
        }
    }

    if(_hasSelection)
    {
        if(result)
        {
            bool objInSelection = false;
            // compute the offset for each object
            for(SelectedObjectVector::iterator it = _selected.begin(), itEnd = _selected.end(); it != itEnd; ++it)
            {
                it->second = it->first->getPosition();
                if(it->first == oneSelectedObj.first)
                {
                    objInSelection = true;
                }
            }
            if(!objInSelection)
            {
                _hasSelection = false;
            }
        }
        else
        {
            _hasSelection = false;
        }
    }
    if(!_hasSelection)
    {
        for(InteractObjectsVector::iterator it = _objects.begin(), itEnd = _objects.end(); it != itEnd; ++it)
        {
            it->setSelected(false);
        }
        _selected.clear();
        if(result)
        {
            _selected.push_back(oneSelectedObj);
        }
    }

    if(_multiSelectionEnabled)
    {
        if(!result)
        {
            _hasSelection = false;
            _creatingSelection = true;
        }
    }

    if(_multiSelectionEnabled || result)
    {
        _params.beginEditBlock("InteractObjectsGroup");
        return true;
    }
    return false;
}