#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);
}
/*
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);
}