-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
// CLASS HEADER
#include "long-press-gesture-processor.h"
* @param[in] localPoint Relative to the actor attached to the detector.
*/
void EmitLongPressSignal(
- Dali::Actor actor,
- LongPressGestureDetectorContainer& gestureDetectors,
+ Actor* actor,
+ const GestureDetectorContainer& gestureDetectors,
const Integration::LongPressGestureEvent& longPressEvent,
Vector2 localPoint)
{
longPress.screenPoint = longPressEvent.point;
longPress.localPoint = localPoint;
- for ( LongPressGestureDetectorContainer::iterator iter = gestureDetectors.begin(), endIter = gestureDetectors.end(); iter != endIter; ++iter )
+ Dali::Actor actorHandle( actor );
+ const GestureDetectorContainer::const_iterator endIter = gestureDetectors.end();
+ for ( GestureDetectorContainer::const_iterator iter = gestureDetectors.begin(); iter != endIter; ++iter )
{
- (*iter)->EmitLongPressGestureSignal(actor, longPress);
+ static_cast< LongPressGestureDetector* >( *iter )->EmitLongPressGestureSignal( actorHandle, longPress );
}
}
* @param[in] detector The detector to check.
* @return true, if not attached, false otherwise.
*/
- bool operator()( const LongPressGestureDetector* detector ) const
+ bool operator()( const GestureDetector* detector ) const
{
return !detector->IsAttached( *actorToCheck );
}
} // unnamed namespace
-struct LongPressGestureProcessor::LongPressEventFunctor : public GestureProcessor::Functor
-{
- /**
- * Constructor
- * @param[in] event The current gesture event.
- * @param[in] processor Reference to the processor.
- */
- LongPressEventFunctor( const Integration::LongPressGestureEvent& event, LongPressGestureProcessor& processor )
- : longPressEvent( event ),
- processor( processor )
- {
- }
-
- /**
- * Check if the detector meets the current gesture event parameters.
- */
- virtual bool operator() ( GestureDetector* detector, Actor* )
- {
- LongPressGestureDetector* longPressDetector ( static_cast< LongPressGestureDetector* >( detector ) );
-
- return ( longPressDetector->GetMinimumTouchesRequired() <= longPressEvent.numberOfTouches ) &&
- ( longPressDetector->GetMaximumTouchesRequired() >= longPressEvent.numberOfTouches );
- }
-
- /**
- * Gestured actor and gesture detectors that meet the gesture's parameters found, emit and save required information.
- */
- virtual void operator() ( Dali::Actor actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates )
- {
- LongPressGestureDetectorContainer derivedContainer;
- DownCastContainer<LongPressGestureDetector>( gestureDetectors, derivedContainer );
-
- // Clear actor as
- processor.mCurrentEmitters.clear();
- processor.ResetActor();
-
- EmitLongPressSignal( actor, derivedContainer, longPressEvent, actorCoordinates );
-
- if ( actor.OnStage() )
- {
- processor.mCurrentEmitters = derivedContainer;
- processor.SetActor( actor );
- }
- }
-
- const Integration::LongPressGestureEvent& longPressEvent;
- LongPressGestureProcessor& processor;
-};
-
-LongPressGestureProcessor::LongPressGestureProcessor(
- Stage& stage,
- Integration::GestureManager& gestureManager)
-: mStage( stage ),
+LongPressGestureProcessor::LongPressGestureProcessor( Stage& stage, Integration::GestureManager& gestureManager)
+: GestureProcessor( Gesture::LongPress ),
+ mStage( stage ),
mGestureManager( gestureManager ),
mGestureDetectors(),
mCurrentEmitters(),
mCurrentRenderTask(),
mMinTouchesRequired( 1 ),
- mMaxTouchesRequired( 1 )
+ mMaxTouchesRequired( 1 ),
+ mCurrentLongPressEvent( NULL )
{
}
HitTestAlgorithm::Results hitTestResults;
if( HitTest( mStage, longPressEvent.point, hitTestResults ) )
{
- SetActor( hitTestResults.actor );
+ SetActor( &GetImplementation( hitTestResults.actor ) );
}
break;
}
if ( currentGesturedActor )
{
HitTestAlgorithm::Results hitTestResults;
- HitTestAlgorithm::HitTest( mStage, longPressEvent.point, hitTestResults );
+ HitTest( mStage, longPressEvent.point, hitTestResults );
if ( hitTestResults.actor && ( currentGesturedActor == &GetImplementation( hitTestResults.actor ) ) )
{
// Record the current render-task for Screen->Actor coordinate conversions
mCurrentRenderTask = hitTestResults.renderTask;
- LongPressEventFunctor functor( longPressEvent, *this );
- GestureDetectorContainer gestureDetectors;
- UpCastContainer<LongPressGestureDetector>( mGestureDetectors, gestureDetectors );
- ProcessAndEmit( hitTestResults, gestureDetectors, functor );
+ // Set mCurrentLongPressEvent to use inside overridden methods called from ProcessAndEmit()
+ mCurrentLongPressEvent = &longPressEvent;
+ ProcessAndEmit( hitTestResults );
+ mCurrentLongPressEvent = NULL;
}
else
{
if ( currentGesturedActor->IsHittable() && !mCurrentEmitters.empty() && mCurrentRenderTask )
{
// Ensure actor is still attached to the emitters, if it is not then remove the emitter.
- LongPressGestureDetectorContainer::iterator endIter = std::remove_if( mCurrentEmitters.begin(), mCurrentEmitters.end(), IsNotAttachedFunctor(currentGesturedActor) );
+ GestureDetectorContainer::iterator endIter = std::remove_if( mCurrentEmitters.begin(), mCurrentEmitters.end(), IsNotAttachedFunctor(currentGesturedActor) );
mCurrentEmitters.erase( endIter, mCurrentEmitters.end() );
if ( !mCurrentEmitters.empty() )
RenderTask& renderTaskImpl( GetImplementation( mCurrentRenderTask ) );
currentGesturedActor->ScreenToLocal( renderTaskImpl, actorCoords.x, actorCoords.y, longPressEvent.point.x, longPressEvent.point.y );
- EmitLongPressSignal( Dali::Actor( currentGesturedActor ), mCurrentEmitters, longPressEvent, actorCoords );
+ EmitLongPressSignal( currentGesturedActor, mCurrentEmitters, longPressEvent, actorCoords );
}
}
}
case Gesture::Continuing:
- DALI_ASSERT_ALWAYS( false && "Incorrect state received from Integration layer: Continuing\n" );
+ {
+ DALI_ABORT( "Incorrect state received from Integration layer: Continuing\n" );
break;
-
+ }
case Gesture::Clear:
- DALI_ASSERT_ALWAYS( false && "Incorrect state received from Integration layer: Clear\n" );
+ {
+ DALI_ABORT( "Incorrect state received from Integration layer: Clear\n" );
break;
+ }
}
}
{
LongPressGestureDetector* current(*iter);
- unsigned int minimum = current->GetMinimumTouchesRequired();
- if (minimum < minimumRequired)
+ if( current )
{
- minimumRequired = minimum;
- }
+ unsigned int minimum = current->GetMinimumTouchesRequired();
+ if (minimum < minimumRequired)
+ {
+ minimumRequired = minimum;
+ }
- unsigned int maximum = current->GetMaximumTouchesRequired();
- if ( maximum > maximumRequired )
- {
- maximumRequired = maximum;
+ unsigned int maximum = current->GetMaximumTouchesRequired();
+ if ( maximum > maximumRequired )
+ {
+ maximumRequired = maximum;
+ }
}
}
mCurrentEmitters.clear();
}
+bool LongPressGestureProcessor::CheckGestureDetector( GestureDetector* detector, Actor* actor )
+{
+ DALI_ASSERT_DEBUG( mCurrentLongPressEvent );
+
+ LongPressGestureDetector* longPressDetector ( static_cast< LongPressGestureDetector* >( detector ) );
+
+ return ( longPressDetector->GetMinimumTouchesRequired() <= mCurrentLongPressEvent->numberOfTouches ) &&
+ ( longPressDetector->GetMaximumTouchesRequired() >= mCurrentLongPressEvent->numberOfTouches );
+}
+
+void LongPressGestureProcessor::EmitGestureSignal( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates )
+{
+ DALI_ASSERT_DEBUG( mCurrentLongPressEvent );
+
+ mCurrentEmitters.clear();
+ ResetActor();
+
+ EmitLongPressSignal( actor, gestureDetectors, *mCurrentLongPressEvent, actorCoordinates );
+
+ if ( actor->OnStage() )
+ {
+ mCurrentEmitters = gestureDetectors;
+ SetActor( actor );
+ }
+}
+
} // namespace Internal
} // namespace Dali