taskswitcher/taskswitcherui/taskswitcherapp/src/tsphysicsengine.cpp
branchRCL_3
changeset 34 5456b4e8b3a8
child 35 3321d3e205b6
equal deleted inserted replaced
33:5f0182e07bfb 34:5456b4e8b3a8
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Taskswitcher physics
       
    15  *
       
    16 */
       
    17 
       
    18 #include <aknphysics.h>
       
    19 
       
    20 #include "tsphysicsengine.h"
       
    21 #include "tsphysics.h"
       
    22 
       
    23 // -----------------------------------------------------------------------------
       
    24 // CTsPhysicsHandler::CTsPhysicsHandler
       
    25 // -----------------------------------------------------------------------------
       
    26 //
       
    27 CTsPhysicsEngine::CTsPhysicsEngine()
       
    28     {
       
    29     // No implementation required
       
    30     }
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CTsPhysicsEngine::~CTsPhysicsEngine
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CTsPhysicsEngine::~CTsPhysicsEngine()
       
    37     {
       
    38     delete iTaskswitcherPhysics;
       
    39     delete iPhysics;
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CTsPhysicsEngine::NewLC
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CTsPhysicsEngine* CTsPhysicsEngine::NewLC(
       
    47         MAknPhysicsObserver& aPhysicObserver, CCoeControl& aViewControl)
       
    48     {
       
    49     CTsPhysicsEngine* self = new (ELeave) CTsPhysicsEngine();
       
    50     CleanupStack::PushL(self);
       
    51     self->ConstructL(aPhysicObserver, aViewControl);
       
    52     return self;
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CTsPhysicsEngine::NewL
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CTsPhysicsEngine* CTsPhysicsEngine::NewL(
       
    60         MAknPhysicsObserver& aPhysicObserver, CCoeControl& aViewControl)
       
    61     {
       
    62     CTsPhysicsEngine* self = CTsPhysicsEngine::NewLC(
       
    63             aPhysicObserver, aViewControl);
       
    64     CleanupStack::Pop(); // self;
       
    65     return self;
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CTsPhysicsEngine::ConstructL
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CTsPhysicsEngine::ConstructL(MAknPhysicsObserver& aPhysicObserver,
       
    73         CCoeControl& aViewControl)
       
    74     {
       
    75     iPhysics = CAknPhysics::NewL(aPhysicObserver, &aViewControl);//TODO:
       
    76     iTaskswitcherPhysics = CTsPhysics::NewL(aPhysicObserver);
       
    77     }
       
    78 
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CTsPhysicsEngine::IsRunning
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 TBool CTsPhysicsEngine::IsRunning() const
       
    85     {
       
    86     return iPhysics->OngoingPhysicsAction() != CAknPhysics::EAknPhysicsActionNone;
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CTsPhysicsEngine::HandleDragEvent
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void CTsPhysicsEngine::HandleDragEvent(
       
    94         AknTouchGestureFw::MAknTouchGestureFwDragEvent& aEvent)
       
    95     {
       
    96     if (AknTouchGestureFw::EAknTouchGestureFwStart == aEvent.State())
       
    97         {
       
    98         iPhysics->StopPhysics();
       
    99         iStartTime.HomeTime();
       
   100         iStartPosition = aEvent.CurrentPosition();
       
   101         iDragDirection = 0;
       
   102         }
       
   103     else if (AknTouchGestureFw::EAknTouchGestureFwOn == aEvent.State())
       
   104         {
       
   105         TInt direction =
       
   106                 aEvent.CurrentPosition().iX > aEvent.PreviousPosition().iX ? -1 : 1;
       
   107         TPoint deltaPoint(aEvent.PreviousPosition() - aEvent.CurrentPosition());
       
   108         iPhysics->RegisterPanningPosition(deltaPoint);
       
   109         if (iDragDirection && iDragDirection != direction)
       
   110             {
       
   111             iStartTime.HomeTime();
       
   112             iStartPosition = aEvent.PreviousPosition();
       
   113             }
       
   114         iDragDirection = direction;
       
   115         }
       
   116     else //AknTouchGestureFw::EAknTouchGestureFwStop
       
   117         {
       
   118         TPoint drag(iStartPosition - aEvent.CurrentPosition());
       
   119         iPhysics->StartPhysics(drag, iStartTime);
       
   120         if( Abs(drag.iX) < iPhysics->DragThreshold() &&
       
   121             (TInt)CAknPhysics::EAknPhysicsActionBouncing != 
       
   122             iPhysics->OngoingPhysicsAction() )
       
   123             {
       
   124             iPhysics->StopPhysics();
       
   125             }
       
   126         }
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CTsPhysicsEngine::Stop
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 void CTsPhysicsEngine::Stop()
       
   134     {
       
   135     iPhysics->StopPhysics();
       
   136     iTaskswitcherPhysics->StopPhysics();
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CTsPhysicsEngine::AnimateToTargetL
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 void CTsPhysicsEngine::AnimateToTarget(const TPoint& aPoint)
       
   144     {
       
   145     iTaskswitcherPhysics->StartPhysics(aPoint);
       
   146     }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CTsPhysicsEngine::ReInitPhysicsL
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 void CTsPhysicsEngine::ReInitPhysicsL(const TSize& aWorldSize,
       
   153         const TSize& aViewSize, TBool aLandscape)
       
   154     {
       
   155     iPhysics->InitPhysicsL(aWorldSize, aViewSize, aLandscape);
       
   156     }
       
   157 
       
   158 //End file