markablegridgamesgrid.cpp

来自「最新官方例子,图形,描述副,基本控件,通讯协议,等等,」· C++ 代码 · 共 172 行

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

// INCLUDE FILES

// Class include
#include "MarkableGridGamesGrid.h"

// System includes
#include <akniconarray.h> // CAknIconArray
#include <aknlists.h> // AknListBoxLayouts
#include <barsread.h> // TResourceReader
#include <markablegrid.rsg> // R_MARKABLEGRID_MARK_ON_VALUE
#include <markablegrid.mbg> // contains icon enumeration
#include <stringloader.h> // StringLoader

// CONSTANTS
const TInt KNumberOfIcons(7);
const TInt KGraphicsHeight = 50;
const TInt KMarkHeight = 20;
const TInt KTextColor = 215;

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

/**
* Symbian OS 2nd phase constructor.  Constructs the grd from aGridResource
* sets up the icons container in the file in aIconFileResource and draws itself.
* @param aGridResource The GRID resource
* @param aIconFileResource The resource defining the icon file name
*/		
void CMarkableGridGamesGrid::ConstructL(TInt aGridResource, TInt aIconFileResource)
	{
	// Construct the grid from resource
	TResourceReader reader;
	CEikonEnv::Static()->CreateResourceReaderLC(reader, aGridResource);
	ConstructFromResourceL(reader);
	CleanupStack::PopAndDestroy(); // reader
	
	// Set up the icons
	SetupGridIconsL (aIconFileResource);

	// Layout the grid
	SizeChanged();
	}


/**
*	
* Sets up the grid's icons, which are contained in a file.
*
* @param aIconFileResource the file name resource
*/
void CMarkableGridGamesGrid::SetupGridIconsL(TInt aIconFileResource)
	{
	// Get the name of the file containing the icons	
	HBufC* iconFileName;
	iconFileName = StringLoader::LoadLC(aIconFileResource); // Pushes iconFileName onto the Cleanup Stack.
	
	// Create an array of icons, reading them from the file
	CArrayPtr<CGulIcon>* icons = new(ELeave) CAknIconArray(KNumberOfIcons);
	CleanupStack::PushL(icons);
	icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmMarkablegridMarkon, EMbmMarkablegridMark_mask));
	icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmMarkablegridMarkoff, EMbmMarkablegridMark_mask));
	icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmMarkablegridSnap, EMbmMarkablegridCard_mask));
	icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmMarkablegridGolf, EMbmMarkablegridCard_mask));
	icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmMarkablegridClock, EMbmMarkablegridCard_mask));
	icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmMarkablegridAces, EMbmMarkablegridCard_mask));
	icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmMarkablegridHearts, EMbmMarkablegridCard_mask));
	icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmMarkablegridRummy, EMbmMarkablegridCard_mask));
	icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmMarkablegridPoker, EMbmMarkablegridCard_mask));
	CleanupStack::Pop(icons);
	CleanupStack::PopAndDestroy(iconFileName);
	
	ItemDrawer()->FormattedCellData()->SetIconArray(icons); // passing ownership of icons
	
	}

/**
*	
* Sets up colors, and subcells for the grid.
*
*/
void CMarkableGridGamesGrid::SetupGrid()
	{

		// Setup text foreground and background colours to default
	AknListBoxLayouts::SetupStandardGrid(*this);

	// Get local copies of data we will need	
	CFormattedCellListBoxItemDrawer* itemDrawer = this->ItemDrawer();
	TInt cellWidth = ColumnWidth();
	TInt cellHeight = ItemHeight();
	
	// Set up graphics subcells
	AknListBoxLayouts::SetupFormGfxCell(*this,	//the grid
		itemDrawer, // the grid's drawer
		0, // index of the graphic within item strings
		0, // left position
		0, // top position
		0, // right - unused
		0, // bottom - unused
		cellWidth, // width of graphic
		KGraphicsHeight, // height of graphic
		TPoint (0, 0), // start position
		TPoint (cellWidth , KGraphicsHeight)); // end position
	
	// Set up text subcells
	const CFont* KFont = LatinBold12();
	TInt baseline = cellHeight - KMarkHeight - KFont->DescentInPixels() - 1;
	
	AknListBoxLayouts::SetupFormTextCell(
		*this, // the grid
		itemDrawer, // the grid's drawer
		1, // index of text within item strings
		KFont, // the font for the text
		KTextColor, // the color of the text - N.B. although commented out in the header file, this is still used!
		0, // left margin
		0, // right margin - unused
		baseline, // Baseline
		cellWidth, // text width (would need to take margin into account if set, i.e. - lm)
		CGraphicsContext::ECenter, // Alignment
		TPoint (0, KGraphicsHeight), // start position
		TPoint(cellWidth, cellHeight - KMarkHeight)); // end position
	
	
	// Set up mark graphics subcells
	AknListBoxLayouts::SetupFormGfxCell(
		*this,	//the grid
		itemDrawer, // the grid's drawer
		2, // index of the graphic within item strings
		0, // left position
		cellHeight - KMarkHeight, // top position
		0, // right - unused
		0, // bottom - unused
		cellWidth, // width of graphic
		KMarkHeight, // height of graphic
		TPoint (0, cellHeight - KMarkHeight), // start position
		TPoint (cellWidth , cellHeight)); // end position
	
	itemDrawer->SetItemMarkPosition(2); // position in item strings of the mark icon	
	if (!iMarkOnValue)
		iMarkOnValue = StringLoader::LoadL(R_MARKABLEGRID_MARK_ON_VALUE);
	itemDrawer->SetItemMarkReplacement(*iMarkOnValue); // the index of the mark on icon
	itemDrawer->SetItemMarkReverse(ETrue); // Don't display all items as marked initially
	}


/**
*	
* Called by framework when the view size is changed and by ConstructL to intialise the grid.  
*
*/
void CMarkableGridGamesGrid::SizeChanged()
	{
	CAknGrid::SizeChanged();

	SetupGrid();
	}


CMarkableGridGamesGrid::~CMarkableGridGamesGrid()
	{
	delete iMarkOnValue;
	}

// End of File	

⌨️ 快捷键说明

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