|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : serverimage.cpp 00004 * Part of : Animation example 00005 * Interface : 00006 * Description : 00007 * Version : 00008 * 00009 * Copyright (c) 2004 - 2006 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 <e32std.h> 00018 #include <e32base.h> 00019 #include <txtfrmat.h> 00020 00021 #include "servertimeouttimer.h" 00022 #include "serverimage.h" 00023 #include "animation.pan" 00024 00025 // ============================ MEMBER FUNCTIONS =============================== 00026 00027 // Animation server object class functions. 00028 // These functions are called by the windows server from 00029 // requests made by the client animation dll. 00030 00031 // ----------------------------------------------------------------------------- 00032 // CImage::CImage() 00033 // C++ default constructor can NOT contain any code, that might leave. 00034 // ----------------------------------------------------------------------------- 00035 // 00036 CImage::CImage() 00037 { 00038 // No implementation required 00039 } 00040 00041 // ----------------------------------------------------------------------------- 00042 // CImage::ConstructL() 00043 // Symbian 2nd phase constructor can leave. 00044 // ----------------------------------------------------------------------------- 00045 // 00046 void CImage::ConstructL( TAny* /* aArgs */, TBool /* aHasFocus */ ) 00047 { 00048 // Initialise starting points to the top left hand corner 00049 iLastPoint.SetXY( 0, 0 ); 00050 iNewPoint.SetXY( 1, 1 ); 00051 00052 // Set up how far the shape moves each timer event 00053 iDeltaX = KStepSize; 00054 iDeltaY = KStepSize; 00055 00056 // Animation reset not requested by user 00057 iAnimationReset = EFalse; 00058 00059 // initiates an initial position update 00060 iDrawn = ETrue; 00061 00062 // Set the rectangles size 00063 iSize.SetSize( 20,20 ); 00064 00065 // Store the screen size 00066 iScreenSize = iWindowFunctions->WindowSize(); 00067 00068 // Set the screen visible 00069 iWindowFunctions->SetVisible( ETrue ); 00070 00071 // We are using a timer, not the built in synchronising, so turn it off 00072 iFunctions->SetSync( MAnimGeneralFunctions::ESyncNone ); 00073 00074 // Create the timeout timer 00075 iServerTimer = CTimeOutTimer::NewL( EPriorityHigh, *this ); 00076 00077 // Set the timeout period 00078 iServerTimer->After( KTimerPeriod ); 00079 } 00080 00081 // ----------------------------------------------------------------------------- 00082 // CImage::~CImage() 00083 // Destructor. 00084 // ----------------------------------------------------------------------------- 00085 // 00086 CImage::~CImage() 00087 { 00088 // If the CTimer derived object exists and has an outstanding request, 00089 // cancel it. 00090 if ( iServerTimer ) 00091 { 00092 iServerTimer->Cancel(); 00093 } 00094 00095 // Then delete the timer object 00096 delete iServerTimer; 00097 iServerTimer = NULL; 00098 } 00099 00100 // ----------------------------------------------------------------------------- 00101 // CImage::Redraw() 00102 // Redraw the animation server object, includes rubbing out the old object. 00103 // ----------------------------------------------------------------------------- 00104 // 00105 void CImage::Redraw() 00106 { 00107 // get the background colour 00108 TLogicalRgb backgroundColour( TLogicalRgb::ESystemBackgroundColor ); 00109 00110 // Clear the old image. 00111 iGc->SetPenSize( TSize( 3,3 ) ); 00112 iGc->SetPenColor( backgroundColour ); 00113 iGc->DrawRect( TRect( iLastPoint, iSize ) ); 00114 00115 // Draw a shape at the new position 00116 iGc->SetPenSize( TSize( 1,1 ) ); 00117 iGc->SetPenColor( KRgbBlack ); 00118 iGc->DrawRect( TRect( iNewPoint, iSize ) ); 00119 00120 // signal that the current position has been drawn 00121 iDrawn = ETrue; 00122 } 00123 00124 // ----------------------------------------------------------------------------- 00125 // CImage::FocusChanged() 00126 // Not bothered if the focus has changed. 00127 // ----------------------------------------------------------------------------- 00128 // 00129 void CImage::FocusChanged( TBool /* aState */ ) 00130 { 00131 } 00132 00133 // ----------------------------------------------------------------------------- 00134 // CImage::Animate() 00135 // Animate the animation server object. 00136 // ----------------------------------------------------------------------------- 00137 // 00138 void CImage::Animate( TDateTime* /* aDateTime */ ) 00139 { 00140 00141 // if the last position has been drawn, update the position 00142 if ( iDrawn ) 00143 { 00144 // this position has not been drawn, so clear the flag 00145 iDrawn = EFalse; 00146 00147 00148 // Save the current position, so we can rub it out later 00149 iLastPoint = iNewPoint; 00150 00151 // Check current position, 00152 // reverse the direction if either limit is reached 00153 if ( ( iNewPoint.iX == iScreenSize.iTl.iX ) || 00154 ( ( iNewPoint.iX + iSize.iWidth ) == iScreenSize.iBr.iX ) ) 00155 { 00156 iDeltaX = -iDeltaX; 00157 } 00158 00159 // Setup the next X coordinate 00160 iNewPoint.iX += iDeltaX; 00161 00162 // Repeat for y coordinate 00163 if ( ( iNewPoint.iY == iScreenSize.iTl.iY ) || 00164 ( ( iNewPoint.iY + iSize.iHeight ) == iScreenSize.iBr.iY ) ) 00165 { 00166 iDeltaY = -iDeltaY; 00167 } 00168 iNewPoint.iY += iDeltaY; 00169 00170 // Check for user requested reset 00171 if ( iAnimationReset ) 00172 { 00173 iNewPoint.iX = 1; 00174 iNewPoint.iY = 1; 00175 iDeltaX = KStepSize; 00176 iDeltaY = KStepSize; 00177 iAnimationReset = EFalse; 00178 } 00179 00180 00181 // Alternative method, works well on the MARM target, jumps on the 00182 // windows emulator, simply uncomment and recompile 00183 //iFunctions->ActivateGc(); 00184 //Redraw(); 00185 00186 // Force a draw to be performed by declaring the screen invalid 00187 iWindowFunctions->Invalidate( iScreenSize ); 00188 } 00189 } 00190 00191 // ----------------------------------------------------------------------------- 00192 // CImage::CommandReplyL() 00193 // Function to be used for nonbuffered commands. Not used in this example. 00194 // ----------------------------------------------------------------------------- 00195 // 00196 TInt CImage::CommandReplyL( TInt aOpcode, TAny* /* aArgs */ ) 00197 { 00198 return aOpcode; 00199 } 00200 00201 // ----------------------------------------------------------------------------- 00202 // CImage::Command() 00203 // Function for buffered commands and commands that cannot fail/leave. 00204 // ----------------------------------------------------------------------------- 00205 // 00206 void CImage::Command( TInt aOpcode, TAny* /* aArgs */ ) 00207 { 00208 switch ( aOpcode ) 00209 { 00210 case KAnimationReset: 00211 // Set a flag to reset the animation back to the top left 00212 iAnimationReset = ETrue; 00213 break; 00214 00215 case KResolutionChange: 00216 iAnimationReset = ETrue; 00217 iScreenSize = iWindowFunctions->WindowSize(); 00218 break; 00219 00220 default: 00221 User::Panic( KAnimation, EPanicAnimationServer ); 00222 break; 00223 } 00224 } 00225 00226 // ----------------------------------------------------------------------------- 00227 // CImage::TimedOut() 00228 // Timer control, called everytime the time times out. 00229 // ----------------------------------------------------------------------------- 00230 // 00231 void CImage::TimedOut() 00232 { 00233 // Reset the timer timeout period 00234 iServerTimer->After( KTimerPeriod ); 00235 00236 // Call the animation function for this image 00237 iFunctions->Animate( 0 ); 00238 } 00239 00240 // ----------------------------------------------------------------------------- 00241 // CImage::OfferRawEvent() 00242 // For handling raw events. Not used in this example. 00243 // ----------------------------------------------------------------------------- 00244 // 00245 TBool CImage::OfferRawEvent( const TRawEvent& /*aRawEvent*/ ) 00246 { 00247 return ETrue; 00248 } 00249 00250 // End of File
|
© Nokia 2009 |