📄 resaultview.cpp
字号:
// ResaultView.cpp : implementation file
//
#include "stdafx.h"
#include "P_R.h"
#include "ResaultView.h"
#include "globalExt.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// ResaultView
IMPLEMENT_DYNCREATE(ResaultView, CView)
ResaultView::ResaultView()
{
}
ResaultView::~ResaultView()
{
}
BEGIN_MESSAGE_MAP(ResaultView, CView)
//{{AFX_MSG_MAP(ResaultView)
ON_WM_CONTEXTMENU()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// ResaultView drawing
void ResaultView::OnDraw(CDC* pDC)
{
// CDocument* pDoc = GetDocument();
DrawAxis(pDC);
CP_RDoc* pDoc = GetDocument();
CRect rc;
GetClientRect(&rc);
int Dis=rc.right-rc.left-19;
if(g_HaveTerrain)
{
g_Ray= new ray[2*Dis];
for(int i=0;i<Dis;i++)
{
g_Ray[i]=ray((int)g_fEXAxis,(int)g_fEYAxis,rc.left+10+i,rc.top+10);
if(g_Ray[i].PointInRay(rc.left+10+i,rc.top+10))
{
g_Ray[i].PrintPo(pDC,rc.left+10+i,rc.top+10,1.0/double(g_fEYAxis));
}
}
for(i=Dis;i<2*Dis;i++)
{
g_Ray[i]=ray((int)g_fEXAxis,(int)g_fEYAxis,rc.left+10+i,rc.bottom-10);
}
}
// else
// {
// if(g_Ray!=NULL)
// delete []g_Ray;
// }
BeginRay(pDC,Dis);
}
void ResaultView::BeginRay(CDC* pDC,int Dis)
{
CRect rc;
GetClientRect(&rc);
int x;int y;
int flag=g_SumTer;
if(flag)
{
while(flag--)
g_Terrain[flag].Draw(pDC);//给地形类赋值
}
if(g_HaveTerrain)
{
for(int i=Dis;i<2*Dis;i++)
{
/////////////////////////////
int flag=g_SumTer;
if(flag)
{
while(flag--)
g_Ray[i].MakeNew(pDC,g_Terrain[flag],x,y);
// g_Terrain[flag].Draw(pDC);//给地形类赋值
}
/////////////////////////////
//bool ray::MakeNew(CDC* pDC,Terrain temp,int &x,int &y)
//g_Ray[i]=ray((int)g_fEXAxis,(int)g_fEYAxis,rc.left+10+i,rc.bottom-10);
}
}
}
/*
void ResaultView::DrawA(CDC* pDC)
{
CP_RDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
//CPen pen(2,1,RGB(255,0,0)); //创建画笔
//CPen* pOldPen=pDC->SelectObject(&pen);//选入画笔
DrawAxis(pDC);
//int i=g_TotleP;
CBrush b;
b.CreateSolidBrush(RGB(0,255,0)); // 创建填充色画刷
CBrush* pOldBrush=(CBrush*)pDC->SelectObject(&b);//选择对象进DC
// pDC->Ellipse((int)g_Array(i,0)-3,(int)g_Array(i,1)-3,
// (int)g_Array(i,0)+3,(int)g_Array(i,1)+3);
//画点(以圆代替点)
pDC->SelectObject(pOldBrush);//恢复原始画刷
b.DeleteObject();
// pDC->SelectObject(pOldPen); //恢复画笔
}
*/
void ResaultView::DrawAxis(CDC* pDC)
{ //画坐标线的函数
//确定图象显示大小
CRect rc;
GetClientRect(&rc);
//确定X,Y轴每单位显示宽度
pDC->TextOut(0,0,"(0,0)");
CPen pen(0,2,RGB(0,0,0)); //创建画笔
CPen* pOldPen=pDC->SelectObject(&pen);//选入画笔
pDC->MoveTo(rc.left+10,rc.top+10);
pDC->LineTo(rc.right-10,rc.top+10);//画出X轴
pDC->MoveTo(rc.left+10,rc.top+10);
pDC->LineTo(rc.left+10,rc.bottom-10);//画出Y轴
pDC->SelectObject(pOldPen); //恢复画笔
//////////////////////////////////////////////////////
CPen pen2(0,1,RGB(0,0,0)); //创建画笔
CPen* pOldPen2=pDC->SelectObject(&pen2);//选入画笔
for(double ii=rc.left+10+37.8/2;ii<rc.right-10;ii+=37.8)
{
pDC->MoveTo(int(ii),rc.top+10);
pDC->LineTo(int(ii),rc.top+15);//X轴每5毫米一个间隔
}
for(ii=rc.top+10+37.8/2;ii<rc.bottom-10;ii+=37.8)
{
pDC->MoveTo(rc.left+10,int(ii));//Y轴每5毫米一个间隔
pDC->LineTo(rc.left+15,int(ii));
}
CString strAxis;
int k=0;
for(ii=rc.left+10;ii<rc.right-10;ii+=37.8)
{
pDC->MoveTo(int(ii),rc.top+10);
pDC->LineTo(int(ii),rc.top+20);////X轴每10毫米一个间隔
/*
k++;
if(k>1)
{
strAxis.Format("%.0f",double(k-1)*(g_fXDis/500.0/13.0)*g_fXDis);
pDC->TextOut(int(ii)-5,rc.top+20,strAxis);
}
*/
}
strAxis.Format("%.0f 米",g_fXDis);
int L=strAxis.GetLength();
pDC->TextOut(rc.right-L*7,rc.top+20,strAxis);
// k=0;
for(ii=rc.top+10;ii<rc.bottom-10;ii+=37.8)
{
pDC->MoveTo(rc.left+10,int(ii));
pDC->LineTo(rc.left+20,int(ii));////Y轴每10毫米一个间隔
/*
k++;
if(k>1)
{
strAxis.Format("%.0f",double(k-1)*(g_fYDis/600.0/16.0)*g_fYDis);
pDC->TextOut(rc.left+20,int(ii)-7,strAxis);
}
*/
}
CFont vFont;//第三个参数是字体的旋转角度,为了竖排输出文字
vFont.CreateFont(13,0,-900,
0,0,
FALSE,
FALSE,
FALSE,
ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
PROOF_QUALITY,
DEFAULT_PITCH+FF_ROMAN,
"Times New Roman"
);
CFont* pOldFont=pDC->SelectObject(&vFont);//选入画笔
strAxis.Format("%.0f 千米",g_fYDis);
L=strAxis.GetLength();
pDC->TextOut(rc.left+30,rc.bottom-6*L,strAxis);
pDC->SelectObject(pOldFont);
pDC->SelectObject(pOldPen2); //恢复画笔
}
COLORREF ResaultView::GotColor(int mem)
{
//
COLORREF pattern1[]={
0x00, 0x01, 0x80, 0x00,
0x00, 0x03, 0xc0, 0x00,
0x00, 0x07, 0xe0, 0x00,
0x00, 0x0f, 0xf0, 0x00,
0x00, 0x1f, 0xf8, 0x00,
0x00, 0x3f, 0xfc, 0x00,
0x00, 0x7f, 0xfe, 0x00,
0x00, 0xff, 0xff, 0x00,
0x01, 0xff, 0xff, 0x80,
0x03, 0xff, 0xff, 0xc0,
0x07, 0xff, 0xff, 0xe0,
0x0f, 0xff, 0xff, 0xf0,
0x1f, 0xff, 0xff, 0xf8,
0x3f, 0xff, 0xff, 0xfc,
0x7f, 0xff, 0xff, 0xfe,
0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff,
0x7f, 0xff, 0xff, 0xfe,
0x3f, 0xff, 0xff, 0xfc,
0x1f, 0xff, 0xff, 0xf8,
0x0f, 0xff, 0xff, 0xf0,
0x07, 0xff, 0xff, 0xe0,
0x03, 0xff, 0xff, 0xc0,
0x01, 0xff, 0xff, 0x80,
0x00, 0xff, 0xff, 0x00,
0x00, 0x7f, 0xfe, 0x00,
0x00, 0x3f, 0xfc, 0x00,
0x00, 0x1f, 0xf8, 0x00,
0x00, 0x0f, 0xf0, 0x00,
0x00, 0x07, 0xe0, 0x00,
0x00, 0x03, 0xc0, 0x00,
0x00, 0x01, 0x80, 0x00
};
COLORREF pattern2[]=
{
RGB(255,0,0), RGB(0,255,0), RGB(0,0,255),
RGB(255,255,0), RGB(255,0,255), RGB(0,255,255),
RGB(255,153,102), RGB(255,153,153),RGB(153,0,51)
};
if(mem<9)
return pattern2[mem];
else if(mem<100)
return pattern1[mem];
else
{
int r=rand()%256; // 为star[loop]设置随机红色分量
int g=rand()%256; // 为star[loop]设置随机红色分量
int b=rand()%256; // 为star[loop]设置随机红色分量
return RGB(r,g,b);
}
return RGB((int)255-255*(float)mem/100,(int)0+255*(float)mem/100,
(int)100+155*(float)mem/100);
}
/////////////////////////////////////////////////////////////////////////////
// ResaultView diagnostics
#ifdef _DEBUG
void ResaultView::AssertValid() const
{
CView::AssertValid();
}
void ResaultView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CP_RDoc* ResaultView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CP_RDoc)));
return (CP_RDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// ResaultView message handlers
void ResaultView::OnContextMenu(CWnd* pWnd, CPoint point)
{
/* CMenu menu;
menu.LoadMenu(IDR_MAINFRAME); //这个ID对应你在资源中创建的一个菜单
CMenu *submenu=menu.GetSubMenu(3); //对应你自定义菜单的第一列
submenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,point.x,point.y,this);//显示菜单
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -