📄 block.cpp
字号:
// BlockDialog.cpp : implementation file
//
#include "stdafx.h"
#include "draw.h"
#include "drawdoc.h"
#include "drawview.h"
#include "Block.h"
#include "tag.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// BlockDialog dialog
extern int nCharHeight,nCharWidth;
extern CDrawView *p_View;
//类的构造函数
//参数:pDoc-指向当前文档对象的指针;
// BlockIndex-当前选择的图形块的序号;
// bModify-识别是否能够在对话框中修改图形块1-正常操作0-只能从对话框中选择图形块
BlockDialog::BlockDialog(CDrawDoc* p_Doc,int BlockIndex,BOOL bModify,CWnd* pParent /*=NULL*/)
: CDialog(BlockDialog::IDD, pParent)
{
pDoc=p_Doc;
int nn=pDoc->GetBlockUpperbound();
n_Block=0;
m_BlockIndex=BlockIndex;
m_bModify=bModify;
m_BlockIndex1=-1;
for(int i=0;i<nn;i++) //得到各个图形块在对象数组中存储的序号
{
if(pDoc->GetBlock(i))
{
if(m_BlockIndex==i)
m_BlockIndex1=n_Block; //得到选中的图例的序号
Index[n_Block++]=i;
}
}
//{{AFX_DATA_INIT(BlockDialog)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void BlockDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(BlockDialog)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
//设置对话框中按钮的状态
void BlockDialog::OnUpdate1(CCmdUI* pCmdUI)
{
if(m_bModify&&m_BlockIndex1>=0) //如果能够修改图形块并且选中了图形块
pCmdUI->Enable(TRUE);
else //如果没有选中图形块或者不能进行修改操作
pCmdUI->Enable(FALSE);
}
//制作新图形块
void BlockDialog::OnBlockNew()
{
map.DeleteObject(); //删除存储的图象
m_BlockIndex=Index[m_BlockIndex1];
EndDialog(ID_BLOCK_NEW);
}
//修改既有图形块
void BlockDialog::OnBlockModify()
{
map.DeleteObject();
m_BlockIndex=Index[m_BlockIndex1];
EndDialog(IDD_BLOCK_MODIFY);
}
//对话框的绘制函数,绘制对话框中的各个图形块
void BlockDialog::draw()
{
int i;
CPaintDC ddd(this);
CPen pen(0,1,RGB(255,128,0));
CPen *pOldPen;
pOldPen=ddd.SelectObject(&pen);
ddd.SetBkMode(TRANSPARENT);
ddd.SetROP2(R2_COPYPEN);
POINT bc1[4];
if(b_DrawAllBlock==1||b_DrawSelectBlock==1)
{
bc1[0].x=-2;
bc1[0].y=-2;
bc1[1].x=rectwidth*10;
bc1[1].y=-2;
bc1[2].x=rectwidth*10;
bc1[2].y=rectheight*10;
bc1[3].x=-2;
bc1[3].y=rectheight*10;
for(i=0;i<6;i++) //绘制各个对话框中的方格
{
ddd.MoveTo((i+1)*rectwidth,0);
ddd.LineTo((i+1)*rectwidth,6*rectheight);
ddd.MoveTo(0,(i+1)*rectheight);
ddd.LineTo(rectwidth*6,(i+1)*rectheight);
}
}
ddd.SelectObject(pOldPen);
draw1(); //绘制各个图形块
}
//绘制图形块
void BlockDialog::draw1()
{
int i,i1,i2;
CClientDC ddd(this);
if(b_DrawAllBlock==1) //如果绘制所有的图形块
{
SetCapture();
SetCursor(LoadCursor(NULL,IDC_WAIT));
for(i=0;i<n_Block;i++) //绘制各个图形块
{
i1=(i-1)/10;
i2=i-i1*10;
pDoc->GetBlock(Index[i])->Draw1(&ddd,i2*rectwidth,i1*rectheight,rectwidth,rectheight,rectheight*10,0,0);
}
SetCursor(LoadCursor(NULL,IDC_ARROW));
ReleaseCapture();
b_DrawAllBlock=0;
}
if(m_BlockIndex1>=0) //反色显示选中的图形块
{
i1=m_BlockIndex1/10;
i2=m_BlockIndex1-i1*10;
r1.top=i1*rectheight;
r1.bottom=i1*rectheight+rectheight;
r1.left=i2*rectwidth;
r1.right=i2*rectwidth+rectwidth;
ddd.InvertRect(r1);
}
}
/*void BlockDialog::OnBlockDelete() //删除图例快
{
// 暂不进行删除图形块操作
}*/
//保存对图形块的选择退出对话框
void BlockDialog::OnOk()
{
map.DeleteObject();
m_BlockIndex=Index[m_BlockIndex1];
EndDialog(IDOK);
}
//放弃退出对话框
void BlockDialog::OnCancel()
{
map.DeleteObject();
EndDialog(IDCANCEL);
}
//
void BlockDialog::InitNamesLst()
{
b_DrawAllBlock=1;
if(m_BlockIndex1>=0)
b_DrawSelectBlock=1;
else
b_DrawSelectBlock=0;
UpdateDialogControls(this,TRUE);
}
//初始化函数
BOOL BlockDialog::OnInitDialog()
{
CClientDC ddd(this);
CRgn rgn;
int i;
CButton* pbut;
//以下设置对话框中各按钮的状态
pbut=(CButton *)GetDlgItem(IDD_BLOCK_NEW);
pbut->EnableWindow(m_bModify);
//pbut=(CButton *)GetDlgItem(IDD_BLOCK_DELETE);
pbut->EnableWindow(m_bModify);
pbut=(CButton *)GetDlgItem(IDD_BLOCK_MODIFY);
pbut->EnableWindow(m_bModify);
rectwidth=40*nCharWidth/7; //得到每个方格的宽度
rectheight=40*nCharHeight/16; //得到每个方格的高度
POINT bb[4];
b_RestoreBmp=0;
bb[0].x=0;
bb[0].y=0;
bb[1].x=0;
bb[1].y=rectheight*10-1;
bb[2].x=rectwidth*10-1;
bb[2].y=rectheight*10-1;
bb[3].x=rectwidth*10-1;
bb[3].y=0;
rgn.CreatePolygonRgn(bb,4,0);
//以下创建一个位图对象,用来把显示图形块的区域保存(用来在全屏显示一个图形块后,快速恢复屏幕)
i=map.CreateCompatibleBitmap(&ddd,rectwidth*10,rectheight*10);
if(i!=0)
{
b_RestoreBmp=1;
pDc.CreateCompatibleDC(&ddd);
pDc.SelectObject(&map);
}
InitNamesLst();
return TRUE;
}
//按下鼠标左键的消息处理函数
void BlockDialog::OnLButtonDown(UINT nFlags,CPoint point)
{
int i,j,ii;
int OldIndex;
CClientDC ddd(this);
r1.left=0;
r1.bottom=0;
r1.right=rectwidth*10;
r1.top=rectheight*10;
if(point.x>rectwidth*10||point.x<0||point.y<0||point.y>rectheight*10)
return;
if(b_DrawZoom==1) //如果当前屏幕上正在全屏显示一个图形块
{
b_DrawZoom=0;
b_DrawAllBlock=1;
b_DrawSelectBlock=0;
if(b_RestoreBmp==1) //如果原来的屏幕存在位图对象中
ddd.StretchBlt(0,0,rectwidth*10,rectheight*10,&pDc,0,0,rectwidth*10,rectheight*10,SRCCOPY);
else //否则,重画视图
Invalidate();
return;
}
i=point.y/rectheight*10+point.x/rectwidth;
if(i>=n_Block)
return;
if(i==m_BlockIndex1) //如果点中的是已经点中的图形块,则全屏显示这个图形块
{
b_DrawZoom=1;
b_DrawSelectBlock=0;
b_DrawAllBlock=0;
if(b_RestoreBmp==1)
pDc.BitBlt(0,0,rectwidth*10,rectheight*10,&ddd,0,0,SRCCOPY);
ddd.PatBlt(0,0,rectwidth*10,rectheight*10,0);
pDoc->GetBlock(Index[i])->Draw1(&ddd,0,0,10*rectwidth,10*rectheight,rectheight*10,0,0);
}
else //点中的是另外一个图形块
{
//
OldIndex=m_BlockIndex1;
//以下将点中的图形块反色显示
m_BlockIndex1=i;
b_DrawSelectBlock=1;
b_DrawAllBlock=0;
b_DrawZoom=0;
j=(i)/10;
ii=i-j*10;
r1.top=j*rectheight;
r1.bottom=j*rectheight+rectheight;
r1.left=ii*rectwidth;
r1.right=ii*rectwidth+rectwidth;
ddd.InvertRect(r1);
if(OldIndex>=0) //以下将原来点中的图形块反色显示(去掉原来的反色显示)
{
j=(OldIndex)/10;
ii=OldIndex-j*10;
r1.top=j*rectheight;
r1.bottom=j*rectheight+rectheight;
r1.left=ii*rectwidth;
r1.right=ii*rectwidth+rectwidth;
ddd.InvertRect(r1);
}
}
UpdateDialogControls(this,TRUE);
}
BEGIN_MESSAGE_MAP(BlockDialog, CDialog)
//{{AFX_MSG_MAP(BlockDialog)
//ON_UPDATE_COMMAND_UI(ID_BLOCK_DELETE,OnUpdate1)
ON_UPDATE_COMMAND_UI(IDD_BLOCK_MODIFY,OnUpdate1)
ON_BN_CLICKED(IDOK,OnOk)
ON_BN_CLICKED(IDCANCEL,OnCancel)
ON_BN_CLICKED(IDD_BLOCK_NEW,OnBlockNew)
// ON_BN_CLICKED(IDD_BLOCK_DELETE,OnBlockDelete)
ON_BN_CLICKED(IDD_BLOCK_MODIFY,OnBlockModify)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// BlockDialog message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -