UndoCommandPtr Selection::AddItems(const OS_ObjectDumbPtr &items, const SelectionChangingSignature::Delegate& emitterChanging, const SelectionChangedSignature::Delegate& emitterChanged) { if ( items.Empty() ) { return NULL; } EDITOR_SCENE_SCOPE_TIMER( ("") ); SimpleTimer timer; std::vector<Reflect::Object*> added; OS_ObjectDumbPtr temp = m_Items; OS_ObjectDumbPtr::Iterator itr = items.Begin(); OS_ObjectDumbPtr::Iterator end = items.End(); for ( ; itr != end; ++itr ) { if ( temp.Append(*itr) ) { added.push_back(*itr); } } UndoCommandPtr command; if ( !temp.Empty() ) { SelectionChangingArgs args ( temp ); m_SelectionChanging.RaiseWithEmitter( args, emitterChanging ); if ( !args.m_Veto ) { command = new SelectionChangeCommand( this ); std::vector<Reflect::Object*>::iterator itr = added.begin(); std::vector<Reflect::Object*>::iterator end = added.end(); for ( ; itr != end; ++itr ) { SceneNode *pSceneNode = Reflect::SafeCast<SceneNode>(*itr); if (pSceneNode) { pSceneNode->SetSelected(true); } } m_Items = temp; m_SelectionChanged.RaiseWithEmitter(m_Items, emitterChanged); } } Log::Profile( TXT( "Selection AddItems took %fms\n" ), timer.Elapsed()); return command; }
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; }