fontsandtexteffectscontainer.cpp
来自「series60 应用程序开发的源代码 series60 应用程序开发的源代码」· C++ 代码 · 共 154 行
CPP
154 行
/**
*
* @brief Definition of CFontsAndTextEffectsContainer
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
// INCLUDE FILES
// Class includes
#include "FontsAndTextEffectsContainer.h"
// System includes
#include <eikenv.h> // CEikonEnv iEikonEnv and AKN_LAF_COLOR
#include <fontsandtext.rsg> // R_FONTSANDTEXT_LOCALIZATION_TEXT
#include <StringLoader.h> // StringLoader
// CONSTANTS
const TInt KTextMaxLength = 50;
const TInt KLeftTextHorizAlign = 10;
const TInt KLeftTextVertAlign = 7;
const TReal KRightTextHorizAlign = 0.95;
const TReal KRightTextVertAlign = 0.9;
const TInt KMiddleTextOneHorizAlign = 4;
const TInt KMiddleTextOneVertAlign = 3;
const TInt KMiddleTextTwoVertAlign = 2;
const TReal KMiddleTextThreeVertAlign = 1.5;
const TInt KColorBlue = 210;
const TInt KColorRed = 35;
const TInt KColorGreen = 185;
// ================= MEMBER FUNCTIONS =======================
/**
* Symbian OS 2 phase constructor.
* Constructs the CFontsAndTextEffectsContainer using the NewLC method, popping
* the constructed object from the CleanupStack before returning it.
*
* @param aRect The rectangle for this window
* @return The newly constructed CFontsAndTextEffectsContainer
*/
CFontsAndTextEffectsContainer* CFontsAndTextEffectsContainer::NewL(const TRect& aRect)
{
CFontsAndTextEffectsContainer* self = CFontsAndTextEffectsContainer::NewLC(aRect);
CleanupStack::Pop(self);
return self;
}
/**
* Symbian OS 2 phase constructor.
* Constructs the CFontsAndTextEffectsContainer using the constructor and ConstructL
* method, leaving the constructed object on the CleanupStack before returning it.
*
* @param aRect The rectangle for this window
* @return The newly constructed CFontsAndTextEffectsContainer
*/
CFontsAndTextEffectsContainer* CFontsAndTextEffectsContainer::NewLC(const TRect& aRect)
{
CFontsAndTextEffectsContainer* self = new (ELeave) CFontsAndTextEffectsContainer();
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
/**
* Symbian OS 2nd phase constructor. Creates a Window for the control to draw to.
* Activates the control
* @param aRect The rectangle for this window
*/
void CFontsAndTextEffectsContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
SetRect(aRect);
ActivateL();
}
/**
* Destructor.
*/
CFontsAndTextEffectsContainer::~CFontsAndTextEffectsContainer()
{
}
/**
* This draw function illustrates many of the effects that can be applied
* to text when drawing it. Examples include underlining, strikethrough and vertically
* oriented text.
*
* @param aRect The rectangular area to be drawn to
*/
void CFontsAndTextEffectsContainer::Draw(const TRect& aRect) const
{
// Clear the graphics context.
CWindowGc& gc = SystemGc();
gc.Clear();
// Setup some colours.
TRgb colorBlue = AKN_LAF_COLOR(KColorBlue);
TRgb colorRed = AKN_LAF_COLOR(KColorRed);
TRgb colorGreen = AKN_LAF_COLOR(KColorGreen);
// Use resource architecture to obtain localizable string
TBuf<KTextMaxLength> text;
StringLoader::Load(text, R_FONTSANDTEXT_LOCALIZATION_TEXT);
// Draw black vertical text in title font.
const CFont* font = iEikonEnv->TitleFont();
TPoint textPoint(aRect.Width() / KLeftTextHorizAlign, aRect.Height() / KLeftTextVertAlign);
gc.UseFont(font);
gc.SetPenColor(KRgbBlack);
gc.DrawTextVertical(text, textPoint, EFalse);
gc.DiscardFont();
// Draw black vertical text in annotation font.
font = iEikonEnv->AnnotationFont();
textPoint.SetXY((TInt)(aRect.Width() * KRightTextHorizAlign), (TInt)(aRect.Height() * KRightTextVertAlign));
gc.UseFont(font);
gc.DrawTextVertical(text, textPoint, ETrue);
gc.DiscardFont();
// Draw green strikethrough text in symbol font
font = iEikonEnv->SymbolFont();
textPoint.SetXY(aRect.Width() / KMiddleTextOneHorizAlign, aRect.Height() / KMiddleTextOneVertAlign);
gc.UseFont(font);
gc.SetPenColor(colorGreen);
gc.SetStrikethroughStyle(EStrikethroughOn);
gc.DrawText(text, textPoint);
gc.SetStrikethroughStyle(EStrikethroughOff);
gc.DiscardFont();
// Draw blue underlined text in legend font
font = iEikonEnv->LegendFont();
textPoint.iY = (aRect.Height() / KMiddleTextTwoVertAlign);
gc.UseFont(font);
gc.SetPenColor(colorBlue);
gc.SetUnderlineStyle(EUnderlineOn);
gc.DrawText(text, textPoint);
gc.SetUnderlineStyle(EUnderlineOff);
gc.DiscardFont();
// Draw red text in dense font.
font = iEikonEnv->DenseFont();
textPoint.iY = (TInt)(aRect.Height() / KMiddleTextThreeVertAlign);
gc.UseFont(font);
gc.SetPenColor(colorRed);
gc.DrawText(text, textPoint);
gc.DiscardFont();
}
// End of File
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?