fontsandtextmetricscontainer.cpp

来自「series60 应用程序开发的源代码 series60 应用程序开发的源代码」· C++ 代码 · 共 108 行

CPP
108
字号
/**
 * 
 * @brief Definition of CFontsAndTextMetricsContainer
 *
 * Copyright (c) EMCC Software Ltd 2003
 * @version 1.0
 */

// INCLUDE FILES

// Class includes
#include "FontsAndTextMetricsContainer.h"

// System includes
#include <aknutils.h>        // CEikonEnv iEikonEnv and AKN_LAF_COLOR
#include <FontsAndText.rsg>    // R_FONTSANDTEXT_LOCALIZATION_TEXT
#include <StringLoader.h>    // StringLoader

// CONSTANTS
const TInt KBaselineDivider = 2;
const TInt KColorBlack = 215;
const TInt KTextMaxLength = 50;

// ================= MEMBER FUNCTIONS =======================

/**
 * Symbian OS 2 phase constructor.
 * Constructs the CFontsAndTextMetricsContainer 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 CFontsAndTextMetricsContainer
 */
CFontsAndTextMetricsContainer* CFontsAndTextMetricsContainer::NewL(const TRect& aRect)
{
    CFontsAndTextMetricsContainer* self = CFontsAndTextMetricsContainer::NewLC(aRect);
    CleanupStack::Pop(self);
    return self;
}

/**
 * Symbian OS 2 phase constructor.
 * Constructs the CFontsAndTextMetricsContainer 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 CFontsAndTextMetricsContainer
 */
CFontsAndTextMetricsContainer* CFontsAndTextMetricsContainer::NewLC(const TRect& aRect)
{
    CFontsAndTextMetricsContainer* self = new (ELeave) CFontsAndTextMetricsContainer();
    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 CFontsAndTextMetricsContainer::ConstructL(const TRect& aRect)
{
    CreateWindowL();     
    SetRect(aRect);
    ActivateL();
}

/**
 * Destructor
 *
 */
CFontsAndTextMetricsContainer::~CFontsAndTextMetricsContainer()
{   
}

/**
 * This draw function obtains a handle to a graphics context and clears it.
 * Using the 'Title Font' of the system a text string is drawn
 * The position of the text in the center of the screen is derived from
 * a calculation using the metrics of the font.
 * 
 * @param aRect the rectangular area to draw in. Used to position text
 */
void CFontsAndTextMetricsContainer::Draw(const TRect& aRect) const
{
    CWindowGc& gc = SystemGc();
    gc.Clear();

    TRgb colorBlack = AKN_LAF_COLOR(KColorBlack);
    const CFont* titleFont = iEikonEnv->TitleFont();
    gc.UseFont(titleFont);    

    TInt baseline = (aRect.Height() / KBaselineDivider) + (titleFont->AscentInPixels() / KBaselineDivider); 
    gc.SetPenColor(colorBlack);

    // Use resource architecture to obtain localizable string
    TBuf<KTextMaxLength> text;
    StringLoader::Load(text, R_FONTSANDTEXT_LOCALIZATION_TEXT);

    gc.DrawText(text, aRect, baseline, CGraphicsContext::ECenter);
    gc.DiscardFont();
}


// End of File  

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?