webengine/webkitutils/stmgesturefw/src/genericsimplegesture.cpp
changeset 42 d39add9822e2
equal deleted inserted replaced
38:6297cdf66332 42:d39add9822e2
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Gesture helper implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include "GenericSimpleGesture.h"
       
    19 #include "filelogger.h"
       
    20 
       
    21 using namespace stmGesture ;
       
    22 using stmUiEventEngine::MUiEventSpeed;
       
    23 
       
    24 
       
    25 TGenericSimpleGesture::TGenericSimpleGesture(
       
    26     TGestureUid uid, const TPoint& loc, int type, const MUiEventSpeed* speedIf) :
       
    27     m_location(loc), m_uid(uid), m_type(type), m_details(0), m_speed(speedIf)
       
    28 {
       
    29 }
       
    30 
       
    31 TPoint TGenericSimpleGesture::getLocation()  const
       
    32 {
       
    33     return m_location ;
       
    34 }
       
    35 
       
    36 int TGenericSimpleGesture::getType()  const
       
    37 {
       
    38     return m_type ;
       
    39 }
       
    40 
       
    41 int TGenericSimpleGesture::getDetails() const
       
    42 {
       
    43     return m_details ;
       
    44 }
       
    45 
       
    46 void TGenericSimpleGesture::setName(const TDesC8& aName)
       
    47 {
       
    48     m_name.Set(aName) ;
       
    49 }
       
    50 
       
    51 TPtrC8 TGenericSimpleGesture::getGestureName()
       
    52 {
       
    53     return m_name ;
       
    54 }
       
    55 
       
    56 TDirectionalGesture::TDirectionalGesture(
       
    57     TGestureUid uid, const TPoint& loc, const TPoint& prevLoc,
       
    58     const MUiEventSpeed* speedIf, bool logging) :
       
    59     TGenericSimpleGesture(uid, loc, 0, speedIf), m_loggingEnabled(logging)
       
    60 {
       
    61     setVector(loc, prevLoc);
       
    62 }
       
    63 
       
    64 void TDirectionalGesture::setVector(const TPoint& last, const TPoint& previous)
       
    65 {
       
    66     m_vector = TPoint(last.iX-previous.iX, previous.iY-last.iY) ;  // x > 0 => east, y > 0 => north
       
    67     if (m_loggingEnabled)
       
    68     {
       
    69         LOGARG("CHoveringGesture: x: %d , %d prev: %d, %d", last.iX, last.iY, previous.iX, previous.iY) ;
       
    70     }
       
    71 }
       
    72 
       
    73 TGestureDirection TDirectionalGesture::getDirection() const
       
    74 {
       
    75     TGestureDirection dir = ENorth ;
       
    76     int x = Abs(m_vector.iX) ;
       
    77     int y = Abs(m_vector.iY) ;
       
    78     if (y <= x/2)
       
    79     {
       
    80         if (m_vector.iX < 0)
       
    81             dir = EWest ;
       
    82         else
       
    83             dir = EEast ;
       
    84     }
       
    85     else if (y > x/2 && y <= (x+x/2))
       
    86     {
       
    87         if (m_vector.iX < 0)
       
    88         {
       
    89             if (m_vector.iY < 0 )
       
    90                 dir = ESouthWest ;
       
    91             else
       
    92                 dir = ENorthWest ;
       
    93         }
       
    94         else
       
    95         {
       
    96             if (m_vector.iY < 0 )
       
    97                 dir = ESouthEast ;
       
    98             else
       
    99                 dir = ENorthEast ;
       
   100         }
       
   101     }
       
   102     else if (y > x+x/2)
       
   103     {
       
   104         if (m_vector.iY < 0)
       
   105             dir = ESouth ;
       
   106         else
       
   107             dir = ENorth ;
       
   108     }
       
   109     if (m_loggingEnabled)
       
   110     {
       
   111         LOGARG("CHoveringGesture: x: %d y: %d direction: %d", m_vector.iX, m_vector.iY, dir) ;
       
   112     }
       
   113     return dir ;
       
   114 }
       
   115 
       
   116 TTwoPointGesture::TTwoPointGesture(TGestureUid uid, const TPoint& loc, const TPoint& prevLoc) :
       
   117     TDirectionalGesture(uid, loc, prevLoc, NULL),
       
   118     m_location2(prevLoc)
       
   119 {
       
   120 }
       
   121