Nokia N97 SDK
Example Applications Guide

CTactileExampleAppView Class Reference

#include <tactileexampleappview.h>

Inheritance diagram for CTactileExampleAppView:

List of all members.

Detailed Description

CTactileExampleAppView application view class.

Definition at line 33 of file tactileexampleappview.h.


Public Member Functions

virtual  ~CTactileExampleAppView ()
TInt  CountComponentControls () const
CCoeControl *  ComponentControl (TInt aIndex) const
void  Draw (const TRect &aRect) const
void  SizeChanged ()
void  HandlePointerEventL (const TPointerEvent &aPointerEvent)
void  HandleResourceChange (TInt aType)
void  HandleControlEventL (CCoeControl *aControl, TCoeEvent aEventType)

Static Public Member Functions

static CTactileExampleAppView *  NewL (const TRect &aRect)
static CTactileExampleAppView *  NewLC (const TRect &aRect)

Private Member Functions

  CTactileExampleAppView ()
void  ConstructL (const TRect &aRect)
void  SetObjects ()
void  Move (CCoeControl *aControl, TPoint aPoint)
void  ObjectDimension ()

Private Attributes

TPoint  iDraggingOffset
TRect  iDragArea
TBool  iDragCircle
TBool  iDragSquare
TInt  iObjectDimension
CTactileExampleCircle *  iCircle
CTactileExampleSquare *  iSquare
CAknButton *  iButton
MTouchFeedback *  iFeedback


Constructor & Destructor Documentation

CTactileExampleAppView::~CTactileExampleAppView (   )  [virtual]
 

~CTactileExampleAppView Virtual Destructor.

Definition at line 74 of file tactileexampleappview.cpp.

References iButton, iCircle, and iSquare.

00075     {
00076     delete iButton;
00077     delete iSquare;
00078     delete iCircle;
00079     }

CTactileExampleAppView::CTactileExampleAppView (   )  [private]
 

CTactileExampleAppView. C++ default constructor.

Definition at line 282 of file tactileexampleappview.cpp.

00283     {
00284     // No implementation required
00285     }


Member Function Documentation

CTactileExampleAppView * CTactileExampleAppView::NewL (  const TRect &  aRect  )  [static]
 

NewL. Two-phased constructor. Create a CTactileExampleAppView object, which will draw itself to aRect.

Parameters:
aRect  The rectangle this view will be drawn to.
Returns:
a pointer to the created instance of CTactileExampleAppView.

Definition at line 49 of file tactileexampleappview.cpp.

References NewLC().

Referenced by CTactileExampleAppUi::ConstructL().

00050     {
00051     CTactileExampleAppView* self = CTactileExampleAppView::NewLC( aRect );
00052     CleanupStack::Pop( self );
00053     return self;
00054     }

CTactileExampleAppView * CTactileExampleAppView::NewLC (  const TRect &  aRect  )  [static]
 

NewLC. Two-phased constructor. Create a CTactileExampleAppView object, which will draw itself to aRect.

Parameters:
aRect  Rectangle this view will be drawn to.
Returns:
A pointer to the created instance of CTactileExampleAppView.

Definition at line 61 of file tactileexampleappview.cpp.

References ConstructL().

Referenced by NewL().

00062     {
00063     CTactileExampleAppView* self = new ( ELeave ) CTactileExampleAppView;
00064     CleanupStack::PushL( self );
00065     self->ConstructL( aRect );
00066     return self;
00067     }

TInt CTactileExampleAppView::CountComponentControls (   )  const
 

From CoeControl.

Returns:
Nbr of controls inside this container.

Definition at line 87 of file tactileexampleappview.cpp.

00088     {
00089     return KNumberOfComponents;
00090     }

CCoeControl * CTactileExampleAppView::ComponentControl (  TInt  aIndex  )  const
 

From CCoeControl.

Parameters:
Index  number of the control.
Returns:
Pointer of controls inside this container.

Definition at line 98 of file tactileexampleappview.cpp.

References iButton, iCircle, and iSquare.

00099     {
00100     switch( aIndex )
00101         {
00102         case EButton:
00103             return iButton;
00104         case ESquare:
00105             return iSquare;
00106         case ECircle:
00107             return iCircle;
00108         default:
00109             return NULL;
00110         }
00111     }

void CTactileExampleAppView::Draw (  const TRect &  aRect  )  const
 

From CCoeControl. Draw this CTactileExampleAppView to the screen.

Parameters:
aRect  the rectangle of this view that needs updating

Definition at line 119 of file tactileexampleappview.cpp.

00120     {
00121     // Get the standard graphics context
00122     CWindowGc& gc = SystemGc();
00123 
00124     gc.SetPenStyle( CGraphicsContext::ENullPen );
00125     gc.SetBrushColor( KRgbWhite );
00126     gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
00127 
00128     // Clears the area
00129     gc.Clear( aRect );
00130     }

void CTactileExampleAppView::SizeChanged (   ) 
 

From CoeControl. Called by framework when the view size is changed.

Definition at line 139 of file tactileexampleappview.cpp.

References iButton, iDragArea, and ObjectDimension().

00140     {
00141     // Gets the control's extent
00142     TRect rect( Rect() );
00143 
00144     // Set button's extent
00145     TRect buttonRect = TRect( rect.iTl.iX,
00146                               rect.iBr.iY - rect.Height() / KButtonHeight,
00147                               rect.iBr.iX, rect.iBr.iY );
00148     iButton->SetRect( buttonRect );
00149 
00150     // Set area where dragging is possible
00151     iDragArea.SetRect( rect.iTl.iX, rect.iTl.iY, rect.iBr.iX, buttonRect.iTl.iY );
00152 
00153     // Update object dimension
00154     ObjectDimension();
00155     }

void CTactileExampleAppView::HandlePointerEventL (  const TPointerEvent &  aPointerEvent  ) 
 

From CCoeControl.

Parameters:
aPointerEvent  The pointer event.

Definition at line 163 of file tactileexampleappview.cpp.

References CTactileExampleCircle::HitRegionContains(), iCircle, iDragArea, iDragCircle, iDraggingOffset, and iSquare.

00164     {
00165     TPoint point = aPointerEvent.iPosition;
00166 
00167     if ( iDragArea.Contains( point ))
00168         {
00169         if ( aPointerEvent.iType == TPointerEvent::EButton1Down &&
00170              iSquare->Rect().Center() != iCircle->Rect().Center() )
00171             {
00172             if ( iCircle->HitRegionContains( point, *iCircle ))
00173                 {
00174                 // dragging of circle started
00175                 iDragCircle = ETrue;
00176                 iDraggingOffset = iCircle->Position() - point;
00177                 }
00178             else if ( iSquare->HitRegionContains( point, *iSquare ))
00179                 {
00180                 // dragging of square started
00181                 iDragSquare = ETrue;
00182                 iDraggingOffset = iSquare->Position() - point;
00183                 }
00184             else
00185                 {
00186                 // Cancel dragging just in case
00187                 iDragCircle = EFalse;
00188                 iDragSquare = EFalse;
00189                 }
00190             }
00191 
00192         if ( aPointerEvent.iType == TPointerEvent::EDrag )
00193             {
00194             if( iDragCircle )
00195                 {
00196                 Move( iCircle, point + iDraggingOffset );
00197                 }
00198             else if( iDragSquare )
00199                 {
00200                 Move( iSquare, point + iDraggingOffset );
00201                 }
00202 
00203             if( iSquare->Rect().Center() == iCircle->Rect().Center() )
00204                 {
00205                 // Objects are in end positions -> cancel dragging
00206                 iDragCircle = EFalse;
00207                 iDragSquare = EFalse;
00208 
00209                 // and disable all feedbacks
00210                 iSquare->EnableFeedback( EFalse );
00211                 iCircle->EnableFeedback( EFalse );
00212                 }
00213             }
00214         }
00215 
00216     if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
00217         {
00218         // possible dragging is cancelled if button is released
00219         iDragCircle = EFalse;
00220         iDragSquare = EFalse;
00221         }
00222 
00223     CCoeControl::HandlePointerEventL( aPointerEvent );
00224     }

void CTactileExampleAppView::HandleResourceChange (  TInt  aType  ) 
 

From CCoeControl.

Parameters:
aType  The type of resources that have changed.

Definition at line 232 of file tactileexampleappview.cpp.

References CTactileExampleSquare::EnableFeedback(), CTactileExampleCircle::EnableFeedback(), iCircle, iSquare, and SetObjects().

00233     {
00234     CCoeControl::HandleResourceChange( aType );
00235     if ( aType == KEikDynamicLayoutVariantSwitch )
00236         {
00237         // Set circle and square to default positions
00238         SetObjects();
00239 
00240         // enable feedback again since it might have been disabled
00241         // if square & circle are in end positions
00242         iCircle->EnableFeedback( ETrue );
00243         iSquare->EnableFeedback( ETrue );
00244 
00245         // ohjects are made visible/hidden depending 
00246         // is touch supported for new layout
00247         iSquare->MakeVisible( AknLayoutUtils::PenEnabled() );
00248         iCircle->MakeVisible( AknLayoutUtils::PenEnabled() );
00249         }
00250     }

