📄 cursoreditordlg.cpp
字号:
pBuffer.m_nCol=0;
pBuffer.m_nColor=RGB(0,0,0);
pBuffer.m_nRow=0;
for(int i=0; i<Maxcur; i++)
{
m_pMaxCurBuffer.Add(pBuffer);
}
int m_nnRow=0;int m_nnCol=0;
int a=0;
int z=0;
while(fgets(txt,sizeof(txt)-1,fp))
{
if(txt[0]=='/' && txt[1]=='/')
{
m_nnCol=0;
m_nnRow=0;
z++;
continue;
}
char *c=txt;
while(*c)
{
if(m_nnCol>(m_nMaxCol-1))
{
c++;
continue;
}
if(*c=='1')
{
m_pMaxCurBuffer[a].m_nCol=m_nnCol;
m_pMaxCurBuffer[a].m_nColor=RGB(255,0,0);
m_pMaxCurBuffer[a].m_nRow=m_nnRow;
m_nnCol++;
a++;
}
else if(*c==' ')
{
m_pMaxCurBuffer[a].m_nCol=m_nnCol;
m_pMaxCurBuffer[a].m_nColor=RGB(0,0,0);
m_pMaxCurBuffer[a].m_nRow=m_nnRow;
m_nnCol++;
a++;
}
c++;
}
while(m_nnCol<=(m_nMaxCol-1))
{
m_pMaxCurBuffer[a].m_nCol=m_nnCol;
m_pMaxCurBuffer[a].m_nColor=RGB(0,0,0);
m_pMaxCurBuffer[a].m_nRow=m_nnRow;
m_nnCol++;
a++;
}
if(!feof(fp))
{
m_nnRow++;
m_nnCol=0;
}
}
fclose(fp);
delete m_pSelCur;
m_pSelCur=new CursorBuffer[m_nMaxSelCurPointCount];
for(int j=0; j<m_nMaxSelCurPointCount; j++)
{
m_pSelCur[j].m_nCol=m_pMaxCurBuffer[j].m_nCol;
m_pSelCur[j].m_nColor=m_pMaxCurBuffer[j].m_nColor;
m_pSelCur[j].m_nRow=m_pMaxCurBuffer[j].m_nRow;
}
m_nComboSel=0;
startCurBuf=m_nMaxSelCurPointCount*m_nComboSel;
return true;
}
void CCursorEditorDlg::OnSelchangeCombo1()
{
m_nComboSel=m_combo1.GetCurSel();
startCurBuf=m_nComboSel*m_nMaxSelCurPointCount;
for(int i=startCurBuf; i<(startCurBuf+m_nMaxSelCurPointCount); i++)
{
m_pSelCur[i-startCurBuf].m_nCol = m_pMaxCurBuffer[i].m_nCol;
m_pSelCur[i-startCurBuf].m_nColor = m_pMaxCurBuffer[i].m_nColor;
m_pSelCur[i-startCurBuf].m_nRow = m_pMaxCurBuffer[i].m_nRow;
}
PreviewDrawCur();
// Invalidate(TRUE);
}
void CCursorEditorDlg::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnLButtonDblClk(nFlags, point);
}
void CCursorEditorDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
switch(CUR_EDIT_MODE)
{
case PICTURE_LINE_MODE:
{
if(m_pLineCur!=NULL)
{
return;
}
else
m_pLineCur=new CursorBuffer[m_nMaxSelCurPointCount];
ClientToScreen(&point);
m_pStatic.ScreenToClient(&point);
m_FirPoint.x=point.x/m_pStatic.cCellSize.cx;
m_FirPoint.y=point.y/m_pStatic.cCellSize.cy;
if(m_FirPoint.x>=m_nMaxCol)
m_FirPoint.x=m_nMaxCol-1;
if(m_FirPoint.x<0)
m_FirPoint.x=0;
if(m_FirPoint.y<0)
m_FirPoint.y=0;
if(m_FirPoint.y>=m_nMaxRow)
m_FirPoint.y=m_nMaxRow-1;
for(int j=0; j<m_nMaxRow; j++)
{
for(int k=0; k<m_nMaxCol; k++)
{
m_pLineCur[j*m_nMaxRow+k].m_nCol=k;
m_pLineCur[j*m_nMaxRow+k].m_nColor=RGB(0,0,0);
m_pLineCur[j*m_nMaxRow+k].m_nRow=j;
}
}
}
break;
case PICTURE_POINT_MODE:
{
CRect rect;
m_pStatic.GetWindowRect(&rect);
ScreenToClient(&rect);
if(rect.PtInRect(point))
{
ClientToScreen(&point);
m_pStatic.ScreenToClient(&point);
staticCol=point.x/m_pStatic.cCellSize.cx;
staticRow=point.y/m_pStatic.cCellSize.cy;
CString strsta1,strsta2;
strsta1.Format("%d,%d",staticCol,staticRow);
m_static1.SetWindowText(strsta1);
}
}
break;
case CLEAR_LINEANDPOINT_MODE:
{
CRect rect;
m_pStatic.GetWindowRect(&rect);
ScreenToClient(&rect);
if(rect.PtInRect(point))
{
ClientToScreen(&point);
m_pStatic.ScreenToClient(&point);
staticCol=point.x/m_pStatic.cCellSize.cx;
staticRow=point.y/m_pStatic.cCellSize.cy;
CString strsta1,strsta2;
strsta1.Format("%d,%d",staticCol,staticRow);
m_static1.SetWindowText(strsta1);
}
}
break;
case INVALID_MODE:
return;
}
CDialog::OnLButtonDown(nFlags, point);
}
void CCursorEditorDlg::OnMouseMove(UINT nFlags, CPoint point)
{
if((nFlags & MK_LBUTTON) ==0)
{
return;
}
CRect rect;
m_pStatic.GetWindowRect(&rect);
ScreenToClient(&rect);
switch(CUR_EDIT_MODE)
{
case PICTURE_POINT_MODE:
{
if(rect.PtInRect(point))
{
ClientToScreen(&point);
m_pStatic.ScreenToClient(&point);
EditStaticDrawRect(point);
PreviewDrawCur();
CString strsta1,strsta2;
strsta1.Format("%d,%d",staticCol,staticRow);
m_static1.SetWindowText(strsta1);
}
}
break;
case PICTURE_LINE_MODE:
{
if(rect.PtInRect(point))
{
ClientToScreen(&point);
m_pStatic.ScreenToClient(&point);
CClientDC dc(this);
int dCol,dRow;
double fCol=(double)point.x/(double)m_pStatic.cCellSize.cx;
double fRow=(double)point.y/(double)m_pStatic.cCellSize.cy;
dCol=int(fCol);
dRow=int(fRow);
if(m_pLineCur==NULL)
return;
RushOldLine();
::LineDDA(m_FirPoint.x, m_FirPoint.y, dCol, dRow,func, (LPARAM)this);
PreviewDrawLineCur();
staticCol=dCol;
staticRow=dRow;
CString strsta1,strsta2;
strsta1.Format("%d,%d",staticCol,staticRow);
m_static1.SetWindowText(strsta1);
}
}
break;
case CLEAR_LINEANDPOINT_MODE:
{
ClientToScreen(&point);
m_pStatic.ScreenToClient(&point);
point.x = min (max (point.x, 0), (m_nMaxCol-1)*m_pStatic.cCellSize.cx);
point.y = min (max (point.y, 0), (m_nMaxRow-1)*m_pStatic.cCellSize.cy);
ClearStaticDrawRect(point);
PreviewDrawCur();
CString strsta1,strsta2;
strsta1.Format("%d,%d",staticCol,staticRow);
m_static1.SetWindowText(strsta1);
}
break;
case INVALID_MODE:
return;
}
CDialog::OnMouseMove(nFlags, point);
}
void CCursorEditorDlg::EditStaticDrawRect(CPoint pPoint /*此point为相对于显示区坐标*/)
//将染色区域加入到m_pSelCur中
{
int iCol=pPoint.x/m_pStatic.cCellSize.cx;
int iRow=pPoint.y/m_pStatic.cCellSize.cy;
int ipos=iCol+iRow*m_nMaxCol;
m_pSelCur[ipos].m_nCol=iCol;
m_pSelCur[ipos].m_nColor=RGB(255,0,0);
m_pSelCur[ipos].m_nRow=iRow;
staticRow=iRow;
staticCol=iCol;
}
void CCursorEditorDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
switch (CUR_EDIT_MODE)
{
case PICTURE_POINT_MODE:
{
CRect rect;
m_pStatic.GetWindowRect(&rect);
ScreenToClient(&rect);
if(rect.PtInRect(point))
{
ClientToScreen(&point);
m_pStatic.ScreenToClient(&point);
EditStaticDrawRect(point);
IsSave=0;
PreviewDrawCur();
FromSelToMax(startCurBuf);
}
}
break;
case PICTURE_LINE_MODE:
{
CRect rect;
m_pStatic.GetWindowRect(&rect);
ScreenToClient(&rect);
if(rect.PtInRect(point))
{
ClientToScreen(&point);
m_pStatic.ScreenToClient(&point);
IsSave=0;
int dCol,dRow;
double fCol=(double)point.x/(double)m_pStatic.cCellSize.cx;
double fRow=(double)point.y/(double)m_pStatic.cCellSize.cy;
dCol=int(fCol);
dRow=int(fRow);
int ipos=dCol+dRow*m_nMaxCol;
m_pSelCur[ipos].m_nCol=dCol;
m_pSelCur[ipos].m_nRow=dRow;
m_pSelCur[ipos].m_nColor=RGB(255,0,0);
if(m_pLineCur==NULL)
return;
for(int i=0; i<m_nMaxSelCurPointCount; i++)
{
if(m_pLineCur[i].m_nColor==RGB(255,0,0))
{
m_pSelCur[i].m_nColor=m_pLineCur[i].m_nColor;
m_pSelCur[i].m_nCol=m_pLineCur[i].m_nCol;
m_pSelCur[i].m_nRow=m_pLineCur[i].m_nRow;
}
}
}
if(m_pLineCur!=NULL)
{
delete m_pLineCur;
m_pLineCur=NULL;
}
FromSelToMax(startCurBuf);
// CRect crect;
// m_pStatic.GetClientRect(&crect);
// InvalidateRect(&crect,TRUE);
// m_Picture.GetClientRect(&crect);
// InvalidateRect(&crect,TRUE);
}
break;
case CLEAR_LINEANDPOINT_MODE:
{
CRect rect;
m_pStatic.GetWindowRect(&rect);
ScreenToClient(&rect);
if(rect.PtInRect(point))
{
ClientToScreen(&point);
m_pStatic.ScreenToClient(&point);
ClearStaticDrawRect(point);
IsSave=0;
PreviewDrawCur();
FromSelToMax(startCurBuf);
}
}
break;
case INVALID_MODE:
return;
}
CDialog::OnLButtonUp(nFlags, point);
}
void CCursorEditorDlg::OnSetPointMode()
{
CWnd *cbutton1,*cbutton2,*cbutton3;
cbutton1=GetDlgItem(IDC_BUTTON2);
cbutton2=GetDlgItem(IDC_BUTTON3);
cbutton3=GetDlgItem(IDC_BUTTON8);
CString btlinestr,btpointstr,btclearstr;
btlinestr="画线";
btpointstr="【画点】";
btclearstr="擦除";
cbutton2->SetWindowText(btlinestr);
cbutton1->SetWindowText(btpointstr);
cbutton3->SetWindowText(btclearstr);
CUR_EDIT_MODE=PICTURE_POINT_MODE;
}
void CCursorEditorDlg::OnSetLineMode()
{
// TODO: Add your control notification handler code here
CWnd *cbutton1,*cbutton2,*cbutton3;
cbutton1=GetDlgItem(IDC_BUTTON3);
cbutton2=GetDlgItem(IDC_BUTTON2);
cbutton3=GetDlgItem(IDC_BUTTON8);
CString btlinestr,btpointstr,btclearstr;
btlinestr="【画线】";
btpointstr="画点";
btclearstr="擦除";
cbutton1->SetWindowText(btlinestr);
cbutton2->SetWindowText(btpointstr);
cbutton3->SetWindowText(btclearstr);
CUR_EDIT_MODE=PICTURE_LINE_MODE;
}
void CCursorEditorDlg::PreviewDrawCur() //区域更新
{
CDC *ppDC;
ppDC=m_Picture.GetDC();
int picMultiple;
int xlef=0; int xright=0; int ybottom=0; int ytop=0;
picMultiple=m_pStatic.cCellSize.cx;
for(int j=startCurBuf;j<(startCurBuf+m_nMaxSelCurPointCount);j++)
{
xlef=(m_pSelCur[j-startCurBuf].m_nCol);
ytop=(m_pSelCur[j-startCurBuf].m_nRow);
xright=(m_pSelCur[j-startCurBuf].m_nCol+1);
ybottom=(m_pSelCur[j-startCurBuf].m_nRow+1);
CRect piRect(xlef,ytop,xright,ybottom);
ppDC->FillSolidRect(&piRect,m_pSelCur[j-startCurBuf].m_nColor);
}
m_Picture.Invalidate(TRUE);
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=startCurBuf;i<(startCurBuf+m_nMaxSelCurPointCount);i++)
{
xlef=(m_pSelCur[i-startCurBuf].m_nCol)*multiple;
ytop=(m_pSelCur[i-startCurBuf].m_nRow)*multiple;
xright=(m_pSelCur[i-startCurBuf].m_nCol+1)*multiple;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -