⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 designerview.cpp

📁 《数字图象工程案例》原码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
								(this->m_Paste_Current.RectsInfo[i].location.y +1 )*(int)(m_Step_Line*m_jwm)+OFFSET-tp.y),
								&cbgreen);
				else if(m_Paste_Scr.RectsInfo[i].pc == m_BLUE)
					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),
								&cbblue);
				else if(m_Paste_Scr.RectsInfo[i].pc == m_YELLOW)
					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),
								&cbyellow);
				else if(m_Paste_Scr.RectsInfo[i].pc == m_WHITE)
					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),
								&cbwhite);
			}
			cbred.DeleteObject();
			cbgreen.DeleteObject();
			cbblue.DeleteObject();
			cbyellow.DeleteObject();
			cbwhite.DeleteObject();
			m_Paste_Current.CurrentMouse = cmp;
		}
	}
	if(nFlags & MK_LBUTTON && m_DrawMode == ERASE)
	{
		CPoint tep;
		tep = LocatePoint(point);
		tep.x +=3;
		tep.y +=2;
		if(!(tep.x< 0 || tep.x >=m_LineNum.x-1|| tep.y <0 || tep.y >=m_LineNum.y-1))
		{
		
		
		CBrush m_brush;
		m_brush.CreateSolidBrush(WHITE);
		if(tep.x>=0 && tep.x<m_LineNum.x && tep.y >=0 &&tep.y <m_LineNum.y)
		{
		
			for(int i=-1;i<=1;i++)
				for(int j=-1;j<=1;j++)
				{
					CPoint ttp;
					ttp.x = tep.x +j;
					ttp.y = tep.y +i;
					if(ttp.x >=0 && ttp.x <m_LineNum.x && ttp.y >=0 && ttp.y <m_LineNum.y)
					{
					
						dc->FillRect(CRect((tep.x+j)*m_Step_Line+OFFSET-tp.x+1,(tep.y+i)*(int)(m_Step_Line*m_jwm)+OFFSET-tp.y+1,(tep.x+j)*m_Step_Line+OFFSET-tp.x+m_Step_Line,(tep.y+1+i)*(int)(m_Step_Line*m_jwm)+OFFSET-tp.y),&m_brush);
						m_picture_edge[tep.x+j][tep.y+i] = FALSE;
						m_picture_color[tep.y+i][tep.x+j] = m_WHITE;
					}
				}
		}
	
		m_brush.DeleteObject();
	}
  
	}

	
	if(!(nFlags & MK_LBUTTON) && m_DrawMode == CIRCLEMOVE)
	{
		int radius = pow((m_Circle_Scr.LeftTop.x -m_Circle_Scr.RightBottom.x),2)+pow((m_Circle_Scr.LeftTop.y - m_Circle_Scr.RightBottom.y),2);
		if(radius>(pow((m_Circle_Scr.LeftTop.x - point.x),2)+pow((m_Circle_Scr.LeftTop.y - point.y),2)))
			ghCursor = AfxGetApp()->LoadCursor(IDC_MOVE_RECTAN);
		else
			ghCursor = NULL;
	}
	if(nFlags & MK_LBUTTON && m_DrawMode == CIRCLEMOVE && ghCursor)
	{
		
		int xOffset,yOffset;
		xOffset = gLocatePoint(point,m_jwm,tp).x - gLocatePoint(m_Circle_Scr.CurrentMouse,m_jwm,tp).x;
		yOffset = gLocatePoint(point,m_jwm,tp).y - gLocatePoint(m_Circle_Scr.CurrentMouse,m_jwm,tp).y;
		if(xOffset ==0 && yOffset ==0)
			return;
		this->AntCircle(dc,m_Circle_Scr,tp,false);
		m_Circle_Scr.LeftTop.x +=point.x-m_Circle_Scr.CurrentMouse.x;
		m_Circle_Scr.LeftTop.y +=point.y-m_Circle_Scr.CurrentMouse.y;
		m_Circle_Scr.RightBottom.x +=point.x-m_Circle_Scr.CurrentMouse.x;
		m_Circle_Scr.RightBottom.y +=point.y-m_Circle_Scr.CurrentMouse.y;
		m_Circle_Scr.CurrentMouse = point;
		for(int i=1;i<m_Circle_Scr.RectLen;i++)
		{
			m_Circle_Scr.RectsInfo[i].location.x +=xOffset;
			m_Circle_Scr.RectsInfo[i].location.y +=yOffset;
		}
		
		for( i=1;i<m_Circle_Scr.RectLen;i++)
		{	
			if(m_Circle_Scr.RectsInfo[i].location.x <0 
				|| m_Circle_Scr.RectsInfo[i].location.x > this->m_LineNum.x-1
				|| m_Circle_Scr.RectsInfo[i].location.y <0
				|| m_Circle_Scr.RectsInfo[i].location.y > this->m_LineNum.y -1)
				continue;
			
				
			dc->FillRect(CRect((m_Circle_Scr.RectsInfo[i].location.x )*m_Step_Line+OFFSET+1-tp.x,
								(m_Circle_Scr.RectsInfo[i].location.y )*(int)(m_Step_Line*m_jwm)+OFFSET+1-tp.y,
								(m_Circle_Scr.RectsInfo[i].location.x +1)*m_Step_Line+OFFSET-tp.x,
								(m_Circle_Scr.RectsInfo[i].location.y +1)*(int)(m_Step_Line*m_jwm)+OFFSET-tp.y),&this->m_CBrushWG);
	
			    
			if(this->m_picture_color[m_Circle_Scr.RectsInfo[i].location.y][m_Circle_Scr.RectsInfo[i].location.x] == m_RED)
				m_Circle_Scr.RectsInfo[i].pc = m_RED;
			else if(this->m_picture_color[m_Circle_Scr.RectsInfo[i].location.y][m_Circle_Scr.RectsInfo[i].location.x] == m_GREEN)
				m_Circle_Scr.RectsInfo[i].pc = m_GREEN;
			else if(this->m_picture_color[m_Circle_Scr.RectsInfo[i].location.y][m_Circle_Scr.RectsInfo[i].location.x] == m_BLUE)
				m_Circle_Scr.RectsInfo[i].pc = m_BLUE;
			else if(this->m_picture_color[m_Circle_Scr.RectsInfo[i].location.y][m_Circle_Scr.RectsInfo[i].location.x] == m_YELLOW)
				m_Circle_Scr.RectsInfo[i].pc = m_YELLOW;
			else if(this->m_picture_color[m_Circle_Scr.RectsInfo[i].location.y][m_Circle_Scr.RectsInfo[i].location.x] == m_WHITE)
				m_Circle_Scr.RectsInfo[i].pc = m_WHITE;

		}
		
	}
	

	

