?? axis.cpp
字號(hào):
// Axis.cpp: implementation of the CAxis class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "FilmDesign.h"
#include "Axis.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CAxis::CAxis()
{
this->m_Center.x=60;
this->m_Center.y=620;
this->m_Minx=200;
this->m_Miny=0;
this->m_Maxx=1000;
this->m_Maxy=100;
this->m_Intervalx=50.0f;
this->m_Intervaly=10.0f;
this->m_Color[0]=RGB(255,0,0);
this->m_Color[1]=RGB(255,0,0);
this->m_Lablex="X";
this->m_Labley="Y";
this->m_Width=3;
this->m_LineStyle=PS_SOLID;
this->m_Ratio[0]=2.0;
this->m_Ratio[1]=1.0;
}
CAxis::~CAxis()
{
}
CAxis::CAxis(CPoint center, CPoint min,CPoint max,double interval[2],CString title,CString lable[2],int linestyle,int width,COLORREF color[2])
{
this->m_Center=center;
this->m_Minx =min.x;
this->m_Miny=min.y;
this->m_Maxx=max.x;
this->m_Maxy=max.y;
this->m_Intervalx=interval[0];
this->m_Intervaly=interval[1];
this->m_Lablex=lable[0];
this->m_Labley=lable[1];
this->m_LineStyle=linestyle;
this->m_Color[0]=color[0];
this->m_Color[1]=color[1];
this->m_Width=width;
this->m_Ratio[0]=1.0f;
this->m_Ratio[1]=1.0f;
}
CAxis::CAxis(CAxis &axis)
{
this->m_Center =axis.m_Center ;
this->m_Color[0] =axis.m_Color[0] ;
this->m_Color[1] =axis.m_Color[1] ;
this->m_Intervalx=axis.m_Intervalx;
this->m_Intervaly=axis.m_Intervaly;
this->m_Lablex=axis.m_Lablex;
this->m_Labley=axis.m_Labley;
this->m_LineStyle =axis.m_LineStyle;
this->m_Maxx =axis.m_Maxx ;
this->m_Minx =axis.m_Minx ;
this->m_Miny=axis.m_Miny;
this->m_Maxy=axis.m_Maxy;
this->m_Width=axis.m_Width;
this->m_Ratio[0]=axis.m_Ratio[0] ;
this->m_Ratio[1]=axis.m_Ratio[1] ;
}
void CAxis::Draw(CDC* pDC,CRect rectClient)
{
//Set Ratio;
//initialize Central point of axis
//this->m_Center.x=long(rectClient.right*0.1);
//this->m_Center.y=long(rectClient.bottom*0.90);
CPen *pOldPen,penx(this->m_LineStyle,this->m_Width,m_Color[0]);
CPen peny(this->m_LineStyle,this->m_Width,m_Color[1]);
/**Draw X Coordinate**/
pOldPen=pDC->SelectObject(&penx);
pDC->MoveTo(this->m_Center);
if(rectClient.right<m_Center.x)
rectClient.right =::GetSystemMetrics(SM_CXSCREEN) ; ;
pDC->LineTo(rectClient.right,this->m_Center.y);
// m_Center.x=rectClient.right *0.2;
//m_Center.y=rectClient.bottom*0.8;
//Draw arrow for X coordinate
CPoint m1,m2,m_3;
m1.x=long(rectClient.right*0.96);
m1.y=long(this->m_Center.y*1.01);
m2.x=long(rectClient.right*0.96);
m2.y=long(this->m_Center.y*0.99);
m_3.x=rectClient.right;
m_3.y=this->m_Center.y;
this->DrawArrow(pDC,m_Color[0],m1,m2,m_3);
this->DrawScalex(pDC,rectClient); //Draw x Scale
pDC->SelectObject(pOldPen);
/**End **/
/**Draw Y Coordinate**/
pOldPen=pDC->SelectObject(&peny);
pDC->MoveTo(this->m_Center);
pDC->LineTo(this->m_Center.x,rectClient.top);
//Draw arrow for Y coordinate
m1.x=long(this->m_Center.x*1.06);
m1.y=long(rectClient.bottom*0.08);
m2.x=long(this->m_Center.x*0.94);
m2.y=long(rectClient.bottom*0.08);
m_3.x=this->m_Center.x;
m_3.y=rectClient.top;
this->DrawArrow(pDC,m_Color[1],m1,m2,m_3);
this->DrawScaley(pDC,rectClient);
pDC->SelectObject(pOldPen);
/**End**/
/***Draw Grid for background***/
this->DrawGrid(pDC,rectClient);
/**Lable**/
this->DrawLable(pDC,rectClient);
pDC->SelectObject(pOldPen);
}
void CAxis::DrawArrow(CDC* pDC,COLORREF color,CPoint m1, CPoint m2, CPoint m_3)
{
CPoint pPoint[]={m1,m2,m_3};
pDC->Polyline(pPoint,3);
CRgn Rgn;
CPoint RgnPoint[]={m1,m2,m_3};
CBrush Brush(color);
Rgn.CreatePolygonRgn(RgnPoint,3,WINDING);
pDC->FillRgn(&Rgn,&Brush);
}
void CAxis::DrawScalex(CDC *pDC,CRect rect)
{
/** X Scale***/
m_Ratio[0]=(rect.right-rect.left)/(m_Maxx-m_Minx);
long j=(long)(m_Center.x*0.8); //j is used to control Device axis
long ly=m_Center.y;//used to record y axis
long lx=m_Center.x;
CString str;
for(double i=1.0*(m_Minx);i<=this->m_Maxx;i+=m_Intervalx,j+=(long)(m_Intervalx*m_Ratio[0]),lx+=(long)(m_Intervalx*m_Ratio[0]))
{ //i is used to control user's axis
str.Format("%3.1f",i);
pDC->TextOut(j ,(long)(m_Center.y*1.02),str);
pDC->MoveTo(lx,(long)(ly*1.01));
pDC->LineTo(lx,ly);
}
}
void CAxis::DrawScaley(CDC *pDC,CRect rect)
{
/**Y Scale**/
m_Ratio[1]=(rect.bottom -rect.top )/(m_Maxy-m_Miny);//used to convert from device to user's axis
long j=m_Center.y; //j is used to control Device axis
long ly=m_Center.y; //used to record y axis
long lx=m_Center.x; //i is used to control user's axis
CString str;
for(double i1=1.0*(m_Miny);i1<=this->m_Maxy;i1+=m_Intervaly,j-=(long)(m_Intervaly*m_Ratio[1]),ly-=(long)(m_Intervaly*m_Ratio[1]))
{
lx=m_Center.x;
str.Format("%3.1f",i1);
pDC->TextOut((long)(m_Center.x*0.6),j,str);
pDC->MoveTo(long(lx*0.92),ly);
pDC->LineTo(lx,ly);
}
}
void CAxis::DrawLable(CDC* pDC,CRect rect)
{
pDC->SetBkMode(TRANSPARENT);
pDC->TextOut(m_Center.x+(long)(rect.right/2),(long)(m_Center.y*1.05),this->m_Lablex);//xlable
//make font to show along vertical destination
CFont m_font;
LOGFONT lf;
strcpy(lf.lfFaceName,"Arial");
lf.lfWeight=FW_NORMAL;
lf.lfHeight=20;
lf.lfUnderline =false;
lf.lfItalic=false;
lf.lfStrikeOut=false;
lf.lfEscapement=900;//angles
m_font.CreateFontIndirect(&lf);
CFont *pOldFont=pDC->SelectObject(&m_font);
pDC->TextOut((long)(m_Center.x*0.30),(long)(m_Center.y*0.5),this->m_Labley);
m_font.DeleteObject();
pDC->SelectObject(pOldFont);
}
void CAxis::DrawGrid(CDC *pDC, CRect rect)
{
CPen *pOldPen ,pen(PS_DOT,1,RGB(0,0,20));
pOldPen=pDC->SelectObject(&pen);
for(int j=1;j*m_Intervalx<=m_Maxx-m_Minx;j++)
{
pDC->MoveTo(m_Center.x+long(j*m_Intervalx*m_Ratio[0]),m_Center.y);
pDC->LineTo(m_Center.x+long(j*m_Intervalx*m_Ratio[0]) ,m_Center.y-long((m_Maxy-m_Miny)*m_Ratio[1]));
}
for(int i=1;i*m_Intervaly<=m_Maxy-m_Miny;i++)
{
pDC->MoveTo(m_Center.x,long(m_Center.y-i*m_Intervaly*m_Ratio[1]));
pDC->LineTo(m_Center.x+long((m_Maxx-m_Minx)*m_Ratio[0]),long(m_Center.y-i*m_Intervaly*m_Ratio[1]));
}
pDC->SelectObject(pOldPen);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -