You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
178 lines
4.8 KiB
C
178 lines
4.8 KiB
C
#pragma once
|
|
#include "GlobalDrawMgr.h"
|
|
#include "SequentialPoint.h"
|
|
#include "ObjCircle.h"
|
|
|
|
|
|
//绘制一些简单的图形
|
|
inline void DrawRect(CDC* pDC,CPen&Pen,Dbxy pt1,Dbxy pt2,bool bXor = true)
|
|
{
|
|
CSequentialPoint PtContainer;
|
|
PtContainer.AddDataPoint(Dbxy(pt1.x,pt1.y));
|
|
PtContainer.AddDataPoint(Dbxy(pt1.x,pt2.y));
|
|
PtContainer.AddDataPoint(Dbxy(pt2.x,pt2.y));
|
|
PtContainer.AddDataPoint(Dbxy(pt2.x,pt1.y));
|
|
PtContainer.AddDataPoint(Dbxy(pt1.x,pt1.y));
|
|
|
|
if(bXor)
|
|
{
|
|
int old_rop = pDC->SetROP2(R2_XORPEN);
|
|
PtContainer.Draw( pDC, Pen);
|
|
pDC->SetROP2(old_rop);
|
|
}
|
|
else
|
|
{
|
|
PtContainer.Draw( pDC, Pen);
|
|
}
|
|
}
|
|
inline void DrawRect(CDC* pDC,CPen&Pen,DbRect rect,bool bXor = true)
|
|
{
|
|
Dbxy pt1(rect.L,rect.T);
|
|
Dbxy pt2(rect.R,rect.B);
|
|
DrawRect(pDC,Pen,pt1,pt2,bXor);
|
|
}
|
|
//画一个方形
|
|
inline void DrawRect(CDC* pDC,CPen&Pen,Dbxy pt,double size,bool bXor = true)
|
|
{
|
|
Dbxy pt1(pt.x-size,pt.y+size);
|
|
Dbxy pt2(pt.x+size,pt.y-size);
|
|
DrawRect(pDC,Pen,pt1,pt2,bXor);
|
|
}
|
|
//画一个X 十字
|
|
inline void XorDrawCrossX(CDC* pDC,CPen&Pen,Dbxy pt1,Dbxy pt2)
|
|
{
|
|
CSequentialPoint PtContainer1,PtContainer2;
|
|
PtContainer1.AddDataPoint(Dbxy(pt1.x,pt1.y));
|
|
PtContainer1.AddDataPoint(Dbxy(pt2.x,pt2.y));
|
|
PtContainer2.AddDataPoint(Dbxy(pt2.x,pt1.y));
|
|
PtContainer2.AddDataPoint(Dbxy(pt1.x,pt2.y));
|
|
|
|
int old_rop = pDC->SetROP2(R2_XORPEN);
|
|
PtContainer1.Draw( pDC, Pen);
|
|
PtContainer2.Draw( pDC, Pen);
|
|
pDC->SetROP2(old_rop);
|
|
}
|
|
inline void XorDrawCrossX(CDC* pDC,CPen&Pen,DbRect rect)
|
|
{
|
|
Dbxy pt1(rect.L,rect.T);
|
|
Dbxy pt2(rect.R,rect.B);
|
|
XorDrawCrossX(pDC,Pen,pt1,pt2);
|
|
}
|
|
inline void DrawCrossX(CDC* pDC,CPen&Pen,Dbxy pt1,Dbxy pt2)
|
|
{
|
|
CSequentialPoint PtContainer1,PtContainer2;
|
|
PtContainer1.AddDataPoint(Dbxy(pt1.x,pt1.y));
|
|
PtContainer1.AddDataPoint(Dbxy(pt2.x,pt2.y));
|
|
PtContainer2.AddDataPoint(Dbxy(pt2.x,pt1.y));
|
|
PtContainer2.AddDataPoint(Dbxy(pt1.x,pt2.y));
|
|
|
|
PtContainer1.Draw( pDC, Pen);
|
|
PtContainer2.Draw( pDC, Pen);
|
|
}
|
|
inline void DrawCrossX(CDC* pDC,CPen&Pen,DbRect rect)
|
|
{
|
|
Dbxy pt1(rect.L,rect.T);
|
|
Dbxy pt2(rect.R,rect.B);
|
|
DrawCrossX(pDC,Pen,pt1,pt2);
|
|
}
|
|
inline void XorDrawCross(CDC* pDC,bool bXor,CPen&Pen,Dbxy pt,double size)
|
|
{
|
|
CSequentialPoint PtContainer1,PtContainer2;
|
|
PtContainer1.AddDataPoint(Dbxy(pt.x,pt.y+size));
|
|
PtContainer1.AddDataPoint(Dbxy(pt.x,pt.y-size));
|
|
PtContainer2.AddDataPoint(Dbxy(pt.x-size,pt.y));
|
|
PtContainer2.AddDataPoint(Dbxy(pt.x+size,pt.y));
|
|
|
|
int old_rop;
|
|
if(bXor)
|
|
old_rop = pDC->SetROP2(R2_XORPEN);
|
|
PtContainer1.Draw( pDC, Pen);
|
|
PtContainer2.Draw( pDC, Pen);
|
|
if(bXor)
|
|
pDC->SetROP2(old_rop);
|
|
}
|
|
//画一个实心矩形
|
|
inline void DrawSolidRect(CDC* pDC,COLORREF color,DbRect rect)
|
|
{
|
|
CBrush brush,*pOldBrush;
|
|
brush.CreateSolidBrush(color);
|
|
pOldBrush=pDC->SelectObject(&brush);
|
|
pDC->Rectangle(&gDraw->DbRect2CRect(rect));
|
|
pDC->SelectObject(pOldBrush);
|
|
}
|
|
inline void XorDrawLine(CDC* pDC,CPen&Pen,Dbxy pt1,Dbxy pt2)
|
|
{
|
|
CSequentialPoint PtContainer;
|
|
PtContainer.AddDataPoint(Dbxy(pt1.x,pt1.y));
|
|
PtContainer.AddDataPoint(Dbxy(pt2.x,pt2.y));
|
|
|
|
int old_rop = pDC->SetROP2(R2_XORPEN);
|
|
PtContainer.Draw( pDC, Pen);
|
|
pDC->SetROP2(old_rop);
|
|
}
|
|
inline void DrawLine(CDC* pDC,CPen&Pen,Dbxy pt1,Dbxy pt2)
|
|
{
|
|
CSequentialPoint PtContainer;
|
|
PtContainer.AddDataPoint(Dbxy(pt1.x,pt1.y));
|
|
PtContainer.AddDataPoint(Dbxy(pt2.x,pt2.y));
|
|
PtContainer.Draw( pDC, Pen);
|
|
}
|
|
|
|
//获取反转的颜色
|
|
inline COLORREF GetXorColor(COLORREF color)
|
|
{
|
|
BYTE r = GetRValue(color);
|
|
BYTE g = GetGValue(color);
|
|
BYTE b = GetBValue(color);
|
|
|
|
COLORREF clr = RGB(255-r,255-g,255-b);
|
|
return clr;
|
|
}
|
|
inline void DrawCircle(CDC* pDC,CPen&Pen,Dbxy pt,double R,int DEdgeCnt)
|
|
{
|
|
CObjCircle ObjCircle;
|
|
CCirclePar par;
|
|
par.CenterPt = pt;
|
|
par.Radius = R;
|
|
par.DEdgeCnt = DEdgeCnt;
|
|
ObjCircle.Creat(par);
|
|
ObjCircle.Draw(pDC,Pen);
|
|
}
|
|
inline void DrawSolidCircle(CDC* pDC,COLORREF color,Dbxy pt,double R)
|
|
{
|
|
CBrush brush,*pOldBrush;
|
|
brush.CreateSolidBrush(color);
|
|
pOldBrush=pDC->SelectObject(&brush);
|
|
pDC->Ellipse(&gDraw->DbRect2CRect(DbRect(pt,R)));
|
|
pDC->SelectObject(pOldBrush);
|
|
}
|
|
//在矩形范围内绘制网格线(gap 是网格线的间隔)
|
|
inline void Drawgridding(CDC* pDC,CPen&Pen,DbRect rect,double gap)
|
|
{
|
|
//横线
|
|
{
|
|
Dbxy pt1(rect.L,rect.B);
|
|
Dbxy pt2(rect.R,rect.B);
|
|
double CurY = rect.B;
|
|
while(CurY<rect.T)
|
|
{
|
|
pt1.y = pt2.y = CurY;
|
|
DrawLine(pDC,Pen,pt1,pt2);
|
|
CurY += gap;
|
|
}
|
|
}
|
|
//竖线
|
|
{
|
|
Dbxy pt1(rect.L,rect.B);
|
|
Dbxy pt2(rect.L,rect.T);
|
|
double CurX = rect.L;
|
|
while(CurX<rect.R)
|
|
{
|
|
pt1.x = pt2.x = CurX;
|
|
DrawLine(pDC,Pen,pt1,pt2);
|
|
CurX += gap;
|
|
}
|
|
}
|
|
}
|
|
|