void Dialog::setLayout(Widget * contents, Widget * buttons) { LinearContainer * container = new LinearContainer(); container->setVertical(); container->setSpacing(8); container->addWidget(contents); container->addWidget(buttons); setPadding(8); setContent(container); }
Dialog::Dialog(std::string id, std::string message) : _id(id) { LinearContainer * buttons = new LinearContainer(); buttons->setHorizontal(); buttonOk = new ButtonWidget(new TextWidget("Ok", 0, 0)); buttons->addWidget(buttonOk); setLayout(setTextMessage(message), buttons); _ct = -getWidth(); }
Gadget *StandardNodeGadget::getEdgeGadget( Edge edge ) { LinearContainer *c = noduleContainer( edge ); const size_t s = c->children().size(); if( s != 4 ) { return nullptr; } return c->getChild<Gadget>( s - 2 ); }
Widget * Dialog::setTextMessage(std::string message) { LinearContainer * text = new LinearContainer(); text->setSpacing(4); text->setVertical(); size_t index = 0; while ((index = message.find('\n')) != std::string::npos) { text->addWidget(new TextWidget(message.substr(0, index), 0, 0)); message.erase(0, index + 1); } text->addWidget(new TextWidget(message.substr(0, message.length()), 0, 0)); return text; }
Dialog::Dialog(std::string id, std::string message, std::string positiveButton, std::string negativeButton, std::string neutralButton) : _id(id) { LinearContainer * buttons = new LinearContainer(); buttons->setHorizontal(); buttonPositive = new ButtonWidget(new TextWidget(positiveButton, 0, 0)); buttons->addWidget(buttonPositive); buttonNegative = new ButtonWidget(new TextWidget(negativeButton, 0, 0)); buttons->addWidget(buttonNegative); buttonNeutral = new ButtonWidget(new TextWidget(neutralButton, 0, 0)); buttons->addWidget(buttonNeutral); setLayout(setTextMessage(message), buttons); _ct = -getWidth(); }
void StandardNodeGadget::setEdgeGadget( Edge edge, GadgetPtr gadget ) { GadgetPtr previous = getEdgeGadget( edge ); if( previous == gadget ) { return; } if( IECore::runTimeCast<Nodule>( gadget ) ) { throw IECore::Exception( "End Gadget can not be a Nodule." ); } LinearContainer *c = noduleContainer( edge ); GadgetPtr spacer = boost::static_pointer_cast<Gadget>( c->children().back() ); c->removeChild( spacer ); if( previous ) { c->removeChild( previous ); } if( gadget ) { c->addChild( gadget ); } c->addChild( spacer ); }
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 ); } } } }
Gadget *StandardNodeGadget::getEdgeGadget( Edge edge ) { LinearContainer *c = noduleContainer( edge ); return c->getChild<Gadget>( c->children().size() - 1 ); }
void StandardNodeGadget::setEdgeGadget( Edge edge, GadgetPtr gadget ) { LinearContainer *c = noduleContainer( edge ); c->removeChild( c->getChild<Gadget>( c->children().size() - 1 ) ); c->addChild( gadget ); }
StandardNodeGadget::StandardNodeGadget( Gaffer::NodePtr node ) : NodeGadget( node ), m_nodeEnabled( true ), m_labelsVisibleOnHover( true ), m_dragDestinationProxy( 0 ), m_userColor( 0 ) { // build our ui structure //////////////////////////////////////////////////////// float horizontalNoduleSpacing = 2.0f; float verticalNoduleSpacing = 0.2f; float minWidth = 10.0f; if( IECore::ConstFloatDataPtr d = Metadata::nodeValue<IECore::FloatData>( node.get(), g_horizontalNoduleSpacingKey ) ) { horizontalNoduleSpacing = d->readable(); } if( IECore::ConstFloatDataPtr d = Metadata::nodeValue<IECore::FloatData>( node.get(), g_verticalNoduleSpacingKey ) ) { verticalNoduleSpacing = d->readable(); } if( IECore::ConstFloatDataPtr d = Metadata::nodeValue<IECore::FloatData>( node.get(), g_minWidthKey ) ) { minWidth = d->readable(); } // four containers for nodules - one each for the top, bottom, left and right. // these contain spacers at either end to prevent nodules being placed in // the corners of the node gadget, and also to guarantee a minimim width for the // vertical containers and a minimum height for the horizontal ones. LinearContainerPtr topNoduleContainer = new LinearContainer( "topNoduleContainer", LinearContainer::X, LinearContainer::Centre, horizontalNoduleSpacing ); topNoduleContainer->addChild( new SpacerGadget( Box3f( V3f( 0 ), V3f( 0, 1, 0 ) ) ) ); topNoduleContainer->addChild( new SpacerGadget( Box3f( V3f( 0 ), V3f( 0, 1, 0 ) ) ) ); LinearContainerPtr bottomNoduleContainer = new LinearContainer( "bottomNoduleContainer", LinearContainer::X, LinearContainer::Centre, horizontalNoduleSpacing ); bottomNoduleContainer->addChild( new SpacerGadget( Box3f( V3f( 0 ), V3f( 0, 1, 0 ) ) ) ); bottomNoduleContainer->addChild( new SpacerGadget( Box3f( V3f( 0 ), V3f( 0, 1, 0 ) ) ) ); LinearContainerPtr leftNoduleContainer = new LinearContainer( "leftNoduleContainer", LinearContainer::Y, LinearContainer::Centre, verticalNoduleSpacing, LinearContainer::Decreasing ); leftNoduleContainer->addChild( new SpacerGadget( Box3f( V3f( 0 ), V3f( 1, 0, 0 ) ) ) ); leftNoduleContainer->addChild( new SpacerGadget( Box3f( V3f( 0 ), V3f( 1, 0, 0 ) ) ) ); LinearContainerPtr rightNoduleContainer = new LinearContainer( "rightNoduleContainer", LinearContainer::Y, LinearContainer::Centre, verticalNoduleSpacing, LinearContainer::Decreasing ); rightNoduleContainer->addChild( new SpacerGadget( Box3f( V3f( 0 ), V3f( 1, 0, 0 ) ) ) ); rightNoduleContainer->addChild( new SpacerGadget( Box3f( V3f( 0 ), V3f( 1, 0, 0 ) ) ) ); // column - this is our outermost structuring container LinearContainerPtr column = new LinearContainer( "column", LinearContainer::Y, LinearContainer::Centre, 0.0f, LinearContainer::Decreasing ); column->addChild( topNoduleContainer ); LinearContainerPtr row = new LinearContainer( "row", LinearContainer::X, LinearContainer::Centre, 0.0f ); column->addChild( row ); // central row - this holds our main contents, with the // nodule containers surrounding it. row->addChild( leftNoduleContainer ); LinearContainerPtr contentsColumn = new LinearContainer( "contentsColumn", LinearContainer::Y, LinearContainer::Centre, 0.0f, LinearContainer::Decreasing ); row->addChild( contentsColumn ); IndividualContainerPtr contentsContainer = new IndividualContainer(); contentsContainer->setName( "contentsContainer" ); contentsColumn->addChild( new SpacerGadget( Box3f( V3f( 0 ), V3f( minWidth, 0, 0 ) ) ) ); contentsColumn->addChild( contentsContainer ); contentsColumn->addChild( new SpacerGadget( Box3f( V3f( 0 ), V3f( minWidth, 0, 0 ) ) ) ); row->addChild( rightNoduleContainer ); column->addChild( bottomNoduleContainer ); addChild( column ); setContents( new NameGadget( node ) ); // connect to the signals we need in order to operate //////////////////////////////////////////////////////// node->childAddedSignal().connect( boost::bind( &StandardNodeGadget::childAdded, this, ::_1, ::_2 ) ); node->childRemovedSignal().connect( boost::bind( &StandardNodeGadget::childRemoved, this, ::_1, ::_2 ) ); node->errorSignal().connect( boost::bind( &StandardNodeGadget::error, this, ::_1, ::_2, ::_3 ) ); node->plugDirtiedSignal().connect( boost::bind( &StandardNodeGadget::plugDirtied, this, ::_1 ) ); dragEnterSignal().connect( boost::bind( &StandardNodeGadget::dragEnter, this, ::_1, ::_2 ) ); dragMoveSignal().connect( boost::bind( &StandardNodeGadget::dragMove, this, ::_1, ::_2 ) ); dragLeaveSignal().connect( boost::bind( &StandardNodeGadget::dragLeave, this, ::_1, ::_2 ) ); dropSignal().connect( boost::bind( &StandardNodeGadget::drop, this, ::_1, ::_2 ) ); for( int e = FirstEdge; e <= LastEdge; e++ ) { LinearContainer *c = noduleContainer( (Edge)e ); c->enterSignal().connect( boost::bind( &StandardNodeGadget::enter, this, ::_1 ) ); c->leaveSignal().connect( boost::bind( &StandardNodeGadget::leave, this, ::_1 ) ); } Metadata::plugValueChangedSignal().connect( boost::bind( &StandardNodeGadget::plugMetadataChanged, this, ::_1, ::_2, ::_3, ::_4 ) ); Metadata::nodeValueChangedSignal().connect( boost::bind( &StandardNodeGadget::nodeMetadataChanged, this, ::_1, ::_2, ::_3 ) ); // do our first update //////////////////////////////////////////////////////// updateNoduleLayout(); updateUserColor(); updatePadding(); updateNodeEnabled(); }