VC++开发GIS系统(47)使用自定义CDC类画点

前一篇文章中我们已经成功完成了自定义CDC类的建立,并且已经设置了3个函数用来完成画点、线、面的任务。本文的任务就是实现这个3个函数,实现系统的画点的功能。代码如下:

绘制圆点

/*
* 绘制圆点
*/
void malaCDC::pointDrawCircle(malaPoint Point, malaPointPro PntPro)
{
    //MessageBox(NULL, L"绘制圆形", _T("提示"), MB_OK);
    CClientDC dc(mView);

    CPen pen(0, 1, PntPro.pointColor);
    CPen* OldPen = dc.SelectObject(&pen);
    CBrush MyBrush(PntPro.pointColor);
    CBrush* OldBrush = dc.SelectObject(&MyBrush);
    CPoint Point1, Point2;
    Point1.x = Point.x - PntPro.pointRadio;
    Point1.y = Point.y - PntPro.pointRadio;
    Point2.x = Point.x + PntPro.pointRadio;
    Point2.y = Point.y + PntPro.pointRadio;
    dc.Ellipse(CRect(Point1, Point2));
    dc.SelectObject(OldPen);
    dc.SelectObject(OldBrush);
}

绘制三角形点

/*
* 绘制三角形点
*/
void malaCDC::pointDrawTriangle(malaPoint Point, malaPointPro PntPro)
{
    //MessageBox(NULL, L"绘制三角形", _T("提示"), MB_OK);
    CClientDC dc(mView);
    CPen pen(0, 1, PntPro.pointColor);
    CPen* OldPen = dc.SelectObject(&pen);
    CBrush MyBrush(PntPro.pointColor);
    CBrush* OldBrush = dc.SelectObject(&MyBrush);
    double radio = PntPro.pointRadio;
    double r1 = sqrtf(3) / 2 * radio;
    CPoint* MyArray = new CPoint[3];
    MyArray[0].x = Point.x - r1;
    MyArray[0].y = Point.y + (double)radio/2;
    MyArray[1].x = Point.x + r1;
    MyArray[1].y = Point.y + (double)radio / 2;
    MyArray[2].x = Point.x;
    MyArray[2].y = Point.y-radio;

    dc.Polygon(MyArray, 3);
    dc.SelectObject(OldPen);
    dc.SelectObject(OldBrush);
}

这个地方的坐标设置是绘制一个等边三角形,原理如图:

绘制矩(方)形点

/*
* 绘制矩(方)形点
*/
void malaCDC::pointDrawRect(malaPoint Point, malaPointPro PntPro)
{
    //MessageBox(NULL, L"绘制方形", _T("提示"), MB_OK);
    CClientDC dc(mView);

    CPen pen(0, 1, PntPro.pointColor);
    CPen* OldPen = dc.SelectObject(&pen);
    CBrush MyBrush(PntPro.pointColor);
    CBrush* OldBrush = dc.SelectObject(&MyBrush);
    CPoint Point1, Point2;
    Point1.x = Point.x - PntPro.pointRadio;
    Point1.y = Point.y - PntPro.pointRadio;
    Point2.x = Point.x + PntPro.pointRadio;
    Point2.y = Point.y + PntPro.pointRadio;

    dc.Rectangle(CRect(Point1, Point2));
    dc.SelectObject(OldPen);
    dc.SelectObject(OldBrush);
}

如果不明白其中的绘图原理,可以参考下面的文章:

效果图:

VC++开发GIS系统(46)自定义一个CDC绘图类 VC++开发GIS系统(48)屏幕坐标转换原理

作者:,GIS爱好者。
分享本文,请您带上本文链接
分享到:

发表评论