示例#1
0
typename Signal::result_type ViewportGadget::dispatchEvent( GadgetPtr gadget, Signal &(Gadget::*signalGetter)(), const Event &event )
{
	Event transformedEvent( event );
	eventToGadgetSpace( transformedEvent, gadget.get() );
	Signal &s = (gadget.get()->*signalGetter)();
	return s( gadget.get(), transformedEvent );
}
示例#2
0
void ViewportGadget::emitEnterLeaveEvents( GadgetPtr newGadgetUnderMouse, GadgetPtr oldGadgetUnderMouse, const ButtonEvent &event )
{
	// figure out the lowest point in the hierarchy where the entered status is unchanged.
	GadgetPtr lowestUnchanged = this;
	if( oldGadgetUnderMouse && newGadgetUnderMouse )
	{
		if( oldGadgetUnderMouse->isAncestorOf( newGadgetUnderMouse.get() ) )
		{
			lowestUnchanged = oldGadgetUnderMouse;
		}
		else if( newGadgetUnderMouse->isAncestorOf( oldGadgetUnderMouse.get() ) )
		{
			lowestUnchanged = newGadgetUnderMouse;
		}
		else
		{
			lowestUnchanged = oldGadgetUnderMouse->commonAncestor<Gadget>( newGadgetUnderMouse.get() );
		}
	}

	// emit leave events, innermost first
	if( oldGadgetUnderMouse )
	{
		GadgetPtr leaveTarget = oldGadgetUnderMouse;
		while( leaveTarget != lowestUnchanged )
		{
			dispatchEvent( leaveTarget.get(), &Gadget::leaveSignal, event );
			leaveTarget = leaveTarget->parent<Gadget>();
		}
	}

	// emit enter events, outermost first
	if( newGadgetUnderMouse )
	{
		std::vector<GadgetPtr> enterTargets;
		GadgetPtr enterTarget = newGadgetUnderMouse;
		while( enterTarget != lowestUnchanged )
		{
			enterTargets.push_back( enterTarget );
			enterTarget = enterTarget->parent<Gadget>();
		}
		for( std::vector<GadgetPtr>::const_reverse_iterator it = enterTargets.rbegin(); it!=enterTargets.rend(); it++ )
		{
			dispatchEvent( *it, &Gadget::enterSignal, event );
		}
	}
};
示例#3
0
ConnectionGadget *GraphGadget::reconnectionGadgetAt( NodeGadget *gadget, const IECore::LineSegment3f &lineInGadgetSpace ) const
{
	std::vector<GadgetPtr> gadgetsUnderMouse;

	Imath::V3f center = gadget->transformedBound( this ).center();
	const Imath::V3f corner0 = center - Imath::V3f( 2, 2, 1 );
	const Imath::V3f corner1 = center + Imath::V3f( 2, 2, 1 );

	std::vector<IECoreGL::HitRecord> selection;
	{
		ViewportGadget::SelectionScope selectionScope( corner0, corner1, this, selection, IECoreGL::Selector::IDRender );

		const Style *s = style();
		s->bind();

		for ( ChildContainer::const_iterator it = children().begin(); it != children().end(); ++it )
		{
			if ( ConnectionGadget *c = IECore::runTimeCast<ConnectionGadget>( it->get() ) )
			{
				// don't consider the node's own connections, or connections without a source nodule
				if ( c->srcNodule() && gadget->node() != c->srcNodule()->plug()->node() && gadget->node() != c->dstNodule()->plug()->node() )
				{
					c->render( s );
				}
			}
		}
	}

	for ( std::vector<IECoreGL::HitRecord>::const_iterator it = selection.begin(); it != selection.end(); ++it )
	{
		GadgetPtr gadget = Gadget::select( it->name.value() );
		if ( gadget )
		{
			return runTimeCast<ConnectionGadget>( gadget.get() );
		}
	}

	return 0;
}
示例#4
0
void NoduleLayout::updateLayout()
{
	// Figure out the order we want to display things in
	// and clear our main container ready for filling in
	// that order.
	vector<GadgetKey> items = layoutOrder();

	LinearContainer *gadgetContainer = noduleContainer();
	gadgetContainer->clearChildren();

	vector<Gadget *> added;
	vector<GadgetPtr> removed;

	// Iterate over the items we need to lay out, creating
	// or reusing gadgets and adding them to the layout.
	for( vector<GadgetKey>::const_iterator it = items.begin(), eIt = items.end(); it != eIt; ++it )
	{
		const GadgetKey &item = *it;
		const IECore::InternedString gadgetType = ::gadgetType( m_parent.get(), *it );

		GadgetPtr gadget;
		GadgetMap::iterator gadgetIt = m_gadgets.find( item );
		if( gadgetIt != m_gadgets.end() && gadgetIt->second.type == gadgetType )
		{
			gadget = gadgetIt->second.gadget;
		}
		else
		{
			// No gadget created yet, or it's the wrong type
			if( item.which() == 0 )
			{
				gadget = Nodule::create( const_cast<Plug *>( boost::get<const Plug *>( item ) ) ); /// \todo Fix cast
			}
			else
			{
				gadget = createCustomGadget( gadgetType, m_parent.get() );
			}

			added.push_back( gadget.get() );
			if( gadgetIt != m_gadgets.end() )
			{
				removed.push_back( gadgetIt->second.gadget );
			}
			m_gadgets[item] = TypeAndGadget( gadgetType, gadget );
		}

		if( gadget )
		{
			gadgetContainer->addChild( gadget );
		}
	}

	// Remove any gadgets we didn't use
	boost::container::flat_set<GadgetKey> itemsSet( items.begin(), items.end() );
	for( GadgetMap::iterator it = m_gadgets.begin(), eIt = m_gadgets.end(); it != eIt; )
	{
		GadgetMap::iterator next = it; ++next;
		if( itemsSet.find( it->first ) == itemsSet.end() )
		{
			removed.push_back( it->second.gadget );
			m_gadgets.erase( it );
		}
		it = next;
	}

	// Let everyone know what we've done.
	/// \todo Maybe we shouldn't know about the NodeGadget?
	if( NodeGadget *nodeGadget = ancestor<NodeGadget>() )
	{
		for( vector<GadgetPtr>::const_iterator it = removed.begin(), eIt = removed.end(); it != eIt; ++it )
		{
			if( Nodule *n = runTimeCast<Nodule>( it->get() ) )
			{
				nodeGadget->noduleRemovedSignal()( nodeGadget, n );
			}
		}

		for( vector<Gadget *>::const_iterator it = added.begin(), eIt = added.end(); it != eIt; ++it )
		{
			if( Nodule *n = runTimeCast<Nodule>( *it ) )
			{
				nodeGadget->noduleAddedSignal()( nodeGadget, n );
			}
		}
	}
}