Example #1
0
void RenderableGadget::doRender( const Style *style ) const
{
	if( IECoreGL::Selector::currentSelector() )
	{
		// our scene may contain shaders which don't work with
		// the selector so we early out for now. we could override
		// the base state with an appropriate selection shader and
		// a name component matching the name for the gadget, but
		// right now we have no need for that.
		return;
	}

	if( m_scene )
	{
		m_scene->render( m_baseState.get() );
	}

	if( m_dragSelecting )
	{
		const ViewportGadget *viewportGadget = ancestor<ViewportGadget>();
		ViewportGadget::RasterScope rasterScope( viewportGadget );

		Box2f b;
		b.extendBy( viewportGadget->gadgetToRasterSpace( m_dragStartPosition, this ) );
		b.extendBy( viewportGadget->gadgetToRasterSpace( m_lastDragPosition, this ) );

		style->renderSelectionBox( b );
	}
}
Example #2
0
void GraphGadget::updateDragSelection( bool dragEnd )
{
	Box2f selectionBound;
	selectionBound.extendBy( m_dragStartPosition );
	selectionBound.extendBy( m_lastDragPosition );

	for( NodeGadgetMap::const_iterator it = m_nodeGadgets.begin(), eIt = m_nodeGadgets.end(); it != eIt; ++it )
	{
		NodeGadget *nodeGadget = it->second.gadget;
		const Box3f nodeBound3 = nodeGadget->transformedBound();
		const Box2f nodeBound2( V2f( nodeBound3.min.x, nodeBound3.min.y ), V2f( nodeBound3.max.x, nodeBound3.max.y ) );
		if( boxContains( selectionBound, nodeBound2 ) )
		{
			nodeGadget->setHighlighted( true );
			if( dragEnd )
			{
				m_scriptNode->selection()->add( const_cast<Gaffer::Node *>( it->first ) );
			}
		}
		else
		{
			nodeGadget->setHighlighted( m_scriptNode->selection()->contains( it->first ) );
		}
	}
}
Example #3
0
    void updateDragRectangle( const GafferUI::DragDropEvent &event, RectangleChangedReason reason )
    {
        const V2f p = eventPosition( event );
        Box2f b = m_dragStartRectangle;
        if( m_xDragEdge == -1 )
        {
            b.min.x = p.x;
        }
        else if( m_xDragEdge == 1 )
        {
            b.max.x = p.x;
        }

        if( m_yDragEdge == -1 )
        {
            b.min.y = p.y;
        }
        else if( m_yDragEdge == 1 )
        {
            b.max.y = p.y;
        }

        // fix max < min issues
        Box2f c;
        c.extendBy( b.min );
        c.extendBy( b.max );

        setRectangleInternal( c, reason );
    }