void CTactileExampleAppView::HandleControlEventL (  CCoeControl *  aControl,
TCoeEvent  aEventType
) 
 

From MCoeControlObserver. Handles an event of type aEventType

Parameters:
aControl  Pointer to component control
aEventType  Event code

Definition at line 258 of file tactileexampleappview.cpp.

References CTactileExampleSquare::EnableFeedback(), CTactileExampleCircle::EnableFeedback(), iButton, iCircle, iSquare, and SetObjects().

00260     {
00261     if ( aControl == iButton )
00262         {
00263         if ( aEventType == EEventStateChanged )
00264             {
00265             // Button press resets object positions
00266             SetObjects();
00267             DrawDeferred();
00268 
00269             // enable feedback again since it might have been disabled
00270             // if square & circle are in end positions
00271             iCircle->EnableFeedback( ETrue );
00272             iSquare->EnableFeedback( ETrue );
00273             }
00274         }
00275     }

void CTactileExampleAppView::ConstructL (  const TRect &  aRect  )  [private]
 

ConstructL

2nd phase constructor. Perform the second phase construction of a CTactileExampleAppView object.

Parameters:
aRect  The rectangle this view will be drawn to.

Definition at line 292 of file tactileexampleappview.cpp.

References iButton, iCircle, iFeedback, iObjectDimension, iSquare, CTactileExampleCircle::NewL(), CTactileExampleSquare::NewL(), ObjectDimension(), and SetObjects().

Referenced by NewLC().

00293     {
00294     // Create a window for this application view
00295     CreateWindowL();
00296 
00297     // Load a string from the resource file to be used as button label
00298     HBufC* textResource = StringLoader::LoadLC( R_TACT_BUTTON_TEXT );
00299 
00300     // Create button
00301     iButton = CAknButton::NewL( NULL, NULL, NULL, NULL,
00302               *textResource, KNullDesC, KAknButtonSizeFitText, 0 );
00303     User::LeaveIfNull( iButton );
00304     iButton->SetContainerWindowL( *this );
00305     iButton->MakeVisible( ETrue );
00306     iButton->SetObserver( this );
00307 
00308     // Update object dimesion
00309     ObjectDimension();
00310 
00311     // Create square
00312     iSquare = CTactileExampleSquare::NewL( TRect( TSize( iObjectDimension,
00313                                           iObjectDimension )), this );
00314     iSquare->SetContainerWindowL( *this );
00315     iSquare->MakeVisible( AknLayoutUtils::PenEnabled() );
00316 
00317     // Create circle
00318     iCircle = CTactileExampleCircle::NewL( TRect( TSize( iObjectDimension,
00319                                           iObjectDimension )), this );
00320     iCircle->SetContainerWindowL( *this );
00321     iCircle->MakeVisible( AknLayoutUtils::PenEnabled() );
00322 
00323     // Pop HBuf from CleanUpStack and Destroy it.
00324     CleanupStack::PopAndDestroy( textResource );
00325 
00326 
00327     // Set the windows size
00328     SetRect( aRect );
00329 
00330     // Set objects to default positions
00331     SetObjects();
00332 
00333     // Get a pointer to touch feedback instance
00334     iFeedback = MTouchFeedback::Instance();
00335     User::LeaveIfNull( iFeedback );
00336 
00337     EnableDragEvents();
00338 
00339     // Activate the window, which makes it ready to be drawn
00340     ActivateL();
00341     }

void CTactileExampleAppView::SetObjects (   )  [private]
 

SetObjects Sets the circle and square objects to default position

Definition at line 348 of file tactileexampleappview.cpp.

References iCircle, iDragArea, iObjectDimension, and iSquare.

Referenced by ConstructL(), HandleControlEventL(), and HandleResourceChange().

00349     {
00350     TPoint squarePos = TPoint( iDragArea.iBr.iX - iObjectDimension,
00351                                iDragArea.iBr.iY - iObjectDimension );
00352 
00353     // modify coordinates to match the grid
00354     squarePos.iX = squarePos.iX - squarePos.iX % KMovementGrid;
00355     squarePos.iY = squarePos.iY - squarePos.iY % KMovementGrid;
00356 
00357     iSquare->SetExtent( squarePos, TSize( iObjectDimension, iObjectDimension ));
00358     iCircle->SetExtent( TPoint( iDragArea.iTl.iX, iDragArea.iTl.iY ),
00359                         TSize( iObjectDimension, iObjectDimension ));
00360     }

