📄 cursoreditordlg.cpp
字号:
ybottom=(m_pSelCur[i-startCurBuf].m_nRow+1)*multiple;
CRect picRect(xlef+1,ytop+1,xright,ybottom);
cpDC->FillSolidRect(&picRect,m_pSelCur[i-startCurBuf].m_nColor);
}
m_pStatic.Invalidate(TRUE);
m_pStatic.ReleaseDC(cpDC);
}
void CCursorEditorDlg::OnSaveCurToFile()
{
IsSave=1;
if(strszfile!="")
{
if(m_ncurcount==0)
{
AfxMessageBox("你保存的光标为空",MB_OK,0);
return;
}
PutBufferWriteToFile();
}
//如果当前是没有文件,作为另存为方式
if(strszfile=="")
{
m_ncurcount=1;
int c=0;
startCurBuf=0;
for(int i=startCurBuf;i<(startCurBuf+m_nMaxSelCurPointCount); i++)
{
if(m_pSelCur[i].m_nColor!=0)
{
c++;
}
}
while(c==0)
{
AfxMessageBox("这个光标为空",MB_OK,0);
return;
}
CursorBuffer pBuffer;
pBuffer.m_nCol=0;
pBuffer.m_nColor=RGB(0,0,0);
pBuffer.m_nRow=0;
for(int m=0; m<m_nMaxSelCurPointCount; m++)
{
m_pMaxCurBuffer.Add(pBuffer);
m_pMaxCurBuffer[m+startCurBuf].m_nColor=m_pSelCur[m].m_nColor;
m_pMaxCurBuffer[m+startCurBuf].m_nCol =m_pSelCur[m].m_nCol;
m_pMaxCurBuffer[m+startCurBuf].m_nRow =m_pSelCur[m].m_nRow;
}
CFileDialog dlg(FALSE,"","");
if(dlg.DoModal()==IDOK)
{
CStdioFile file;
strszfile=dlg.GetPathName();
PutBufferWriteToFile();
MessageBox("您的位图保存成功","保存成功",MB_OK);
}
for(int k=1;k<=m_ncurcount;k++)
{
CString strcombo;
strcombo.Format(_T(">>--%d--<<"),k);
m_combo1.AddString(strcombo);
}
}
}
void CCursorEditorDlg::OnAddCurToFile()
{
if(strszfile=="")
{
AfxMessageBox("请选择要添加的文件",MB_OK,0);
return;
}
IsSave=0;
startCurBuf=m_ncurcount*m_nMaxSelCurPointCount;
m_ncurcount++;
CursorBuffer pBuffer;
pBuffer.m_nCol=0;
pBuffer.m_nColor=RGB(0,0,0);
pBuffer.m_nRow=0;
for(int k=startCurBuf; k<(startCurBuf+m_nMaxSelCurPointCount); k++)
{
m_pMaxCurBuffer.Add(pBuffer);
}
for(int j=0; j<m_nMaxRow; j++)
{
for(int i=0; i<m_nMaxCol; i++)
{
m_pSelCur[j*m_nMaxRow+i].m_nCol=i;
m_pSelCur[j*m_nMaxRow+i].m_nColor=RGB(0,0,0);
m_pSelCur[j*m_nMaxRow+i].m_nRow=j;
}
}
CString sscombo;
sscombo.Format(_T(">>--%d--<<"),m_ncurcount);
m_combo1.AddString(sscombo);
m_combo1.SetCurSel(m_ncurcount-1);
m_nComboSel=m_ncurcount-1;
CWnd *cbutton1,*cbutton2,*cbutton3;
cbutton1=GetDlgItem(IDC_BUTTON2);
cbutton2=GetDlgItem(IDC_BUTTON3);
cbutton3=GetDlgItem(IDC_BUTTON8);
CString btlinestr1,btlinestr2,btpointstr1,btpointstr2,btclearstr1,btclearstr2,btstr1,btstr2;
btlinestr1="画线";
btlinestr2="【画线】";
btpointstr1="画点";
btpointstr2="【画点】";
btclearstr1="擦除";
btclearstr2="【擦除】";
cbutton3->GetWindowText(btstr1);
cbutton1->GetWindowText(btstr2);
if(m_ncurcount>0)
{
cbutton1->EnableWindow(TRUE);
cbutton2->EnableWindow(TRUE);
cbutton3->EnableWindow(TRUE);
if(btstr1==btclearstr2)
{
CUR_EDIT_MODE=CLEAR_LINEANDPOINT_MODE;
}
else if(btstr2==btpointstr1)
{
CUR_EDIT_MODE=PICTURE_LINE_MODE;
}
else
{
CUR_EDIT_MODE=PICTURE_POINT_MODE;
}
}
PreviewDrawCur();
}
void CCursorEditorDlg::OnDeleteCursorInFile()
{
if(m_nComboSel==-1)
{
AfxMessageBox("请选择要删除的光标",MB_OK,0);
return;
}
IsSave=0;
if(m_ncurcount<1)
{
AfxMessageBox("没有光标",MB_OK,0);
return;
}
m_ncurcount--;
int n=m_nComboSel*m_nMaxSelCurPointCount;
m_pMaxCurBuffer.RemoveAt(n,m_nMaxSelCurPointCount);
startCurBuf=startCurBuf-m_nMaxSelCurPointCount;
if(m_nComboSel>=m_ncurcount)
{
m_nComboSel=m_nComboSel-1;
n=m_nComboSel*m_nMaxSelCurPointCount;
}
PutBufferWriteToFile();
if(m_nComboSel<0)
{
for(int y=0; y<m_nMaxRow; y++)
{
for(int x=0; x<m_nMaxCol; x++)
{
m_pSelCur[y*m_nMaxCol+x].m_nCol=x;
m_pSelCur[y*m_nMaxCol+x].m_nColor=RGB(0,0,0);
m_pSelCur[y*m_nMaxCol+x].m_nRow=y;
}
}
startCurBuf=0;
}
else
{
for(int k=n; k<n+m_nMaxSelCurPointCount; k++)
{
m_pSelCur[k-n].m_nCol=m_pMaxCurBuffer[k].m_nCol;
m_pSelCur[k-n].m_nColor=m_pMaxCurBuffer[k].m_nColor;
m_pSelCur[k-n].m_nRow=m_pMaxCurBuffer[k].m_nRow;
}
}
for(int j=m_ncurcount; j>=0; j--)
{
m_combo1.DeleteString(j);
}
if(m_ncurcount<1)
{
CString strcom;
strcom="";
m_combo1.SetWindowText(strcom);
CWnd *cbutton1,*cbutton2,*cbutton3;
cbutton1=GetDlgItem(IDC_BUTTON2);
cbutton2=GetDlgItem(IDC_BUTTON3);
cbutton3=GetDlgItem(IDC_BUTTON8);
cbutton1->EnableWindow(FALSE);
cbutton2->EnableWindow(FALSE);
cbutton3->EnableWindow(FALSE);
}
else
{
CString strcombo;
for(int i=1;i<=m_ncurcount;i++)
{
strcombo.Format(_T(">>--%d--<<"),i);
m_combo1.AddString(strcombo);
}
m_combo1.SetCurSel(m_nComboSel);
}
PreviewDrawCur();
// Invalidate(TRUE);
}
void CCursorEditorDlg::FromDlgWriteToBuffer()
{
CursorBuffer pBuffer;
pBuffer.m_nCol=0;
pBuffer.m_nColor=RGB(0,0,0);
pBuffer.m_nRow=0;
for(int i=startCurBuf; i<(startCurBuf+m_nMaxSelCurPointCount); i++)
{
m_pMaxCurBuffer.Add(pBuffer);
m_pMaxCurBuffer[i].m_nColor=m_pSelCur[i-startCurBuf].m_nColor;
m_pMaxCurBuffer[i].m_nCol =m_pSelCur[i-startCurBuf].m_nCol;
m_pMaxCurBuffer[i].m_nRow =m_pSelCur[i-startCurBuf].m_nRow;
}
}
void CCursorEditorDlg::PutBufferWriteToFile()
{
CStdioFile file;
// CStidioFile sfile;
file.Open(strszfile,CFile::modeCreate | CFile::modeWrite /*CFile::typeText*/,NULL);
CString ss;
CString str;
str.Format("%d %d %d",m_ncurcount,m_nMaxCol,m_nMaxRow);
str+="\n";
int a=1;
int MaxCurPoint=m_nMaxSelCurPointCount*m_ncurcount;
for(int j=0; j<m_ncurcount; j++)
{
ss.Format("// %d",a);
a++;
str+=ss;
for(int i=0; i<m_nMaxRow; i++)
{
str+="\n";
for(int k=0; k<m_nMaxCol; k++){
char ssr;
if(m_pMaxCurBuffer[ j*m_nMaxCol*m_nMaxRow + i*m_nMaxRow + k ].m_nColor!=0){
ssr='1';
str+=ssr;
}
else {
ssr=' ';
str+=ssr;
}
}
}
str+="\n";
}
file.WriteString(str);
file.Close();
str.Empty();
}
void CCursorEditorDlg::PreviewDrawLineCur() //划直线再mousemove时的局部刷新
{
int xlef=0; int xright=0; int ybottom=0; int ytop=0;
CDC *ppDC;
ppDC=m_Picture.GetDC();
for(int j=0;j<m_nMaxSelCurPointCount;j++)
{
xlef=(m_pLineCur[j].m_nCol);
ytop=(m_pLineCur[j].m_nRow);
xright=(m_pLineCur[j].m_nCol+1);
ybottom=(m_pLineCur[j].m_nRow+1);
CRect piRect(xlef+1,ytop+1,xright,ybottom);
ppDC->FillSolidRect(&piRect,m_pLineCur[j].m_nColor);
}
m_Picture.ReleaseDC(ppDC);
int multiple=0;
CRect crect;
m_pStatic.GetClientRect(&crect);
multiple=m_pStatic.cCellSize.cx;
CDC *cpDC;
cpDC=m_pStatic.GetDC();
for(int i=0; i<m_nMaxSelCurPointCount; i++)
{
if(m_pLineCur[i].m_nColor==RGB(255,0,0))
{
xlef=(m_pLineCur[i].m_nCol)*multiple;
ytop=(m_pLineCur[i].m_nRow)*multiple;
xright=(m_pLineCur[i].m_nCol+1)*multiple;
ybottom=(m_pLineCur[i].m_nRow+1)*multiple;
CRect picRect(xlef+1,ytop+1,xright,ybottom);
cpDC->FillSolidRect(&picRect,m_pLineCur[i].m_nColor);
// TRACE("%d %d %d",m_pLineCur[i].m_nCol,m_pLineCur[i].m_nRow,m_pLineCur[i].m_nColor);
}
}
m_pStatic.ReleaseDC(cpDC);
}
void CCursorEditorDlg::EditLineCurDrawRect(CPoint mPoint)
{
int iCol=mPoint.x;
int iRow=mPoint.y;
int ipos=iCol+iRow*m_nMaxCol;
m_pLineCur[ipos].m_nCol=iCol;
m_pLineCur[ipos].m_nRow=iRow;
m_pLineCur[ipos].m_nColor=RGB(255,0,0);
}
CCursorEditorDlg::~CCursorEditorDlg()
{
delete m_pSelCur;
}
void CCursorEditorDlg::OnCorrectCursorSize()
{
// TODO: Add your control notification handler code here
CCorrectCursorSizeDlg CurSizeDlg;
CurSizeDlg.DoModal();
Invalidate(TRUE);
}
void CCursorEditorDlg::RushOldLine()
{
CRect rect;
m_pStatic.GetClientRect(&rect);
CDC *cpDC;
cpDC=m_pStatic.GetDC();
int xlef,ytop,xright,ybottom;
for(int i=0; i<m_nMaxSelCurPointCount; i++)
{
if(m_pSelCur[i].m_nColor==RGB(0,0,0) && m_pLineCur[i].m_nColor==RGB(255,0,0))
{
m_pLineCur[i].m_nColor=RGB(0,0,0);
xlef=(m_pLineCur[i].m_nCol)*m_pStatic.cCellSize.cx;
ytop=(m_pLineCur[i].m_nRow)*m_pStatic.cCellSize.cx;
xright=(m_pLineCur[i].m_nCol+1)*m_pStatic.cCellSize.cx;
ybottom=(m_pLineCur[i].m_nRow+1)*m_pStatic.cCellSize.cx;
CRect picRect(xlef+1,ytop+1,xright,ybottom);
cpDC->FillSolidRect(&picRect,m_pLineCur[i].m_nColor);
}
}
m_pStatic.ReleaseDC(cpDC);
}
void CCursorEditorDlg::ClearStaticDrawRect(CPoint Clpoint)
{
int iCol=Clpoint.x/m_pStatic.cCellSize.cx;
int iRow=Clpoint.y/m_pStatic.cCellSize.cy;
staticRow=iRow;
staticCol=iCol;
int ipos=iCol+iRow*m_nMaxCol;
m_pSelCur[ipos].m_nCol=iCol;
m_pSelCur[ipos].m_nColor=RGB(0,0,0);
m_pSelCur[ipos].m_nRow=iRow;
}
void CCursorEditorDlg::FromSelToMax(int starpos)
{
for(int i=starpos; i<starpos+m_nMaxSelCurPointCount; i++)
{
m_pMaxCurBuffer[i].m_nCol=m_pSelCur[i-starpos].m_nCol;
m_pMaxCurBuffer[i].m_nColor=m_pSelCur[i-starpos].m_nColor;
m_pMaxCurBuffer[i].m_nRow=m_pSelCur[i-starpos].m_nRow;
}
}
void CCursorEditorDlg::OnClearButton()
{
// TODO: Add your control notification handler code here
CWnd *cbutton1,*cbutton2,*cbutton3;
cbutton1=GetDlgItem(IDC_BUTTON2);
cbutton2=GetDlgItem(IDC_BUTTON3);
cbutton3=GetDlgItem(IDC_BUTTON8);
CString btlinestr1,btlinestr2,btpointstr1,btpointstr2,btclearstr1,btclearstr2,btstr;
btlinestr1="画线";
btlinestr2="【画线】";
btpointstr1="画点";
btpointstr2="【画点】";
btclearstr1="擦除";
btclearstr2="【擦除】";
cbutton1->SetWindowText(btpointstr1);
cbutton2->SetWindowText(btlinestr1);
cbutton3->SetWindowText(btclearstr2);
CUR_EDIT_MODE=CLEAR_LINEANDPOINT_MODE;
}
void CCursorEditorDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
if(IsSave==0)
{
if(MessageBox("你是否要保存所改的光标","光标保存",MB_OKCANCEL)==IDOK)
{
OnSaveCurToFile();
}
}
CDialog::OnClose();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -