#ifndef GLOBALDEFINE_H
#define GLOBALDEFINE_H
#include <e32def.h>
#include <e32std.h>
#include <e32debug.h>//RDebug
//////////////////////////////////////////////////////
//打包时开关和版本号特别需要注意
//打包时请务必把开关关闭并修改相应的版本信息
//////////////////////////////////////////////////////
#define __S60_V3__
//////////////////////////////////////////////////////
//调试基础引擎
//#define _DUG_BASICENGINE_
//#define _DUG_BASICENGINE_DRAWRIM_
//#define _DUG_BASICENGINE_DRAWSOLID_
//#define _DUG_BASICENGINE_DRAWRIMSOLID_
//#define _DUG_BASICENGINE_DRAWSLTEXT_
//#define _DUG_BASICENGINE_DRAWMLTEXTL_
//#define _DUG_BASICENGINE_DRAWMLTEXT2L_
//#define _DUG_BASICENGINE_DRAWSOLIDFRAMEWORK_
//#define _DUG_BASICENGINE_DRAWRIMSOLIDFRAMEWORK_
//#define _DUG_BASICENGINE_DRAWGRADIENT_
//#define _DUG_BASICENGINE_DRAWBITMAP_
#ifdef _DUG_BASICENGINE_
_LIT(KSingleLineTextTest,"SingleLineText");
_LIT(KMultiLineTextTest,"MultiLineText1/nMultiLineText2 MultiLineText3");
_LIT(KTestMbm,"//resource//apps//TravelBook//Test.mbm");
#endif
//////////////////////////////////////////////////////
//屏幕的各种尺寸参数
//全屏区域
#define _FULL_SCREEN_
#define KFullScreenRect ApplicationRect()
#define KClientRect ClientRect()
//////////////////////////////////////////////////////
//状态栏定义(注意:只能令其中一个有效)
//普通状态栏
//#define _NORMAL_STATUSPANE_
//小状态栏
//#define _SMALL_STATUSPANE_
//无状态栏
//#define _NO_STATUSPANE_
//////////////////////////////////////////////////////
//绘制的各种默认参数
//默认画笔尺寸
#define KDefaultPenSize TSize(1,1)
//默认矩形圆角尺寸
#define KDefaultConerSize TSize(10,10)
//使用TBidiText绘制多行文本时的最大行数
const TInt KTBidiTextMaxLines = 30;
//////////////////////////////////////////////////////
//各种字体设置
//#define _DUG_FONT_SIZE_
#ifdef _DUG_FONT_SIZE_
_LIT(KTitleFontText,"TitleFont!");
_LIT(KNormalFontText,"NormalFont!");
_LIT(KLegendFontText,"LegendFont!");
_LIT(KAnnotationFontText,"AnnotationFont!");
_LIT(KPlain16FontText,"Plain16Font!");
#endif
//大字体(Bold)
#define KTitleFont CEikonEnv::Static()->TitleFont()
#define KTitleFontHeight CEikonEnv::Static()->TitleFont()->HeightInPixels()
//中等字体(Plain)
#define KNormalFont CEikonEnv::Static()->NormalFont()
#define KNormalFontHeight CEikonEnv::Static()->NormalFont()->HeightInPixels()
//中等字体(Bold)
#define KLegendFont CEikonEnv::Static()->LegendFont()
#define KLegendFontHeight CEikonEnv::Static()->LegendFont()->HeightInPixels()
//小字体(Plain)
#define KAnnotationFont CEikonEnv::Static()->AnnotationFont()
#define KAnnotationFontHeight CEikonEnv::Static()->AnnotationFont()->HeightInPixels()
//16号字体
#define KPlain16Font ApacPlain16()
#define KPlain16FontHeight ApacPlain16()->HeightInPixels()
#ifdef __S60_V3__
#define KSoftTitleFont KLegendFont//标题字体(v3)
#define KSoftTitleFontHeight KLegendFontHeight
#define KSoftNormalFont KLegendFont//普通字体(v3)
#define KSoftNormalFontHeight KLegendFontHeight
#define KSoftSmallFont KPlain16Font//小字体(v3)
#define KSoftSmallFontHeight KPlain16FontHeight
#else
#define KSoftTitleFont KTitleFont//标题字体(v5)
#define KSoftTitleFontHeight KTitleFontHeight
#define KSoftNormalFont KNormalFont//普通字体(v5)
#define KSoftNormalFontHeight KNormalFontHeight
#define KSoftSmallFont KLegendFont//小字体(v5)
#define KSoftSmallFontHeight KLegendFontHeight
#endif
//////////////////////////////////////////////////////
//各种透明参数
const TInt KAlphaOpaque = 255; //不透明
const TInt KAlphaMid = 130; //半透明
const TInt KAlphaTransparen = 0; //全透明
//////////////////////////////////////////////////////
//各种颜色参数
#define KColorSkin TRgb( 0x00A772 )//程序皮肤00A772
#endif /*GLOBALDEFINE_H*/
/*
============================================================================
Name : BasicEngine.h
Author : ShiJinPing
Version : 1.0
Copyright : Your copyright notice
Description : CBasicEngine declaration基础引擎,包括绘制基本图形及绘制文本
============================================================================
*/
#ifndef BASICENGINE_H
#define BASICENGINE_H
// INCLUDES
#include <e32std.h>
#include <e32base.h>
#include <gdi.h>
#include <w32std.h>
#include <eikdef.h>
#include <eikenv.h>//for CGraphicsContext
#include <biditext.h>//for TBidiText
#include "GloableDefine.h"
// CLASS DECLARATION
/**
* CBasicEngine
*
*/
class CBasicEngine : public CBase,public CGraphicsContext//for CEikonEnv::Static()->NormalFont()
{
public:
enum TAreaType
{
ERect,//矩形
ERoundRect,//圆角矩形
EEllipse,//椭圆
};
enum TFrameworkRect
{
ETitleRect,
ETotalCBARect,
ELeftCBARect,
ECenterCBARect,
ERightCBARect
};
enum TGradientDirection
{
EVerticalGradient,
EHorizontalGradient,
EVToMidGradient,
EHToMidGradient
};
public:
/////////////////////////////////////////////////////////////////
//绘制边框
//参数说明: aRect:绘制区域;
// aAreaType:绘制区域类型;
// aPenColor:画笔颜色;
// aPenSize:画笔尺寸;
// aAlpha:透明度(0-255,255为不透明);
// aPenStyle:画笔风格;
// aConerSize:圆角尺寸;
/////////////////////////////////////////////////////////////////
static void DrawRim(CWindowGc &aGc,
const TRect &aRect,
const TAreaType &aAreaType = ERect,
TRgb aPenColor = KRgbBlack,
const TSize &aPenSize = KDefaultPenSize,
const TInt &aAlpha = KAlphaOpaque,
const TPenStyle &aPenStyle = ESolidPen,
const TSize &aConerSize = KDefaultConerSize);
static void DrawRim(CBitmapContext &aGc,
const TRect &aRect,
const TAreaType &aAreaType = ERect,
TRgb aPenColor = KRgbBlack,
const TSize &aPenSize = KDefaultPenSize,
const TInt &aAlpha = KAlphaOpaque,
const TPenStyle &aPenStyle = ESolidPen,
const TSize &aConerSize = KDefaultConerSize);
/////////////////////////////////////////////////////////////////
//绘制实心区域(无边框)
//参数说明: aRect:绘制区域;
// aAreaType:绘制区域类型;
// aBrushColor:笔刷颜色(填充颜色);
// aAlpha:透明度(0-255,255为不透明);
// aBrushStyle:笔刷风格;
// aConerSize:圆角尺寸;
/////////////////////////////////////////////////////////////////
static void DrawSolid(CWindowGc &aGc,
const TRect &aRect,
const TAreaType &aAreaType = ERect,
TRgb aBrushColor = KRgbWhite,
const TInt &aAlpha = KAlphaOpaque,
const TBrushStyle &aBrushStyle = ESolidBrush,
const TSize &aConerSize = KDefaultConerSize);
static void DrawSolid(CBitmapContext &aGc,
const TRect &aRect,
const TAreaType &aAreaType = ERect,
TRgb aBrushColor = KRgbWhite,
const TInt &aAlpha = KAlphaOpaque,
const TBrushStyle &aBrushStyle = ESolidBrush,
const TSize &aConerSize = KDefaultConerSize);
/////////////////////////////////////////////////////////////////
//绘制带边框的实心区域
//参数说明: aRect:绘制区域;
// aAreaType:绘制区域类型;
// aBrushColor:笔刷颜色(填充颜色);
// aPenColor:画笔颜色;
// aPenSize:画笔尺寸;
// aBrushAlpha:笔刷透明度(0-255,255为不透明);
// aPenAlpha:画笔透明度(0-255,255为不透明);
// aBrushStyle:笔刷风格;
// aPenStyle:画笔风格;
// aConerSize:圆角尺寸;
/////////////////////////////////////////////////////////////////
static void DrawRimSolid(CWindowGc &aGc,
const TRect &aRect,
const TAreaType &aAreaType = ERect,
TRgb aBrushColor = KRgbWhite,
TRgb aPenColor = KRgbBlack,
const TSize &aPenSize = KDefaultPenSize,
const TInt &aBrushAlpha = KAlphaOpaque,
const TInt &aPenAlpha = KAlphaOpaque,
const TBrushStyle &aBrushStyle = ESolidBrush,
const TPenStyle &aPenStyle = ESolidPen,
const TSize &aConerSize = KDefaultConerSize);
static void DrawRimSolid(CBitmapContext &aGc,
const TRect &aRect,
const TAreaType &aAreaType = ERect,
TRgb aBrushColor = KRgbWhite,
TRgb aPenColor = KRgbBlack,
const TSize &aPenSize = KDefaultPenSize,
const TInt &aBrushAlpha = KAlphaOpaque,
const TInt &aPenAlpha = KAlphaOpaque,
const TBrushStyle &aBrushStyle = ESolidBrush,
const TPenStyle &aPenStyle = ESolidPen,
const TSize &aConerSize = KDefaultConerSize);
/////////////////////////////////////////////////////////////////
//绘制单行文本
//参数说明: aRect:绘制区域;
// aText:绘制文本内容;
// aPenColor:画笔颜色(文本颜色);
// aFontUsed:使用的字体;
// aTextAlign:文本对齐方式;
/////////////////////////////////////////////////////////////////
static void DrawSLText(CWindowGc &aGc,
const TRect &aRect,
const TDesC &aText,
const TRgb &aPenColor = KRgbBlack,
const CFont *aFontUsed = KNormalFont,
const TTextAlign &aTextAlign = ELeft);
static void DrawSLText(CBitmapContext &aGc,
const TRect &aRect,
const TDesC &aText,
const TRgb &aPenColor = KRgbBlack,
const CFont *aFontUsed = KNormalFont,
const TTextAlign &aTextAlign = ELeft);
/////////////////////////////////////////////////////////////////
//绘制多行文本(方法1,使用AknTextUtils::WrapToArrayL)
//参数说明: aRect:绘制区域;
// aText:绘制文本内容;
// aPenColor:画笔颜色(文本颜色);
// aFontUsed:使用的字体;
/////////////////////////////////////////////////////////////////
static void DrawMLTextL(CWindowGc &aGc,
const TRect &aRect,
const TDesC &aText,
const TRgb &aPenColor = KRgbBlack,
const CFont *aFontUsed = KNormalFont);
static void DrawMLTextL(CBitmapContext &aGc,
const TRect &aRect,
const TDesC &aText,
const TRgb &aPenColor = KRgbBlack,
const CFont *aFontUsed = KNormalFont);
/////////////////////////////////////////////////////////////////
//绘制多行文本(方法2,使用TBidiText,有最大行数限制)
//参数说明: aRect:绘制区域;
// aText:绘制文本内容;
// aPenColor:画笔颜色(文本颜色);
// aFontUsed:使用的字体;
/////////////////////////////////////////////////////////////////
static void DrawMLText2L(CWindowGc &aGc,
const TRect &aRect,
const TDesC &aText,
const TRgb &aPenColor = KRgbBlack,
const CFont *aFontUsed = KNormalFont);
static void DrawMLText2L(CBitmapContext &aGc,
const TRect &aRect,
const TDesC &aText,
const TRgb &aPenColor = KRgbBlack,
const CFont *aFontUsed = KNormalFont);
/////////////////////////////////////////////////////////////////
//获取框架各部分区域
//参数说明: aRect:绘制区域;
// aFramworkRect:框架区域类型;
//返回值: 框架区域;
/////////////////////////////////////////////////////////////////
static TRect CalcFrameworkRect(const TRect &aRect,
const TFrameworkRect &aFramworkRect);
/////////////////////////////////////////////////////////////////
//绘制纯色框架(无边框)
//参数说明: aRect:绘制区域;
// aTitleText:顶部内容;
// aLeftCBAText:左键菜单内容;
// aRightCBAText:右键菜单内容;
// aCenterCBAText:中键菜单内容;
// aSkinColor:皮肤颜色;
// aAlpha:皮肤透明度(0-255,255为不透明);
/////////////////////////////////////////////////////////////////
static void DrawSolidFramework(CWindowGc &aGc,
const TRect &aRect,
const TDesC &aTitleText = KNullDesC,
const TDesC &aRightCBAText = KNullDesC,
const TDesC &aLeftCBAText = KNullDesC,
const TDesC &aCenterCBAText = KNullDesC,
TRgb aSkinColor = KColorSkin,
const TInt &aAlpha = KAlphaOpaque);
static void DrawSolidFramework(CBitmapContext &aGc,
const TRect &aRect,
const TDesC &aTitleText = KNullDesC,
const TDesC &aRightCBAText = KNullDesC,
const TDesC &aLeftCBAText = KNullDesC,
const TDesC &aCenterCBAText = KNullDesC,
TRgb aSkinColor = KColorSkin,
const TInt &aAlpha = KAlphaOpaque);
/////////////////////////////////////////////////////////////////
//绘制纯色框架(有边框)
//参数说明: aRect:绘制区域;
// aTitleText:顶部内容;
// aLeftCBAText:左键菜单内容;
// aRightCBAText:右键菜单内容;
// aCenterCBAText:中键菜单内容;
// aSkinColor:皮肤颜色;
// aRimColor:边框颜色;
// aRimSize:边框尺寸;
// aSkinAlpha:皮肤透明度(0-255,255为不透明);
// aRimAlpha:边框透明度(0-255,255为不透明);
/////////////////////////////////////////////////////////////////
static void DrawRimSolidFramework(CWindowGc &aGc,
const TRect &aRect,
const TDesC &aTitleText = KNullDesC,
const TDesC &aRightCBAText = KNullDesC,
const TDesC &aLeftCBAText = KNullDesC,
const TDesC &aCenterCBAText = KNullDesC,
TRgb aSkinColor = KColorSkin,
TRgb aRimColor = KRgbBlack,
const TSize &aRimSize = KDefaultPenSize,
const TInt &aSkinAlpha = KAlphaOpaque,
const TInt &aRimAlpha = KAlphaOpaque);
static void DrawRimSolidFramework(CBitmapContext &aGc,
const TRect &aRect,
const TDesC &aTitleText = KNullDesC,
const TDesC &aRightCBAText = KNullDesC,
const TDesC &aLeftCBAText = KNullDesC,
const TDesC &aCenterCBAText = KNullDesC,
TRgb aSkinColor = KColorSkin,
TRgb aRimColor = KRgbBlack,
const TSize &aRimSize = KDefaultPenSize,
const TInt &aSkinAlpha = KAlphaOpaque,
const TInt &aRimAlpha = KAlphaOpaque);
/////////////////////////////////////////////////////////////////
//绘制渐变色
//参数说明: aRect:绘制区域;
// aStartColor:开始颜色;
// aEndColor:结束颜色;
// aGradientDirection:绘制方向,默认纵向(纵向或横向);
/////////////////////////////////////////////////////////////////
static void DrawGradientL(CWindowGc &aGc,
const TRect &aRect,
TRgb aStartColor,
TRgb aEndColor,
const TGradientDirection &aGradientDirection = EVerticalGradient);
static void DrawGradientL(CBitmapContext &aGc,
const TRect &aRect,
TRgb aStartColor,
TRgb aEndColor,
const TGradientDirection &aGradientDirection = EVerticalGradient);
/////////////////////////////////////////////////////////////////
//绘制bmp
//参数说明: aMbmPath:mbm文件;
// aBmpId:bmp的id;
// aBmpMaskId:mask图的id;
// aDestRect:目标绘制区域;
/////////////////////////////////////////////////////////////////
static void DrawBmpL(CWindowGc &aGc,
const TDesC &aMbmPath,
const TInt &aBmpId,
const TInt &aBmpMaskId,
const TRect &aDestRect);
static void DrawBmpL(CBitmapContext &aGc,
const TDesC &aMbmPath,
const TInt &aBmpId,
const TInt &aBmpMaskId,
const TRect &aDestRect);
};
#endif // BASICENGINE_H
/*
============================================================================
Name : BasicEngine.cpp
Author : ShiJinPing
Version : 1.0
Copyright : Your copyright notice
Description : CBasicEngine implementation
============================================================================
*/
#include "BasicEngine.h"
#include <aknutils.h>//for WrapToArrayL
void CBasicEngine::DrawRim(CWindowGc& aGc, const TRect& aRect,
const TAreaType &aAreaType,TRgb aPenColor,const TSize &aPenSize, const TInt &aAlpha,
const TPenStyle &aPenStyle,const TSize &aConerSize)
{
aPenColor.SetAlpha(aAlpha);
aGc.SetDrawMode(CGraphicsContext::EDrawModePEN);
aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
aGc.SetPenStyle(aPenStyle);
aGc.SetPenColor(aPenColor);
aGc.SetPenSize(aPenSize);
switch(aAreaType)
{
case ERect:
aGc.DrawRect(aRect);
break;
case ERoundRect:
aGc.DrawRoundRect(aRect,aConerSize);
break;
case EEllipse:
aGc.DrawEllipse(aRect);
break;
}
}
void CBasicEngine::DrawRim(CBitmapContext& aGc, const TRect& aRect,
const TAreaType &aAreaType,TRgb aPenColor,const TSize &aPenSize, const TInt &aAlpha,
const TPenStyle &aPenStyle,const TSize &aConerSize)
{
aPenColor.SetAlpha(aAlpha);
aGc.SetDrawMode(CGraphicsContext::EDrawModePEN);
aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
aGc.SetPenStyle(aPenStyle);
aGc.SetPenColor(aPenColor);
aGc.SetPenSize(aPenSize);
switch(aAreaType)
{
case ERect:
aGc.DrawRect(aRect);
break;
case ERoundRect:
aGc.DrawRoundRect(aRect,aConerSize);
break;
case EEllipse:
aGc.DrawEllipse(aRect);
break;
}
}
void CBasicEngine::DrawSolid(CWindowGc &aGc,const TRect &aRect,
const TAreaType &aAreaType,TRgb aBrushColor,const TInt &aAlpha,
const TBrushStyle &aBrushStyle,const TSize &aConerSize)
{
aBrushColor.SetAlpha(aAlpha);
aGc.SetDrawMode(CGraphicsContext::EDrawModePEN);
aGc.SetPenStyle(CGraphicsContext::ENullPen);
aGc.SetBrushStyle(aBrushStyle);
aGc.SetBrushColor(aBrushColor);
switch(aAreaType)
{
case ERect:
aGc.DrawRect(aRect);
break;
case ERoundRect:
aGc.DrawRoundRect(aRect,aConerSize);
break;
case EEllipse:
aGc.DrawEllipse(aRect);
break;
}
}
void CBasicEngine::DrawSolid(CBitmapContext &aGc,const TRect &aRect,
const TAreaType &aAreaType,TRgb aBrushColor,const TInt &aAlpha,
const TBrushStyle &aBrushStyle,const TSize &aConerSize)
{
aBrushColor.SetAlpha(aAlpha);
aGc.SetDrawMode(CGraphicsContext::EDrawModePEN);
aGc.SetPenStyle(CGraphicsContext::ENullPen);
aGc.SetBrushStyle(aBrushStyle);
aGc.SetBrushColor(aBrushColor);
switch(aAreaType)
{
case ERect:
aGc.DrawRect(aRect);
break;
case ERoundRect:
aGc.DrawRoundRect(aRect,aConerSize);
break;
case EEllipse:
aGc.DrawEllipse(aRect);
break;
}
}
void CBasicEngine::DrawRimSolid(CWindowGc &aGc,const TRect &aRect,
const TAreaType &aAreaType, TRgb aBrushColor,TRgb aPenColor,const TSize &aPenSize,
const TInt &aBrushAlpha ,const TInt &aPenAlpha,
const TBrushStyle &aBrushStyle,const TPenStyle &aPenStyle,const TSize &aConerSize)
{
aBrushColor.SetAlpha(aBrushAlpha);
aPenColor.SetAlpha(aPenAlpha);
aGc.SetDrawMode(CGraphicsContext::EDrawModePEN);
aGc.SetBrushStyle(aBrushStyle);
aGc.SetBrushColor(aBrushColor);
aGc.SetPenStyle(aPenStyle);
aGc.SetPenColor(aPenColor);
aGc.SetPenSize(aPenSize);
switch(aAreaType)
{
case ERect:
aGc.DrawRect(aRect);
break;
case ERoundRect:
aGc.DrawRoundRect(aRect,aConerSize);
break;
case EEllipse:
aGc.DrawEllipse(aRect);
break;
}
}
void CBasicEngine::DrawRimSolid(CBitmapContext &aGc,const TRect &aRect,
const TAreaType &aAreaType, TRgb aBrushColor,TRgb aPenColor,const TSize &aPenSize,
const TInt &aBrushAlpha ,const TInt &aPenAlpha,
const TBrushStyle &aBrushStyle,const TPenStyle &aPenStyle,const TSize &aConerSize)
{
aBrushColor.SetAlpha(aBrushAlpha);
aPenColor.SetAlpha(aPenAlpha);
aGc.SetDrawMode(CGraphicsContext::EDrawModePEN);
aGc.SetBrushStyle(aBrushStyle);
aGc.SetBrushColor(aBrushColor);
aGc.SetPenStyle(aPenStyle);
aGc.SetPenColor(aPenColor);
aGc.SetPenSize(aPenSize);
switch(aAreaType)
{
case ERect:
aGc.DrawRect(aRect);
break;
case ERoundRect:
aGc.DrawRoundRect(aRect,aConerSize);
break;
case EEllipse:
aGc.DrawEllipse(aRect);
break;
}
}
void CBasicEngine::DrawSLText(CWindowGc &aGc, const TRect &aRect,const TDesC &aText,
const TRgb &aPenColor, const CFont *aFontUsed, const TTextAlign &aTextAlign)
{
aGc.SetDrawMode(CGraphicsContext::EDrawModePEN);
aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
aGc.SetPenColor(aPenColor);
aGc.UseFont(aFontUsed);
TInt baseLine = aRect.Height() / 2 + aFontUsed->AscentInPixels() / 2;
aGc.DrawText(aText, aRect, baseLine, aTextAlign);
aGc.DiscardFont();
}
void CBasicEngine::DrawSLText(CBitmapContext &aGc, const TRect &aRect,const TDesC &aText,
const TRgb &aPenColor, const CFont *aFontUsed, const TTextAlign &aTextAlign)
{
aGc.SetDrawMode(CGraphicsContext::EDrawModePEN);
aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
aGc.SetPenColor(aPenColor);
aGc.UseFont(aFontUsed);
TInt baseLine = aRect.Height() / 2 + aFontUsed->AscentInPixels() / 2;
aGc.DrawText(aText, aRect, baseLine, aTextAlign);
aGc.DiscardFont();
}
void CBasicEngine::DrawMLTextL(CWindowGc &aGc, const TRect &aRect,const TDesC &aText,
const TRgb &aPenColor, const CFont *aFontUsed)
{
aGc.SetDrawMode(CGraphicsContext::EDrawModePEN);
aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
aGc.SetPenColor(aPenColor);
aGc.UseFont(aFontUsed);
RBuf buf;
buf.CreateL(aText);
CArrayFix<TPtrC>* WrappedArray = new (ELeave) CArrayFixFlat<TPtrC> (1);
CleanupStack::PushL(WrappedArray);
AknTextUtils::WrapToArrayL(buf, aRect.Width(), *aFontUsed, *WrappedArray);
TInt lines = WrappedArray->Count();
TInt height = aFontUsed->HeightInPixels();
TPoint p(aRect.iTl.iX, aRect.iTl.iY);
for (TInt i = 0; i < lines; i++)
{
p.iY += height;
aGc.DrawText((WrappedArray->At(i)), p);
}
buf.Close();
CleanupStack::PopAndDestroy();//WrappedArray
aGc.DiscardFont();
}
void CBasicEngine::DrawMLTextL(CBitmapContext &aGc, const TRect &aRect,const TDesC &aText,
const TRgb &aPenColor, const CFont *aFontUsed)
{
aGc.SetDrawMode(CGraphicsContext::EDrawModePEN);
aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
aGc.SetPenColor(aPenColor);
aGc.UseFont(aFontUsed);
RBuf buf;
buf.CreateL(aText);
CArrayFix<TPtrC>* WrappedArray = new (ELeave) CArrayFixFlat<TPtrC> (1);
CleanupStack::PushL(WrappedArray);
AknTextUtils::WrapToArrayL(buf, aRect.Width(), *aFontUsed, *WrappedArray);
TInt lines = WrappedArray->Count();
TInt height = aFontUsed->HeightInPixels();
TPoint p(aRect.iTl.iX, aRect.iTl.iY);
for (TInt i = 0; i < lines; i++)
{
p.iY += height;
aGc.DrawText((WrappedArray->At(i)), p);
}
buf.Close();
CleanupStack::PopAndDestroy();//WrappedArray
aGc.DiscardFont();
}
void CBasicEngine::DrawMLText2L(CWindowGc &aGc, const TRect &aRect,const TDesC &aText,
const TRgb &aPenColor,const CFont *aFontUsed)
{
aGc.SetDrawMode(CGraphicsContext::EDrawModePEN);
aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
aGc.SetPenColor(aPenColor);
aGc.UseFont(aFontUsed);
TBidiText *bidiText = TBidiText::NewL(aText, KTBidiTextMaxLines);
bidiText->WrapText(aRect.Width(), *aFontUsed);
TInt lines = bidiText->NumberOfLinesInDisplayText();
TInt height = aFontUsed->HeightInPixels();
TPoint p(aRect.iTl.iX, aRect.iTl.iY);
for (TInt i = 0; i < lines; i++)
{
p.iY += height;
TInt width = 0;
TPtrC text = bidiText->LineOfDisplayText(i, width);
aGc.DrawText(text, p);
}
delete bidiText;
aGc.DiscardFont();
}
void CBasicEngine::DrawMLText2L(CBitmapContext &aGc, const TRect &aRect,const TDesC &aText,
const TRgb &aPenColor,const CFont *aFontUsed)
{
aGc.SetDrawMode(CGraphicsContext::EDrawModePEN);
aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
aGc.SetPenColor(aPenColor);
aGc.UseFont(aFontUsed);
TBidiText *bidiText = TBidiText::NewL(aText, KTBidiTextMaxLines);
bidiText->WrapText(aRect.Width(), *aFontUsed);
TInt lines = bidiText->NumberOfLinesInDisplayText();
TInt height = aFontUsed->HeightInPixels();
TPoint p(aRect.iTl.iX, aRect.iTl.iY);
for (TInt i = 0; i < lines; i++)
{
p.iY += height;
TInt width = 0;
TPtrC text = bidiText->LineOfDisplayText(i, width);
aGc.DrawText(text, p);
}
delete bidiText;
aGc.DiscardFont();
}
TRect CBasicEngine::CalcFrameworkRect(const TRect &aRect,const TFrameworkRect &aFramworkRect)
{
TRect cbaRect(TPoint(0,aRect.Height() - KSoftTitleFontHeight),TSize(aRect.Width(),KSoftTitleFontHeight));
if(aFramworkRect == ETitleRect)
{
TRect titleRect(aRect.iTl,TSize(aRect.Width(),KSoftTitleFontHeight));
return titleRect;
}
switch(aFramworkRect)
{
case ELeftCBARect:
{
cbaRect.iTl.iX = 0;
cbaRect.iBr.iX = aRect.Width()*3/8;
}
break;
case ECenterCBARect:
{
cbaRect.iTl.iX = aRect.Width()*3/8;
cbaRect.iBr.iX = aRect.Width() * 5 /8;
}
break;
case ERightCBARect:
{
cbaRect.iTl.iX = aRect.Width() * 5/8;
cbaRect.iBr.iX = aRect.Width();
}
break;
case ETotalCBARect:
break;
}
return cbaRect;
}
void CBasicEngine::DrawSolidFramework(CWindowGc &aGc, const TRect &aRect,const TDesC &aTitleText,const TDesC &aRightCBAText, const TDesC &aLeftCBAText,
const TDesC &aCenterCBAText, TRgb aSkinColor,const TInt &aAlpha )
{
TRect topRect = CalcFrameworkRect(aRect,ETitleRect);
TRect totalCBARect = CalcFrameworkRect(aRect,ETotalCBARect);
TRect leftCBARect = CalcFrameworkRect(aRect,ELeftCBARect);
TRect centerCBARect = CalcFrameworkRect(aRect,ECenterCBARect);
TRect rightCBARect = CalcFrameworkRect(aRect,ERightCBARect);
DrawSolid(aGc,topRect,ERect,aSkinColor,aAlpha);
DrawSolid(aGc,totalCBARect,ERect,aSkinColor,aAlpha);
DrawSLText(aGc,topRect,aTitleText,KRgbBlack,KSoftTitleFont,ECenter);
DrawSLText(aGc,rightCBARect,aRightCBAText,KRgbBlack,KSoftTitleFont,ERight);
DrawSLText(aGc,centerCBARect,aCenterCBAText,KRgbBlack,KSoftTitleFont,ECenter);
DrawSLText(aGc,leftCBARect,aLeftCBAText,KRgbBlack,KSoftTitleFont);
}
void CBasicEngine::DrawSolidFramework(CBitmapContext &aGc, const TRect &aRect,const TDesC &aTitleText,const TDesC &aRightCBAText, const TDesC &aLeftCBAText,
const TDesC &aCenterCBAText, TRgb aSkinColor,const TInt &aAlpha )
{
TRect topRect = CalcFrameworkRect(aRect,ETitleRect);
TRect totalCBARect = CalcFrameworkRect(aRect,ETotalCBARect);
TRect leftCBARect = CalcFrameworkRect(aRect,ELeftCBARect);
TRect centerCBARect = CalcFrameworkRect(aRect,ECenterCBARect);
TRect rightCBARect = CalcFrameworkRect(aRect,ERightCBARect);
DrawSolid(aGc,topRect,ERect,aSkinColor,aAlpha);
DrawSolid(aGc,totalCBARect,ERect,aSkinColor,aAlpha);
DrawSLText(aGc,topRect,aTitleText,KRgbBlack,KSoftTitleFont,ECenter);
DrawSLText(aGc,rightCBARect,aRightCBAText,KRgbBlack,KSoftTitleFont,ERight);
DrawSLText(aGc,centerCBARect,aCenterCBAText,KRgbBlack,KSoftTitleFont,ECenter);
DrawSLText(aGc,leftCBARect,aLeftCBAText,KRgbBlack,KSoftTitleFont);
}
void CBasicEngine::DrawRimSolidFramework(CWindowGc &aGc, const TRect &aRect,const TDesC &aTitleText,const TDesC &aRightCBAText,
const TDesC &aLeftCBAText,const TDesC &aCenterCBAText, TRgb aSkinColor,TRgb aRimColor,const TSize &aRimSize,
const TInt &aSkinAlpha,const TInt &aRimAlpha )
{
TRect topRect = CalcFrameworkRect(aRect,ETitleRect);
TRect totalCBARect = CalcFrameworkRect(aRect,ETotalCBARect);
TRect leftCBARect = CalcFrameworkRect(aRect,ELeftCBARect);
TRect centerCBARect = CalcFrameworkRect(aRect,ECenterCBARect);
TRect rightCBARect = CalcFrameworkRect(aRect,ERightCBARect);
DrawRimSolid(aGc,topRect,ERect,aSkinColor,aRimColor,aRimSize,aSkinAlpha,aRimAlpha);
DrawRimSolid(aGc,totalCBARect,ERect,aSkinColor,aRimColor,aRimSize,aSkinAlpha,aRimAlpha);
DrawSLText(aGc,topRect,aTitleText,KRgbBlack,KSoftTitleFont,ECenter);
DrawSLText(aGc,rightCBARect,aRightCBAText,KRgbBlack,KSoftTitleFont,ERight);
DrawSLText(aGc,centerCBARect,aCenterCBAText,KRgbBlack,KSoftTitleFont,ECenter);
DrawSLText(aGc,leftCBARect,aLeftCBAText,KRgbBlack,KSoftTitleFont);
}
void CBasicEngine::DrawRimSolidFramework(CBitmapContext &aGc, const TRect &aRect,const TDesC &aTitleText,const TDesC &aRightCBAText,
const TDesC &aLeftCBAText,const TDesC &aCenterCBAText, TRgb aSkinColor,TRgb aRimColor,const TSize &aRimSize,
const TInt &aSkinAlpha,const TInt &aRimAlpha )
{
TRect topRect = CalcFrameworkRect(aRect,ETitleRect);
TRect totalCBARect = CalcFrameworkRect(aRect,ETotalCBARect);
TRect leftCBARect = CalcFrameworkRect(aRect,ELeftCBARect);
TRect centerCBARect = CalcFrameworkRect(aRect,ECenterCBARect);
TRect rightCBARect = CalcFrameworkRect(aRect,ERightCBARect);
DrawRimSolid(aGc,topRect,ERect,aSkinColor,aRimColor,aRimSize,aSkinAlpha,aRimAlpha);
DrawRimSolid(aGc,totalCBARect,ERect,aSkinColor,aRimColor,aRimSize,aSkinAlpha,aRimAlpha);
DrawSLText(aGc,topRect,aTitleText,KRgbBlack,KSoftTitleFont,ECenter);
DrawSLText(aGc,rightCBARect,aRightCBAText,KRgbBlack,KSoftTitleFont,ERight);
DrawSLText(aGc,centerCBARect,aCenterCBAText,KRgbBlack,KSoftTitleFont,ECenter);
DrawSLText(aGc,leftCBARect,aLeftCBAText,KRgbBlack,KSoftTitleFont);
}
void CBasicEngine::DrawGradientL(CWindowGc &aGc,const TRect &aRect,TRgb aStartColor,TRgb aEndColor,
const TGradientDirection &aGradientDirection)
{
CFbsBitmap* fbsBitmap=new(ELeave)CFbsBitmap;
TRgb startColor=aStartColor;
TRgb endColor=aEndColor;
TInt brushWidth = 0;
ColorUtils::TBitmapOrientation bitmapOrientation;
switch(aGradientDirection)
{
case EVerticalGradient:
{
brushWidth=aRect.Height();
bitmapOrientation=ColorUtils::EBitmapOrientationVertical;
ColorUtils::CreateGradientBitmapL(*fbsBitmap,CEikonEnv::Static()->WsSession(),brushWidth,bitmapOrientation, startColor, endColor);
#ifndef __S60_V3__
fbsBitmap->SetDisplayMode(EColor64K);
#endif
aGc.DrawBitmap(aRect,fbsBitmap);
}
break;
case EHorizontalGradient:
{
brushWidth=aRect.Width();
bitmapOrientation=ColorUtils::EBitmapOrientationHorizontal;
ColorUtils::CreateGradientBitmapL(*fbsBitmap,CEikonEnv::Static()->WsSession(),brushWidth,bitmapOrientation, startColor, endColor);
#ifndef __S60_V3__
fbsBitmap->SetDisplayMode(EColor64K);
#endif
aGc.DrawBitmap(aRect,fbsBitmap);
}
break;
case EVToMidGradient:
{
brushWidth=aRect.Height()/2;
bitmapOrientation=ColorUtils::EBitmapOrientationVertical;
TSize tmpSize(0,0);
tmpSize.iWidth = aRect.Width();
tmpSize.iHeight = aRect.Height()/2;
TRect upRect(aRect.iTl,tmpSize);
TRect downRect(TPoint(aRect.iTl.iX,aRect.iTl.iY + aRect.Height()/2),tmpSize);
ColorUtils::CreateGradientBitmapL(*fbsBitmap,CEikonEnv::Static()->WsSession(),brushWidth,bitmapOrientation, startColor, endColor);
#ifndef __S60_V3__
fbsBitmap->SetDisplayMode(EColor64K);
#endif
aGc.DrawBitmap(upRect,fbsBitmap);
ColorUtils::CreateGradientBitmapL(*fbsBitmap,CEikonEnv::Static()->WsSession(),brushWidth,bitmapOrientation, endColor, startColor);
#ifndef __S60_V3__
fbsBitmap->SetDisplayMode(EColor64K);
#endif
aGc.DrawBitmap(downRect,fbsBitmap);
}
break;
case EHToMidGradient:
{
brushWidth=aRect.Width()/2;
bitmapOrientation=ColorUtils::EBitmapOrientationHorizontal;
TSize tmpSize(0,0);
tmpSize.iWidth = aRect.Width()/2;
tmpSize.iHeight = aRect.Height();
TRect leftRect(aRect.iTl,tmpSize);
TRect RightRect(TPoint(aRect.iTl.iX + aRect.Width()/2,aRect.iTl.iY),tmpSize);
ColorUtils::CreateGradientBitmapL(*fbsBitmap,CEikonEnv::Static()->WsSession(),brushWidth,bitmapOrientation, startColor, endColor);
#ifndef __S60_V3__
fbsBitmap->SetDisplayMode(EColor64K);
#endif
aGc.DrawBitmap(leftRect,fbsBitmap);
ColorUtils::CreateGradientBitmapL(*fbsBitmap,CEikonEnv::Static()->WsSession(),brushWidth,bitmapOrientation, endColor, startColor);
#ifndef __S60_V3__
fbsBitmap->SetDisplayMode(EColor64K);
#endif
aGc.DrawBitmap(RightRect,fbsBitmap);
}
break;
}
delete fbsBitmap;
}
void CBasicEngine::DrawGradientL(CBitmapContext &aGc,const TRect &aRect,TRgb aStartColor,TRgb aEndColor,
const TGradientDirection &aGradientDirection)
{
CFbsBitmap* fbsBitmap=new(ELeave)CFbsBitmap;
TRgb startColor=aStartColor;
TRgb endColor=aEndColor;
TInt brushWidth = 0;
ColorUtils::TBitmapOrientation bitmapOrientation;
switch(aGradientDirection)
{
case EVerticalGradient:
{
brushWidth=aRect.Height();
bitmapOrientation=ColorUtils::EBitmapOrientationVertical;
ColorUtils::CreateGradientBitmapL(*fbsBitmap,CEikonEnv::Static()->WsSession(),brushWidth,bitmapOrientation, startColor, endColor);
#ifndef __S60_V3__
fbsBitmap->SetDisplayMode(EColor64K);
#endif
aGc.DrawBitmap(aRect,fbsBitmap);
}
break;
case EHorizontalGradient:
{
brushWidth=aRect.Width();
bitmapOrientation=ColorUtils::EBitmapOrientationHorizontal;
ColorUtils::CreateGradientBitmapL(*fbsBitmap,CEikonEnv::Static()->WsSession(),brushWidth,bitmapOrientation, startColor, endColor);
#ifndef __S60_V3__
fbsBitmap->SetDisplayMode(EColor64K);
#endif
aGc.DrawBitmap(aRect,fbsBitmap);
}
break;
case EVToMidGradient:
{
brushWidth=aRect.Height()/2;
bitmapOrientation=ColorUtils::EBitmapOrientationVertical;
TSize tmpSize(0,0);
tmpSize.iWidth = aRect.Width();
tmpSize.iHeight = aRect.Height()/2;
TRect upRect(aRect.iTl,tmpSize);
TRect downRect(TPoint(aRect.iTl.iX,aRect.iTl.iY + aRect.Height()/2),tmpSize);
ColorUtils::CreateGradientBitmapL(*fbsBitmap,CEikonEnv::Static()->WsSession(),brushWidth,bitmapOrientation, startColor, endColor);
#ifndef __S60_V3__
fbsBitmap->SetDisplayMode(EColor64K);
#endif
aGc.DrawBitmap(upRect,fbsBitmap);
ColorUtils::CreateGradientBitmapL(*fbsBitmap,CEikonEnv::Static()->WsSession(),brushWidth,bitmapOrientation, endColor, startColor);
#ifndef __S60_V3__
fbsBitmap->SetDisplayMode(EColor64K);
#endif
aGc.DrawBitmap(downRect,fbsBitmap);
}
break;
case EHToMidGradient:
{
brushWidth=aRect.Width()/2;
bitmapOrientation=ColorUtils::EBitmapOrientationHorizontal;
TSize tmpSize(0,0);
tmpSize.iWidth = aRect.Width()/2;
tmpSize.iHeight = aRect.Height();
TRect leftRect(aRect.iTl,tmpSize);
TRect RightRect(TPoint(aRect.iTl.iX + aRect.Width()/2,aRect.iTl.iY),tmpSize);
ColorUtils::CreateGradientBitmapL(*fbsBitmap,CEikonEnv::Static()->WsSession(),brushWidth,bitmapOrientation, startColor, endColor);
#ifndef __S60_V3__
fbsBitmap->SetDisplayMode(EColor64K);
#endif
aGc.DrawBitmap(leftRect,fbsBitmap);
ColorUtils::CreateGradientBitmapL(*fbsBitmap,CEikonEnv::Static()->WsSession(),brushWidth,bitmapOrientation, endColor, startColor);
#ifndef __S60_V3__
fbsBitmap->SetDisplayMode(EColor64K);
#endif
aGc.DrawBitmap(RightRect,fbsBitmap);
}
break;
}
delete fbsBitmap;
}
void CBasicEngine::DrawBmpL(CWindowGc &aGc,const TDesC &aMbmPath,const TInt &aBmpId,const TInt &aBmpMaskId,const TRect &aDestRect)
{
TFileName fileName(aMbmPath);
CompleteWithAppPath(fileName);
CFbsBitmap* iBmp = new (ELeave) CFbsBitmap();
CleanupStack::PushL(iBmp);
CFbsBitmap* iBmpMask = new (ELeave) CFbsBitmap();
CleanupStack::PushL(iBmpMask);
User::LeaveIfError(iBmp ->Load(fileName,aBmpId));
User::LeaveIfError(iBmpMask ->Load(fileName,aBmpMaskId));
// 不带缩放
// aGc.BitBltMasked(aDestRect.iTl, iBmp, TRect(iBmp->SizeInPixels()), iBmpMask, ETrue);
// 带缩放
aGc.DrawBitmapMasked(aDestRect, iBmp, TRect(iBmp->SizeInPixels()), iBmpMask, ETrue);
CleanupStack::PopAndDestroy(iBmpMask);
CleanupStack::PopAndDestroy(iBmp);
}
void CBasicEngine::DrawBmpL(CBitmapContext &aGc,const TDesC &aMbmPath,const TInt &aBmpId,const TInt &aBmpMaskId,const TRect &aDestRect)
{
TFileName fileName(aMbmPath);
CompleteWithAppPath(fileName);
CFbsBitmap* iBmp = new (ELeave) CFbsBitmap();
CleanupStack::PushL(iBmp);
CFbsBitmap* iBmpMask = new (ELeave) CFbsBitmap();
CleanupStack::PushL(iBmpMask);
User::LeaveIfError(iBmp ->Load(fileName,aBmpId));
User::LeaveIfError(iBmpMask ->Load(fileName,aBmpMaskId));
// 不带缩放
// aGc.BitBltMasked(aDestRect.iTl, iBmp, TRect(iBmp->SizeInPixels()), iBmpMask, EFalse);
// 带缩放
aGc.DrawBitmapMasked(aDestRect, iBmp, TRect(iBmp->SizeInPixels()), iBmpMask, ETrue);
CleanupStack::PopAndDestroy(iBmpMask);
CleanupStack::PopAndDestroy(iBmp);
}