📄 designerview.cpp
字号:
dp.Circle(dc,point,EDGECOLOR,m_jwm,true,tempp,&(this->m_Circle_Scr));
this->m_Circle_Scr.LeftTop.x +=tempp.x;
this->m_Circle_Scr.LeftTop.y +=tempp.y;
this->m_DrawMode = CIRCLEMOVE;
CPoint m_MousePosi ;
m_MousePosi.x = point.x + tempp.x;
m_MousePosi.y = point.y + tempp.y;
if(m_UndoStruct.m_CurrentP < UNDOLENTH)
{
m_UndoStruct.m_Undo_Mode_Stack[m_UndoStruct.m_CurrentP] = CIRCLE;
m_UndoStruct.m_Undo_Data_Stack[m_UndoStruct.m_CurrentP].m_Point1 = m_CircleCenter;
m_UndoStruct.m_Undo_Data_Stack[m_UndoStruct.m_CurrentP].m_Point2 = m_MousePosi;
m_UndoStruct.m_CurrentP++;
}
else
{
for(int i =1;i<UNDOLENTH;i++)
{
m_UndoStruct.m_Undo_Data_Stack[i-1].m_Point1 = m_UndoStruct.m_Undo_Data_Stack[i].m_Point1;
m_UndoStruct.m_Undo_Data_Stack[i-1].m_Point2 = m_UndoStruct.m_Undo_Data_Stack[i].m_Point2;
m_UndoStruct.m_Undo_Mode_Stack[i-1] = m_UndoStruct.m_Undo_Mode_Stack[i];
}
m_UndoStruct.m_Undo_Data_Stack[i-1].m_Point1 = m_CircleCenter;
m_UndoStruct.m_Undo_Data_Stack[i-1].m_Point2 = m_MousePosi;
m_UndoStruct.m_Undo_Mode_Stack[i-1] = CIRCLE;
m_UndoStruct.m_CurrentP=UNDOLENTH;
}
}
m_color = GetPixel(dc->GetSafeHdc(),point.x,point.y);
//手工勾画边框(点)
if(m_color != WGCOLOR && m_Fill_Picture == FALSE && m_Base_Create ==TRUE && m_DrawMode == MANUAL)
{
CPoint tp;
tp = LocatePoint(point);
if(tp.x< 0 || tp.x >=m_LineNum.x || tp.y <0 || tp.y >=m_LineNum.y)
goto L;
CBrush m_brush;
m_brush.CreateSolidBrush(EDGECOLOR);
dc->FillRect(CRect(tp.x*m_Step_Line+OFFSET-tempp.x,tp.y*(int)(m_Step_Line*m_jwm)+OFFSET-tempp.y,tp.x*m_Step_Line+OFFSET-tempp.x+m_Step_Line,(tp.y+1)*(int)(STEP*m_jwm)+OFFSET-tempp.y),&m_brush);
m_picture_edge[tp.x][tp.y] = TRUE;
m_picture_color[tp.x][tp.y] = m_OTHER;
ReleaseDC(dc);
m_brush.DeleteObject();
}
//橡皮擦
if(m_color != WGCOLOR && m_Fill_Picture == FALSE && m_Base_Create ==TRUE && m_DrawMode == ERASE)
{
CPoint tp;
tp = LocatePoint(point);
tp.x +=3;
tp.y +=2;
if(tp.x< 0 || tp.x >=m_LineNum.x-1|| tp.y <0 || tp.y >=m_LineNum.y-1)
goto L;
CBrush m_brush;
m_brush.CreateSolidBrush(WHITE);
if(tp.x>=0 && tp.x<m_LineNum.x && tp.y >=0 &&tp.y <m_LineNum.y)
{
for(int i=-1;i<=1;i++)
for(int j=-1;j<=1;j++)
{
CPoint ttp;
ttp.x = tp.x +j;
ttp.y = tp.y +i;
if(ttp.x >=0 && ttp.x <m_LineNum.x && ttp.y >=0 && ttp.y <m_LineNum.y)
{
dc->FillRect(CRect((tp.x+j)*m_Step_Line+OFFSET-tempp.x+1,(tp.y+i)*(int)(m_Step_Line*m_jwm)+OFFSET-tempp.y+1,(tp.x+j)*m_Step_Line+OFFSET-tempp.x+m_Step_Line,(tp.y+1+i)*(int)(m_Step_Line*m_jwm)+OFFSET-tempp.y),&m_brush);
m_picture_edge[tp.x+j][tp.y+i] = FALSE;
m_picture_color[tp.y+i][tp.x+j] = m_WHITE;
}
}
}
ReleaseDC(dc);
m_brush.DeleteObject();
}
if(m_color != WGCOLOR && m_Fill_Picture == TRUE )
{
int curx = m_width/2;
int cury = m_height/2;
FillPicture(dc,point,curx,cury);
m_Fill_Picture = FALSE;
if(m_UndoStruct.m_CurrentP < UNDOLENTH)
{
m_UndoStruct.m_Undo_Mode_Stack[m_UndoStruct.m_CurrentP] = FILL;
m_UndoStruct.m_Undo_Data_Stack[m_UndoStruct.m_CurrentP].m_Point1 = point;
m_UndoStruct.m_CurrentP++;
}
else
{
for(int i =1;i<UNDOLENTH;i++)
{
m_UndoStruct.m_Undo_Data_Stack[i-1].m_Point1 = m_UndoStruct.m_Undo_Data_Stack[i].m_Point1;
m_UndoStruct.m_Undo_Data_Stack[i-1].m_Point2 = m_UndoStruct.m_Undo_Data_Stack[i].m_Point2;
m_UndoStruct.m_Undo_Mode_Stack[i-1] = m_UndoStruct.m_Undo_Mode_Stack[i];
}
m_UndoStruct.m_Undo_Data_Stack[i-1].m_Point1 = point;
m_UndoStruct.m_Undo_Mode_Stack[i-1] = FILL;
m_UndoStruct.m_CurrentP=UNDOLENTH;
}
ReleaseDC(dc);
}
L: CScrollView::OnLButtonDown(nFlags, point);
}
CPoint CDesignerView::LocatePoint(CPoint point)
{
CPoint p = this->GetScrollPosition();
int temp = (int)(m_Step_Line*m_jwm);
CPoint tp;
point.x +=p.x;
point.y +=p.y;
if(point.x-OFFSET <0)
tp.x = -1;
else
tp.x = (point.x-OFFSET)/m_Step_Line;
if(point.y - OFFSET <0)
tp.y = -1;
else
tp.y = (long)((point.y -OFFSET)/(temp));
return tp;
}
int CDesignerView::FillPicture( CDC *pDC,CPoint point,int curx,int cury)
{
CBrush cbr;
int i =0;
int j = 0;
CPoint pp = point;
int temp = (int)(m_Step_Line*m_jwm);
CPoint scpoint = this->GetScrollPosition();
scpoint.x = scpoint.x / m_Step_Line *m_Step_Line;
scpoint.y = scpoint.y /temp * temp;
COLORREF ccolor= GetPixel(pDC->GetSafeHdc(),pp.x,pp.y);
while(ccolor != global_ccomm)
{
i++;
pp.x--;
ccolor = GetPixel(pDC->GetSafeHdc(),pp.x,pp.y);
}
pp.x +=i;
ccolor = GetPixel(pDC->GetSafeHdc(),pp.x,pp.y);
while(ccolor != global_ccomm )
{
j++;
pp.y--;
ccolor = GetPixel(pDC->GetSafeHdc(),pp.x,pp.y);
}
pp.x -=i;
pp.x -=scpoint.x;
pp.y -= scpoint.y;
RecersiveFill(pDC,pp,curx,cury,true);
cbr.DeleteObject();
for( i=0;i<LINENUM ;i++)
for(int j=0;j<LINENUM;j++)
m_picture_edge[i][j] = false;
Invalidate();
return 1;
}
void CDesignerView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
//CPoint point = this->GetScrollPosition();
//int a = point.y-(int)(LINENUM*STEP*this->m_jwm);
//if(a>0)
// m_Strolloffsetv +=point.y;
CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
}
void CDesignerView::ShowPictEdge(CDC* pDC ,int StepLen)
{
CBrush cbr;
CPoint tp = this->GetScrollPosition();
cbr.CreateSolidBrush(EDGECOLOR);
int temp = (int)(StepLen*m_jwm);
for(int i =0;i<m_LineNum.y;i++)
for(int j =0;j<m_LineNum.x;j++)
{
if(m_picture_edge[j][i] == TRUE)
pDC->FillRect(CRect(j*StepLen+OFFSET+1-tp.x,(int)(i*temp)+OFFSET+1-tp.y,j*StepLen+StepLen+OFFSET-tp.x,(int)((i+1)*temp)+OFFSET)-tp.y,&cbr);
}
cbr.DeleteObject();
}
void CDesignerView::ShowPict(CDC *pDC,int StepLen)
{
CBrush cbrr,cbrg,cbrb,cbry,cbrw;
cbrr.CreateSolidBrush(RED);
cbrg.CreateSolidBrush(GREEN);
cbrb.CreateSolidBrush(BLUE);
cbry.CreateSolidBrush(YELLOW);
cbrw.CreateSolidBrush(WHITE);
int temp = (int)(StepLen*m_jwm);
CPoint point= this->GetScrollPosition();
point.x = point.x /StepLen *StepLen;
point.y = point.y /temp * temp;
point.x = point.y = 0;
for(int i=0;i<m_LineNum.y;i++)
for(int j=0;j<m_LineNum.x;j++)
{
if(m_picture_color[i][j]==m_RED )
pDC->FillRect(CRect(j*StepLen+OFFSET+1-point.x,(int)(i*temp)+OFFSET+1-point.y,j*StepLen+StepLen+OFFSET-point.x,(int)((i+1)*temp)+OFFSET-point.y),&cbrr);
else if(m_picture_color[i][j] ==m_GREEN)
pDC->FillRect(CRect(j*StepLen+OFFSET+1-point.x,(int)(i*temp)+OFFSET+1-point.y,j*StepLen+StepLen+OFFSET-point.x,(int)((i+1)*temp)+OFFSET-point.y),&cbrg);
else if(m_picture_color[i][j] ==m_BLUE)
pDC->FillRect(CRect(j*StepLen+OFFSET+1-point.x,(int)(i*temp)+OFFSET+1-point.y,j*StepLen+StepLen+OFFSET-point.x,(int)((i+1)*temp)+OFFSET-point.y),&cbrb);
else if(m_picture_color[i][j] ==m_YELLOW)
pDC->FillRect(CRect(j*StepLen+OFFSET+1-point.x,(int)(i*temp)+OFFSET+1-point.y,j*StepLen+StepLen+OFFSET-point.x,(int)((i+1)*temp)+OFFSET-point.y),&cbry);
else if(m_picture_color[i][j] ==m_WHITE)
pDC->FillRect(CRect(j*StepLen+OFFSET+1-point.x,(int)(i*temp)+OFFSET+1-point.y,j*StepLen+StepLen+OFFSET-point.x,(int)((i+1)*temp)+OFFSET-point.y),&cbrw);
else
continue;
}
cbrr.DeleteObject();
cbrg.DeleteObject();
cbrb.DeleteObject();
cbry.DeleteObject();
cbrw.DeleteObject();
}
void CDesignerView::RecersiveFill(CDC *pDC, CPoint pointbig,int curx,int cury,bool type)
{
CBrush cbr;
PICTURECOLOR pictc;
CPoint tp;
tp.x = pointbig.x +1;
tp.y = pointbig.y +1;
CPoint temp = this->LocatePoint(tp);
if(type== true){
if(m_jwlabel[curx][cury] == 1)
{
cbr.CreateSolidBrush(RED);
pictc = m_RED;
}
else if(m_jwlabel[curx][cury]==2)
{
cbr.CreateSolidBrush(GREEN);
pictc = m_GREEN;
}
else if(m_jwlabel[curx][cury]==3)
{
cbr.CreateSolidBrush(BLUE);
pictc = m_BLUE;
}
else if(m_jwlabel[curx][cury]==4)
{
cbr.CreateSolidBrush(YELLOW);
pictc = m_YELLOW;
}
else if(m_jwlabel[curx][cury] == 0)
{
cbr.CreateSolidBrush(RGB(255,255,255));
pictc = m_WHITE;
}
}
else
{
cbr.CreateSolidBrush(RGB(255,255,255));
pictc = m_WHITE;
}
if(m_IsBoxFilled[temp.x][temp.y] == FALSE && m_picture_edge[temp.x][temp.y] ==FALSE && type == true)
{
pDC->FillRect(CRect(pointbig.x+1,pointbig.y+1,pointbig.x+m_Step_Line,pointbig.y+(int)(m_Step_Line*m_jwm)),&cbr);
cbr.DeleteObject();
m_IsBoxFilled[temp.x][temp.y] = TRUE;
m_picture_color[temp.y][temp.x] = pictc;//
CPoint pt;
int cx,cy;
pt.x = pointbig.x -m_Step_Line;
pt.y = pointbig.y ;
if(curx ==0)
cx = m_width-1;
else
cx = curx-1;
cy = cury;
RecersiveFill(pDC,pt,cx,cy,type);
if(cury == m_height-1)
cy = 0;
else
cy = cury +1;
cx = curx;
pt.x = pointbig.x;
pt.y = pointbig.y +(int)(m_Step_Line*m_jwm);
RecersiveFill(pDC,pt,cx,cy,type);
if(curx == m_width-1)
cx =0;
else
cx = curx+1;
cy = cury;
pt.x = pointbig.x +m_Step_Line;
pt.y = pointbig.y;
RecersiveFill(pDC,pt,cx,cy,type);
if(cury ==0)
cy = m_height-1;
else
cy = cury-1;
cx = curx;
pt.x = pointbig.x;
pt.y = pointbig.y -(int)(m_Step_Line*m_jwm);
RecersiveFill(pDC,pt,cx,cy,type);
}
if(m_IsBoxFilled[temp.x][temp.y] == TRUE && m_picture_edge[temp.x][temp.y] ==FALSE && type == false)
{
pDC->FillRect(CRect(pointbig.x+1,pointbig.y+1,pointbig.x+m_Step_Line,pointbig.y+(int)(m_Step_Line*m_jwm)),&cbr);
cbr.DeleteObject();
m_IsBoxFilled[temp.x][temp.y] = FALSE;
m_picture_color[temp.x][temp.y] = pictc;
CPoint pt;
int cx,cy;
pt.x = pointbig.x -m_Step_Line;
pt.y = pointbig.y ;
if(curx ==0)
cx = m_width-1;
else
cx = curx-1;
cy = cury;
RecersiveFill(pDC,pt,cx,cy,type);
if(cury == m_height-1)
cy = 0;
else
cy = cury +1;
cx = curx;
pt.x = pointbig.x;
pt.y = pointbig.y +(int)(m_Step_Line*m_jwm);
RecersiveFill(pDC,pt,cx,cy,type);
if(curx == m_width-1)
cx =0;
else
cx = curx+1;
cy = cury;
pt.x = pointbig.x +m_Step_Line;
pt.y = pointbig.y;
RecersiveFill(pDC,pt,cx,cy,type);
if(cury ==0)
cy = m_height-1;
else
cy = cury-1;
cx = curx;
pt.x = pointbig.x;
pt.y = pointbig.y -(int)(m_Step_Line*m_jwm);
RecersiveFill(pDC,pt,cx,cy,type);
}
}
void CDesignerView::OnMouseMove(UINT nFlags, CPoint point)
{
DrawPicture dp;
CDC *dc = GetDC();
CPoint tp = this->GetScrollPosition();
if( !(nFlags & MK_LBUTTON) && m_DrawMode == PASTE )
{
CPoint ttp = gLocatePoint(point,m_jwm,tp);
if(ttp.x >=this->m_Paste_Current.LeftTop.x &&
ttp.x <=this->m_Paste_Current.RightBottom.x &&
ttp.y <=this->m_Paste_Current.RightBottom.y &&
ttp.y >=this->m_Paste_Current.LeftTop.y)
ghCursor = AfxGetApp()->LoadCursor(IDC_CURSOR_MOVEPASTE);
else
ghCursor = NULL;
}
if(nFlags & MK_LBUTTON && m_DrawMode == PASTE)
{
CPoint cmp = gLocatePoint(point,m_jwm,tp);
if(cmp.x != this->m_Paste_Current.CurrentMouse.x ||
cmp.y != this->m_Paste_Current.CurrentMouse.y)
{
this->AntPasteColor(dc,this->m_Paste_Current,tp);
int xo = cmp.x -m_Paste_Current.CurrentMouse.x;
int yo = cmp.y - m_Paste_Current.CurrentMouse.y;
m_Paste_Current.LeftTop.x +=xo;
m_Paste_Current.LeftTop.y +=yo;
m_Paste_Current.RightBottom.x +=xo;
m_Paste_Current.RightBottom.y +=yo;
for(int i=0;i<m_Paste_Current.RectLen;i++)
{
m_Paste_Current.RectsInfo[i].location.x +=xo;
m_Paste_Current.RectsInfo[i].location.y +=yo;
if(this->m_picture_edge[m_Paste_Current.RectsInfo[i].location.x][m_Paste_Current.RectsInfo[i].location.y] == true)
{
m_Paste_Current.RectsInfo[i].pc = m_OTHER;
continue;
}
if(this->m_picture_color[m_Paste_Current.RectsInfo[i].location.y][m_Paste_Current.RectsInfo[i].location.x] == m_RED)
m_Paste_Current.RectsInfo[i].pc = m_RED;
else if(this->m_picture_color[m_Paste_Current.RectsInfo[i].location.y][m_Paste_Current.RectsInfo[i].location.x] == m_GREEN)
m_Paste_Current.RectsInfo[i].pc = m_GREEN;
else if(this->m_picture_color[m_Paste_Current.RectsInfo[i].location.y][m_Paste_Current.RectsInfo[i].location.x] == m_BLUE)
m_Paste_Current.RectsInfo[i].pc = m_BLUE;
else if(this->m_picture_color[m_Paste_Current.RectsInfo[i].location.y][m_Paste_Current.RectsInfo[i].location.x] == m_YELLOW)
m_Paste_Current.RectsInfo[i].pc = m_YELLOW;
else if(this->m_picture_color[m_Paste_Current.RectsInfo[i].location.y][m_Paste_Current.RectsInfo[i].location.x] == m_WHITE)
m_Paste_Current.RectsInfo[i].pc = m_WHITE;
}
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_Scr.RectLen;i++)
{
if(m_Paste_Scr.RectsInfo[i].pc == m_RED)
dc->FillRect(CRect((this->m_Paste_Current.RectsInfo[i].location.x )*m_Step_Line+OFFSET+1-tp.x,
(this->m_Paste_Current.RectsInfo[i].location.y )*(int)(m_Step_Line*m_jwm)+OFFSET +1-tp.y,
(this->m_Paste_Current.RectsInfo[i].location.x +1)*m_Step_Line+OFFSET-tp.x,
(this->m_Paste_Current.RectsInfo[i].location.y +1 )*(int)(m_Step_Line*m_jwm)+OFFSET-tp.y),
&cbred);
else if(m_Paste_Scr.RectsInfo[i].pc == m_GREEN)
dc->FillRect(CRect((this->m_Paste_Current.RectsInfo[i].location.x )*m_Step_Line+OFFSET+1-tp.x,
(this->m_Paste_Current.RectsInfo[i].location.y )*(int)(m_Step_Line*m_jwm)+OFFSET +1-tp.y,
(this->m_Paste_Current.RectsInfo[i].location.x +1)*m_Step_Line+OFFSET-tp.x,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -