|
||
BitmapsShell
: dealing with bitmaps
Note: This example is designed to work with TechView and there is no guarantee that it will work with other interfaces.
The source code for this example application can be found in the directory:
examples\Graphics\Bitmaps
The files reproduced here are the main files contained in the examples directory. Some extra files may be needed to run the examples, and these will be found in the appropriate examples directory.
// BitmapsGraphicsControl.h
//
// Copyright (c) 2000 Symbian Ltd. All rights reserved.
#ifndef __BitmapsGraphicsControl_H
#define __BitmapsGraphicsControl_H
#include <coecntrl.h>
#include <s32file.h>
#include "CommonGraphicsControlFramework.h"
class CBitmapControl : public CGraphicExampleControl
{
public:
CBitmapControl() { SetMaxPhases(8); };
~CBitmapControl() { delete(iBitmap); delete(iMaskBitmap); };
void UpdateModelL();
void Draw(const TRect& aRect) const;
private:
void LoadBitmapL(CFbsBitmap* aBitMap,const TDesC& aPathAndFile,TInt aId,TBool aShareIfLoaded);
private:
CFbsBitmap* iBitmap;
CFbsBitmap* iMaskBitmap;
};
class CFbsControl : public CGraphicExampleControl
{
public:
CFbsControl() { SetMaxPhases(10); };
~CFbsControl();
void UpdateModelL();
void Draw(const TRect& aRect) const;
private:
void DrawL(CWindowGc& aGc);
void DrawSmiley(CGraphicsContext& aGc);
void CreateRotatedBitmap();
void DrawSingleBitmap(CFbsBitmap* aDrawBitmap,CWindowGc& aGc) const;
void DrawTwoBitmaps(CFbsBitmap* aBitmap1,CFbsBitmap* aBitmap2,CWindowGc& aGc) const;
void LoadBitmapL(CFbsBitmap* aBitMap,const TDesC& aPathAndFile,TInt aId,TBool aShareIfLoaded);
CFbsBitmap* iBitmap1;
CFbsBitmap* iBitmap2;
CFbsBitmap* iBitmap3;
CFbsBitmap* iBitmap4;
};
#endif
// BitmapsGraphicsShell.h
//
// Copyright (c) 2000 Symbian Ltd. All rights reserved.
#ifndef __BitmapsGraphicsShell_H
#define __BitmapsGraphicsShell_H
#include <coecntrl.h>
#include <coeccntx.h>
#include <eikappui.h>
#include <eikapp.h>
#include <eikdoc.h>
#include "BitmapsGraphicsControl.h"
// UID of app
const TUid KUidExampleShellApp={ 0x1000525B };
//
// TExampleShellModel
//
class TExampleShellModel
{
public:
TExampleShellModel();
TBool Differs(const TExampleShellModel* aCompare) const;
public:
TFileName iLibrary; // active control
};
//
// class CExampleShellContainer
//
class CExampleShellContainer : public CCoeControl,
public MCoeControlBrushContext,
public MGraphicsExampleObserver
{
public:
void ConstructL(const TRect& aRect, TExampleShellModel* aModel);
~CExampleShellContainer();
// changing view
void ResetExampleL(CGraphicExampleControl* aExample);
private: // from CCoeControl
void Draw(const TRect& /*aRect*/) const;
TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
TInt CountComponentControls() const;
CCoeControl* ComponentControl(TInt aIndex) const;
private: // from MGraphicsExampleObserver
void NotifyGraphicExampleFinished();
public: // also from MGraphicsExampleObserver
void NotifyStatus(const TDesC& aMessage);
private: // new function
void CreateLabelL();
private: // data
CGraphicExampleControl* iExampleControl; // example control
CEikLabel* iLabel; // label for status messages
// irrelevant
TExampleShellModel* iModel;
};
//
// CExampleShellDocument
//
class CExampleShellDocument : public CEikDocument
{
public:
CExampleShellDocument(CEikApplication& aApp): CEikDocument(aApp) { }
TExampleShellModel* Model() { return(&iModel); }
private: // from CEikDocument
CEikAppUi* CreateAppUiL();
private:
TExampleShellModel iModel;
};
//
// CExampleShellAppUi
//
class CExampleShellAppUi : public CEikAppUi
{
public:
void ConstructL();
~CExampleShellAppUi();
private: // from CEikAppUi
void HandleCommandL(TInt aCommand);
private: // internal use
// void PrepareToolbarButtons();
private:
CExampleShellContainer* iContainer;
TExampleShellModel* iModel;
};
//
// CExampleShellApplication
//
class CExampleShellApplication : public CEikApplication
{
private: // from CApaApplication
CApaDocument* CreateDocumentL();
TUid AppDllUid() const;
};
#endif
// Bitmap.cpp
//
// Copyright (c) 2000-2005 Symbian Software Ltd. All rights reserved.
#include "BitmapsGraphicsControl.h"
#include <grbmap.mbg>
_LIT(KTxtZDrive,"Z:");
void CBitmapControl::LoadBitmapL(CFbsBitmap* aBitMap,const TDesC& aPathAndFile,TInt aId,TBool aShareIfLoaded)
{
TParse mbfn;
TDriveUnit sysDrive (RFs::GetSystemDrive());
TDriveName sysDriveName (sysDrive.Name());
TFileName fileName(sysDriveName);
fileName.Append(aPathAndFile);
mbfn.Set(aPathAndFile,&fileName,NULL);
if (!aBitMap->Load(mbfn.FullName(),aId,aShareIfLoaded))
return;
mbfn.Set(aPathAndFile,&KTxtZDrive,NULL);
User::LeaveIfError(aBitMap->Load(mbfn.FullName(),aId,aShareIfLoaded));
return;
}
// Text printed to the console
_LIT(KTxtCase0,"draw bitmap, centered on screen using block transfer");
_LIT(KTxtCase1,"draw piece of bitmap using block transfer");
_LIT(KTxtCase2,"draw bitmap described in twips using DrawBitmap()");
_LIT(KTxtCase3,"draw stretched bitmap");
_LIT(KTxtCase4,"tile rectangle, using bitmap as the brush pattern");
_LIT(KTxtCase5,"tile rectangle, tiling around center of screen");
_LIT(KTxtCase6,"masks: the problem of drawing a bitmap on different backgrounds");
_LIT(KTxtCase7,"masks: using a mask to give a bitmap a transparent background");
// The name of the multi-bitmap file containing the bitmap
// and bitmap mask files.
_LIT(KTxtMBMname,"\\resource\\apps\\grbmap.mbm");
void CBitmapControl::UpdateModelL()
{
// set up name for bitmap sharing
TBool shareIfLoaded(ETrue);
switch (Phase())
{
case 0:
// load the bitmap and mask bitmap
iBitmap = new (ELeave) CFbsBitmap();
LoadBitmapL(iBitmap,KTxtMBMname,EMbmGrbmapSmiley,shareIfLoaded);
iMaskBitmap = new (ELeave) CFbsBitmap();
LoadBitmapL(iMaskBitmap,KTxtMBMname,EMbmGrbmapSmilmask,shareIfLoaded);
iGraphObserver->NotifyStatus(KTxtCase0);
break;
case 1:
iGraphObserver->NotifyStatus(KTxtCase1);
break;
case 2:
iGraphObserver->NotifyStatus(KTxtCase2);
break;
case 3:
iGraphObserver->NotifyStatus(KTxtCase3);
break;
case 4:
iGraphObserver->NotifyStatus(KTxtCase4);
break;
case 5:
iGraphObserver->NotifyStatus(KTxtCase5);
break;
case 6:
iGraphObserver->NotifyStatus(KTxtCase6);
break;
case 7:
iGraphObserver->NotifyStatus(KTxtCase7);
break;
}
}
void CBitmapControl::Draw(const TRect& /* aRect */) const
{
// draw surrounding rectangle
CWindowGc& gc=SystemGc(); // graphics context we draw to
gc.UseFont(iMessageFont); // use the system message font
gc.Clear(); // clear the area to be drawn to
SystemGc().DrawRect(Rect()); // surrounding rectangle to draw into
TRect rect=Rect(); // a centered rectangle of the default size
TRect bmpPieceRect=Rect(); // a rectangle to define a piece of bitmap
TInt xDelta=0; // for x coordinates
TInt yDelta=0; // for y coordinates
TPoint screenCenterPoint=rect.Center(); // the center of the screen
// decide what to do, and do it
switch (Phase())
{
case 0:
// draw a whole bitmap centered on the screen,
// using bitmap block transfer
{
// calculate position for top left of bitmap so it is centered
TSize bmpSizeInPixels=iBitmap->SizeInPixels();
xDelta=(rect.Width()-bmpSizeInPixels.iWidth)/2;
yDelta=(rect.Height()-bmpSizeInPixels.iHeight)/2;
TPoint pos=TPoint(xDelta,yDelta); // displacement vector
pos+=rect.iTl; // bitmap top left corner position
gc.BitBlt(pos, iBitmap); // CWindowGc member function
}
break;
case 1:
// draw a rectangular piece of a bitmap, centered on the screen,
// using bitmap block transfer
{
// calculate bitmap piece, half size from center of source bitmap
TSize bmpSizeInPixels=iBitmap->SizeInPixels();
TSize bmpPieceSize(bmpSizeInPixels.iWidth*2/3,bmpSizeInPixels.iHeight*2/3);
TPoint bmpPieceTopLeft(0,0);
bmpPieceRect.SetRect(bmpPieceTopLeft,bmpPieceSize);
// calculate position for top left of bitmap piece so it is centered
xDelta=(rect.Width()-bmpPieceRect.Width())/2;
yDelta=(rect.Height()-bmpPieceRect.Height())/2;
TPoint pos=TPoint(xDelta,yDelta); // displacement vector
pos+=rect.iTl; // bitmap piece top left corner position
gc.BitBlt(pos, iBitmap, bmpPieceRect); // using bitmap piece
}
break;
case 2:
// draw a bitmap to a defined size in twips
// in the top left corner the rectangle,
// using the GDI DrawBitmap() function
{
TSize bmpSizeInTwips(600,600); // must set twips size, default (0,0)
iBitmap->SetSizeInTwips(bmpSizeInTwips);
gc.DrawBitmap(rect.iTl, iBitmap);
}
break;
case 3:
// draw a stretched bitmap inside the rectangle,
// using the GDI DrawBitmap() function
{
gc.DrawBitmap(rect, iBitmap);
}
break;
case 4:
{
// use bitmap as brush pattern, tiling from top left of rectangle
// set brush pattern and style to use the bitmap
gc.UseBrushPattern(iBitmap);
gc.SetBrushStyle(CGraphicsContext::EPatternedBrush);
gc.DrawRect(rect);
gc.DiscardBrushPattern();
}
break;
case 5:
{
// use bitmap as brush pattern, tiling around center of screen
// set brush pattern and style to use the bitmap
gc.SetBrushOrigin(screenCenterPoint);
gc.UseBrushPattern(iBitmap);
gc.SetBrushStyle(CGraphicsContext::EPatternedBrush);
gc.DrawRect(rect);
gc.DiscardBrushPattern();
}
break;
case 6:
// bisect screen into two different coloured rects
{
TRect screenRect=Rect();
TInt bisect = (screenRect.iBr.iX-screenRect.iTl.iX)/2 + screenRect.iTl.iX;
TRect leftRect(screenRect.iTl,TPoint(bisect,screenRect.iBr.iY));
TRect rightRect(TPoint(bisect,screenRect.iTl.iY),screenRect.iBr);
TRgb darkGray(85,85,85);
gc.SetBrushColor(darkGray);
gc.Clear(leftRect);
TRgb black(0,0,0);
gc.SetBrushColor(black);
gc.Clear(rightRect);
TSize bmpSizeInPixels=iBitmap->SizeInPixels();
TSize bmpPieceSize(bmpSizeInPixels.iWidth,bmpSizeInPixels.iHeight);
TPoint bmpPieceTopLeft(0,0);
bmpPieceRect.SetRect(bmpPieceTopLeft,bmpPieceSize);
// center bitmap on left
xDelta=(leftRect.Width()-bmpPieceRect.Width())/2;
yDelta=(leftRect.Height()-bmpPieceRect.Height())/2;
TPoint pos=TPoint(xDelta,yDelta); // displacement vector
pos += leftRect.iTl; // bitmap piece top left corner position
gc.BitBlt(pos,iBitmap);
// center bitmap on right
xDelta=(rightRect.Width()-bmpPieceRect.Width())/2;
yDelta=(rightRect.Height()-bmpPieceRect.Height())/2;
TPoint pos2=TPoint(xDelta,yDelta); // displacement vector
pos2 += rightRect.iTl; // bitmap piece top left corner position
gc.BitBlt(pos2,iBitmap);
}
break;
case 7:
// bisect screen into two different coloured rects
{
TRect screenRect=Rect();
TInt bisect = (screenRect.iBr.iX-screenRect.iTl.iX)/2 + screenRect.iTl.iX;
TRect leftRect(TPoint(screenRect.iTl.iX,screenRect.iTl.iY+50),TPoint(bisect,screenRect.iBr.iY));
TRect rightRect(TPoint(bisect,screenRect.iTl.iY+50),screenRect.iBr);
TRgb darkGray(85,85,85);
gc.SetBrushColor(darkGray);
gc.Clear(leftRect);
TRgb black(0,0,0);
gc.SetBrushColor(black);
gc.Clear(rightRect);
TSize bmpSizeInPixels=iBitmap->SizeInPixels();
TSize bmpPieceSize(bmpSizeInPixels.iWidth,bmpSizeInPixels.iHeight);
TPoint bmpPieceTopLeft(0,0);
bmpPieceRect.SetRect(bmpPieceTopLeft,bmpPieceSize);
// center bitmap on left
xDelta=(leftRect.Width()-bmpPieceRect.Width())/2;
yDelta=(leftRect.Height()-bmpPieceRect.Height())/2;
TPoint pos=TPoint(xDelta,yDelta); // displacement vector
pos += leftRect.iTl; // bitmap piece top left corner position
gc.BitBltMasked(pos,iBitmap,bmpPieceRect,iMaskBitmap,EFalse); // CWindowGc member function
// center bitmap on right
xDelta=(rightRect.Width()-bmpPieceRect.Width())/2;
yDelta=(rightRect.Height()-bmpPieceRect.Height())/2;
TPoint pos2=TPoint(xDelta,yDelta); // displacement vector
pos2 += rightRect.iTl; // bitmap piece top left corner position
gc.BitBltMasked(pos2,iBitmap,bmpPieceRect,iMaskBitmap,EFalse); // CWindowGc member function
_LIT(KTxtTheBitmap,"The bitmap:");
_LIT(KTxtBitmapMask,"The bitmap's mask:");
gc.DrawText(KTxtTheBitmap,TPoint(5,20));
gc.BitBlt(TPoint(130,0),iBitmap);
gc.DrawText(KTxtBitmapMask,TPoint(197,20));
gc.BitBlt(TPoint(400,0),iMaskBitmap);
}
break;
default:
break;
}
}
// BitmapsGraphicsControl.cpp
//
// Copyright (c) 2000 Symbian Ltd. All rights reserved.
#include "BitmapsGraphicsControl.h"
#include <coemain.h>
#include <coeaui.h>
_LIT(KtxtSwiss,"Swiss");
void CGraphicExampleControl::ConstructL(const TRect& aRect, MGraphicsExampleObserver* aGraphObserver, const CCoeControl& aParent)
{
// remember the graphics observer
iGraphObserver=aGraphObserver;
// create window
CreateWindowL(&aParent);
// construct font for messages
TFontSpec spec(KtxtSwiss,213);
iMessageFont=iCoeEnv->CreateScreenFontL(spec);
// set rectangle to prescription
SetRect(aRect);
// go for it
ActivateL();
UpdateModelL(); // phase 0
}
CGraphicExampleControl::~CGraphicExampleControl()
{
iCoeEnv->ReleaseScreenFont(iMessageFont);
}
void CGraphicExampleControl::Quit()
{
iGraphObserver->NotifyGraphicExampleFinished();
}
void CGraphicExampleControl::NextPhaseL()
{
if (++iPhase >= iMaxPhases)
Quit();
else
{
UpdateModelL();
DrawNow();
}
}
void CGraphicExampleControl::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
if (aPointerEvent.iType==TPointerEvent::EButton1Down) NextPhaseL();
}
TKeyResponse CGraphicExampleControl::OfferKeyEventL(
const TKeyEvent& aKeyEvent,TEventCode aType
)
{
if (aType!=EEventKey) return EKeyWasNotConsumed;
TInt code=aKeyEvent.iCode;
switch (code)
{
case ' ':
NextPhaseL();
break;
default:
return EKeyWasNotConsumed;
}
return EKeyWasConsumed;
}
// FontBitmapServer.cpp
//
// Copyright (c) 2000-2005 Symbian Software Ltd. All rights reserved.
#include "BitmapsGraphicsControl.h"
// header for multi-bitmap file grbitmap.mbm containing 2 bitmaps to use
#include <grbmap.mbg>
// The name of the multi-bitmap file containing the bitmap
// and bitmap mask files.
_LIT(KTxtMBMname,"\\resource\\apps\\grbmap.mbm");
CFbsControl::~CFbsControl()
{
// as the user can exit the example at any phase
// delete any member data that may cause a memory leak
if (Phase()==1 || Phase()==7 || Phase()==8) delete(iBitmap1);
if (Phase()==3 || Phase()==4) delete(iBitmap2);
if (Phase()==4 || Phase()==5) delete(iBitmap3);
if (Phase()==8) delete(iBitmap4);
}
// Text printed to the console
_LIT(KTxtUpdateModelCase0,"Load, draw and delete bitmap");
_LIT(KTxtUpdateModelCase1,"Load and draw bitmap");
_LIT(KTxtUpdateModelCase2,"Delete bitmap");
_LIT(KTxtUpdateModelCase3,"Create bitmap2 and draw");
_LIT(KTxtUpdateModelCase4,"Duplicate bitmap 2 as bitmap 3 and draw both");
_LIT(KTxtUpdateModelCase5,"Delete bitmap 2, draw bitmap 3");
_LIT(KTxtUpdateModelCase6,"Delete bitmap 3");
_LIT(KTxtUpdateModelCase7,"Reload and draw bitmap1");
_LIT(KTxtUpdateModelCase8,"Make bitmap 4 as transposed bitmap 1 and draw both");
_LIT(KTxtUpdateModelCase9,"Delete bitmaps 1 and 4");
void CFbsControl::UpdateModelL()
{
// set up name for bitmap sharing
TBool shareIfLoaded(ETrue);
// device and context for drawing to the in-memory bitmap
CFbsBitmapDevice* iBitmapDevice2;
CGraphicsContext* iBitmapContext2;
switch (Phase())
{
case 0:
// NB. in this phase, loading of the bitmap occurs in Draw()
iGraphObserver->NotifyStatus(KTxtUpdateModelCase0);
break;
case 1:
// load bitmap1 from .mbm file
iBitmap1 = new (ELeave) CFbsBitmap();
LoadBitmapL(iBitmap1,KTxtMBMname,EMbmGrbmapSmiley,shareIfLoaded);
iGraphObserver->NotifyStatus(KTxtUpdateModelCase1);
break;
case 2:
// delete bitmap1
delete iBitmap1;
iGraphObserver->NotifyStatus(KTxtUpdateModelCase2);
break;
case 3:
// create bitmap 2
iBitmap2 = new (ELeave) CFbsBitmap();
iBitmap2->Create(TSize(100,100),EGray4);
// create a device and gc for it
iBitmapDevice2 = CFbsBitmapDevice::NewL(iBitmap2);
iBitmapDevice2->CreateContext(iBitmapContext2);
// draw to it
DrawSmiley(*iBitmapContext2);
// delete the context and device for bitmap 2
delete iBitmapContext2;
delete iBitmapDevice2;
// and blit it (in the Draw() function)
iGraphObserver->NotifyStatus(KTxtUpdateModelCase3);
break;
case 4:
// create bitmap 3 as a duplicate of bitmap 2
iBitmap3 = new (ELeave) CFbsBitmap();
iBitmap3->Duplicate(iBitmap2->Handle());
iGraphObserver->NotifyStatus(KTxtUpdateModelCase4);
break;
case 5:
// delete bitmap 2
delete iBitmap2;
iGraphObserver->NotifyStatus(KTxtUpdateModelCase5);
break;
case 6:
// delete bitmap 3
delete iBitmap3;
iGraphObserver->NotifyStatus(KTxtUpdateModelCase6);
break;
case 7:
// reload bitmap 1 from .mbm file
iBitmap1 = new (ELeave) CFbsBitmap();
LoadBitmapL(iBitmap1,KTxtMBMname,EMbmGrbmapSmiley,shareIfLoaded);
iGraphObserver->NotifyStatus(KTxtUpdateModelCase7);
break;
case 8:
// create bitmap 4 as rotated bitmap 1
CreateRotatedBitmapL();
iGraphObserver->NotifyStatus(KTxtUpdateModelCase8);
break;
case 9:
// delete remaing bitmaps (1 and 4)
delete iBitmap1;
delete iBitmap4;
iGraphObserver->NotifyStatus(KTxtUpdateModelCase9);
}
}
void CFbsControl::Draw(const TRect& /* aRect */) const
{
// draw surrounding rectangle
CWindowGc& gc=SystemGc(); // graphics context we draw to
gc.UseFont(iMessageFont); // use the system message font
gc.Clear(); // clear the area to be drawn to
TRect rect=Rect(); // a centered rectangle of the default size
gc.DrawRect(rect); // surrounding rectangle to draw into
TRgb darkGray(85,85,85);
// decide what to do, and do it
switch (Phase())
{
case 0:
{
// perform (leavable) draw function
TRAP_IGNORE(MUTABLE_CAST(CFbsControl*,this)->DrawL(gc));
}
break;
case 1:
// draw bitmap, centered on the screen,
// using bitmap block transfer
{
DrawSingleBitmap(iBitmap1,gc);
}
break;
case 2:
{
// no bitmaps are loaded so draw gray screen
gc.SetBrushColor(darkGray);
gc.Clear(rect);
}
break;
case 3:
// draw bitmap2
{
DrawSingleBitmap(iBitmap2,gc);
}
break;
case 4:
// draw bitmap 2 and bitmap3
{
DrawTwoBitmaps(iBitmap2,iBitmap3,gc);
}
break;
case 5:
// draw bitmap3
{
DrawSingleBitmap(iBitmap3,gc);
}
break;
case 6:
{
// no bitmaps are loaded so draw gray screen
gc.SetBrushColor(darkGray);
gc.Clear(rect);
}
break;
case 7:
{
DrawSingleBitmap(iBitmap1,gc);
}
break;
case 8:
// draw bitmap and bitmap4
{
DrawTwoBitmaps(iBitmap1,iBitmap4,gc);
}
break;
case 9:
{
// no bitmaps are loaded so draw gray screen
gc.SetBrushColor(darkGray);
gc.Clear(rect);
}
break;
default:
break;
}
}
_LIT(KTxtZDrive,"Z:");
void CFbsControl::LoadBitmapL(CFbsBitmap* aBitMap,const TDesC& aPathAndFile,TInt aId,TBool aShareIfLoaded)
{
TParse mbfn;
TDriveUnit sysDrive (RFs::GetSystemDrive());
TDriveName sysDriveName (sysDrive.Name());
TFileName fileName(sysDriveName);
fileName.Append(aPathAndFile);
mbfn.Set(aPathAndFile,&fileName,NULL);
if (!aBitMap->Load(mbfn.FullName(),aId,aShareIfLoaded))
return;
mbfn.Set(aPathAndFile,&KTxtZDrive,NULL);
User::LeaveIfError(aBitMap->Load(mbfn.FullName(),aId,aShareIfLoaded));
return;
}
void CFbsControl::DrawL(CWindowGc& aGc)
// draw a whole bitmap centered on the screen,
// using bitmap block transfer
{
// set up name for bitmap sharing
TBool shareIfLoaded(ETrue);
// load the bitmap and mask bitmap
iBitmap1 = new (ELeave) CFbsBitmap();
// Load the bitmap
LoadBitmapL(iBitmap1,KTxtMBMname,EMbmGrbmapSmiley,shareIfLoaded);
// calculate position for top left of bitmap so it is centered
DrawSingleBitmap(iBitmap1,aGc);
// delete bitmap from memory
delete(iBitmap1);
}
void CFbsControl::DrawSmiley(CGraphicsContext& aGc)
{
// setup pens for drawing smiley
TSize penSizeBold(3,3);
TSize penSizeFat(5,5);
aGc.SetPenSize(penSizeFat);
// setup sizes/offsets for the face
TInt leftOffset = 22;
TInt rightOffset = 38;
TInt circleSize = 50;
TInt shrinkSize = 10;
// draw eyes and outline of face (circle)
TPoint leftEye(leftOffset,21);
TPoint rightEye(rightOffset,21);
aGc.Plot(leftEye);
aGc.Plot(rightEye);
aGc.SetPenSize(penSizeBold);
TRect circle(TPoint(10,10),TPoint(circleSize,circleSize));
aGc.DrawEllipse(circle);
// draw the smile
TRect smile = circle;
smile.Shrink(shrinkSize,shrinkSize);
aGc.DrawArc(smile,TPoint(10,circleSize-shrinkSize),TPoint(circleSize,circleSize-shrinkSize));
}
void CFbsControl::CreateRotatedBitmapL()
{
// create iBitmap4 as the same size as iBitmap, but with the height and width swapped
iBitmap4 = new (ELeave) CFbsBitmap();
TSize inSize = iBitmap1->SizeInPixels();
iBitmap4->Create(TSize(inSize.iHeight,inSize.iWidth),iBitmap1->DisplayMode());
// create the bitmap utils
TBitmapUtil* iBitmap1Util = new (ELeave) TBitmapUtil(iBitmap1);
TBitmapUtil* iBitmap4Util = new (ELeave) TBitmapUtil(iBitmap4);
iBitmap1Util->Begin(TPoint(0,0)); // lock the stack and perform a SetPos(TPoint(0,0)) on iBitmap1Util
iBitmap4Util->Begin(TPoint(0,0),*iBitmap1Util); // perform a SetPos(TPoint(0,0)) on iBitmap4Util, but does not lock the stack again
// set the bits of iBitmap4 as iBitmap1, rotated through 90 degrees
TInt xPos;
for (TInt yPos=0;yPos<inSize.iHeight;yPos++)
{
iBitmap1Util->SetPos(TPoint(0,yPos));
iBitmap4Util->SetPos(TPoint(yPos,0));
for (xPos=0;xPos<inSize.iWidth;xPos++)
{
iBitmap4Util->SetPixel(*iBitmap1Util);
iBitmap1Util->IncXPos();
iBitmap4Util->IncYPos();
}
}
// each Begin() must have a corresponding End()
iBitmap1Util->End();
iBitmap4Util->End();
// delete the bitmap utils
delete iBitmap1Util;
delete iBitmap4Util;
}
void CFbsControl::DrawSingleBitmap(CFbsBitmap* aDrawBitmap,CWindowGc& aGc) const
{
// calculate position for top left of bitmap so it is centered
TSize bmpSizeInPixels=aDrawBitmap->SizeInPixels();
TRect rect=Rect(); // a centered rectangle of the default size
TInt xDelta=(rect.Width()-bmpSizeInPixels.iWidth)/2;
TInt yDelta=(rect.Height()-bmpSizeInPixels.iHeight)/2;
TPoint pos=TPoint(xDelta,yDelta); // displacement vector
pos+=rect.iTl; // bitmap top left corner position
aGc.BitBlt(pos, aDrawBitmap); // CWindowGc member function
}
void CFbsControl::DrawTwoBitmaps(CFbsBitmap* aBitmap1,CFbsBitmap* aBitmap2,CWindowGc& aGc) const
{
// calculate position for top left of bitmap so it is centered
TSize bmpSizeInPixels=aBitmap1->SizeInPixels();
TRect rect=Rect(); // a centered rectangle of the default size
TInt xDelta=(rect.Width()-bmpSizeInPixels.iWidth)/4;
TInt yDelta=(rect.Height()-bmpSizeInPixels.iHeight)/4;
TPoint pos=TPoint(xDelta,yDelta); // displacement vector
TPoint pos2=TPoint(xDelta*3,yDelta);
pos+=rect.iTl; // bitmap top left corner position
pos2+=rect.iTl;
aGc.BitBlt(pos, aBitmap1); // CWindowGc member function
aGc.BitBlt(pos2, aBitmap2);
}
// BitmapsGraphicsShell.cpp
//
// Copyright (c) 2000-2005 Symbian Software Ltd. All rights reserved.
#include <e32keys.h>
#include <coemain.h>
#include <eikenv.h>
#include <eikdef.h>
#include <eikon.hrh>
#include <eiklabel.h>
#include <eikstart.h>
#include <BitmapsShell.rsg>
#include "BitmapsShell.hrh"
#include "BitmapsShell.h"
//
// TExampleShellModel
//
TExampleShellModel::TExampleShellModel()
{
iLibrary=KNullDesC;
}
TBool TExampleShellModel::Differs(const TExampleShellModel* aCompare) const
{
return((*(TInt32*)this)!=(*(TInt32*)aCompare));
}
//
// class CExampleShellContainer
//
void CExampleShellContainer::ConstructL(const TRect& aRect, TExampleShellModel* aModel)
{
iModel=aModel;
CreateWindowL();
Window().SetShadowDisabled(ETrue);
iContext=this;
iBrushStyle=CGraphicsContext::ESolidBrush;
iBrushColor=KRgbWhite;
SetRect(aRect);
CreateLabelL();
ActivateL();
}
CExampleShellContainer::~CExampleShellContainer()
{
delete iExampleControl;
delete iLabel;
}
TInt CExampleShellContainer::CountComponentControls() const
{
return 1 + (iExampleControl ? 1 : 0);
}
CCoeControl* CExampleShellContainer::ComponentControl(TInt aIndex) const
{
switch (aIndex)
{
case 0: return iLabel;
case 1: return iExampleControl;
default: return 0;
};
}
const TInt KLabelHeight=20;
void CExampleShellContainer::CreateLabelL()
{
iLabel=new (ELeave) CEikLabel;
TRect rect=Rect();
rect.iTl.iY=rect.iBr.iY-KLabelHeight; // make it bottom 20 pixels
iLabel->SetContainerWindowL(*this);
iLabel->SetRect(rect);
iLabel->SetAlignment(EHCenterVCenter); // center text
iLabel->SetBufferReserveLengthL(200); // nice long buffer
iLabel->SetFont(iEikonEnv->AnnotationFont());
iLabel->ActivateL(); // now ready
}
void CExampleShellContainer::ResetExampleL(CGraphicExampleControl* aExample)
{
// get rid of old control
delete iExampleControl;
// set up new one
iExampleControl=aExample;
// if non-zero, then carry on
if (!iExampleControl) return;
TRect rect=Rect(); // get our rect
rect.iBr.iY-=KLabelHeight; // make way for label
rect.Shrink(2,2); // shrink it a bit
iExampleControl->ConstructL(rect,this,*this); // construct, giving rect and observer
}
_LIT(KTxtFinished,"example finished");
void CExampleShellContainer::NotifyGraphicExampleFinished()
{
NotifyStatus(KTxtFinished);
}
void CExampleShellContainer::NotifyStatus(const TDesC& aMessage)
{
iLabel->SetTextL(aMessage);
if (IsActivated()) iLabel->DrawNow();
}
TKeyResponse CExampleShellContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
if (iExampleControl)
return iExampleControl->OfferKeyEventL(aKeyEvent,aType);
else
return EKeyWasNotConsumed;
}
void CExampleShellContainer::Draw(const TRect& /*aRect*/) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(Rect());
}
//
// CExampleShellAppUi
//
_LIT(KTxtInitialized,"initialized");
void CExampleShellAppUi::ConstructL()
{
BaseConstructL();
iModel=((CExampleShellDocument*)iDocument)->Model();
iContainer=new(ELeave) CExampleShellContainer;
iContainer->ConstructL(ClientRect(),iModel);
iContainer->NotifyStatus(KTxtInitialized);
// add container to stack; enables key event handling.
AddToStackL(iContainer);
}
void CExampleShellAppUi::HandleCommandL(TInt aCommand)
{
switch (aCommand)
{
case EExampleShellSelectBitmap:
iContainer->ResetExampleL(new (ELeave) CBitmapControl);
return;
case EExampleShellSelectFbs:
iContainer->ResetExampleL(new (ELeave) CFbsControl);
return;
case EEikCmdExit:
Exit();
return;
}
}
CExampleShellAppUi::~CExampleShellAppUi()
{
RemoveFromStack(iContainer);
delete iContainer;
}
//
// CExampleShellDocument
//
CEikAppUi* CExampleShellDocument::CreateAppUiL()
{
return(new(ELeave) CExampleShellAppUi);
}
//
// CExampleShellApplication
//
TUid CExampleShellApplication::AppDllUid() const
{
return KUidExampleShellApp;
}
CApaDocument* CExampleShellApplication::CreateDocumentL()
{
return new(ELeave) CExampleShellDocument(*this);
}
//
// EXPORTed functions
//
EXPORT_C CApaApplication* NewApplication()
{
return new CExampleShellApplication;
}
GLDEF_C TInt E32Main()
{
return EikStart::RunApplication(NewApplication);
}
// BitmapsShell.hrh
//
// Copyright (c) 2000 Symbian Ltd. All rights reserved.
enum TExampleMenuCommands
{
EExampleShellSelectBitmap=100,
EExampleShellSelectFbs=101
};
// BLD.INF
// Component description file
//
// Copyright (c) 2000 Symbian Ltd. All rights reserved.
PRJ_MMPFILES
BitmapsShell.mmp
// BitmapsShell.mmp
//
// Copyright (c) 2000-2005 Symbian Software Ltd. All rights reserved.
// using relative paths for source and userinclude directories
TARGET BitmapsShell.exe
TARGETTYPE exe
UID 0x100039ce 0x1000525B
VENDORID 0x70000001
SOURCEPATH .
SOURCE Bitmap.cpp BitmapsShell.cpp FontBitmapServer.cpp
SOURCE BitmapsGraphicsControl.cpp
START RESOURCE BitmapsShell.rss
TARGETPATH \resource\apps
HEADER
END
USERINCLUDE .
USERINCLUDE ..\CommonGraphicsExampleFiles
SYSTEMINCLUDE \Epoc32\include
SYSTEMINCLUDE \epoc32\include\techview
LIBRARY euser.lib efsrv.lib
LIBRARY gdi.lib bitgdi.lib ws32.lib fbscli.lib
LIBRARY cone.lib apparc.lib
LIBRARY eikcore.lib eikcoctl.lib
START BITMAP grbmap.mbm
TARGETPATH \resource\apps
HEADER
SOURCE c8 Smiley.bmp Smilmask.bmp
END
START RESOURCE BitmapsShell_reg.rss
TARGETPATH \private\10003a3f\apps
END
// BitmapsShell.rss
//
// Copyright (c) 2000 Symbian Ltd. All rights reserved.
NAME GRSH
#include <eikon.rh>
#include "BitmapsShell.hrh"
RESOURCE RSS_SIGNATURE { }
RESOURCE TBUF { buf=""; }
RESOURCE EIK_APP_INFO
{
menubar=r_grsh_menubar;
hotkeys=r_grsh_hotkeys;
}
RESOURCE HOTKEYS r_grsh_hotkeys
{
control=
{
HOTKEY { command=EEikCmdExit; key='e'; }
};
}
RESOURCE MENU_BAR r_grsh_menubar
{
titles=
{
MENU_TITLE {menu_pane=menu1; txt="File"; },
MENU_TITLE {menu_pane=menu2; txt="List Of Programs "; }
};
}
RESOURCE MENU_PANE menu1
{
items=
{
MENU_ITEM { command=EEikCmdExit; txt="Exit"; }
};
}
RESOURCE MENU_PANE menu2
{
items=
{
MENU_ITEM { command=EExampleShellSelectBitmap; txt="Bitmap"; },
MENU_ITEM { command=EExampleShellSelectFbs; txt="FontBitmapServer"; }
};
}
BitmapsShell.rss
#include <appinfo.rh>
UID2 KUidAppRegistrationResourceFile
UID3 0x1000525B // application UID
RESOURCE APP_REGISTRATION_INFO
{
app_file = "BitmapsShell";
}
BitmapsShell
provides an application shell, and two
concrete controls.
CGraphicExampleControl
is a control class, derived from
CCoeControl
, which links the app shell to the particular controls.
The CBitmapControl
and CFbsControl
classes,
derived from CGraphicExampleControl
, define behaviour for their
particular controls.
CBitmapControl
illustrates the handling and rendering of
bitmaps.
CFbsControl
illustrates the use of the font and bitmap
server.
The source code for this example application can be found in the directory:
examples\Graphics\Bitmaps
It may be in the directory in which you installed Symbian OS, or it may
be in src\common\developerlibrary\
. It includes the two project
files needed for building: bld.inf
and the .mmp
file.
The Symbian OS build process describes how to build this application. For the emulator, an
application called BitmapsShell.exe
is created in
epoc32\release\winscw\<udeb or urel>\
.
Launch the emulator:
\epoc32\release\winscw\<urel or udeb>\EPOC.EXE
.
Click on BITMAPSSHELL
to run the application. If
using the TechView emulator, this will be in the
Extras menu.
The controls are listed on the menu List of
Programs
. Press the appropriate menu item to select a specific
control.
Step through each phase of an example by pressing the space bar or by tapping on the window drawn by that example.
By the bitmap control:
TPoint
: 2-dimensional geometric point
TRect
: a geometric rectangle
TSize
: 2-dimensional geometric size
CWindowGc
: the window graphics context
TRgb
: colour representation
CFont
: font interface class
CFbsBitmap
: Bitmap managed by the font and bitmap
server
By the font and bitmap server control:
CWindowGc
: the graphics context
CFbsBitmap
: Bitmap managed by the font and bitmap
server