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

📄 mypaintview.cpp

📁 用Visual C++实现的绘制函数图像的程序。给定任意函数表达式
💻 CPP
📖 第 1 页 / 共 2 页
字号:
					pk1=pk1/(pk1-LENS);
					net1.x=(eye.x-p_line->point[n].x*fov*zoom)*pk1;
					net1.y=(eye.y-p_line->point[n].y*fov*zoom)*pk1;
					net1.z=(eye.z-p_line->point[n].z*fov*zoom)*pk1;
					r1.x=r[0][0]*net1.x+r[0][1]*net1.y+r[0][2]*net1.z;
					r1.y=r[1][0]*net1.x+r[1][1]*net1.y+r[1][2]*net1.z;
				}
				else
					r1.x=r1.y=0;
				nl1.x=(r[0][0]*p_line->point[n].x+r[0][1]*p_line->point[n].y+r[0][2]*p_line->point[n].z)*fov*zoom+r1.x;
				nl1.y=(r[1][0]*p_line->point[n].x+r[1][1]*p_line->point[n].y+r[1][2]*p_line->point[n].z)*fov*zoom+r1.y;
				dc.SetPixel(nl1.x+x,-nl1.y+y,p_line->color);	
			}
		p_line=p_line->next;
		pen.DeleteObject();
	}
	////////////////把内存DC的图像COPY到视图DC
	pDC->BitBlt(m_rectClient.left,
				m_rectClient.top, 
				m_rectClient.Width(),
				m_rectClient.Height(),
				&dc,
				0,
				0,
				SRCCOPY);
	dc.SelectObject(pOldBitmap);
}
void CMyPaintView::OnMouseMove(UINT nFlags, CPoint point) 
{
	CString mouse_x,mouse_y;
	extern CMainFrame* mainwnd;	
	char i;
	short temp;
	if(flag_xy)
	{		
		if(flag_rotexy)
		{
			SetCapture();
			if(point.x-mouse_down.x<0)
				a2+=0.03;
			else
			if(point.x-mouse_down.x>0)
				a2-=0.03;
			if(point.y-mouse_down.y<0)
				a1+=0.03;
			else
			if(point.y-mouse_down.y>0)
				a1-=0.03;
			mouse_down=point;
			Invalidate(TRUE);
		}
		SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
	}
	else
	if(flag_z)
	{
		if(flag_rotez)
		{
			SetCapture();
			if(point.x-mouse_down.x>0)
				a3-=0.03;
			else
			if(point.x-mouse_down.x<0)	
				a3+=0.03;
			mouse_down=point;
			Invalidate(TRUE);
		}
		SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE));
	}
	else
	if(flag_FOV)
	{
		if(flag_zoom)
		{
			SetCapture();
			temp=point.y-tmp_point.y;
			CRect r_view,r_wnd;	
			GetClientRect(&r_view);
			mainwnd->GetWindowRect(r_wnd);								
			if(point.y<20)
				SetCursorPos(point.x+r_wnd.left,y_screen-40);
			else
			if(point.y>y_screen-r_wnd.top-100)
				SetCursorPos(point.x+r_wnd.left,r_wnd.top+100);
			if(temp<0)
				zoom=zoom/80.0+zoom;
			else
				zoom=-zoom/80.0+zoom;
			tmp_point=point;	
			if(zoom<0.1)
				zoom=0.1;
			if(zoom>8)
				zoom=8;
			Invalidate(TRUE);
		}
		SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));	
	}
	else
	if(flag_drag)
	{	
		SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
		SetCapture();
		xs=point.x-mouse_down.x;
		ys=point.y-mouse_down.y;		
		Invalidate(TRUE);		
	}
	else
	if(flag_texdrag)
	{
		SetCapture();
		MY_LINE *p_line=head;
		i=select_line;	
		while(i!=0)
		{
			p_line=p_line->next;
			i--;
		}
		p_line->tem_xs=point.x-mouse_down.x;
		p_line->tem_ys=point.y-mouse_down.y;
		Invalidate(TRUE);
	}
	else
	if(!flag_drag&&!flag_zoom)
	{
		ReleaseCapture();
		SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
		mouse_x.Format("%s%.2f","X=",(point.x-x)/(fov*zoom));
		mouse_y.Format("%s%.2f","Y=",(y-point.y)/(fov*zoom));
		mainwnd->m_wndStatusBar.SetPaneText(1,mouse_x,TRUE);
		mainwnd->m_wndStatusBar.SetPaneText(2,mouse_y,TRUE);
		/////////////////////
		i=0;
		MY_LINE *p_line=head;
		while(p_line!=NULL)
		{
			short length=26+6*strlen(p_line->expres);
			if(point.x>(15+p_line->tex_xs+x_tex)&&point.x<=(length+p_line->tex_xs+x_tex)&&point.y>(17+20*i+p_line->tex_ys+y_tex)&&point.y<(34+i*20+p_line->tex_ys+y_tex))
			{
				SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));
				flag_del=1;
				select_line=i;
				break;
			}
			else
				flag_del=0;
			i++;
			p_line=p_line->next;
		}
		
	}

	CView::OnMouseMove(nFlags, point);
}