void CTactileExampleAppView::Move (  CCoeControl *  aControl,
TPoint  aPoint
)  [private]
 

Move Moves the control snapping to imaginary grid lines

Parameters:
aControl  Control which is moved.
aPoint  Point where control is moved to.

Definition at line 367 of file tactileexampleappview.cpp.

References iFeedback.

00368     {
00369     TPoint newPosition;
00370     
00371     // adjust aPoint to match the grid    
00372     newPosition.iX = aPoint.iX - aPoint.iX % KMovementGrid;
00373     newPosition.iY = aPoint.iY - aPoint.iY % KMovementGrid;
00374     
00375     if ( newPosition != aControl->Position() )
00376         {
00377         // Feedback is given as early as possible
00378         iFeedback->InstantFeedback( aControl, ETouchFeedbackSensitive );
00379 
00380         // Define the changed area
00381         TRect drawRect = TRect( newPosition, aControl->Size() );
00382         drawRect.BoundingRect( aControl->Rect() );
00383 
00384         // set control to new position
00385         aControl->SetPosition( newPosition );
00386 
00387         // draw only changed area
00388         DrawNow( drawRect );
00389         }
00390     }

void CTactileExampleAppView::ObjectDimension (   )  [private]
 

ObjectDimension Calculates object's side length related to screen size

Definition at line 397 of file tactileexampleappview.cpp.

References iObjectDimension.

Referenced by ConstructL(), and SizeChanged().

00398     {
00399     TPixelsAndRotation ScreenSize;
00400     iCoeEnv->ScreenDevice()->GetDefaultScreenSizeAndRotation( ScreenSize );
00401     TInt side = ScreenSize.iPixelSize.iWidth < ScreenSize.iPixelSize.iHeight ?
00402             ScreenSize.iPixelSize.iWidth / KObjSize : ScreenSize.iPixelSize.iHeight / KObjSize;
00403 
00404     // size is adjusted to match the grid
00405     iObjectDimension = ( side - side % ( KMovementGrid * 2 ));
00406     }


Member Data Documentation

TPoint CTactileExampleAppView::iDraggingOffset [private]
 

Offset from the object's top left corner to the point of touch

Definition at line 162 of file tactileexampleappview.h.

Referenced by HandlePointerEventL().

TRect CTactileExampleAppView::iDragArea [private]
 

Area where dragging is possible

Definition at line 167 of file tactileexampleappview.h.

Referenced by HandlePointerEventL(), SetObjects(), and SizeChanged().

TBool CTactileExampleAppView::iDragCircle [private]
 

Flag indicating circle is dragged

Definition at line 172 of file tactileexampleappview.h.

Referenced by HandlePointerEventL().

TBool CTactileExampleAppView::iDragSquare [private]
 

Flag indicating square is dragged

Definition at line 177 of file tactileexampleappview.h.

TInt CTactileExampleAppView::iObjectDimension [private]
 

Size of objects related to screen size

Definition at line 182 of file tactileexampleappview.h.

Referenced by ConstructL(), ObjectDimension(), and SetObjects().

CTactileExampleCircle* CTactileExampleAppView::iCircle [private]
 

Circle object Own.

Definition at line 188 of file tactileexampleappview.h.

Referenced by ComponentControl(), ConstructL(), HandleControlEventL(), HandlePointerEventL(), HandleResourceChange(), SetObjects(), and ~CTactileExampleAppView().

CTactileExampleSquare* CTactileExampleAppView::iSquare [private]
 

Square object Own.

Definition at line 194 of file tactileexampleappview.h.

Referenced by ComponentControl(), ConstructL(), HandleControlEventL(), HandlePointerEventL(), HandleResourceChange(), SetObjects(), and ~CTactileExampleAppView().

CAknButton* CTactileExampleAppView::iButton [private]
 

Reset button Own.

Definition at line 200 of file tactileexampleappview.h.

Referenced by ComponentControl(), ConstructL(), HandleControlEventL(), SizeChanged(), and ~CTactileExampleAppView().

MTouchFeedback* CTactileExampleAppView::iFeedback [private]
 

Pointer to touch feedback instance Not own.

Definition at line 206 of file tactileexampleappview.h.

Referenced by ConstructL(), and Move().


The documentation for this class was generated from the following files:

© Nokia 2009

Back to top