int
SoXipOverlayTransformBoxManip::pickControlPoint( SoHandleEventAction* action )
{
	if( mControlPointsSwitch->whichChild.getValue() != -1 )
	{
		SbVec2f mousePt = action->getEvent()->getNormalizedPosition( action->getViewportRegion() );
		SbVec3f screenPt;

		const SbVec3f* point = mControlPointsCoords->point.getValues(0);

		int numPoints = mControlPointsCoords->point.getNum();
		for( int i = 0; i < numPoints; ++ i )
		{
			mViewVolume.projectToScreen( point[i], screenPt );

			SbVec2f d = SbVec2f( screenPt[0], screenPt[1] ) - mousePt;
			if( d.length() < 0.01 )
				return i;
		}
	}
	return -1;
}
Пример #2
0
int
IfHasher::addVector(const SbVec2f &newVector)
{
    ASSERT(vectorDict != NULL);
    ASSERT(dimension == 2);

    // See if we need to add this one, or is it already there
    int index;
    SbBool notThere = addIfNotThere(newVector.getValue(), index);

    // If it's not there, we need to add it to the field
    if (notThere)
	vectors2[index] = newVector;

    return index;
}
Пример #3
0
void SoFCColorBar::handleEvent (SoHandleEventAction *action) 
{
    const SoEvent * event = action->getEvent();

    // check for mouse button events
    if (event->getTypeId().isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) {
        const SoMouseButtonEvent*  e = static_cast<const SoMouseButtonEvent*>(event);

        // calculate the mouse position relative to the colorbar
        //
        const SbViewportRegion&  vp = action->getViewportRegion(); 
        float fRatio = vp.getViewportAspectRatio();
        SbVec2f pos = event->getNormalizedPosition(vp);
        float pX,pY; pos.getValue(pX,pY);

        pX = pX*10.0f-5.0f;
        pY = pY*10.0f-5.0f;

        // now calculate the real points respecting aspect ratio information
        //
        if (fRatio > 1.0f) {
            pX = pX * fRatio;
        }
        else if (fRatio < 1.0f) {
            pY = pY / fRatio;
        }

        // check if the cursor is near to the color bar
        if (_fMinX > pX || pX > _fMaxX || _fMinY > pY || pY > _fMaxY)
            return; // not inside the rectangle

        // left mouse pressed
        action->setHandled();
        if ((e->getButton() == SoMouseButtonEvent::BUTTON1)) {
            if (e->getState() == SoButtonEvent::DOWN) {
                // double click event
                if (_timer.restart() < QApplication::doubleClickInterval()) {
                    QApplication::postEvent(
                        new SoFCColorBarProxyObject(this),
                        new QEvent(QEvent::User));
                }
            }
        }
        // right mouse pressed
        else if ((e->getButton() == SoMouseButtonEvent::BUTTON2)) {
            if (e->getState() == SoButtonEvent::UP) {
                SoFCColorBarBase* current = getActiveBar();
                QMenu menu;
                int i=0;
                for (std::vector<SoFCColorBarBase*>::const_iterator it = _colorBars.begin(); it != _colorBars.end(); ++it) {
                    QAction* item = menu.addAction(QLatin1String((*it)->getColorBarName()));
                    item->setCheckable(true);
                    item->setChecked((*it) == current);
                    item->setData(QVariant(i++));
                }

                menu.addSeparator();
                QAction* option = menu.addAction(QObject::tr("Options..."));
                QAction* action = menu.exec(QCursor::pos());

                if (action == option) {
                    QApplication::postEvent(
                        new SoFCColorBarProxyObject(this),
                        new QEvent(QEvent::User));
                }
                else if (action) {
                    int id = action->data().toInt();
                    pColorMode->whichChild = id;
                }
            }
        }
    }
}