void CMyPaintView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	mouse_down=point;
	if(flag_xy)
		flag_rotexy=1;
	else
	if(flag_z)
		flag_rotez=1;
	else
	if(flag_FOV)
		flag_zoom=1;
	if(!flag_del)
	{		
		if(!flag_FOV&&!flag_xy&&!flag_z)
			SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL));	
		if(paint.flag_modify==1)
		{
			paint.flag_modify=0;
			paint.OnSelchangeTab();
		}
		flag_drag=1;
	}
	else
	{	
		flag_texdrag=1;
		flag_drag=0;
	}
	CView::OnLButtonDown(nFlags, point);
}

void CMyPaintView::OnLButtonUp(UINT nFlags, CPoint point) 
{	
	bufferx=x;
	buffery=y;
	ReleaseCapture();
	if(flag_texdrag)
	{
		MY_LINE *p_line=head;
		char i=select_line;	
		while(i!=0)
		{
			p_line=p_line->next;
			i--;
		}
		p_line->tex_xs=p_line->tem_xs+p_line->tex_xs;
		p_line->tex_ys=p_line->tem_ys+p_line->tex_ys;
		p_line->tem_xs=p_line->tem_ys=0;
	}
	flag_rotexy=0;
	flag_rotez=0;
	flag_zoom=0;
	flag_texdrag=0;
	flag_drag=0;
	flag_zoom=0;
	
	xs=ys=0;
	SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
	CView::OnLButtonUp(nFlags, point);
}
void CMyPaintView::OnRButtonDown(UINT nFlags, CPoint point) 
{
	tmp_point=point;
	flag_zoom=flag_xy=flag_z=flag_rotexy=flag_rotez=flag_FOV=0;
	if(flag_drag==0)
	{
		if(paint.flag_modify==1)
		{
			paint.flag_modify=0;
			paint.OnSelchangeTab();
		}
		/////////////////////////////右键弹出菜单
		CMenu PopMenu,*pMenu;
		CPoint pt=point;
		ClientToScreen (&pt); 
		PopMenu.LoadMenu(IDR_POPMENU);
		pMenu = PopMenu.GetSubMenu (0); 
		pMenu->TrackPopupMenu(TPM_LEFTBUTTON,pt.x+2,pt.y+2,this);
	}
	CView::OnRButtonDown(nFlags, point);
}

void CMyPaintView::OnRButtonUp(UINT nFlags, CPoint point) 
{
	flag_zoom=0;
	ReleaseCapture();
	CView::OnRButtonUp(nFlags, point);
}


void CMyPaintView::OnShowHide() 
{
	net_show=!net_show;
	Invalidate(TRUE);
}

void CMyPaintView::OnNNet() 
{
	net_style=0;
	net_show=1;
	Invalidate(TRUE);
}

void CMyPaintView::OnPNet() 
{
	if(a1||a2||a3)
		MessageBox("对不起,旋转时不能显示极坐标网格!","抱歉",MB_OK);
	else
	{
		net_style=1;
		net_show=1;
		Invalidate(TRUE);
	}	
}

void CMyPaintView::OnPopHelp() 
{	
	mainwnd->OnAppAbout();
}

BOOL CMyPaintView::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	return TRUE;
	//return CView::OnEraseBkgnd(pDC);
}

void CMyPaintView::OnDeleteLine() 
{
	MY_LINE *temp1=head,*temp2;
	extern MY_LINE *p2;
	if(flag_del)
	{
		if(select_line==0)
		{
			MY_LINE *temp1=head;
			head=head->next;			
			delete(temp1);
		}
		else
		if(select_line+1==line_count)		
		{
			while(select_line!=0)
			{
				temp2=temp1;
				temp1=temp1->next;
				select_line--;
			}
			temp2->next=NULL;
			p2=temp2;
			delete(temp1);
		}
		else
		{
			while(select_line!=0)
			{
				temp2=temp1;
				temp1=temp1->next;
				select_line--;
			}
			temp2->next=temp1->next;			
			delete(temp1);
		}
		line_count--;
		flag_del=0;
		Invalidate(TRUE);
	}
	else
		MessageBox("请选中要删除的对象!","错误",MB_OK);
	select_line=-1;
	paint.flag_modify=0;
	paint.OnSelchangeTab();
}

void CMyPaintView::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	if(flag_del)
	{
		MY_LINE *p_line=head;
		char i=select_line;	
		while(i!=0)
		{
			p_line=p_line->next;
			i--;
		}
		short length=26+6*strlen(p_line->expres);
		switch (p_line->tag)
		{
		case 0:paint.m_expres=p_line->real_expres[0];break;
		case 1:paint.m_xexpres=p_line->real_expres[0],
			   paint.m_yexpres=p_line->real_expres[1],
			   paint.m_zexpres=p_line->real_expres[2];break;
		case 2:paint.m_pexpres=p_line->real_expres[0];break;
		}
		paint.flag_modify=1;
		paint.SetWindowPos(NULL,length+p_line->tem_xs+p_line->tex_xs+x_tex+2,46+20*i+p_line->tem_ys+p_line->tex_ys+y_tex,0,0,SWP_NOSIZE);
		paint.color=p_line->color;
		paint.m_choices.SetCurSel(p_line->tag);
		paint.m_a=p_line->m_a;
		paint.m_b=p_line->m_b;	
		paint.m_pattern.SetCurSel(p_line->style);
		paint.OnSelchangeTab();
		paint.UpdateData(FALSE);			
		paint.ShowWindow(SW_SHOW);
	}

	CView::OnLButtonDblClk(nFlags, point);
}


void CMyPaintView::OnSet() 
{
	mainwnd->OnSet();
}

void CMyPaintView::OnAboutMe() 
{
	mainwnd->OnAboutMe();
}

void CMyPaintView::OnSaveBmp() 
{
	CFileDialog dlg(false,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
		"位图文件(*.bmp)|*.bmp|",
		NULL);
	if (dlg.DoModal()!= IDOK)
		return;
	CString filename = dlg.GetFileName() + ".bmp";
	//////////////////////////////////
	CRect rect_view;
	GetClientRect(&rect_view);
	int iWidth = rect_view.Width();
	int iHeight = rect_view.Height();
	int iPixel = 16;
	//图形格式参数
	LPBITMAPINFO lpbmih = new BITMAPINFO;
	lpbmih->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	lpbmih->bmiHeader.biWidth = iWidth;
	lpbmih->bmiHeader.biHeight = iHeight;
	lpbmih->bmiHeader.biPlanes = 1;
	lpbmih->bmiHeader.biBitCount = iPixel;
	lpbmih->bmiHeader.biCompression = BI_RGB;
	lpbmih->bmiHeader.biSizeImage = 0;
	lpbmih->bmiHeader.biXPelsPerMeter = 0;
	lpbmih->bmiHeader.biYPelsPerMeter = 0;
	lpbmih->bmiHeader.biClrUsed = 0;
	lpbmih->bmiHeader.biClrImportant = 0;
	
	//创建位图数据
	HDC hdc,hdcMem;
	HBITMAP hBitMap = NULL;
	CBitmap *pBitMap = NULL;
	CDC *pMemDC = NULL;
	BYTE *pBits;
	
	hdc = CreateIC(TEXT("DISPLAY"),NULL,NULL,NULL);
	hdcMem = CreateCompatibleDC(hdc);
	hBitMap = CreateDIBSection(hdcMem,lpbmih,DIB_PAL_COLORS,(void **)&pBits,NULL,0);
	pBitMap = new CBitmap;
	pBitMap->Attach(hBitMap);
	pMemDC = new CDC;
	pMemDC->Attach(hdcMem);
	pMemDC->SelectObject(pBitMap);
	//
	pMemDC->SetBkMode(TRANSPARENT);
	//添加自绘图形 
	OnDraw(pMemDC);
	//保存到文件并创建位图结构
	BITMAPFILEHEADER bmfh;
	ZeroMemory(&bmfh,sizeof(BITMAPFILEHEADER));
	*((char *)&bmfh.bfType) = 'B';
	*(((char *)&bmfh.bfType) + 1) = 'M';
	bmfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
	bmfh.bfSize = bmfh.bfOffBits + (iWidth * iHeight) * iPixel / 8;
	
	TCHAR szBMPFileName[128];
	int iBMPBytes = iWidth * iHeight * iPixel / 8;
	strcpy(szBMPFileName,filename);
	CFile file;
	if(file.Open(szBMPFileName,CFile::modeWrite | CFile::modeCreate))
	{
		file.Write(&bmfh,sizeof(BITMAPFILEHEADER));
		file.Write(&(lpbmih->bmiHeader),sizeof(BITMAPINFOHEADER));
		file.Write(pBits,iBMPBytes);
		file.Close();
	}	
	pMemDC->DeleteDC();
	delete pMemDC; pMemDC = NULL;
	delete pBitMap; pBitMap = NULL;
	delete lpbmih; lpbmih = NULL;
}

void CMyPaintView::OnIdPaint() 
{
	mainwnd->OnIdPaint();
}

⌨️ 快捷键说明

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