web_plat/rt_gesturehelper_api/inc/rt_gestureobserver.h
branchRCL_3
changeset 48 79859ed3eea9
equal deleted inserted replaced
47:e1bea15f9a39 48:79859ed3eea9
       
     1 /*
       
     2 * Copyright (c) 2008-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 the License "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:  RT Gesture helper interface
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef _RT_GESTUREOBSERVER_H_
       
    19 #define _RT_GESTUREOBSERVER_H_
       
    20 
       
    21 #warning The RT Gesture API will be removed wk25. Please see http://wikis.in.nokia.com/Browser/APIMigration for more information
       
    22 
       
    23 #include <e32std.h>
       
    24 
       
    25 namespace RT_GestureHelper
       
    26 {
       
    27 
       
    28 /// flag that indicates gesture code is a holding code
       
    29 /// clients should use MGestureEvent::IsHolding
       
    30 const TInt EFlagHold       = 0x10000000;
       
    31 
       
    32 enum TGestureCode
       
    33     {
       
    34     // states
       
    35     EGestureStart          = 0x00000001, // gesture just started (user pressed stylus down)
       
    36     EGestureDrag           = 0x00000002, // user moved stylus (may be holding or not holding)
       
    37     EGestureReleased       = 0x00000003, // user lifted stylus while user was holding
       
    38     // gestures
       
    39     EGestureUnknown        = 0x00000005, // gesture was not recognised
       
    40     // these codes are sent when user lifts stylus (if holding not started)
       
    41     EGestureTap            = 0x00000006,
       
    42     EGestureDoubleTap      = 0x00000007, // only if double tap is enabled 
       
    43                                          // (via CGestureHelper::SetDoubleTapEnabled or
       
    44                                          // CGestureControl::SetDoubleTapEnabled)
       
    45     EGestureSwipeLeft      = 0x00000008,
       
    46     EGestureSwipeRight     = 0x00000009,
       
    47     EGestureSwipeUp        = 0x0000000A,
       
    48     EGestureSwipeDown      = 0x0000000B,
       
    49     
       
    50     EGestureFlick          = 0x0000000C,
       
    51     EGestureLongTap        = 0x0000000D,
       
    52     EGestureDrop           = 0x0000000E,
       
    53         
       
    54     // these codes are sent when user initiates holding by keeping stylus in
       
    55     // same place for a longer duration
       
    56     EGestureHoldLeft       = EGestureSwipeLeft  | EFlagHold,
       
    57     EGestureHoldRight      = EGestureSwipeRight | EFlagHold,
       
    58     EGestureHoldUp         = EGestureSwipeUp    | EFlagHold,
       
    59     EGestureHoldDown       = EGestureSwipeDown  | EFlagHold
       
    60     };
       
    61 
       
    62 /**
       
    63  * Point of float accuracy
       
    64  */
       
    65 NONSHARABLE_STRUCT( TRealPoint )
       
    66     {
       
    67     inline TRealPoint();
       
    68     inline TRealPoint( const TRealPoint& aPoint );
       
    69     inline TRealPoint( TReal aX, TReal aY );
       
    70     inline TBool operator==( const TRealPoint& aPoint ) const;
       
    71 
       
    72     TReal32 iX;
       
    73     TReal32 iY;
       
    74     };
       
    75 
       
    76 /**
       
    77  * a gesture event
       
    78  */
       
    79 
       
    80 enum TAxis
       
    81     {
       
    82     EAxisBoth,
       
    83     EAxisHorizontal,
       
    84     EAxisVertical
       
    85     };
       
    86 
       
    87 
       
    88 class TGestureEvent
       
    89 {
       
    90 public:    
       
    91     inline TGestureCode Code( TAxis /*aRelevantAxis*/ ) const { return iCode; };
       
    92     inline TBool IsHolding() const { return iIsHolding; };
       
    93     inline TPoint StartPos() const { return iStartPos; };
       
    94     inline TPoint CurrentPos() const { return iCurrPos; }; 
       
    95     inline TRealPoint Speed() const { return iSpeed; };
       
    96     inline TRealPoint SpeedPercent ( const TRect& /*aEdges*/ ) const { return iSpeedPercent; };
       
    97     inline TPoint Distance() const { return iDistance; }; 
       
    98     
       
    99     inline void SetCurrentPos(TPoint aPos) { iCurrPos = aPos; };
       
   100     inline void SetStartPos(TPoint aPos) {iStartPos = aPos; };
       
   101     inline void SetCode(TGestureCode aCode) {iCode = aCode; };
       
   102     inline void SetSpeed(TRealPoint aSpeed) { iSpeed = aSpeed; };
       
   103     inline void SetDistance(TPoint aDistance) { iDistance = aDistance; };
       
   104     inline void SetSpeedPercent(TRealPoint aSpeedPercent) { iSpeedPercent = aSpeedPercent; };
       
   105     
       
   106     inline void SetIsHolding(TBool aIsHolding) { iIsHolding = aIsHolding; };
       
   107     
       
   108 private:    
       
   109     TGestureCode   iCode;
       
   110     TBool          iIsHolding;
       
   111     TPoint         iStartPos;
       
   112     TPoint         iCurrPos;
       
   113     TRealPoint     iSpeed;
       
   114     TRealPoint     iSpeedPercent;
       
   115     TPoint         iDistance;
       
   116 };
       
   117 
       
   118     
       
   119 /** 
       
   120  * Observer that will be notified when user makes gestures
       
   121  */
       
   122 class MGestureObserver
       
   123     {
       
   124 public:
       
   125     /**
       
   126      * Handle the gesture event
       
   127      * @param aEvent event describing the gesture 
       
   128      */
       
   129     virtual void HandleGestureL( const TGestureEvent& aEvent ) = 0;
       
   130     };
       
   131 
       
   132 // ----------------------------------------------------------------------------
       
   133 // Default constructor for real point
       
   134 // ----------------------------------------------------------------------------
       
   135 //
       
   136 inline TRealPoint::TRealPoint()
       
   137         : iX( 0 ), iY( 0 )
       
   138     {    
       
   139     }
       
   140 
       
   141 // ----------------------------------------------------------------------------
       
   142 // Copy constructor for real point
       
   143 // ----------------------------------------------------------------------------
       
   144 //
       
   145 inline TRealPoint::TRealPoint( const TRealPoint& aPoint )
       
   146         : iX( aPoint.iX ), iY( aPoint.iY )
       
   147     {    
       
   148     }
       
   149 
       
   150 // ----------------------------------------------------------------------------
       
   151 // Copy constructor for real point
       
   152 // ----------------------------------------------------------------------------
       
   153 //
       
   154 inline TRealPoint::TRealPoint( TReal aX, TReal aY )
       
   155         : iX( aX ), iY( aY )
       
   156     {    
       
   157     }
       
   158 
       
   159 // ----------------------------------------------------------------------------
       
   160 // Default constructor for real point
       
   161 // ----------------------------------------------------------------------------
       
   162 //
       
   163 inline TBool TRealPoint::operator==( const TRealPoint& aPoint ) const
       
   164     {    
       
   165     return iX == aPoint.iX && iY == aPoint.iY;
       
   166     }
       
   167 
       
   168     
       
   169 } // namespace RT_GestureHelper
       
   170 
       
   171 #endif // _RT_GESTUREOBSERVER_H_