|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * ============================================================================ 00003 * Name : tactileexamplecircle.cpp 00004 * Part of : Tactile Example 00005 * Interface : N/A 00006 * Description : Circle custom control implementation 00007 * Version : 00008 * 00009 * Copyright (c) 2008 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================ 00014 */ 00015 00016 // INCLUDE FILES 00017 #include <e32math.h> 00018 #include <akndef.h> 00019 #include <touchfeedback.h> 00020 #include "tactileexamplecircle.h" 00021 00022 00023 // ============================ MEMBER FUNCTIONS ============================= 00024 00025 // --------------------------------------------------------------------------- 00026 // Two-phased constructor. 00027 // --------------------------------------------------------------------------- 00028 // 00029 CTactileExampleCircle* CTactileExampleCircle::NewL( const TRect& aRect, 00030 const CCoeControl* aParent ) 00031 { 00032 CTactileExampleCircle* self = new ( ELeave ) CTactileExampleCircle; 00033 CleanupStack::PushL( self ); 00034 self->ConstructL( aRect, aParent ); 00035 CleanupStack::Pop( self ); 00036 return self; 00037 } 00038 00039 00040 // --------------------------------------------------------------------------- 00041 // Destructor 00042 // --------------------------------------------------------------------------- 00043 // 00044 CTactileExampleCircle::~CTactileExampleCircle() 00045 { 00046 } 00047 00048 00049 // --------------------------------------------------------------------------- 00050 // Enables/disables feedback for this control 00051 // --------------------------------------------------------------------------- 00052 // 00053 void CTactileExampleCircle::EnableFeedback( TBool aEnabled ) 00054 { 00055 MTouchFeedback* feedback = MTouchFeedback::Instance(); 00056 if ( feedback ) 00057 { 00058 feedback->EnableFeedbackForControl( this, aEnabled ); 00059 } 00060 } 00061 00062 00063 // --------------------------------------------------------------------------- 00064 // From class CCoeControl. 00065 // 00066 // --------------------------------------------------------------------------- 00067 // 00068 void CTactileExampleCircle::Draw( const TRect& /*aRect*/ ) const 00069 { 00070 CWindowGc& gc = SystemGc(); 00071 gc.SetPenStyle( CGraphicsContext::ENullPen ); 00072 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); 00073 gc.SetBrushColor( KRgbBlue ); 00074 gc.DrawEllipse( Rect() ); 00075 } 00076 00077 00078 // --------------------------------------------------------------------------- 00079 // From class CCoeControl. 00080 // Gets called when circle is touched 00081 // Plays feedback using instant feedback method 00082 // --------------------------------------------------------------------------- 00083 // 00084 void CTactileExampleCircle::HandlePointerEventL( const TPointerEvent& aPointerEvent ) 00085 { 00086 if ( aPointerEvent.iType == TPointerEvent::EButton1Down ) 00087 { 00088 MTouchFeedback* feedback = MTouchFeedback::Instance(); 00089 if ( feedback ) 00090 { 00091 feedback->InstantFeedback( this, ETouchFeedbackBasic ); 00092 } 00093 } 00094 CCoeControl::HandlePointerEventL( aPointerEvent ); 00095 } 00096 00097 00098 // --------------------------------------------------------------------------- 00099 // From class MCoeControlHitTest. 00100 // Tests whether a pointer event occurred inside the control's hit region 00101 // Calculates distance of the pointer event from center of the circle and compares 00102 // it to the radius 00103 // --------------------------------------------------------------------------- 00104 // 00105 TBool CTactileExampleCircle::HitRegionContains( const TPoint& aPoint, 00106 const CCoeControl& /*aControl*/ ) const 00107 { 00108 TBool hit; 00109 00110 if ( this->IsVisible() ) 00111 { 00112 TReal distance; // aPoint's distance from center of the circle 00113 TReal pow1; 00114 TReal pow2; 00115 TPoint offSet = Rect().Center() - aPoint; 00116 Math::Pow( pow1, offSet.iX, 2 ); 00117 Math::Pow( pow2, offSet.iY, 2 ); 00118 Math::Sqrt( distance, pow1 + pow2 ); 00119 00120 hit = ( distance > ( Rect().Width()/2 )) ? EFalse : ETrue; 00121 } 00122 else 00123 { 00124 hit = EFalse; 00125 } 00126 00127 return hit; 00128 } 00129 00130 00131 // --------------------------------------------------------------------------- 00132 // C++ default constructor can NOT contain any code, that might leave. 00133 // --------------------------------------------------------------------------- 00134 // 00135 CTactileExampleCircle::CTactileExampleCircle() 00136 { 00137 // No implementation required 00138 } 00139 00140 00141 // --------------------------------------------------------------------------- 00142 // Symbian 2nd phase constructor can leave. 00143 // --------------------------------------------------------------------------- 00144 // 00145 void CTactileExampleCircle::ConstructL( const TRect& aRect, const CCoeControl* aParent ) 00146 { 00147 SetContainerWindowL( *aParent ); 00148 SetRect( aRect ); 00149 00150 // Set hit tester to be object itself 00151 SetHitTest( this ); 00152 00153 ActivateL(); 00154 }
|
© Nokia 2009 |