LLL: ;	


	if(nFlags & MK_LBUTTON && m_DrawMode == RENYITXDRAW)
	{
		CPoint judge = gLocatePoint(point,m_jwm,tp);
		CPoint temp;			
		if(judge.x != m_Rytx_Draw_CurrentPoint.x || judge.y != m_Rytx_Draw_CurrentPoint.y)
		
			{
			 if(judge.x <0)
			 {   
				 temp.x =0;
				 if(judge.y <0)
				 	temp.y =0;					 
				 else if(judge.y >m_LineNum.y-1)
					 temp.y = m_LineNum.y-1;
				 else 
					 temp.y = judge.y;
				 m_picture_edge[temp.x][temp.y] = true;
				 
			 }
			else if(judge.x>m_LineNum.x-1)
			{
				temp.x = m_LineNum.x-1;
				 if(judge.y <0)
				 	temp.y =0;					 
				 else if(judge.y >m_LineNum.y-1)
					 temp.y = m_LineNum.y-1;
				 else 
					 temp.y = judge.y;
				 m_picture_edge[temp.x][temp.y]=true;
				
			}
		   else
		   {
			   temp.x = judge.x;
			   if(judge.y <0)
				 	temp.y =0;					 
				 else if(judge.y >m_LineNum.y-1)
					 temp.y = m_LineNum.y-1;
				 else 
					 temp.y = judge.y;
				 m_picture_edge[temp.x][temp.y]=true;

		   }
			//m_Rytx_Draw_Struct.m_Location[m_Rytx_Draw_Struct.m_CurrPoint] = judge;
			//	m_Rytx_Draw_Struct.m_CurrPoint++;
				dc->FillRect(CRect(temp.x * m_Step_Line+OFFSET +1 -tp.x,temp.y * (int)(m_Step_Line*m_jwm)+OFFSET+1-tp.y,
								(temp.x+1) * m_Step_Line+OFFSET-tp.x ,(temp.y+1)*(int)(m_Step_Line*m_jwm)+OFFSET-tp.y),&m_CBrushWG);
				this->m_Rytx_Draw_CurrentPoint = judge;
				//m_picture_edge[judge.x][judge.y] = true;
				
			}

	}
	

	
	if(!(nFlags & MK_LBUTTON) && m_DrawMode == RECTMOVE)
	{
		CPoint k ;
		k.x = point.x +tp.x;
		k.y = point.y +tp.y;
		if(k.x >=RectLeftTop.x && k.x <RectRightBottom.x && k.y >=RectLeftTop.y && k.y <=RectRightBottom.y)
		{
			ghCursor = AfxGetApp()->LoadCursor(IDC_MOVE_RECTAN);
		}
		else 
			ghCursor = NULL;
	}
	if(nFlags & MK_LBUTTON && m_DrawMode == RECTMOVE && ghCursor)
	{	
		int xOffset,yOffset;
		if(m_Current_Mouse.x != point.x || m_Current_Mouse.y !=point.y)
		{
			xOffset = point.x -m_Current_Mouse.x;
			yOffset = point.y - m_Current_Mouse.y;
		}
		this->AntRectang(dc,tp);
		this->m_RectsInfo.RectLen =0;
		RectLeftTop.x +=xOffset;
		RectRightBottom.x +=xOffset;
		RectLeftTop.y +=yOffset;
		RectRightBottom.y +=yOffset;
		dp.Rectang(dc,RectLeftTop,RectRightBottom,WGCOLOR,m_Step_Line,this->m_jwm,false,tp);
		m_Current_Mouse.x = point.x;
		m_Current_Mouse.y = point.y;
	}

	if(nFlags & MK_LBUTTON && this->m_DrawMode == RECTDRAW)
	{
		if(m_RectsInfo.IsValide == true)
		{
	
			this->AntRectang(dc,tp);
			this->m_RectsInfo.RectLen =0;
			dp.Rectang(dc,this->RectLeftTop,point,WGCOLOR,m_Step_Line,this->m_jwm,false,tp);
		}
		
	}


	if(m_DrawMode == CIRCLE && m_Circle_Scr.IsValide && !m_Circle_Scr.IsFinish )
	{
		if(point.x != m_CircleCenter.x || point.y != m_CircleCenter.y )
		{	
			this->AntCircle(dc,m_Circle_Scr,tp,false);
			dp.Circle(dc,point,EDGECOLOR,m_jwm,false,tp,&(this->m_Circle_Scr));
			this->m_Circle_Scr.CurrentMouse = point;
				

		}
	}


	ReleaseDC(dc);
	CScrollView::OnMouseMove(nFlags, point);
}

