(13) one-step development of a simple CAD-like rubber band

Source: Internet
Author: User

You can drag a rubber band to reuse an object such as draw a line or draw a circle. This rubber band can be in 8 directions and can indicate the direction at 45 degrees.

 

 

Class ceraseline // image rubber band class, which can be drawn in eight directions
{
Public:
Ceraseline ();
Virtual ~ Ceraseline ();
Public:
Void setbegin (cposition begin );
Void setend (cposition end );
Void setcancle (cposition POS );
Bool getpoints (cposition CEN); // obtain the coordinates of the second actual point

Void onlbuttondown (uint nflags, cposition POS );
Void onmousemove (uint nflags, cposition POS );
Void onrbuttondown (uint nflags, cposition POS );

Public:
Cposition m_begin;
Cposition m_end;
Int m_nstep;


};

 

 

 

Ceraseline: ceraseline ()
{
M_nstep = 1;
 
}

Ceraseline ::~ Ceraseline ()
{

}

Void ceraseline: setbegin (cposition begin)
{

Onlbuttondown (0, begin );
 

}

Void ceraseline: setend (cposition end)
{

Onmousemove (0, end );
Getpoints (end );
}

Bool ceraseline: getpoints (cposition CEN) // if the second point changes, the changed point is reversed.
{

 


Cline * line [8];
CDC * PDC = g_pview-> getdc ();
For (INT I = 0; I <8; I ++)
{

Line [I] = new Cline (m_begin, m_begin + cposition (COS (45 * I * PI/180), sin (45 * I * PI/180) * 1000 );


If (line [I]-> picksolid (m_end, g_pview-> m_scale * 5) & m_nstep = 2) // only draws
{
 
 
Line [I]-> drawsolid (PDC, select );

}

Else
{
Line [I]-> drawsolid (PDC, back );
 
}

Delete line [I];

}

G_pview-> releasedc (PDC );
 
Return true;


}

Void ceraseline: onlbuttondown (uint nflags, cposition POS)
{

Switch (m_nstep)
{

Case 1: // output prompt information
{

 

M_end = m_begin = Pos;
M_nstep ++;
Break;

}

Case 2:
{

M_end = Pos;

CDC * PDC = g_pview-> getdc ();
Cline * line1 = new Cline (m_begin, m_end); // portrait Leather line, eliminating the previous
Line1-> drawsolid (PDC, drag );
Delete line1;
G_pview-> releasedc (PDC );
M_nstep = 1;
}

 
Default:
Break;
}
 

}

Void ceraseline: onmousemove (uint nflags, cposition POS)
{

Switch (m_nstep)
{
Case 2:


CDC * PDC = g_pview-> getdc ();


Cline * line1 = new Cline (m_begin, m_end); // portrait Leather line, eliminating the previous
Line1-> drawsolid (PDC, drag );
Delete line1;
 
G_pview-> m_suject-> sort y ();

Cline * line = new Cline (m_begin, POS); // portrait leather Line, Last
Line-> drawsolid (PDC, normal );
Delete line;

M_end = Pos;
 

G_pview-> releasedc (PDC );
 
Break;
}
}

Void ceraseline: onrbuttondown (uint nflags, cposition POS)
{
CDC * PDC = g_pview-> getdc ();
Cline * line1 = new Cline (m_begin, POS); // portrait Leather line, eliminating the previous
Line1-> drawsolid (PDC, back );
Delete line1;
G_pview-> releasedc (PDC );

M_nstep = 1;
}

Void ceraseline: setcancle (cposition POS)
{
Onrbuttondown (0, POS );

}

 

Int g_refresh = 0; // record the number of screen refreshes
Int c_refresh = 0;

Ccreateline: ccreateline ()
{
M_nstep = 1;
C_refresh = g_refresh;

}

Ccreateline ::~ Ccreateline ()
{

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.