Categories: Symbian C++ | How To | Code Examples | UI
Draw an icon on the screen from a MIF file
From Forum Nokia Wiki
Contents |
In the MMP file
// Put what ever is necessary for an applicaion. // .. LIBRARY aknicon.lib // AknIconUtils // ..
In the header file of the view (container)
#ifndef __MYAPPVIEW_H__ #define __MYAPPVIEW_H__ // INCLUDES #include <coecntrl.h> // FORWARD DECLARATION class CFbsBitmap; // CLASS DECLARATION class CMyAppView : public CCoeControl { public: // New methods /** * NewL. * Two-phased constructor. * Create a CMyAppView object, which will draw itself to aRect. * @param aRect The rectangle this view will be drawn to. * @return a pointer to the created instance of CMyAppView. */ static CMyAppView* NewL( const TRect& aRect ); /** * NewLC. * Two-phased constructor. * Create a CMyAppView object, which will draw itself * to aRect. * @param aRect Rectangle this view will be drawn to. * @return A pointer to the created instance of CMyAppView. */ static CMyAppView* NewLC( const TRect& aRect ); /** * ~CMyAppView * Virtual Destructor. */ virtual ~CMyAppView(); private: // Constructors /** * ConstructL * 2nd phase constructor. * Perform the second phase construction of a * CMyAppView object. * @param aRect The rectangle this view will be drawn to. */ void ConstructL(const TRect& aRect); /** * CMyAppView. * C++ default constructor. */ CMyAppView(); public: // Functions from base classes /** * From CCoeControl, Draw * Draw this CMyAppView to the screen. * @param aRect the rectangle of this view that needs updating */ void Draw( const TRect& aRect ) const; /** * From CoeControl, SizeChanged. * Called by framework when the view size is changed. */ void SizeChanged(); private: // Member data /** * The bitmap object. * Owned by CMyAppView */ CFbsBitmap* iMyIcon; /** * The bitmap mask object. * Owned by CMyAppView */ CFbsBitmap* iMyIconMask; } #endif // __MYAPPVIEW_H__ // End of File
In the cpp file of the view (container)
// INCLUDES #include <coemain.h> #include <eikenv.h> #include <akniconutils.h> // for AknIconUtils #include <My_Icon.mbg> #include "MyAppView.h" // IMPLEMENTATION SPECIFIC CONSTANTS // The mif file from where you would like to show the // icon on the screen. _LIT(KMyIconMif, "c:\\resource\\apps\\My_Icon.mif"); // If your image is created from an SVG then image would be // of a scalable one. In that case even if you change the // width and height the look of the image would be smooth. const TInt KMyIconMaxWidth(100); const TInt KMyIconMaxHeight(100); // ============================ MEMBER FUNCTIONS =============================== // ----------------------------------------------------------------------------- // CMyAppView::NewL() // Two-phased constructor. // ----------------------------------------------------------------------------- // CMyAppView* CMyAppView::NewL( const TRect& aRect ) { CMyAppView* self = CMyAppView::NewLC( aRect ); CleanupStack::Pop( self ); return self; } // ----------------------------------------------------------------------------- // CMyAppView::NewLC() // Two-phased constructor. // ----------------------------------------------------------------------------- // CMyAppView* CMyAppView::NewLC( const TRect& aRect ) { CMyAppView* self = new ( ELeave ) CMyAppView; CleanupStack::PushL( self ); self->ConstructL( aRect ); return self; } // ----------------------------------------------------------------------------- // CMyAppView::~CMyAppView() // Destructor. // ----------------------------------------------------------------------------- // CMyAppView::~CMyAppView() { if(iMyIconMask) { delete iMyIconMask; iMyIconMask = NULL; } if(iMyIcon) { delete iMyIcon; iMyIcon = NULL; } } // ----------------------------------------------------------------------------- // CMyAppView::ConstructL() // Symbian 2nd phase constructor can leave. // ----------------------------------------------------------------------------- // void CMyAppView::ConstructL( const TRect& aRect ) { // Create a window for this application view CreateWindowL(); // Set the windows size SetRect( aRect ); // This view is a full-screen view. SetExtentToWholeScreen(); // Create the bitmap and mask to draw. AknIconUtils::CreateIconL(iMyIcon, iMyIconMask, KMyIconMif, EMbmMy_iconMy_icon, EMbmMy_iconMy_icon_mask); // Set size for the bitmap and mask AknIconUtils::SetSize(iMyIcon, TSize(KMyIconMaxWidth, KMyIconMaxHeight)); AknIconUtils::SetSize(iMyIconMask, TSize(KMyIconMaxWidth, KMyIconMaxHeight)); // Activate the window, which makes it ready to be drawn ActivateL(); } // ----------------------------------------------------------------------------- // CMyAppView::CMyAppView() // C++ default constructor can NOT contain any code, that might leave. // ----------------------------------------------------------------------------- // CMyAppView::CMyAppView() { // No implementation required } // ----------------------------------------------------------------------------- // CMyAppView::Draw() // Draws the display. // ----------------------------------------------------------------------------- // void CMyAppView::Draw( const TRect& aRect ) const { // Get the standard graphics context CWindowGc& gc = SystemGc(); // Clears the screen gc.SetBrushColor(KRgbBlack); gc.Clear( aRect ); TPoint point = TPoint(aRect.Center().iX - (KMyIconMaxWidth/2), aRect.Center().iY - (KMyIconMaxHeight/2)); // Draw the bitmap gc.BitBltMasked(point, iMyIcon, aRect, iMyIconMask, EFalse); } // ----------------------------------------------------------------------------- // CMyAppView::SizeChanged() // Called by framework when the view size is changed. // ----------------------------------------------------------------------------- // void CMyAppView::SizeChanged() { DrawNow(); } // End of File
In the PKG file
; Normal lines for a package file ; and other files for the application "\epoc32\data\z\resource\apps\My_Icon.mif"-"c:\resource\apps\My_Icon.mif"
Related Links
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SVG and circles + phone restart | ljubex | General Symbian C++ | 4 | 2007-01-10 20:12 |
| SVG drawing to screen | kmaraczi | Graphics & Video & Streaming | 4 | 2008-05-06 17:46 |
| how to remove avkon 0 panic | mallikachand | Symbian User Interface | 1 | 2008-04-29 11:02 |
| How to show two icon one for enabled and other for disabled my application | Anurag Bansal | General Symbian C++ | 0 | 2008-08-20 13:48 |
| Recognizer + application icon | kylom | General Symbian C++ | 0 | 2007-03-21 14:18 |
