dependencies/physics_api/inc/aknphysics.h
branchv5backport
changeset 21 11157e26c4a7
equal deleted inserted replaced
20:d2ab7c3d0c48 21:11157e26c4a7
       
     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:  AknPhysics
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef C_AKNPHYSICS_H
       
    19 #define C_AKNPHYSICS_H
       
    20 
       
    21 #include <e32base.h>
       
    22 
       
    23 class MAknPhysicsObserver;
       
    24 class CAknPhysicsParameterProvider;
       
    25 class CAknPhysicsRestrictor;
       
    26 class CAknPhysicsConeObserver;
       
    27 class CAknPhysicsEngine;
       
    28 class CCoeControl;
       
    29 class CAknHighResPeriodic;
       
    30 class MTouchFeedback;
       
    31 
       
    32 
       
    33 /**
       
    34  *  CAknPhysics
       
    35  *
       
    36  *  @lib aknphysics
       
    37  *  @since S60 v5.0
       
    38  */
       
    39 NONSHARABLE_CLASS( CAknPhysics ) : public CBase
       
    40     {
       
    41     
       
    42 public:
       
    43 
       
    44     /**  CAknPhysics action definition */
       
    45     enum TAknPhysicsAction
       
    46         {
       
    47         EAknPhysicsActionNone = 1,
       
    48         EAknPhysicsActionFlicking,
       
    49         EAknPhysicsActionBouncing,
       
    50         EAknPhysicsActionDragging
       
    51         };
       
    52 
       
    53 
       
    54     /**
       
    55      * Two-phased constructor.
       
    56      * @param aObserver Observer of the physics object.
       
    57      * @param aViewControl Physics view control.
       
    58      */
       
    59     IMPORT_C static CAknPhysics* NewL( MAknPhysicsObserver& aObserver,
       
    60                                        CCoeControl* aViewControl );
       
    61     
       
    62     /**
       
    63     * Destructor.
       
    64     */
       
    65     virtual ~CAknPhysics();
       
    66     
       
    67 public:
       
    68 
       
    69     /**
       
    70      * Physics initialization.
       
    71      *
       
    72      * @since S60 v5.0
       
    73      * @param aWorldSize Physics world size.
       
    74      * @param aViewSize Physics (visible) view size.
       
    75      * @param aLandscape ETrue if physics should work in landscape.
       
    76      */
       
    77     IMPORT_C void InitPhysicsL( const TSize& aWorldSize, 
       
    78                                 const TSize& aViewSize, 
       
    79                                 TBool aLandscape );
       
    80 
       
    81     /**
       
    82      * Starts physics simulation and applies drag event. The action is
       
    83      * done only if the drag distance is greater than the drag threshold.
       
    84      * Drag distance is adjusted by physics, if the dragging direction
       
    85      * has been changed during the dragging event.
       
    86      *
       
    87      * @param aDrag Drag distance.
       
    88      * @param aStartTime Dragging start time.
       
    89      * @return ETrue if physics was started and drag was applied.
       
    90      */
       
    91     IMPORT_C TBool StartPhysics( TPoint& aDrag, const TTime& aStartTime );
       
    92 
       
    93     /**
       
    94      * Stops physics simulation.
       
    95      *
       
    96      * @since S60 v5.0
       
    97      */
       
    98     IMPORT_C void StopPhysics();
       
    99 
       
   100     /**
       
   101      * Returns CAknPhysics action code i.e. which action CAknPhysics 
       
   102      * is currently performing.
       
   103      *
       
   104      * @since S60 v5.0
       
   105      * @return TAknPhysicsAction type action code.
       
   106      */
       
   107     IMPORT_C TInt OngoingPhysicsAction() const;
       
   108     
       
   109 
       
   110     /**
       
   111      * Registers view panning position. Used when view is panned
       
   112      * (dragged).
       
   113      *
       
   114      * @since S60 v5.0
       
   115      * @param aDelta Dragging distance.
       
   116      */
       
   117     IMPORT_C void RegisterPanningPosition( const TPoint& aDelta );
       
   118 
       
   119     /**
       
   120      * Sets friction.
       
   121      *
       
   122      * @since S60 v5.0
       
   123      * @param aFriction
       
   124      */
       
   125     IMPORT_C void SetFriction( TReal aFriction );
       
   126 
       
   127     /**
       
   128      * Resets friction.
       
   129      *
       
   130      * @since S60 v5.0
       
   131      */
       
   132     IMPORT_C void ResetFriction();
       
   133 
       
   134     /**
       
   135      * Returns highlight timeout parameter.
       
   136      *
       
   137      * @since S60 v5.0
       
   138      * @return Highlight timeout.
       
   139      */
       
   140     IMPORT_C TInt HighlightTimeout() const;
       
   141 
       
   142     /**
       
   143      * Returns drag threshold parameter.
       
   144      *
       
   145      * @since S60 v5.0
       
   146      * @return Drag threshold.
       
   147      */
       
   148     IMPORT_C TInt DragThreshold() const;
       
   149 
       
   150     /**
       
   151      * Returns feature enabled parameter.
       
   152      *
       
   153      * @since S60 v5.0
       
   154      * @return ETrue if kinetic scrolling feature is enabled.
       
   155      */
       
   156     IMPORT_C static TBool FeatureEnabled();
       
   157 
       
   158     /**
       
   159      * Returns EFalse if events should not be handled. This is the case if
       
   160      * flick is interrupted via key or pointer event or view is bouncing.
       
   161      *
       
   162      * @since S60 v5.0
       
   163      * @return ETrue if key and pointer events can be handled normally.
       
   164      */
       
   165     IMPORT_C TBool EventHandlingAllowed() const;
       
   166 
       
   167     /**
       
   168      * Updates view window control (in case e.g. view control container
       
   169      * window has changed).
       
   170      *
       
   171      * @since S60 v5.0
       
   172      * @param aControl New view control if view control itself has changed.
       
   173      */
       
   174     IMPORT_C void UpdateViewWindowControl( CCoeControl* aControl = NULL );
       
   175     
       
   176     /**
       
   177      * Suspends physics simulation, but doesn't reset current force or
       
   178      * velocity. When simulation is suspended, it is possible to change
       
   179      * view position.
       
   180      *
       
   181      * @since S60 v5.2
       
   182      */
       
   183     IMPORT_C void SuspendPhysics();
       
   184     
       
   185     /**
       
   186      * Resumes physics simulation with current view position, force
       
   187      * and velocity. 
       
   188      *
       
   189      * @since S60 v5.2
       
   190      */
       
   191     IMPORT_C void ResumePhysics();
       
   192 
       
   193 // internal AknPhysics methods
       
   194 
       
   195     /**
       
   196      * Checks if view position needs updating.
       
   197      *
       
   198      * @since S60 v5.0
       
   199      * @internal
       
   200      */
       
   201     void UpdateViewPosition();
       
   202 
       
   203     /**
       
   204      * Returns ETrue if physics works in landscape.
       
   205      *
       
   206      * @since S60 v5.0
       
   207      * @internal
       
   208      * @return ETrue if physics works in landscape.
       
   209      */
       
   210     const TBool& Landscape();
       
   211 
       
   212     /**
       
   213      * Returns current view size.
       
   214      *
       
   215      * @since S60 v5.0
       
   216      * @internal
       
   217      * @return Current view size.
       
   218      */
       
   219     const TSize& ViewSize();
       
   220 
       
   221     /**
       
   222      * Returns current world size.
       
   223      *
       
   224      * @since S60 v5.0
       
   225      * @internal
       
   226      * @return Current world size.
       
   227      */
       
   228     const TSize& WorldSize();
       
   229 
       
   230     /**
       
   231      * Returns current surface erp value.
       
   232      *
       
   233      * @since S60 v5.0
       
   234      * @internal
       
   235      * @return Current surface erp value.
       
   236      */
       
   237     TInt SurfaceErp() const;
       
   238 
       
   239     /**
       
   240      * Returns current surface cfm value.
       
   241      *
       
   242      * @since S60 v5.0
       
   243      * @internal
       
   244      * @return Current surface cfm value.
       
   245      */
       
   246     TInt SurfaceCfm() const;
       
   247 
       
   248     /**
       
   249      * Returns frame delay value.
       
   250      *
       
   251      * @since S60 v5.0
       
   252      * @internal
       
   253      * @return Frame delay.
       
   254      */
       
   255     TInt FrameDelay() const;
       
   256 
       
   257 	/**
       
   258      * Returns min frame interval value.
       
   259      *
       
   260      * @since S60 v5.0
       
   261      * @internal
       
   262      * @return Min frame interval.
       
   263      */
       
   264     TInt MinFrameInterval() const;
       
   265     
       
   266     /**
       
   267      * Draws the view in the current position.
       
   268      */
       
   269     void DrawViewInCurrentPosition();
       
   270 
       
   271     /**
       
   272      * Sets the iBounceTactileFeedback flag value.
       
   273      * 
       
   274      * @since S60 v5.2
       
   275      * @param aBounceTactileFeedback Whether tactile feedback is to be
       
   276      *        produced for bounce or not.
       
   277      */
       
   278     void SetBounceTactileFeedback( TBool aBounceTactileFeedback );
       
   279 
       
   280     /**
       
   281      * Checks if view is not drawn during panning 
       
   282      * because of high CPU usage
       
   283      *
       
   284      * @since S60 v5.2
       
   285      * @internal
       
   286      */
       
   287      TBool IsPanningDrawOmitted() const;
       
   288 
       
   289 protected:
       
   290 
       
   291     /**
       
   292      * C++ constructor.
       
   293      */
       
   294     CAknPhysics( MAknPhysicsObserver& aObserver );
       
   295 
       
   296     /**
       
   297      * Symbian second-phase constructor.
       
   298      */
       
   299     void ConstructL( CCoeControl* aViewControl );
       
   300     
       
   301 private:
       
   302 
       
   303     /**
       
   304      * Physics start.
       
   305      */
       
   306     void StartPhysics();
       
   307 
       
   308     /**
       
   309      * Apply drag.
       
   310      *
       
   311      * @param aDrag Dragging distance.
       
   312      * @param aMoveTime Dragging movetime.
       
   313      */
       
   314     void ApplyDrag( TPoint aDrag, TInt aMoveTime );
       
   315 
       
   316     /**
       
   317      * Timer callback.
       
   318      */
       
   319     static TInt Simulate(TAny* aSelf);
       
   320 
       
   321     /**
       
   322      * Physics simulation function.
       
   323      */
       
   324     void DoSimulation();
       
   325 
       
   326     /**
       
   327      * Cancels the physics timer and resets action state.
       
   328      */
       
   329     void CancelPhysicsTimer();
       
   330 
       
   331     /**
       
   332      * Updates ongoing action state according to whether physics timer is 
       
   333      * active or not and collision status.
       
   334      */
       
   335     void UpdateActionState();
       
   336 
       
   337     /**
       
   338      * Returns ETrue if observer view position reveals empty space i.e.
       
   339      * view is about to bounce.
       
   340      *
       
   341      * @return ETrue if observer view position reveals empty space.
       
   342      */
       
   343     TBool ViewAboutToBounce();
       
   344 
       
   345     /**
       
   346      * Wrapper method for notifying observer of view position change.
       
   347 	 *
       
   348      * @param  aPosition  New view position.
       
   349 	 * @param  aDrawNow   @c ETrue to inform the observer that it's
       
   350 	 *                    view should be drawn, @c EFalse otherwise,
       
   351 	 *                    in which case the observer should only update
       
   352 	 *                    the logical position.
       
   353      */
       
   354     void NotifyViewPositionChanged( const TPoint& aPosition,
       
   355 									TBool aDrawNow = ETrue );
       
   356     
       
   357 private: // data
       
   358 
       
   359     /**
       
   360      * Simulation timer.
       
   361      */
       
   362     CAknHighResPeriodic* iPhysics; // Own
       
   363     
       
   364     /**
       
   365      * Physics observer.
       
   366      */
       
   367     MAknPhysicsObserver& iObserver;
       
   368     
       
   369     /**
       
   370      * Current world size.
       
   371      */
       
   372     TSize iWorldSize;
       
   373 
       
   374     /**
       
   375      * Current view size.
       
   376      */
       
   377     TSize iViewSize;
       
   378     
       
   379     /**
       
   380      * ETrue if physics works in landscape.
       
   381      */
       
   382     TBool iLandscape;
       
   383     
       
   384     /**
       
   385      * Ongoing action.
       
   386      */
       
   387     TAknPhysicsAction iOngoingAction;
       
   388     
       
   389     /**
       
   390      * Counter to keep track of same successive view positions.
       
   391      */
       
   392     TInt iSamePositionCounter;
       
   393 
       
   394     /**
       
   395      * Physics parameter provider.
       
   396      * Own.
       
   397      */
       
   398     CAknPhysicsParameterProvider* iParamProvider;
       
   399 
       
   400     /**
       
   401      * Physics restrictor.
       
   402      * Own.
       
   403      */
       
   404     CAknPhysicsRestrictor* iRestrictor;
       
   405 
       
   406     /**
       
   407      * CONE observer.
       
   408      * Own.
       
   409      */
       
   410     CAknPhysicsConeObserver* iConeObserver;
       
   411     
       
   412     /**
       
   413      * Physics engine.
       
   414      * Own.
       
   415      */
       
   416     CAknPhysicsEngine* iEngine;
       
   417 
       
   418     /**
       
   419      * ETrue if maximum flick time exceeded.
       
   420      */
       
   421     TBool iFlickTimeExceeded;
       
   422     
       
   423     /**
       
   424      * Handle to the null thread, used for performance monitoring.
       
   425      */
       
   426     RThread iNullThread;
       
   427     
       
   428     /**
       
   429      * CPU time used by the null thread after the last view draw.
       
   430      */
       
   431     TInt64 iNullThreadTime;
       
   432 
       
   433     /**
       
   434      * Time of the last view draw.
       
   435      */
       
   436     TTime iTimeOfLastDraw;
       
   437 
       
   438     /**
       
   439      * Pointer to touch feedback instance
       
   440      * Not own.
       
   441      */
       
   442     MTouchFeedback* iFeedback;
       
   443 
       
   444     /**
       
   445      * Flag that indicates whether or not to give tactile feedback when
       
   446      * bouncing.
       
   447      */
       
   448     TBool iBounceTactileFeedback;
       
   449 
       
   450     /**
       
   451      * ETrue if a panning frame is not drawn on screen because of
       
   452      * high CPU usage.
       
   453      */
       
   454     TBool iPanningDrawOmitted;
       
   455 
       
   456     /**
       
   457      * ETrue if physics simulation is suspended. 
       
   458      */
       
   459     TBool iSuspended;
       
   460     };
       
   461 
       
   462 #endif // C_AKNPHYSICS_H