examples/SFExamples/RockPaperScissorsGameSourceCode_S60/RPS/src/rpsAppView.cpp

00001 /*
00002 Copyright (c) 2002-2011 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  
00028 */ 
00029 
00030 // INCLUDE FILES
00031 #include <coemain.h>
00032 #include "rpsAppView.h"
00033 #include "common.hrh"
00034 #include "rpsgamescreens.h"
00035 
00036 
00037 // -----------------------------------------------------------------------------
00038 // CRpsAppView::NewL()
00039 // Two-phased constructor.
00040 // -----------------------------------------------------------------------------
00041 //
00042 CRpsAppView* CRpsAppView::NewL(MAppViewObserver& aObs, const TRect& aRect)
00043         {
00044         CRpsAppView* self = CRpsAppView::NewLC(aObs, aRect);
00045         CleanupStack::Pop( self );
00046         return self;
00047         }
00048 
00049 // -----------------------------------------------------------------------------
00050 // CRpsAppView::NewLC()
00051 // Two-phased constructor.
00052 // -----------------------------------------------------------------------------
00053 //
00054 CRpsAppView* CRpsAppView::NewLC(MAppViewObserver& aObs, const TRect& aRect)
00055         {
00056         CRpsAppView* self = new ( ELeave ) CRpsAppView(aObs);
00057         CleanupStack::PushL( self );
00058         self->ConstructL(aRect);
00059         return self;
00060         }
00061 
00062 // -----------------------------------------------------------------------------
00063 // CRpsAppView::ConstructL()
00064 // Symbian 2nd phase constructor can leave.
00065 // -----------------------------------------------------------------------------
00066 //
00067 void CRpsAppView::ConstructL( const TRect& aRect )
00068         {
00069         // Create a window for this application view
00070         CreateWindowL();
00071 
00072         SetRect( aRect );
00073         
00074         // Activate the window, which makes it ready to be drawn and starts the heartbeat
00075         ActivateL();
00076         }
00077 
00078 
00079 // -----------------------------------------------------------------------------
00080 // CRpsAppView::CRpsAppView()
00081 // C++ default constructor can NOT contain any code, that might leave.
00082 // -----------------------------------------------------------------------------
00083 //
00084 CRpsAppView::CRpsAppView(MAppViewObserver& aObs): iObs(aObs)
00085         {
00086         // No implementation required
00087         }
00088 
00089 
00090 // -----------------------------------------------------------------------------
00091 // CRpsAppView::~CRpsAppView()
00092 // Destructor.
00093 // -----------------------------------------------------------------------------
00094 CRpsAppView::~CRpsAppView()
00095         {
00096         }
00097 
00098 // -----------------------------------------------------------------------------
00099 // CRpsAppView::SizeChanged()
00100 // Called by framework when the view size is changed.
00101 // -----------------------------------------------------------------------------
00102 //
00103 void CRpsAppView::SizeChanged()
00104         {  
00105         TRect rect(Rect());
00106         gScreenWidth = rect.Width();
00107         gScreenHeight = rect.Height();
00108         
00109         DrawNow();
00110         }
00111 
00112 // --------------------------------------------------------------------------
00113 // FocusChanged
00114 // --------------------------------------------------------------------------
00115 void CRpsAppView::FocusChanged(TDrawNow aDrawNow)
00116         {
00117         iObs.FocusChanged(IsFocused());
00118         
00119         if(aDrawNow)
00120                 DrawNow();
00121         }
00122 
00123 
00124 TKeyResponse CRpsAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
00125         {
00126         TKeyResponse response = EKeyWasConsumed;
00127         TUint input = 0x00000000;
00128 
00129         switch (aKeyEvent.iScanCode)
00130                 {
00131                 case EStdKeyUpArrow:    
00132                         input = KControllerUp;
00133                         break;
00134                 case EStdKeyDownArrow: 
00135                         input = KControllerDown;
00136                         break;
00137                 case EStdKeyDevice3:  
00138                         input = KControllerCentre;
00139                         break;
00140                 case '5': 
00141                         input = KKey5;
00142                         break;
00143                 default:
00144                         response = EKeyWasNotConsumed;// Keypress was not handled
00145                         break;
00146                 }
00147         
00148         if (EEventKeyDown == aType)
00149                 {
00150                 iKeyState |= input; // set bitmask
00151                 }
00152         else if (EEventKeyUp == aType)
00153                 {
00154                 iKeyState &= ~input; // clear bitmask
00155                 }
00156         
00157         iObs.KeyEvent(iKeyState);
00158         
00159     return (response);
00160         }
00161 
00162 // -----------------------------------------------------------------------------
00163 // CRpsAppView::Draw()
00164 // Draws the display.
00165 // -----------------------------------------------------------------------------
00166 void CRpsAppView::Draw( const TRect& /*aRect*/ ) const
00167         {
00168         // Get the standard graphics context
00169         CWindowGc& gc = SystemGc();
00170         gc.Clear( Rect() );
00171         
00172         iObs.DrawGameScreen();
00173         }
00174 
00175 
00176 // End of File

Generated by  doxygen 1.6.2