void CDesignerView::OnRButtonDown(UINT nFlags, CPoint point) 
{
			
	DrawPicture dp;
	CBrush cbr;
	CDC* dc = GetDC();
	CPoint tp = this->GetScrollPosition();
	
	

	
	if(m_DrawMode == CIRCLE)
	{
		if(this->m_Circle_Scr.IsValide)
		{	
			this->m_Circle_Scr.IsValide = false;
			this->AntCircle(dc,this->m_Circle_Scr,tp,false);
		}
				
	}
	ReleaseDC(dc);
	CScrollView::OnRButtonDown(nFlags, point);
}


void CDesignerView::OnLButtonUp(UINT nFlags, CPoint point) 
{

	CDC *dc = GetDC();
	CPoint Scroll = this->GetScrollPosition();
	


	if(m_DrawMode == CIRCLEMOVE && ghCursor)
	{
		for(int i=0;i<m_LineNum.y;i++)
			for(int j=0;j<m_LineNum.x;j++)
				this->m_picture_edge[j][i] = false;
			for(i=0;i<m_Circle_Scr.RectLen;i++)
				this->m_picture_edge[m_Circle_Scr.RectsInfo[i].location.x][m_Circle_Scr.RectsInfo[i].location.y] = true;
			
	}

	if(m_DrawMode == RECTDRAW)
	{	
		if(m_RectsInfo.IsValide == true)
		{
		
			DrawPicture dp;
			dp.Rectang(dc,this->RectLeftTop,point,WGCOLOR,m_Step_Line,m_jwm,true,Scroll);
			RectRightBottom = gLocatePoint(point,m_jwm,Scroll);
			RectRightBottom.x = RectRightBottom.x * m_Step_Line+OFFSET -Scroll.x+1 ;
			RectRightBottom.y = RectRightBottom.y *(int)(m_Step_Line*m_jwm) - Scroll.y+OFFSET+1;
			this->m_RectsInfo.RightBottom = RectRightBottom;
			this->m_DrawMode = RECTMOVE;
			
		
			IsCutUsable = true;
			IsCopyUsable = true;

		}
	
		
	}
	if(m_DrawMode == RECTMOVE && ghCursor)
	{	for(int i=0;i<LINENUM;i++)
			for(int j=0;j<LINENUM;j++)
				this->m_picture_edge[i][j] = false;
		DrawPicture dp;
		dp.Rectang(dc,this->RectLeftTop,RectRightBottom,WGCOLOR,m_Step_Line,m_jwm,true,Scroll);

	}
	
	
	ReleaseDC(dc);
	
	CScrollView::OnLButtonUp(nFlags, point);
}



