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