【VC开源代码栏目提醒】:网学会员为需要VC开源代码的朋友们搜集整理了DiamondShape.cpp相关资料,希望对各位网友有所帮助!
// DiamondShape.cpp: implementation of the CDiamondShape class.
//
// 本程序主要是CDiamondShape, CDiamondStatic;
// CDiamondShape是方块形状类。
// CDiamondStatic是方块窗口类,从CStatic继承的。
/////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CSDemo.h"
#include "DiamondShape.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//==================================================================
// 构造函数
// 形状ID、形状变形序号无效(-1)
// 位置上居中
//==================================================================
CDiamondShape::CDiamondShape()
{
m_nID = -1;
m_nShape = -1;
m_ptBase = CPoint( COL / 2 - 1, 0 );
}
//==================================================================
// Copy Construction
//==================================================================
CDiamondShape::CDiamondShape( const CDiamondShape &sp )
{
m_nID = sp.m_nID;
m_nShape = sp.m_nShape;
m_ptBase = sp.m_ptBase;
InitData();
for( int nIndex = 0; nIndex < 5; nIndex ++ )
m_crData[nIndex] = sp.m_crData[nIndex];
}
//==================================================================
// =重载
//==================================================================
CDiamondShape::operator =(const CDiamondShape &sp )
{
m_nID = sp.m_nID;
m_nShape = sp.m_nShape;
m_ptBase = sp.m_ptBase;
InitData();
for( int nIndex = 0; nIndex < 4; nIndex ++ )
m_crData[nIndex] = sp.m_crData[nIndex];
return 1;
}
//==================================================================
// 析构
//==================================================================
CDiamondShape::~CDiamondShape()
{
}
//==================================================================
// 画形状的一个Cell;
// ptLocal: 二维位置; cr: 颜色; bErase: 是否覆盖?
//==================================================================
void CDiamondShape::DrawCell( CDC *pDC, CPoint ptLocal, COLORREF cr, bool bErase/*= false*/ )
{
CPoint ptTL, ptBR;
int nCol, nRow;
nCol = ptLocal.x;
nRow = ptLocal.y;
ptTL.x = nCol * LEN;
ptTL.y = nRow * LEN;
ptBR.x = ptTL.x + LEN;
ptBR.y = ptTL.y + LEN;
CRect rtCell( ptTL, ptBR );
if( bErase )
pDC->FillRect( &rtCell, &CBrush(GetSysColor(COLOR_3DFACE)) );
else
{
ptTL.x ++;
ptTL.y ++;
ptBR.x --;
ptBR.y --;
rtCell.SetRect( ptTL, ptBR );
pDC->FillRect( &rtCell, &CBrush( cr ) );
CPen pnWhite( PS_SOLID, 1, RGB(255,255,255) );
CPen pnGray( PS_SOLID, 1, RGB(0,0,0) );
CPen *pOld = NULL;
pOld = pDC->SelectObject( &pnWhite );
pDC->MoveTo( ptTL.x, ptBR.y );
pDC->LineTo( ptTL );
pDC->LineTo( ptBR.x, ptTL.y );
pDC->SelectObject( &pnGray );
pDC->LineTo( ptBR );
pDC->LineTo( ptTL.x, ptBR.y );
pDC->SelectObject( pOld );
pnGray.DeleteObject();
pnWhite.DeleteObject();
}
}
//==================================================================
// 初始化形状数据。
// 保存在3 X 3的9个比特位中
//==================================================================
void CDiamondShape::InitData()
{
int nData[][4] = {
// { 000111000, 010010010, 000111000, 010010010 },
{ 0x038, 0x092, 0x038, 0x092 },
// { 010010011, 000111100, 110010010, 001111000 },
{ 0x093, 0x03c, 0x192, 0x078 },
// { 010010110, 100111000, 011010010, 0001110