relativest >> it save the start point for the line
relativend >> it save the end point for the line
all variables defined in the view class
I did the draw inside the on draw function
I only set the points on the mouse events:
here the ondraw function
void Cpatron1View::OnDraw(CDC* pDC)
{
pDC->SetMapMode ( MM_LOMETRIC) ;
Cpatron1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
**********************************************
for(int i=0;i<(int)mylines.size();i++){
mylines.at(i)->drawline(pDC);
}
}
here I set the sel value to true if the line selected by user
void Cpatron1View::OnLButtonDown(UINT nFlags, CPoint point)
{ Cpatron1Doc* doc = GetDocument();
CClientDC dc(this);
dc.SetMapMode(MM_LOMETRIC);
OnPrepareDC(&dc); dc.DPtoLP(&point);
for(int i=0;i<(int)mylines.size();i++){
sel=HitTestLine(mylines.at(i)->getspoints(), mylines.at(i)->getepoints(), point, 6);
selind=i;
if(sel== true){
mylines.at(selind)->setColor(1);
selcurve=false;
Invalidate();
break;
}
}
}
CScrollView::OnLButtonDown(nFlags, point);
}
//here set the relativest and relativend value and dragged to true
void Cpatron1View::OnLButtonDblClk(UINT nFlags, CPoint point)
{
CClientDC dc(this);
dc.SetMapMode(MM_LOMETRIC);
OnPrepareDC(&dc); dc.DPtoLP(&point);
if(sel){
relativest.x=mylines.at(selind)->getspoints().x-point.x;
relativest.y=mylines.at(selind)->getspoints().y-point.y;
relativend.x=mylines.at(selind)->getepoints().x-point.x;
relativend.y=mylines.at(selind)->getepoints().y-point.y;
dragged=true;
}
CScrollView::OnLButtonDblClk(nFlags, point);
}
// here set the new points for the shape as the mouse moved
void Cpatron1View::OnMouseMove(UINT nFlags, CPoint point)
{
CClientDC dc(this);
dc.SetMapMode(MM_LOMETRIC);
OnPrepareDC(&dc); dc.DPtoLP(&point);
if(((nFlags& MK_LBUTTON)== MK_LBUTTON) && dragged){
relativest.x += point.x ;
relativest.y += point.y ;
relativend.x += point.x ;
relativend.y += point.y;
mylines.at(selind)->setPoints(relativest,relativend);
Invalidate();
}
CScrollView::OnMouseMove(nFlags, point);
}
here change the dragged to false to stop moving the shape
void Cpatron1View::OnLButtonUp(UINT nFlags, CPoint point)
{
CClientDC dc(this);
dc.SetMapMode(MM_LOMETRIC);
OnPrepareDC(&dc); dc.DPtoLP(&point);
if(dragged){
dragged=false;
}
CScrollView::OnLButtonUp(nFlags, point);
}
please help me in find what wrong with moving part