mfc笔刷实现算法,每次画新线时不需要从新绘制以前的线

#include "OScriBrush.h"
/*


this code writen by lizhi
*/


void OScriBrush::SetStyle(int iwidth,COLORREF icolor)
{
width = iwidth;
color = icolor;
}


void OScriBrush::DrawScriBrush(CDC * pDC)
{
CPen newPen(PS_SOLID,width,color);
CPen * oldPen = pDC->SelectObject(&newPen);
POINT t_p;
int m_f_isNew = 1;//当鼠标左键松开的时候,一条新线开始画了

if(!scriPoint.empty())
{
for(std::vector<POINT>::iterator  it = scriPoint.begin();it != scriPoint.end();++it)
{
t_p = *it;



if(m_f_isNew == 1)
{
pDC->MoveTo(t_p.x,t_p.y);
m_f_isNew = 0;
}
else
{
if(t_p.x < 0 || t_p.y < 0)//when a line is end,left bottom up,set point(x,y)<0
{
m_f_isNew = 1;//to decide is a new line, here
}
else
{
pDC->LineTo(t_p.x,t_p.y);//when we reuse the lineto funciton,don't need moveto function any more
}
}
}
}

pDC->SelectObject(oldPen);
}


void OScriBrush::UpdateOnMouseMove(CDC * pDC,long x,long y)
{



CPen newPen(PS_SOLID,width,color);
CPen * oldPen = pDC->SelectObject(&newPen);
POINT t_p;
t_p = scriPoint.back();



pDC->MoveTo(t_p.x,t_p.y);
pDC->LineTo(x,y);
t_p.x = x;
t_p.y = y;
fprintf(fp,"a=%d b=%d\n ",t_p.x,t_p.y);//tesing code
scriPoint.push_back(t_p);
pDC->SelectObject(oldPen);





}


void OScriBrush::UpdateOnLButtonUp(CDC * pDC,long x,long y)
{
CPen newPen(PS_SOLID,width,color);
CPen * oldPen = pDC->SelectObject(&newPen);


POINT t_p;
t_p = scriPoint.back();
pDC->MoveTo(t_p.x,t_p.y);
pDC->LineTo(x,y);
t_p.x = x;
t_p.y = y;
scriPoint.push_back(t_p);
t_p.x = -1;t_p.y = -1;
scriPoint.push_back(t_p);


pDC->SelectObject(oldPen);
}


void OScriBrush::UpdateOnLButtonDown(long x,long y)
{
POINT t_p;
t_p.x = x;
t_p.y = y;
scriPoint.push_back(t_p);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值