void CDesignerView::OnMenuGyQuzadian() 
{	
	DeleteScatter ds;
	ds.DoModal();
	// TODO: Add your command handler code here
	
}











void CDesignerView::OnMenuPicReducecolor() 
{
	// TODO: Add your command handler code here
		REDUCECOLOR rc;
	if(rc.DoModal() == IDOK)
	{
		UpdateData(FALSE);
		m_Num_Color = rc.m_Num_Color;
		if(0<m_Num_Color && m_Num_Color<=5)
		{
			DIB tempdib;
			ASSERT(hDIB != NULL);
			tempdib.ReduceColor(hDIB,m_Num_Color);
		if(m_jwm == 0.0)
			m_jwm = 1.0;
			tempdib.WangGeHua(hDIB,m_Step_Line,this->m_jwm);
			LPBITMAPINFOHEADER lpbi;
			LPBYTE lpData = tempdib.FindDIBBits(hDIB);
			lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB);
			WORD wBytesPerLine  = tempdib.BytePerLine(hDIB);
			int templen = (int)(m_Step_Line*m_jwm);
			for(int i=0;i<m_LineNum.y;i++)
				for(int j=0;j<m_LineNum.x;j++)
				{
					long lOffset = tempdib.PixelOffset(i*templen+1,j*m_Step_Line+1,wBytesPerLine);
					int b = *(lpData+lOffset++);
					int g = *(lpData+lOffset++);
					int r = *(lpData+lOffset++);
					if((r|(g<<8)|(b<<16)) == 0x000000ff)
						this->m_picture_color[m_LineNum.y-1-i][j] = m_RED;
					else if ((r|(g<<8)|(b<<16)) == 0x0000ff00)
						this->m_picture_color[m_LineNum.y-1-i][j] = m_GREEN;
					else if ((r|(g<<8)|(b<<16)) == 0x00ff0000)
						this->m_picture_color[m_LineNum.y-1-i][j] = m_BLUE;
					else if ((r|(g<<8)|(b<<16)) == 0x0000ffff)
						this->m_picture_color[m_LineNum.y-1-i][j] = m_YELLOW;
					else if ((r|(g<<8)|(b<<16)) == 0x00ffffff)
						this->m_picture_color[m_LineNum.y-1-i][j] = m_WHITE;
				}
		   
				
			
			IsOtherPictureMenuUsable = true;
			
			Invalidate();
			GlobalUnlock(hDIB);	
			m_ReduceColor = true;
			this->m_Fill_Picture = false;
			this->m_DrawMode = OTHER;

		
		}
	
	}
}

































void CDesignerView::AntRectang(CDC *pDC,CPoint Scroll)
{
	CBrush cbred,cbgreen,cbblue,cbyellow,cbwhite;
	cbred.CreateSolidBrush(RED);
	cbgreen.CreateSolidBrush(GREEN);
	cbblue.CreateSolidBrush(BLUE);
	cbyellow.CreateSolidBrush(YELLOW);
	cbwhite.CreateSolidBrush(WHITE);
	for(int i=0;i<this->m_RectsInfo.RectLen;i++)
	{
		if(m_RectsInfo.RectsInfo[i].pc == m_RED)
			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),
								&cbred);
		if(m_RectsInfo.RectsInfo[i].pc == m_GREEN)
			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),
								&cbgreen);
		if(m_RectsInfo.RectsInfo[i].pc == m_BLUE)
			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),

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -