📄 designerview.cpp
字号:
&cbblue);
if(m_RectsInfo.RectsInfo[i].pc == m_YELLOW)
pDC->FillRect(CRect(m_RectsInfo.RectsInfo[i].location.x*m_Step_Line+OFFSET-Scroll.x+1 ,
m_RectsInfo.RectsInfo[i].location.y *(int)(m_Step_Line*m_jwm)+OFFSET-Scroll.y+1,
m_RectsInfo.RectsInfo[i].location.x *m_Step_Line +m_Step_Line+OFFSET-Scroll.x,
(m_RectsInfo.RectsInfo[i].location.y+1) * (int)(m_Step_Line*m_jwm)+OFFSET-Scroll.y),
&cbyellow);
if(m_RectsInfo.RectsInfo[i].pc == m_WHITE)
pDC->FillRect(CRect(m_RectsInfo.RectsInfo[i].location.x*m_Step_Line+OFFSET-Scroll.x+1 ,
m_RectsInfo.RectsInfo[i].location.y *(int)(m_Step_Line*m_jwm)+OFFSET-Scroll.y+1,
m_RectsInfo.RectsInfo[i].location.x *m_Step_Line +m_Step_Line+OFFSET-Scroll.x,
(m_RectsInfo.RectsInfo[i].location.y+1) * (int)(m_Step_Line*m_jwm)+OFFSET-Scroll.y),
&cbwhite);
}
cbred.DeleteObject();
cbgreen.DeleteObject();
cbblue.DeleteObject();
cbyellow.DeleteObject();
cbwhite.DeleteObject();
}
BOOL CDesignerView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if(ghCursor)
{
SetCursor(ghCursor);
return true;
}
return CScrollView::OnSetCursor(pWnd, nHitTest, message);
}
BOOL CDesignerView::IsInRYTX(CPoint loca)
{
if(this->m_picture_edge[loca.x][loca.y] == true)
return false;
for(int i=0;i<loca.x;i++)
if(this->m_picture_edge[i][loca.y])
break;
if(i==loca.x)
return FALSE;
for(i=loca.x+1;i<LINENUM;i++)
if(this->m_picture_edge[i][loca.y])
return TRUE;
return FALSE;
}
void CDesignerView::YouQiTong(CDC *pDC, CPoint CurrestPoint, CPoint SCroll,PICTURECOLOR pc, COLORREF color)
{
PICTURECOLOR temppc;
if(color == RED)
temppc = m_RED;
else if (color == GREEN)
temppc = m_GREEN;
else if (color == BLUE)
temppc = m_BLUE;
else if (color == YELLOW)
temppc = m_YELLOW;
else if (color ==WHITE)
temppc = m_WHITE;
if(pc == temppc)
return;
if(this->m_picture_color[CurrestPoint.y][CurrestPoint.x] == pc)
{
CBrush cbr;
CPoint tp;
cbr.CreateSolidBrush(color);
pDC->FillRect(CRect(CurrestPoint.x * m_Step_Line + OFFSET +1 -SCroll.x,
CurrestPoint.y * (int)(m_Step_Line*m_jwm)+OFFSET+1-SCroll.y,
(CurrestPoint.x +1)* m_Step_Line+OFFSET - SCroll.x,
(CurrestPoint.y +1) *(int)(m_Step_Line*m_jwm)+OFFSET-SCroll.y),&cbr);
if(color == RED)
this->m_picture_color[CurrestPoint.y][CurrestPoint.x] = m_RED;
else if(color == GREEN)
this->m_picture_color[CurrestPoint.y][CurrestPoint.x] = m_GREEN;
else if(color == BLUE)
this->m_picture_color[CurrestPoint.y][CurrestPoint.x] = m_BLUE;
else if(color == YELLOW)
this->m_picture_color[CurrestPoint.y][CurrestPoint.x] = m_YELLOW;
else if(color == WHITE)
this->m_picture_color[CurrestPoint.y][CurrestPoint.x] = m_WHITE;
cbr.DeleteObject();
if(CurrestPoint.x <m_LineNum.x-1)
{
tp.x = CurrestPoint.x+1;
tp.y = CurrestPoint.y;
YouQiTong(pDC,tp,SCroll,pc,color);
}
if(CurrestPoint.x >0)
{
tp.x = CurrestPoint.x -1;
tp.y = CurrestPoint.y ;
YouQiTong(pDC,tp,SCroll,pc,color);
}
if(CurrestPoint.y <m_LineNum.y-1)
{
tp.x = CurrestPoint.x;
tp.y = CurrestPoint.y +1;
YouQiTong(pDC,tp,SCroll,pc,color);
}
if(CurrestPoint.y >0)
{
tp.x = CurrestPoint.x;
tp.y = CurrestPoint.y -1;
YouQiTong(pDC,tp,SCroll,pc,color);
}
}
}
void CDesignerView::AntCircle(CDC *pDC, RECTSINFO CircleInfo, CPoint Scroll,bool type)
{
CBrush cbred,cbgreen,cbblue,cbyellow,cbwhite;
cbred.CreateSolidBrush(RED);
cbgreen.CreateSolidBrush(GREEN);
cbblue.CreateSolidBrush(BLUE);
cbyellow.CreateSolidBrush(YELLOW);
cbwhite.CreateSolidBrush(WHITE);
for(int i=1;i<CircleInfo.RectLen;i++)
{
if(CircleInfo.RectsInfo[i].location.x <0
|| CircleInfo.RectsInfo[i].location.x >this->m_LineNum.x-1
|| CircleInfo.RectsInfo[i].location.y <0
|| CircleInfo.RectsInfo[i].location.y > this->m_LineNum.y -1)
continue;
if(this->IsInRYTX(CircleInfo.RectsInfo[i].location) && type ==true)
{
pDC->FillRect(CRect(CircleInfo.RectsInfo[i].location.x*m_Step_Line+OFFSET+1-Scroll.x,
CircleInfo.RectsInfo[i].location.y*(int)(m_Step_Line*m_jwm)+OFFSET+1-Scroll.y,
(CircleInfo.RectsInfo[i].location.x+1)*m_Step_Line+OFFSET-Scroll.x,
(CircleInfo.RectsInfo[i].location.y+1)*(int)(m_Step_Line*m_jwm)+OFFSET-Scroll.y),
&cbwhite);
continue;
}
if(CircleInfo.RectsInfo[i].pc == m_RED)
pDC->FillRect(CRect(CircleInfo.RectsInfo[i].location.x * m_Step_Line+OFFSET+1-Scroll.x,
CircleInfo.RectsInfo[i].location.y * (int)(m_Step_Line*m_jwm)+OFFSET+1-Scroll.y,
(CircleInfo.RectsInfo[i].location.x+1)*m_Step_Line+OFFSET-Scroll.x,
(CircleInfo.RectsInfo[i].location.y +1)*(int)(m_Step_Line*m_jwm)+OFFSET-Scroll.y),&cbred);
else if(CircleInfo.RectsInfo[i].pc == m_GREEN)
pDC->FillRect(CRect(CircleInfo.RectsInfo[i].location.x * m_Step_Line+OFFSET+1-Scroll.x,
CircleInfo.RectsInfo[i].location.y * (int)(m_Step_Line*m_jwm)+OFFSET+1-Scroll.y,
(CircleInfo.RectsInfo[i].location.x+1)*m_Step_Line+OFFSET-Scroll.x,
(CircleInfo.RectsInfo[i].location.y +1)*(int)(m_Step_Line*m_jwm)+OFFSET-Scroll.y),&cbgreen);
else if(CircleInfo.RectsInfo[i].pc == m_BLUE)
pDC->FillRect(CRect(CircleInfo.RectsInfo[i].location.x * m_Step_Line+OFFSET+1-Scroll.x,
CircleInfo.RectsInfo[i].location.y * (int)(m_Step_Line*m_jwm)+OFFSET+1-Scroll.y,
(CircleInfo.RectsInfo[i].location.x+1)*m_Step_Line+OFFSET-Scroll.x,
(CircleInfo.RectsInfo[i].location.y +1)*(int)(m_Step_Line*m_jwm)+OFFSET-Scroll.y),&cbblue);
else if(CircleInfo.RectsInfo[i].pc == m_YELLOW)
pDC->FillRect(CRect(CircleInfo.RectsInfo[i].location.x * m_Step_Line+OFFSET+1-Scroll.x,
CircleInfo.RectsInfo[i].location.y * (int)(m_Step_Line*m_jwm)+OFFSET+1-Scroll.y,
(CircleInfo.RectsInfo[i].location.x+1)*m_Step_Line+OFFSET-Scroll.x,
(CircleInfo.RectsInfo[i].location.y +1)*(int)(m_Step_Line*m_jwm)+OFFSET-Scroll.y),&cbyellow);
else if(CircleInfo.RectsInfo[i].pc == m_WHITE)
pDC->FillRect(CRect(CircleInfo.RectsInfo[i].location.x * m_Step_Line+OFFSET+1-Scroll.x,
CircleInfo.RectsInfo[i].location.y * (int)(m_Step_Line*m_jwm)+OFFSET+1-Scroll.y,
(CircleInfo.RectsInfo[i].location.x+1)*m_Step_Line+OFFSET-Scroll.x,
(CircleInfo.RectsInfo[i].location.y +1)*(int)(m_Step_Line*m_jwm)+OFFSET-Scroll.y),&cbwhite);
}
cbgreen.DeleteObject();
cbred.DeleteObject();
cbblue.DeleteObject();
cbyellow.DeleteObject();
cbwhite.DeleteObject();
}
void CDesignerView::OnToolbarPolygon()
{
CDC *dc = GetDC();
CPoint Scroll = this->GetScrollPosition();
if(this->m_Circle_Scr.IsValide == true)
this->AntCircle(dc,this->m_Circle_Scr,Scroll,false);
if(this->m_RectsInfo.IsValide)
this->AntRectang(dc,Scroll);
ReleaseDC(dc);
for(int k=0;k<LINENUM;k++)
for(int j=0;j<LINENUM;j++)
this->m_picture_edge[k][j] = false;
this->m_DrawMode = POLYGON;
this->m_Fill_Picture = false;
this->m_Circle_Scr.IsValide = false;
this->m_RectsInfo.IsValide = false;
ghCursor = AfxGetApp()->LoadCursor(IDC_CURSOR_POLY);
}
void CDesignerView::RecursiveJudge(int x, int y, bool coloredge[][LINENUM],int *len)
{
if(*len>1000)
return;
if(this->m_picture_edge[x][y] == false && coloredge[x][y] == false)
{
coloredge[x][y] = true;
(*len)++;
int xx=x+1;
int yy =y;
if(xx<this->m_LineNum.x && coloredge[xx][yy] == false)
RecursiveJudge(xx,yy,coloredge,len);
xx = x-1;
if(xx>=0 && coloredge[xx][yy]==false)
RecursiveJudge(xx,yy,coloredge,len);
xx = x;
yy = y+1;
if(yy<this->m_LineNum.y && coloredge[xx][yy]==false)
RecursiveJudge(xx,yy,coloredge,len);
yy = y-1;
if(yy>=0 && coloredge[xx][yy] == false)
RecursiveJudge(xx,yy,coloredge,len);
}
}
void CDesignerView::OnEditCut()
{
IsPasteUsable = true;
CPoint Scroll = this->GetScrollPosition();
CDC *pDC = GetDC();
CBrush cbrwhite;
cbrwhite.CreateSolidBrush(WHITE);
for(int i=0;i<m_LineNum.y;i++)
for(int j=0;j<m_LineNum.x;j++)
this->m_picture_color3[i][j] = m_OTHER;
if(this->m_Circle_Scr.IsValide == true)
{
for(int i=0;i<LINENUM;i++)
for(int j=0;j<LINENUM;j++)
this->m_picture_edge[i][j] = false;
for(i =0;i<this->m_Circle_Scr.RectLen;i++)
this->m_picture_edge[this->m_Circle_Scr.RectsInfo[i].location.x][this->m_Circle_Scr.RectsInfo[i].location.y] = true;
for(i=0;i<LINENUM;i++)
for(int j=0;j<LINENUM;j++)
{
CPoint pt;
pt.x = j;
pt.y =i;
if(this->IsInRYTX(pt))
{
this->m_picture_color3[i][j] = this->m_picture_color[i][j];
this->m_picture_color[i][j]= m_WHITE;
pDC->FillRect(CRect(j * m_Step_Line+OFFSET +1-Scroll.x ,
i *(int)(m_Step_Line* m_jwm)+OFFSET+1 -Scroll.y,
(j +1)* m_Step_Line+OFFSET-Scroll.x,
(i +1)*(int)(m_Step_Line*m_jwm)+OFFSET-Scroll.y),&cbrwhite);
}
}
}
else if(this->m_RectsInfo.IsValide == true)
{
CPoint tempLT = gLocatePoint(this->RectLeftTop,m_jwm,Scroll);
CPoint tempRB = gLocatePoint(this->RectRightBottom,m_jwm,Scroll);
for(int i = tempLT.x+1;i<tempRB.x;i++)
for(int j = tempLT.y+1;j<tempRB.y;j++)
{
this->m_picture_color3[j][i] = this->m_picture_color[j][i];
this->m_picture_color[j][i] = m_WHITE;
pDC->FillRect(CRect(i * m_Step_Line+OFFSET +1-Scroll.x ,
j *(int)(m_Step_Line* m_jwm)+OFFSET+1 -Scroll.y,
(i +1)* m_Step_Line+OFFSET-Scroll.x,
(j +1)*(int)(m_Step_Line*m_jwm)+OFFSET-Scroll.y),&cbrwhite);
}
}
ReleaseDC(pDC);
cbrwhite.DeleteObject();
}
void CDesignerView::OnEditCopy()
{
IsPasteUsable = true;
for(int i=0;i<LINENUM;i++)
for(int j=0;j<LINENUM;j++)
this->m_picture_color3[i][j]=m_OTHER;
CPoint Scroll = this->GetScrollPosition();
if(this->m_Circle_Scr.IsValide == true)
{
for(int i=0;i<LINENUM;i++)
for(int j=0;j<LINENUM;j++)
this->m_picture_edge[i][j] = false;
for(i =0;i<this->m_Circle_Scr.RectLen;i++)
this->m_picture_edge[this->m_Circle_Scr.RectsInfo[i].location.x][this->m_Circle_Scr.RectsInfo[i].location.y] = true;
for(i=0;i<LINENUM;i++)
for(int j=0;j<LINENUM;j++)
{
CPoint pt;
pt.x = j;
pt.y =i;
if(this->IsInRYTX(pt))
{
this->m_picture_color3[i][j]= this->m_picture_color[i][j];
}
}
}
else if(this->m_RectsInfo.IsValide == true)
{
CPoint tempLT = gLocatePoint(this->RectLeftTop,m_jwm,Scroll);
CPoint tempRB = gLocatePoint(this->RectRightBottom,m_jwm,Scroll);
for(int i = tempLT.x+1;i<tempRB.x;i++)
for(int j = tempLT.y+1;j<tempRB.y;j++)
{
this->m_picture_color3[j][i] = this->m_picture_color[j][i];
}
}
}
void CDesignerView::OnEditPaste()
{
this->m_DrawMode = PASTE;
this->m_Paste_Scr.RectLen =0;
this->m_Paste_Current.RectLen =0;
this->m_Paste_Current.LeftTop.x = LINENUM;
this->m_Paste_Current.LeftTop.y = LINENUM;
this->m_Paste_Current.RightBottom.x = 0;
this->m_Paste_Current.RightBottom.y = 0;
for(int i=0;i<m_LineNum.y;i++)
for(int j=0;j<m_LineNum.x;j++)
{
if(this->m_picture_color3[i][j] !=m_OTHER)
{
m_Paste_Scr.RectsInfo[m_Paste_Scr.RectLen].location.y = i;
m_Paste_Scr.RectsInfo[m_Paste_Scr.RectLen].location.x = j;
m_Paste_Scr.RectsInfo[m_Paste_Scr.RectLen].pc = this->m_picture_color3[i][j];
m_Paste_Current.RectsInfo[m_Paste_Current.RectLen].location.y = i;
m_Paste_Current.RectsInfo[m_Paste_Current.RectLen].location.x = j;
m_Paste_Current.RectsInfo[m_Paste_Current.RectLen].pc = this->m_picture_color3[i][j];
m_Paste_Scr.RectLen++;
m_Paste_Current.RectLen++;
if(i<m_Paste_Current.LeftTop.y)
m_Paste_Current.LeftTop.y = i;
if(i>m_Paste_Current.RightBottom.y)
m_Paste_Current.RightBottom.y = i;
if(j<m_Paste_Current.LeftTop.x )
m_Paste_Current.LeftTop.x = j;
if(j>m_Paste_Current.RightBottom.x)
m_Paste_Current.RightBottom.x = j;
}
}
CDC *dc = GetDC();
CPoint Scroll = this->GetScrollPosition();
CBrush cbred,cbgreen,cbblue,cbyellow,cbwhite;
cbred.CreateSolidBrush(RED);
cbgreen.CreateSolidBrush(GREEN);
cbblue.CreateSolidBrush(BLUE);
cbyellow.CreateSolidBrush(YELLOW);
cbwhite.CreateSolidBrush(WHITE);
for(i =0;i<m_Paste_Current.RectLen;i++)
{
if(m_Paste_Scr.RectsInfo[i].pc == m_RED)
dc->FillRect(CRect(m_Paste_Current.RectsInfo[i].location.x*m_Step_Line+1+OFFSET-Scroll.x,
m_Paste_Current.RectsInfo[i].location.y *(int)(m_Step_Line*m_jwm)+1+OFFSET-Scroll.y,
(m_Paste_Current.RectsInfo[i].location.x+1)*m_Step_Line+OFFSET-Scroll.x,
(m_Paste_Current.RectsInfo[i].location.y +1)*(int)(m_Step_Line*m_jwm)+OFFSET-Scroll.y),
&cbred);
else if(m_Paste_Scr.RectsInfo[i].pc == m_GREEN)
dc->FillRect(CRect(m_Paste_Current.RectsInfo[i].location.x*m_Step_Line+1+OFFSET-Scroll.x,
m_Paste_Current.RectsInfo[i].location.y *(int)(m_Step_Line*m_jwm)+1+OFFSET-Scroll.y,
(m_Paste_Current.RectsInfo[i].location.x+1)*m_Step_Line+OFFSET-Scroll.x,
(m_Paste_Current.RectsInfo[i].location.y +1)*(int)(m_Step_Line*m_jwm)+OFFSET-Scroll.y),
&cbgreen);
else if(m_Paste_Scr.RectsInfo[i].pc == m_BLUE)
dc->FillRect(CRect(m_Paste_Current.RectsInfo[i].location.x*m_Step_Line+1+OFFSET-Scroll.x,
m_Paste_Current.RectsInfo[i].location.y *(int)(m_Step_Line*m_jwm)+1+OFFSET-Scroll.y,
(m_Paste_Current.RectsInfo[i].location.x+1)*m_Step_Line+OFFSET-Scroll.x,
(m_Paste_Current.RectsInfo[i].location.y +1)*(int)(m_Step_Line*m_jwm)+OFFSET-Scroll.y),
&cbblue);
else if(m_Paste_Scr.RectsInfo[i].pc == m_YELLOW)
dc->FillRect(CRect(m_Paste_Current.RectsInfo[i].location.x*m_Step_Line+1+OFFSET-Scroll.x,
m_Paste_Current.RectsInfo[i].location.y *(int)(m_Step_Line*m_jwm)+1+OFFSET-Scroll.y,
(m_Paste_Current.RectsInfo[i].location.x+1)*m_Step_Line+OFFSET-Scroll.x,
(m_Paste_Current.RectsInfo[i].location.y +1)*(int)(m_Step_Line*m_jwm)+OFFSET-Scroll.y),
&cbyellow);
else if(m_Paste_Scr.RectsInfo[i].pc == m_WHITE)
dc->FillRect(CRect(m_Paste_Current.RectsInfo[i].location.x*m_Step_Line+1+OFFSET-Scroll.x,
m_Paste_Current.RectsInfo[i].location.y *(int)(m_Step_Line*m_jwm)+1+OFFSET-Scroll.y,
(m_Paste_Current.RectsInfo[i].location.x+1)*m_Step_Line+OFFSET-Scroll.x,
(m_Paste_Current.RectsInfo[i].location.y +1)*(int)(m_Step_Line*m_jwm)+OFFSET-Scroll.y),
&cbwhite);
}
ReleaseDC(dc);
cbred.DeleteObject();
cbgreen.DeleteObject();
cbblue.DeleteObject();
cbyellow.DeleteObject();
cbwhite.DeleteObject();
}
void CDesignerView::AntPasteColor(CDC *pDC, RECTSINFO PasteInfo, CPoint Scroll)
{
CBrush cbred,cbgreen,cbblue,cbyellow,cbwhite,cbedge;
cbred.CreateSolidBrush(RED);
cbgreen.CreateSolidBrush(GREEN);
cbblue.CreateSolidBrush(BLUE);
cbyellow.CreateSolidBrush(YELLOW);
cbwhite.CreateSolidBrush(WHITE);
cbedge.CreateSolidBrush(WGCOLOR);
for(int i=0;i<PasteInfo.RectLen;i++)
{
if(PasteInfo.RectsInfo[i].pc == m_RED)
pDC->FillRect(CRect(PasteInfo.RectsInfo[i].location.x*m_Step_Line+1+OFFSET-Scroll.x,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -