📄 panes.cpp
字号:
// Panes.cpp: implementation of the CPanes class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
//【】#include "Test.h"
#include "Panes.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CPanes::~CPanes()
{
}
CPanes::CPanes()
{
}
CPanes::CPanes(CDialog *pDlg,int x0, int y0, int row,int col,int height,int width,
COLORREF panesBkColor,COLORREF borderColor,COLORREF paneFillColor,COLORREF paneNullColor,
int ppDistance, CString title
){
this->pDlg=pDlg;
this->x0=x0;
this->y0=y0;
this->row=row;
this->col=col;
this->height=height;
this->width=width;
x1=x0+col*width;
y1=y0+row*height;
this->panesBkColor=panesBkColor;
this->borderColor=borderColor;
this->paneFillColor=paneFillColor;
this->paneNullColor=paneNullColor;
this->ppDistance=ppDistance;
this->title=title;
this->sample="";
int i,j;
table= (int**) calloc(row, sizeof(int*));
for (i=0; i<row; i++) {
table[i]=(int*) calloc(col, sizeof(int));
}
for(i=0; i<row; i++){
for(j=0; j<row; j++){
table[i][j]=-1;
}
}
pDC=pDlg->GetDC();
penBorder.CreatePen(PS_COSMETIC,1,borderColor);
pPen=pDC->SelectObject(&penBorder);
pBrushPanes=new CBrush( panesBkColor );
pBrushPaneFill=new CBrush( paneFillColor );
pBrushPaneNull=new CBrush( paneNullColor );
font.CreatePointFont(1,"宋体");
pFont=pDC->SelectObject(&font);
bDrawing=false;
}
int CPanes::DRAW_SAMPLE=1;
void CPanes::Draw(int drawPart){
if(drawPart==DRAW_SAMPLE){
CFont font,*pFont;
//font.CreatePointFont(1, "宋体");
font.CreateFont( /*int nHeight*/sampleLfheight, /*int nWidth*/sampleLfwidth,
/*int nEscapement*/0, /*int nOrientation*/1, /*int nWeight*/FW_NORMAL,
/*BYTE bItalic*/0, /*BYTE bUnderline*/0, /*BYTE cStrikeOut*/0,
/*BYTE nCharSet*/DEFAULT_CHARSET, /*BYTE nOutPrecision*/700,
/* BYTE nClipPrecision*/100, /*BYTE nQuality*/0 ,
/*BYTE nPitchAndFamily*/DEFAULT_PITCH,
/*LPCTSTR lpszFacename*/sampleFont );
pFont=pDC->SelectObject(&font);
pDC->SetTextColor(sampleColor);
pDC->SetBkColor(sampleBkColor);
pDC->TextOut(sampleX0,sampleY0,sample);
pDC->SelectObject(pFont);
}
int i,j;
pDC->SetBkColor(RGB(0x0,0x4d,0x99));
pDC->SetTextColor(RGB(0xff,0xff,0x00));
//画边框
if(title!="")
pDC->TextOut(x0,y0-17,title);
pDC->FillRect(CRect(x0,y0,x1,y1),pBrushPanes);
//画边界
for(i=0; i<=row; i++){
pDC->MoveTo(x0,y0+i*height);
pDC->LineTo(x1,y0+i*height);
}
for(j=0; j<=col; j++){
pDC->MoveTo(x0+j*width,y0);
pDC->LineTo(x0+j*width,y1);
}
//画掩膜
for(i=0; i<row; i++){
for(j=0; j<col; j++){
if(table[i][j]==1)
pBrush=pBrushPaneFill;
else
pBrush=pBrushPaneNull;
pDC->FillRect(
CRect(x0+j*width+ppDistance,y0+i*height+ppDistance,
x0+(j+1)*width,y0+(i+1)*height),
pBrush);
}
}
}
void CPanes::Draw(int r,int c,int bin){
table[r][c]=bin;
if(table[r][c]==1)
pBrush=pBrushPaneFill;
else
pBrush=pBrushPaneNull;
pDC->FillRect(
CRect(x0+c*width+ppDistance,y0+r*height+ppDistance,
x0+(c+1)*width,y0+(r+1)*height),
pBrush);
}
void CPanes::DoLButtonDown(CPoint point){
if(point.x<x0 || point.x>=x1 || point.y<y0 || point.y>=y1){
return;
}
bDrawing=true;
int r,c;
r=(point.y-y0)/height;
c=(point.x-x0)/width;
if(table[r][c]==1)
return;
table[r][c]=1;
pDC->FillRect(
CRect(x0+c*width+ppDistance,y0+r*height+ppDistance,
x0+(c+1)*width,y0+(r+1)*height),
pBrushPaneFill);
}
void CPanes::DoMouseMove(CPoint point){
if(point.x<x0 || point.x>=x1 || point.y<y0 || point.y>=y1){
bDrawing=false;
}
if(!bDrawing)
return;
int r,c;
r=(point.y-y0)/height;
c=(point.x-x0)/width;
if(table[r][c]==1)
return;
table[r][c]=1;
pDC->FillRect(
CRect(x0+c*width+ppDistance,y0+r*height+ppDistance,
x0+(c+1)*width,y0+(r+1)*height),
pBrushPaneFill);
}
void CPanes::DoLButtonUp(CPoint point){
bDrawing=false;
}
void CPanes::Clear(){
int i,j;
for(i=0; i<row; i++){
for(j=0; j<col; j++){
table[i][j]=-1;
}
}
Draw();
}
void CPanes::ToFile(CString fileName, CString sBlank){
int i,j;
CString sBin,s;
s.Format("%d行×%d列\n",row,col);
sBin+=s;
for(i=0; i<row; i++){
for(j=0; j<col; j++){
s.Format("%d,\t",table[i][j]);
sBin+=s;
}
sBin+="\n";
}
CStdioFile out;
out.Open(fileName, CFile::modeCreate | CFile::modeWrite);
out.WriteString(sBin);
out.Close();
}
void CPanes::Get(int p[]){
int i,j;
for(i=0; i<row; i++){
for(j=0; j<col; j++){
p[i*col+j]=table[i][j];
}
}
}
void CPanes::Get(int **p){
int i,j;
for(i=0; i<row; i++){
for(j=0; j<col; j++){
p[i][j]=table[i][j];
}
}
}
void CPanes::Fill(int p[]){
int i,j;
for(i=0; i<row; i++){
for(j=0; j<col; j++){
table[i][j]=p[i*col+j];
}
}
Draw();
}
void CPanes::Fill(int **p){
int i,j;
for(i=0; i<row; i++){
for(j=0; j<col; j++){
table[i][j]=p[i][j];
}
}
Draw();
}
void CPanes::SetSample( CString sample,
int sampleX0,int sampleY0,
CString sampleFont,
COLORREF sampleBkColor,COLORREF sampleColor){
this->sample=sample;
this->sampleBkColor=sampleBkColor;
this->sampleColor=sampleColor;
this->sampleFont=sampleFont;
this->sampleLfheight=row;
this->sampleLfwidth=9;col;
this->sampleX0=sampleX0;
this->sampleY0=sampleY0;
Draw(DRAW_SAMPLE);
}
void CPanes::GetSample(int x,int y){
int i,j;
samplePixels= (int**) calloc(row, sizeof(int*));
for (i=0; i<row; i++) {
samplePixels[i]=(int*) calloc(col, sizeof(int));
}
for(i=0; i<row; i++){
for(j=0; j<col; j++){
if(pDC->GetPixel(x+j,y+i)==sampleColor){
samplePixels[i][j]=1;
}
else{
samplePixels[i][j]=-1;
}
}
}
}
void CPanes::FillSample(int x,int y){
this->GetSample(x,y);
this->Fill(samplePixels);
}
void CPanes::useFuncPoint(void (*pFunc)()){
if(pFunc==NULL)
::AfxMessageBox("函数的函数参数为空!");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -