UndoCommandPtr Selection::SetItems(const OS_SceneNodeDumbPtr& items, const SelectionChangingSignature::Delegate& emitterChanging, const SelectionChangedSignature::Delegate& emitterChanged) { OS_ObjectDumbPtr objects; OS_SceneNodeDumbPtr::Iterator itr = items.Begin(); OS_SceneNodeDumbPtr::Iterator end = items.End(); for ( ; itr != end; ++itr ) { objects.Append( *itr ); } return SetItems( objects, emitterChanging, emitterChanged ); }
UndoCommandPtr Selection::RemoveItems(const OS_ObjectDumbPtr& items, const SelectionChangingSignature::Delegate& emitterChanging, const SelectionChangedSignature::Delegate& emitterChanged) { // no selected items if ( m_Items.Empty() ) { return NULL; } EDITOR_SCENE_SCOPE_TIMER( ("") ); SimpleTimer timer; std::vector<Reflect::Object*> removed; OS_ObjectDumbPtr temp = m_Items; OS_ObjectDumbPtr::Iterator itr = items.Begin(); OS_ObjectDumbPtr::Iterator end = items.End(); for ( ; itr != end; ++itr ) { if ( temp.Remove(*itr) ) { removed.push_back(*itr); } } UndoCommandPtr command; SelectionChangingArgs args ( temp ); m_SelectionChanging.RaiseWithEmitter( args, emitterChanging ); if ( !args.m_Veto ) { command = new SelectionChangeCommand( this ); std::vector<Reflect::Object*>::iterator itr = removed.begin(); std::vector<Reflect::Object*>::iterator end = removed.end(); for ( ; itr != end; ++itr ) { SceneNode *pSceneNode = Reflect::SafeCast<SceneNode>( *itr ); if (pSceneNode) { pSceneNode->SetSelected(false); } } m_Items = temp; m_SelectionChanged.RaiseWithEmitter(m_Items, emitterChanged); } Log::Profile( TXT( "Selection RemoveItems took %fms\n" ), timer.Elapsed()); return command; }
UndoCommandPtr Selection::SetItem(Reflect::Object* item, const SelectionChangingSignature::Delegate& emitterChanging, const SelectionChangedSignature::Delegate& emitterChanged) { if (item == NULL) { return Clear(emitterChanging, emitterChanged); } OS_ObjectDumbPtr temp; temp.Append(item); return SetItems(temp, emitterChanging, emitterChanged); }
UndoCommandPtr Selection::RemoveItem(Reflect::Object* item, const SelectionChangingSignature::Delegate& emitterChanging, const SelectionChangedSignature::Delegate& emitterChanged) { // no item to remove or no items to remove from if ( item == NULL || m_Items.Empty() ) { return NULL; } OS_ObjectDumbPtr temp; temp.Append(item); return RemoveItems(temp, emitterChanging, emitterChanged); }
/////////////////////////////////////////////////////////////////////////////// // Callback for when a row's selectability checkbox is changed in the grid. // Changes the selectability member of the layer to match the row that was // changed. // void LayersPanel::LayerSelectableChanged( const GridRowChangeArgs& args ) { const std::string& name = m_Grid->GetRowName( args.m_RowNumber ); M_LayerDumbPtr::const_iterator layerItr = m_Layers.find( name ); if ( layerItr != m_Layers.end() ) { Layer* layer = layerItr->second; bool selectable = m_Grid->IsRowSelectableChecked( args.m_RowNumber ); layer->SetSelectable( selectable ); if (!selectable) { OS_ObjectDumbPtr newSelection; OS_ObjectDumbPtr selection = layer->GetOwner()->GetSelection().GetItems(); OS_ObjectDumbPtr::Iterator itr = selection.Begin(); OS_ObjectDumbPtr::Iterator end = selection.End(); for ( ; itr != end; ++itr ) { SceneNode* node = Reflect::SafeCast<SceneNode>( *itr ); if (!node || !layer->ContainsMember( node )) { newSelection.Append(*itr); } } if (newSelection.Size() != selection.Size()) { layer->GetOwner()->GetSelection().SetItems( newSelection ); } } layer->GetOwner()->Execute( false ); } else { Log::Error( TXT( "LayerSelectableChanged - layer named %s not found\n" ), name.c_str() ); HELIUM_BREAK(); } }
bool CurveEditTool::ValidateSelection( OS_ObjectDumbPtr& items ) { OS_ObjectDumbPtr result; OS_ObjectDumbPtr::Iterator itr = items.Begin(); OS_ObjectDumbPtr::Iterator end = items.End(); for( ; itr != end; ++itr ) { CurveControlPoint* p = Reflect::SafeCast<CurveControlPoint>( *itr ); if ( !p ) { continue; } bool appendPoint = true; if ( s_CurrentSelection ) { appendPoint = false; OS_SceneNodeDumbPtr::Iterator curveItr = m_SelectedCurves.Begin(); OS_SceneNodeDumbPtr::Iterator curveEnd = m_SelectedCurves.End(); for ( ; curveItr != curveEnd; ++curveItr ) { if ( p->GetParent() == *curveItr ) { appendPoint = true; break; } } } if ( appendPoint ) { result.Append( p ); } } items = result; if ( items.Empty() ) { OS_ObjectDumbPtr::Iterator itr = items.Begin(); OS_ObjectDumbPtr::Iterator end = items.End(); for( ; itr != end; ++itr ) { Curve* c = Reflect::SafeCast<Curve>( *itr ); if ( !c ) { continue; } result.Append( c ); break; } } items = result; return !items.Empty(); }
void CurveEditTool::KeyPress( const KeyboardInput& e ) { if ( !m_Scene->IsEditable() ) { return; } int32_t keyCode = e.GetKeyCode(); if ( keyCode == KeyCodes::Left || keyCode == KeyCodes::Up || keyCode == KeyCodes::Right || keyCode == KeyCodes::Down ) { OS_ObjectDumbPtr selection = m_Scene->GetSelection().GetItems(); if ( selection.Empty() ) { return; } CurveControlPoint* point = Reflect::SafeCast<CurveControlPoint>( selection.Front() ); if ( !point ) { return; } Curve* curve = Reflect::SafeCast<Curve>( point->GetParent() ); if ( !curve ) { return; } int32_t index = curve->GetIndexForControlPoint( point ); if ( index == -1 ) { return; } uint32_t countControlPoints = curve->GetNumberControlPoints(); if ( keyCode == KeyCodes::Left || keyCode == KeyCodes::Down ) { index--; index += countControlPoints; index %= countControlPoints; } else if ( keyCode == KeyCodes::Right || keyCode == KeyCodes::Up ) { index++; index %= countControlPoints; } point = curve->GetControlPointByIndex( index ); selection.Clear(); selection.Append( point ); m_Scene->GetSelection().SetItems( selection ); } Base::KeyPress( e ); }
UndoCommandPtr Selection::SetItems(const OS_ObjectDumbPtr& items, const SelectionChangingSignature::Delegate& emitterChanging, const SelectionChangedSignature::Delegate& emitterChanged) { if (items.Empty()) { return Clear(emitterChanging, emitterChanged); } EDITOR_SCENE_SCOPE_TIMER( ("") ); SimpleTimer timer; OS_ObjectDumbPtr selectableItems; { OS_ObjectDumbPtr::Iterator itr = items.Begin(); OS_ObjectDumbPtr::Iterator end = items.End(); for ( ; itr != end; ++itr ) { SceneNode *pSceneNode = Reflect::SafeCast<SceneNode>(*itr); if (!pSceneNode || pSceneNode->IsSelectable()) { selectableItems.Append(*itr); } } } UndoCommandPtr command; SelectionChangingArgs args ( items ); m_SelectionChanging.RaiseWithEmitter( args , emitterChanging); if ( !args.m_Veto ) { command = new SelectionChangeCommand( this ); { OS_ObjectDumbPtr::Iterator itr = m_Items.Begin(); OS_ObjectDumbPtr::Iterator end = m_Items.End(); for ( ; itr != end; ++itr ) { SceneNode *pSceneNode = Reflect::SafeCast<SceneNode>(*itr); if (pSceneNode) { pSceneNode->SetSelected(false); } } } m_Items = selectableItems; { OS_ObjectDumbPtr::Iterator itr = m_Items.Begin(); OS_ObjectDumbPtr::Iterator end = m_Items.End(); for ( ; itr != end; ++itr ) { SceneNode *pSceneNode = Reflect::SafeCast<SceneNode>(*itr); if (pSceneNode) { pSceneNode->SetSelected(true); } } } m_SelectionChanged.RaiseWithEmitter(m_Items, emitterChanged); } Log::Profile( TXT( "Selection SetItems took %fms\n" ), timer.Elapsed()); return command; }