00001 /* 00002 Copyright (c) 2000-2010 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 00031 00032 #ifndef __CommonGraphicsControlFramework_H 00033 #define __CommonGraphicsControlFramework_H 00034 00035 #include <coecntrl.h> 00036 #include <s32file.h> 00037 00038 // 00039 // class MGraphicsExampleObserver 00040 // 00041 00042 class MGraphicsExampleObserver 00043 { 00044 public: 00045 virtual void NotifyGraphicExampleFinished()=0; 00046 virtual void NotifyStatus(const TDesC& aMessage)=0; 00047 }; 00048 00049 // 00050 // class CGraphicExampleControl 00051 // 00052 00053 /* 00054 Usage 00055 00056 Use this class as a base class for examples for the 00057 graphics layer. It uses CONE's facilities to provide 00058 an initailized graphics environment. 00059 00060 It creates a 600x200 window in which you can do your 00061 drawing. 00062 00063 it supports multiple phases, so you can do different drawings 00064 from one phase to another. Tap the spacebar or click the 00065 mouse (anywhere) to advance a phase. 00066 00067 Quit the program with CTRL-Q, or by advancing beyond the last 00068 phase. 00069 00070 Writing derived classes 00071 00072 A minimal derived class should have a Draw() function 00073 which puts a drawing onto the screen. 00074 00075 If you are using multiplephases, code a constructor which 00076 calls SetMaxPhases() specifying the number of phases. Have 00077 Draw() honour the phase number, available using Phase(). 00078 */ 00079 00080 #pragma warning(disable : 4100) 00081 // disable "parameter not used" warning on HandleKey() 00082 00083 class CGraphicExampleControl : public CCoeControl 00084 { 00085 public: 00086 // construct/destruct 00087 void ConstructL(const TRect& aRect, MGraphicsExampleObserver* aGraphObserver, const CCoeControl& aParent); 00088 // second-phase construction 00089 // when all initialized, calls GraphicTestEnvironmentComplete() 00090 ~CGraphicExampleControl(); 00091 // allow access by container 00092 TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType); 00093 // intercepts ctrl-Q and space; offers other keys to derived classes 00094 protected: 00095 // derived classes must provide these 00096 virtual void UpdateModelL() =0; // empty update model function 00097 virtual void Draw(const TRect& /* aRect */) const {}; // empty draw function 00098 // use Phase() in Draw() to tell what phase we're in 00099 TInt Phase() const { return iPhase; }; // get phase number 00100 void SetMaxPhases(TInt aMaxPhases) { iMaxPhases=aMaxPhases; }; 00101 // use this from derived-class constructor to set number of phases 00102 CFont* iMessageFont; // font for messages 00103 private: 00104 // functions provided for CCoeControl protocol 00105 void HandlePointerEventL(const TPointerEvent& aPointerEvent); 00106 // advances phase on pointer-down 00107 void Quit(); // does termination 00108 void NextPhaseL(); // advances phase: quits if all phases done 00109 // phase control for graphics examples 00110 TInt iPhase; // phase number 00111 TInt iMaxPhases; // maximum phases 00112 protected: 00113 MGraphicsExampleObserver* iGraphObserver; 00114 }; 00115 00116 #endif