📄 basicdrawingcontainer.cpp
字号:
/**
*
* @brief Definition of CBasicDrawingContainer
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
// INCLUDE FILES
// Class includes
#include "BasicDrawingContainer.h"
// System includes
#include <eikenv.h> // AKN_LAF_COLOR
//CONSTANTS
// Color Constants
const TInt KColorBlue = 210;
const TInt KColorRed = 35;
const TInt KColorGreen = 185;
const TInt KColorYellow = 5;
// Point Constants
const TInt KPoint1Begin = 10;
const TInt KPoint1End = 40;
const TInt KPoint2Begin = 166;
const TInt KPoint2End = 40;
// For a TPoint use #define not const TPoint because of OS global data rules
#define KIncrementPoint TPoint(0, 15)
// Pen Size Constants
const TInt KPenSize = 2;
#define KIncrementPenSize TSize(2, 2)
// ================= MEMBER FUNCTIONS =======================
/**
* Symbian OS 2 phase constructor.
* Constructs the CBasicDrawingContainer 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 CBasicDrawingContainer
*/
CBasicDrawingContainer* CBasicDrawingContainer::NewL(const TRect& aRect)
{
CBasicDrawingContainer* self = CBasicDrawingContainer::NewLC(aRect);
CleanupStack::Pop(self);
return self;
}
/**
* Symbian OS 2 phase constructor.
* Constructs the CBasicDrawingContainer 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 CBasicDrawingContainer
*/
CBasicDrawingContainer* CBasicDrawingContainer::NewLC(const TRect& aRect)
{
CBasicDrawingContainer* self = new (ELeave) CBasicDrawingContainer();
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 CBasicDrawingContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
SetRect(aRect);
ActivateL();
}
/**
* Destructor
*/
CBasicDrawingContainer::~CBasicDrawingContainer()
{
}
/**
* The Draw() function of a CCoeControl is crucial to displaying graphics
* when using the application framework.
* This draw function obtains a handle to the System graphics context
* and draws a series of horizontal lines below each other and with
* increasing width.
* This function covers many of the basic aspects of the Series 60 graphics
* architecture, ranging from geometry to color.
*
* @param aRect The rectangular area to draw in (not used)
**/
void CBasicDrawingContainer::Draw(const TRect& /*aRect*/) const
{
// Get graphics context and clear it
CWindowGc& gc = SystemGc();
gc.Clear();
// Set up points and increment value for drawing
TPoint point1(KPoint1Begin, KPoint1End);
TPoint point2(KPoint2Begin, KPoint2End);
// Set up pen sizes for drawing
TSize penSize(KPenSize, KPenSize);
//Set up colors for drawing by using the AKN_LAF_COLOR() macro
TRgb colorBlue = AKN_LAF_COLOR(KColorBlue);
TRgb colorRed = AKN_LAF_COLOR(KColorRed);
TRgb colorGreen = AKN_LAF_COLOR(KColorGreen);
TRgb colorYellow = AKN_LAF_COLOR(KColorYellow);
// Set pen to be blue and solid. Then draw line
gc.SetPenColor(colorBlue);
gc.SetPenStyle(CGraphicsContext::ESolidPen); // make pen solid
gc.DrawLine(point1, point2);
// Draw Red Line (increase pen size and set pen to be dotted)
gc.SetPenColor(colorRed);
gc.SetPenStyle(CGraphicsContext::EDottedPen); // make pen dotted
gc.SetPenSize(penSize); // set pen size to (2, 2)
point1 += KIncrementPoint; // increment starting point of line
point2 += KIncrementPoint; // increment ending point of line
gc.DrawLine(point1, point2);
// Draw Green Line
gc.SetPenColor(colorGreen);
gc.SetPenStyle(CGraphicsContext::EDashedPen); // make pen dashed
penSize += KIncrementPenSize; // increase the size of the pen
gc.SetPenSize(penSize); // set pen size to that of incremented value
point1 += KIncrementPoint; // increment starting point of line
point2 += KIncrementPoint; // increment ending point of line
gc.DrawLine(point1, point2);
// Draw Yellow Line
gc.SetPenColor(colorYellow);
gc.SetPenStyle(CGraphicsContext::EDotDashPen); // make pen dot dashed
penSize += KIncrementPenSize; // increase the size of the pen
gc.SetPenSize(penSize); // set pen size to that of incremented value
point1 += KIncrementPoint; // increment starting point of line
point2 += KIncrementPoint; // increment ending point of line
gc.DrawLine(point1, point2);
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -