uifw/AvKon/aknphysics/src/aknphysics.cpp
branchRCL_3
changeset 56 d48ab3b357f1
parent 55 aecbbf00d063
equal deleted inserted replaced
55:aecbbf00d063 56:d48ab3b357f1
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009, 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
   424 //
   424 //
   425 EXPORT_C TBool CAknPhysics::StartPhysics( TPoint& aDrag, 
   425 EXPORT_C TBool CAknPhysics::StartPhysics( TPoint& aDrag, 
   426                                           const TTime& aStartTime )
   426                                           const TTime& aStartTime )
   427     {
   427     {
   428     // Check that world really exists
   428     // Check that world really exists
   429     if ( !iEngine || !iEngine->WorldExists() )
   429     if ( iEngine )
       
   430         {
       
   431         if ( ( !iLandscape && iWorldSize.iHeight <= iViewSize.iHeight ) ||
       
   432                 ( iLandscape && iWorldSize.iWidth <= iViewSize.iWidth ) )
       
   433             {
       
   434             return EFalse;
       
   435             }
       
   436         }
       
   437     else
   430         {
   438         {
   431         return EFalse;
   439         return EFalse;
   432         }
   440         }
   433     
   441     
   434     iSuspended = EFalse;
   442     iSuspended = EFalse;
   542 // CAknPhysics::RegisterPanningPosition
   550 // CAknPhysics::RegisterPanningPosition
   543 // ---------------------------------------------------------------------------
   551 // ---------------------------------------------------------------------------
   544 //
   552 //
   545 EXPORT_C void CAknPhysics::RegisterPanningPosition( const TPoint& aDelta )
   553 EXPORT_C void CAknPhysics::RegisterPanningPosition( const TPoint& aDelta )
   546     {
   554     {
       
   555     TInt viewSize = !iLandscape ? iViewSize.iHeight : iViewSize.iWidth;
       
   556     TInt worldSize = !iLandscape ? iWorldSize.iHeight : iWorldSize.iWidth;
       
   557     
       
   558     if ( worldSize <= viewSize )
       
   559         {
       
   560         return;
       
   561         }
       
   562 	
   547     TTimeIntervalMicroSeconds time;
   563     TTimeIntervalMicroSeconds time;
   548     TInt err( KErrNone );
   564     TInt err( KErrNone );
   549     if ( iNullThread.Handle() )
   565     if ( iNullThread.Handle() )
   550         {
   566         {
   551         err = iNullThread.GetCpuTime( time );
   567         err = iNullThread.GetCpuTime( time );
   587         }
   603         }
   588 
   604 
   589     iPanningDrawOmitted = !drawNow;
   605     iPanningDrawOmitted = !drawNow;
   590     
   606     
   591     TPoint position( iObserver.ViewPosition() );
   607     TPoint position( iObserver.ViewPosition() );
   592     position += aDelta;
   608     
       
   609     TPoint movement( aDelta );
   593 
   610 
   594     if ( iRestrictor && iRestrictor->AllowedViewPosition( position ) )
   611     if ( iRestrictor && iRestrictor->AllowedViewPosition( position ) )
   595         {
   612         {
   596         if ( OngoingPhysicsAction() == EAknPhysicsActionNone )
   613         if ( OngoingPhysicsAction() == EAknPhysicsActionNone )
   597             {
   614             {
   600             if ( iParamProvider->FpsLoggingEnabled() )
   617             if ( iParamProvider->FpsLoggingEnabled() )
   601                 {
   618                 {
   602                 iEngine->StartFpsLogging();
   619                 iEngine->StartFpsLogging();
   603                 }
   620                 }
   604             }
   621             }
       
   622 
       
   623         // reduce movement if content is dragged over boundaries
       
   624         if ( OngoingPhysicsAction() == EAknPhysicsActionDragging )
       
   625             {
       
   626             TInt currentPosition = !iLandscape ? position.iY : position.iX;
       
   627             TInt* movementPtr = !iLandscape ? &movement.iY : &movement.iX;
       
   628         
       
   629             TInt top = viewSize / 2;
       
   630             TInt bottom = worldSize - top;
       
   631             
       
   632             if ( currentPosition < top || currentPosition > bottom )
       
   633                 {
       
   634                 *movementPtr /= 2;
       
   635                 }
       
   636             }
       
   637 
       
   638         position += movement;
   605         
   639         
   606         NotifyViewPositionChanged( position, drawNow );
   640         NotifyViewPositionChanged( position, drawNow );
   607         
   641         
   608         if ( drawNow )
   642         if ( drawNow )
   609             {
   643             {
   895 // ---------------------------------------------------------------------------
   929 // ---------------------------------------------------------------------------
   896 //
   930 //
   897 void CAknPhysics::DrawViewInCurrentPosition()
   931 void CAknPhysics::DrawViewInCurrentPosition()
   898     {
   932     {
   899     NotifyViewPositionChanged( iObserver.ViewPosition(), ETrue );
   933     NotifyViewPositionChanged( iObserver.ViewPosition(), ETrue );
       
   934     iPanningDrawOmitted = EFalse;
   900     }
   935     }
   901 
   936 
   902 // --------------------------------------------------------------------------
   937 // --------------------------------------------------------------------------
   903 // CAknPhysics::SetBounceTactileFeedback
   938 // CAknPhysics::SetBounceTactileFeedback
   904 // --------------------------------------------------------------------------
   939 // --------------------------------------------------------------------------
   937     TBool nullThreadOpen = FindNullThread( iNullThread );
   972     TBool nullThreadOpen = FindNullThread( iNullThread );
   938     
   973     
   939     // Create Physics timer to step physics emulation
   974     // Create Physics timer to step physics emulation
   940     iPhysics = CAknHighResPeriodic::NewL(
   975     iPhysics = CAknHighResPeriodic::NewL(
   941         CActive::EPriorityStandard, nullThreadOpen ? &iNullThread : NULL );
   976         CActive::EPriorityStandard, nullThreadOpen ? &iNullThread : NULL );
   942     iPhysics->SetMinCallBackPeriod( FrameDelay() * 1000 );
       
   943     
   977     
   944     iEngine = CAknPhysicsEngine::NewL( this );
   978     iEngine = CAknPhysicsEngine::NewL( this );
   945     iParamProvider = CAknPhysicsParameterProvider::NewL();
   979     iParamProvider = CAknPhysicsParameterProvider::NewL();
   946     iRestrictor = CAknPhysicsRestrictor::NewL( iParamProvider );
   980     iRestrictor = CAknPhysicsRestrictor::NewL( iParamProvider );
   947     iConeObserver = CAknPhysicsConeObserver::NewL( this, iRestrictor );
   981     iConeObserver = CAknPhysicsConeObserver::NewL( this, iRestrictor );
   948     iConeObserver->SetViewWindowControl( aViewControl );
   982     iConeObserver->SetViewWindowControl( aViewControl );
   949     iFeedback = MTouchFeedback::Instance();
   983     iFeedback = MTouchFeedback::Instance();
       
   984     iPhysics->SetMinCallBackPeriod( FrameDelay() * 1000 );
   950     }
   985     }
   951 
   986 
   952 
   987 
   953 // ---------------------------------------------------------------------------
   988 // ---------------------------------------------------------------------------
   954 // CAknPhysics::StartPhysics()
   989 // CAknPhysics::StartPhysics()
  1104             iEngine->ResetCollisionState();
  1139             iEngine->ResetCollisionState();
  1105             // boundary effect                       
  1140             // boundary effect                       
  1106             if ( iBounceTactileFeedback && iFeedback )
  1141             if ( iBounceTactileFeedback && iFeedback )
  1107                 {
  1142                 {
  1108                 iFeedback->InstantFeedback( NULL,
  1143                 iFeedback->InstantFeedback( NULL,
  1109                                             ETouchFeedbackBounceEffect,
  1144                                             ETouchFeedbackBoundaryList,
  1110                                             ETouchFeedbackVibra,
  1145                                             ETouchFeedbackVibra,
  1111                                             TPointerEvent() );
  1146                                             TPointerEvent() );
  1112                 }
  1147                 }
  1113             }
  1148             }
  1114 
  1149