Example #4
0
ViewportGadget::SelectionScope::SelectionScope( const Imath::V3f &corner0InGadgetSpace, const Imath::V3f &corner1InGadgetSpace, const Gadget *gadget, std::vector<IECoreGL::HitRecord> &selection, IECoreGL::Selector::Mode mode )
	:	m_selection( selection )
{
	const ViewportGadget *viewportGadget = gadget->ancestor<ViewportGadget>();
	
	Box2f rasterRegion;
	rasterRegion.extendBy( viewportGadget->gadgetToRasterSpace( corner0InGadgetSpace, gadget ) );
	rasterRegion.extendBy( viewportGadget->gadgetToRasterSpace( corner1InGadgetSpace, gadget ) );
	
	begin( viewportGadget, rasterRegion, gadget->fullTransform(), mode );
}
Example #5
0
void GraphGadget::doRender( const Style *style ) const
{
	glDisable( GL_DEPTH_TEST );
	
	// render backdrops before anything else
	/// \todo Perhaps we need a more general layering system as part
	/// of the Gadget system, to allow Gadgets to choose their own layering,
	/// and perhaps to also allow one gadget to draw into multiple layers.
	for( ChildContainer::const_iterator it=children().begin(); it!=children().end(); it++ )
	{
		if( (*it)->isInstanceOf( (IECore::TypeId)BackdropNodeGadgetTypeId ) )
		{
			static_cast<const Gadget *>( it->get() )->render( style );		
		}
	}	
	
	// then render connections so they go underneath the nodes
	for( ChildContainer::const_iterator it=children().begin(); it!=children().end(); it++ )
	{
		ConnectionGadget *c = IECore::runTimeCast<ConnectionGadget>( it->get() );
		if ( c && c != m_dragReconnectCandidate )
		{
			c->render( style );
		}
	}

	// render the new drag connections if they exist
	if ( m_dragReconnectCandidate )
	{
		if ( m_dragReconnectDstNodule )
		{
			const Nodule *srcNodule = m_dragReconnectCandidate->srcNodule();
			const NodeGadget *srcNodeGadget = nodeGadget( srcNodule->plug()->node() );
			const Imath::V3f srcP = srcNodule->fullTransform( this ).translation();
			const Imath::V3f dstP = m_dragReconnectDstNodule->fullTransform( this ).translation();
			const Imath::V3f dstTangent = nodeGadget( m_dragReconnectDstNodule->plug()->node() )->noduleTangent( m_dragReconnectDstNodule );
			/// \todo: can there be a highlighted/dashed state?
			style->renderConnection( srcP, srcNodeGadget->noduleTangent( srcNodule ), dstP, dstTangent, Style::HighlightedState );
		}
		
		if ( m_dragReconnectSrcNodule )
		{
			const Nodule *dstNodule = m_dragReconnectCandidate->dstNodule();
			const NodeGadget *dstNodeGadget = nodeGadget( dstNodule->plug()->node() );
			const Imath::V3f srcP = m_dragReconnectSrcNodule->fullTransform( this ).translation();
			const Imath::V3f dstP = dstNodule->fullTransform( this ).translation();
			const Imath::V3f srcTangent = nodeGadget( m_dragReconnectSrcNodule->plug()->node() )->noduleTangent( m_dragReconnectSrcNodule );
			/// \todo: can there be a highlighted/dashed state?
			style->renderConnection( srcP, srcTangent, dstP, dstNodeGadget->noduleTangent( dstNodule ), Style::HighlightedState );
		}
	}
	
	// then render the rest on top
	for( ChildContainer::const_iterator it=children().begin(); it!=children().end(); it++ )
	{
		if( !((*it)->isInstanceOf( ConnectionGadget::staticTypeId() )) && !((*it)->isInstanceOf( (IECore::TypeId)BackdropNodeGadgetTypeId )) )
		{
			static_cast<const Gadget *>( it->get() )->render( style );
		}
	}

	// render drag select thing if needed
	if( m_dragMode == Selecting )
	{
		const ViewportGadget *viewportGadget = ancestor<ViewportGadget>();
		ViewportGadget::RasterScope rasterScope( viewportGadget );

		Box2f b;
		b.extendBy( viewportGadget->gadgetToRasterSpace( V3f( m_dragStartPosition.x, m_dragStartPosition.y, 0 ), this ) );
		b.extendBy( viewportGadget->gadgetToRasterSpace( V3f( m_lastDragPosition.x, m_lastDragPosition.y, 0 ), this ) );
		style->renderSelectionBox( b );		
	}
	
}
Example #6
0
bool GraphGadget::dragEnd( GadgetPtr gadget, const DragDropEvent &event )
{
	DragMode dragMode = m_dragMode;
	m_dragMode = None;
	Pointer::set( 0 );
	
	if( !m_scriptNode )
	{
		return false;
	}
	
	V3f i;
	if( !event.line.intersect( Plane3f( V3f( 0, 0, 1 ), 0 ), i ) )
	{
		return false;
	}
	
	if( dragMode == Moving )
	{
		if ( m_dragReconnectCandidate )
		{
			if ( m_dragReconnectDstNodule || m_dragReconnectSrcNodule )
			{
				Gaffer::Plug *srcPlug = m_dragReconnectCandidate->srcNodule()->plug();
				Gaffer::Plug *dstPlug = m_dragReconnectCandidate->dstNodule()->plug();
				
				Gaffer::UndoContext undoContext( m_scriptNode );
				
				if ( m_dragReconnectDstNodule )
				{
					m_dragReconnectDstNodule->plug()->setInput( srcPlug );
					dstPlug->setInput( 0 );
				}

				if ( m_dragReconnectSrcNodule )
				{
					dstPlug->setInput( m_dragReconnectSrcNodule->plug() );
				}
			}
		}
		
		m_dragReconnectCandidate = 0;
		renderRequestSignal()( this );
	}
	else if( dragMode == Selecting )
	{
		Box2f selectionBound;
		selectionBound.extendBy( m_dragStartPosition );
		selectionBound.extendBy( m_lastDragPosition );
	
		for( ChildContainer::const_iterator it=children().begin(); it!=children().end(); it++ )
		{
			NodeGadgetPtr nodeGadget = runTimeCast<NodeGadget>( *it );
			if( nodeGadget )
			{
				Box3f nodeBound3 = nodeGadget->transformedBound();
				Box2f nodeBound2( V2f( nodeBound3.min.x, nodeBound3.min.y ), V2f( nodeBound3.max.x, nodeBound3.max.y ) );
				if( boxContains( selectionBound, nodeBound2 ) )
				{
					m_scriptNode->selection()->add( nodeGadget->node() );
				}
			}
		}
	
		renderRequestSignal()( this );
	}

	return true;
}