📄 basegr.cpp
字号:
// BaseGr.cpp: implementation of the CBaseGr class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "BaseGr.h"
#include "math.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CBaseGr::CBaseGr()
{
XName = _T("");
YName = _T("");
YMin = 0;
YMax = 100;
XMin = 0;
XMax = 100;
Title = _T("");
}
CBaseGr::~CBaseGr()
{
}
void CBaseGr::DrawLine(CDC* pDC,POINT FromPoint,POINT ToPoint,int LineSize,COLORREF LineColor)
{
CPen pen(PS_SOLID, LineSize, LineColor);
CPen* pOldPen = pDC->SelectObject(&pen);
pDC->MoveTo(FromPoint);
pDC->LineTo(ToPoint);
pDC->SelectObject(pOldPen);
}
void CBaseGr::DrawDashLine(CDC* pDC,POINT FromPoint,POINT ToPoint,int LineSize,COLORREF LineColor)
{
CPen pen(PS_DASH, LineSize, LineColor);
CPen* pOldPen = pDC->SelectObject(&pen);
pDC->MoveTo(FromPoint);
pDC->LineTo(ToPoint);
pDC->SelectObject(pOldPen);
}
void CBaseGr::DrawLine(CDC* pDC,int fpx,int fpy,int tpx,int tpy,int LineSize,COLORREF LineColor)
{
CPen pen(PS_SOLID, LineSize, LineColor);
CPen* pOldPen = pDC->SelectObject(&pen);
pDC->MoveTo(fpx,fpy);
pDC->LineTo(tpx,tpy);
pDC->SelectObject(pOldPen);
}
void CBaseGr::DrawDashLine(CDC* pDC,int fpx,int fpy,int tpx,int tpy,int LineSize,COLORREF LineColor)
{
CPen pen(PS_DASH, LineSize, LineColor);
CPen* pOldPen = pDC->SelectObject(&pen);
pDC->MoveTo(fpx,fpy);
pDC->LineTo(tpx,tpy);
pDC->SelectObject(pOldPen);
}
void CBaseGr::DrawRectangle(CDC* pDC,POINT LeftTop,POINT RightBottom,int LineSize,COLORREF LineColor,COLORREF FillColor)
{
// Draw with a thick blue pen.
CPen pen(PS_SOLID, LineSize, LineColor);
CPen* pOldPen = pDC->SelectObject(&pen);
// And a solid red brush.
CBrush brush(FillColor);
CBrush* pOldBrush = pDC->SelectObject(&brush);
pDC->Rectangle(LeftTop.x,LeftTop.y,RightBottom.x,RightBottom.y);
// Put back the old objects.
pDC->SelectObject(pOldPen);
pDC->SelectObject(pOldBrush);
}
void CBaseGr::DrawRectangle(CDC* pDC,int LeftTopx,int LeftTopy,int RightBottomx,int RightBottomy,int LineSize,COLORREF LineColor,COLORREF FillColor)
{
CPen pen(PS_SOLID, LineSize, LineColor);
CPen* pOldPen = pDC->SelectObject(&pen);
// And a solid red brush.
CBrush brush(FillColor);
CBrush* pOldBrush = pDC->SelectObject(&brush);
pDC->Rectangle(LeftTopx,LeftTopy,RightBottomx,RightBottomy);
// Put back the old objects.
pDC->SelectObject(pOldPen);
pDC->SelectObject(pOldBrush);
}
void CBaseGr::DrawPolygon(CDC* pDC,LPPOINT lpPoints,int nPointCounts,int LineSize,COLORREF LineColor,COLORREF FillColor)
{
CPen pen(PS_SOLID, LineSize, LineColor);
CPen* pOldPen = pDC->SelectObject(&pen);
CBrush brush(FillColor);
CBrush* pOldBrush = pDC->SelectObject(&brush);
pDC->Polygon(lpPoints,nPointCounts);
pDC->SelectObject(pOldPen);
pDC->SelectObject(pOldBrush);
}
void CBaseGr::DrawArc(CDC* pDC,POINT pCoC,int nRadius,double AngleS,double AngleE,int LineSize,COLORREF LineColor,COLORREF FillColor)
{
/***************************************
起始角度:dAngleS
终止角度: dAngleE
半径 : nRadius
圆点 : pCoc
起始坐标: PointS
终止坐标: PointE
基准坐标: PointBase
***************************************/
DrawArc(pDC,pCoC.x,pCoC.y,nRadius,AngleS,AngleE,LineSize,LineColor,FillColor);
}
void CBaseGr::DrawArc(CDC* pDC,int pCoCx,int pCoCy,int nRadius,double AngleS,double AngleE,int LineSize,COLORREF LineColor,COLORREF FillColor)
{
/***************************************
起始角度:dAngleS
终止角度: dAngleE
半径 : nRadius
圆点 : pCocx,pCocy
起始坐标: PointS
终止坐标: PointE
基准坐标: PointBase
***************************************/
POINT PointS,PointE,PointBase;
PointBase.x = pCoCx - nRadius;
PointBase.y = pCoCy;
if(AngleS > AngleE)
{
double conv = AngleS;
AngleS = AngleE;
AngleE = conv;
}
PointS.x = pCoCx + (int)(nRadius*cos(AngleS) + 0.5);
PointS.y = pCoCy + (int)(nRadius*sin(AngleS) + 0.5);
PointE.x = pCoCx + (int)(nRadius*cos(AngleE) + 0.5);
PointE.y = pCoCy + (int)(nRadius*sin(AngleE) + 0.5);
double AngleTmp = AngleS;
double DetaAngle = PI/180;
int nCount = (int)((AngleE - AngleS)/DetaAngle + 0.5);
CPoint *ArcP = new CPoint[nCount+2];
(*(ArcP+0)).x = pCoCx;
(*(ArcP+0)).y = pCoCy;
int i = 1;
while(AngleTmp <= AngleE)
{
(*(ArcP+i)).x = pCoCx + (int)(nRadius*cos(AngleTmp) + 0.5);
(*(ArcP+i)).y = pCoCy + (int)(nRadius*sin(AngleTmp) + 0.5);
AngleTmp += DetaAngle;
i++;
}
(*(ArcP+nCount)) = PointE;
(*(ArcP+nCount+1)) = (*(ArcP+0));
DrawPolygon(pDC,ArcP,nCount+2,LineSize,LineColor,FillColor);
delete []ArcP;
}
void CBaseGr::DrawColumn(CDC* pDC,int LeftTopx,int LeftTopy,int RightBottomx,int RightBottomy,int Height,int LineSize,COLORREF LineColor,COLORREF FillColor)
{
CPen pen(PS_SOLID, LineSize, LineColor);
CPen* pOldPen = pDC->SelectObject(&pen);
CBrush brush(FillColor);
CBrush* pOldBrush = pDC->SelectObject(&brush);
pDC->Rectangle(LeftTopx,LeftTopy+(RightBottomy-LeftTopy)/2,RightBottomx,LeftTopy+(RightBottomy-LeftTopy)/2+Height);
pDC->Ellipse(LeftTopx,LeftTopy,RightBottomx,RightBottomy);
pDC->Ellipse(LeftTopx,LeftTopy+Height,RightBottomx,RightBottomy+Height);
//Redraw ellipse
CPen PenWhite(PS_SOLID,LineSize,FillColor);
pOldPen = pDC->SelectObject(&PenWhite);
pDC->Ellipse(LeftTopx+LineSize,LeftTopy+Height-LineSize,RightBottomx-LineSize,RightBottomy+Height-LineSize);
pDC->SelectObject(pOldPen);
pDC->SelectObject(pOldBrush);
}
void CBaseGr::DrawCub(CDC* pDC,int Face1x,int Face1y,int Face2x,int Face2y,int Height,int LineSize,COLORREF LineColor,COLORREF FillColor)
{
if(Face1x > Face2x)
{
int tmp = Face1x;
Face1x = Face2x;
Face2x = tmp;
}
CPoint pts[4];
//Draw Face
pts[0].x = Face1x;
pts[0].y = Face1y;
pts[1].x = Face2x;
pts[1].y = Face2y;
pts[2].x = Face2x;
pts[2].y = Face2y+Height;
pts[3].x = Face1x;
pts[3].y = Face1y+Height;
DrawPolygon(pDC,pts,4,LineSize,LineColor,FillColor);
//Draw Top
pts[0].x = Face1x + (Face2x-Face1x)/2;
pts[0].y = Face1y - (Face2x-Face1x)/2;
pts[1].x = Face2x + (Face2x-Face1x)/2;
pts[1].y = Face2y - (Face2x-Face1x)/2;
pts[2].x = Face2x;
pts[2].y = Face2y;
pts[3].x = Face1x;
pts[3].y = Face1y;
DrawPolygon(pDC,pts,4,LineSize,LineColor,FillColor);
//Draw Right
pts[0].x = Face2x;
pts[0].y = Face2y;
pts[1].x = Face2x + (Face2x-Face1x)/2;
pts[1].y = Face2y - (Face2x-Face1x)/2;
pts[2].x = Face2x + (Face2x-Face1x)/2;
pts[2].y = Face2y - (Face2x-Face1x)/2 + Height;
pts[3].x = Face2x;
pts[3].y = Face2y + Height;
DrawPolygon(pDC,pts,4,LineSize,LineColor,FillColor);
}
void CBaseGr::DrawPoint(CDC* pDC,int x,int y,PointType Mode,int Radius,int LineSize,COLORREF LineColor,COLORREF FillColor)
{
switch(Mode)
{
case CIRCLE:
{
CPen pen(PS_SOLID, LineSize, LineColor);
CPen* pOldPen = pDC->SelectObject(&pen);
CBrush BrushWhite(RGB(255,255,255));
CBrush* pOldBrush = pDC->SelectObject(&BrushWhite);
pDC->Ellipse(x-Radius,y-Radius,x+Radius,y+Radius);
pDC->SelectObject(pOldPen);
pDC->SelectObject(pOldBrush);
}
break;
case RECTANGLE:
{
DrawRectangle(pDC,x-Radius,y-Radius,x+Radius,y+Radius,LineSize,LineColor);
}
break;
case DIAMOND:
{
CPoint Diamonds[4];
Diamonds[0].x = x-Radius;
Diamonds[0].y = y;
Diamonds[1].x = x;
Diamonds[1].y = y-Radius;
Diamonds[2].x = x+Radius;
Diamonds[2].y = y;
Diamonds[3].x = x;
Diamonds[3].y = y+Radius;
DrawPolygon(pDC,Diamonds,4,LineSize,LineColor);
}
break;
case TRIANGLE:
{
CPoint Triangles[3];
Triangles[0].x = x;
Triangles[0].y = y-Radius;
Triangles[1].x = x+Radius;
Triangles[1].y = y+Radius;
Triangles[2].x = x-Radius;
Triangles[2].y = y+Radius;
DrawPolygon(pDC,Triangles,3,LineSize,LineColor);
}
break;
case FCIRCLE:
{
CPen pen(PS_SOLID, LineSize, LineColor);
CPen* pOldPen = pDC->SelectObject(&pen);
CBrush Brush(FillColor);
CBrush* pOldBrush = pDC->SelectObject(&Brush);
pDC->Ellipse(x-Radius,y-Radius,x+Radius,y+Radius);
pDC->SelectObject(pOldPen);
pDC->SelectObject(pOldBrush);
}
break;
case FRECTANGLE:
{
DrawRectangle(pDC,x-Radius,y-Radius,x+Radius,y+Radius,LineSize,LineColor,FillColor);
}
break;
case FDIAMOND:
{
CPoint Diamonds[4];
Diamonds[0].x = x-Radius;
Diamonds[0].y = y;
Diamonds[1].x = x;
Diamonds[1].y = y-Radius;
Diamonds[2].x = x+Radius;
Diamonds[2].y = y;
Diamonds[3].x = x;
Diamonds[3].y = y+Radius;
DrawPolygon(pDC,Diamonds,4,LineSize,LineColor,FillColor);
}
break;
case FTRIANGLE:
{
CPoint Triangles[3];
Triangles[0].x = x;
Triangles[0].y = y-Radius;
Triangles[1].x = x+Radius;
Triangles[1].y = y+Radius;
Triangles[2].x = x-Radius;
Triangles[2].y = y+Radius;
DrawPolygon(pDC,Triangles,3,LineSize,LineColor,FillColor);
}
break;
case FIRE:
DrawLine(pDC,x-Radius,y-Radius,x+Radius,y+Radius,LineSize,LineColor);
DrawLine(pDC,x-Radius,y+Radius,x+Radius,y-Radius,LineSize,LineColor);
DrawLine(pDC,x-Radius,y,x+Radius,y,LineSize,LineColor);
DrawLine(pDC,x,y-Radius,x,y+Radius,LineSize,LineColor);
break;
case CROSS:
DrawLine(pDC,x-Radius,y,x+Radius,y,LineSize,LineColor);
DrawLine(pDC,x,y-Radius,x,y+Radius,LineSize,LineColor);
break;
case XCROSS:
DrawLine(pDC,x-Radius,y-Radius,x+Radius,y+Radius,LineSize,LineColor);
DrawLine(pDC,x-Radius,y+Radius,x+Radius,y-Radius,LineSize,LineColor);
break;
}
}
void CBaseGr::DrawCoordinate(CDC* pDC,int LeftTopx,int LeftTopy,int RightBottomx,int RightBottomy,BOOL WithDash)
{
}
void CBaseGr::SetLegend(CString Name,double Value,COLORREF FillColor,PointType GraphMode,int LineSize,COLORREF LineColor)
{
Legend Legend;
Legend.Name = Name;
Legend.Value = Value;
Legend.Graph.FillColor = FillColor;
Legend.Graph.GraphMode = GraphMode;
Legend.Graph.LineColor = LineColor;
Legend.Graph.LineSize = LineSize;
m_Legend.Add(Legend);
}
void CBaseGr::DrawYCoordinateValue(CDC* pDC,int Startx,int Starty,CString Value,Align Mode,COLORREF FontColor)
{
CFont m_font;
m_font.CreateFont(
-12, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -