In order to achieve the sorting, calling and rotating commands, these actions must be performed on the object.
Lines, circles, and rectangles are developed respectively.
Class cmyrect;
Class Cline: Public csolid
{
Public:
Cline ();
Cline (cposition & pos1, cposition & pos2 );
Csolid * copysolid () {return New Cline (this-> m_begin, this-> m_end);} // copy a straight line in Depth
Virtual ~ Cline ();
Public:
Csolid * explan (cposition POs, short zdelta );
Csolid * rotate (const cposition & base, float angle );
Csolid * move (cposition first, cposition second );
Bool picksolid (cposition & Pos, float dis );
Void drawsolid (CDC * PDC, int drawmode );
Void getbox (cbox2d & Box); // enclose the box
Void drawrect (bool Br, cposition & Pos, cposition * BPOs = NULL );
Void getend (cposition & End) {end = m_end ;}
Csolid * Mirror (cposition & first, cposition & second );
Protected:
Cposition m_begin, m_end;
};
Class ccircle: Public csolid // circular image, center, and a point above the circle
{
Public:
Ccircle (){};
Ccircle (const cposition begin, const cposition end );
Csolid * copysolid () {return New ccircle (this-> m_begin, this-> m_end );}
Virtual ~ Ccircle (){};
Public:
Csolid * explan (cposition POs, short zdelta );
Csolid * rotate (const cposition & base, float angle );
Csolid * move (cposition first, cposition second );
Void drawsolid (CDC * PDC, int drawmode); // draw a circle
Bool picksolid (cposition & Pos, float dis );
Void drawrect (bool Br, cposition & Pos, cposition * BPOs = NULL );
Csolid * Mirror (cposition & first, cposition & second );
PRIVATE:
Cposition m_begin, m_end;
};
Class ccrect: Public csolid // two Diagonal Points
{
Public:
Ccrect (){};
Ccrect (const cposition begin, const cposition end );
Csolid * copysolid () {return New ccrect (this-> m_begin, this-> m_end );}
Virtual ~ Ccrect (){};
Public:
Csolid * explan (cposition POs, short zdelta );
Csolid * rotate (const cposition & base, float angle );
Csolid * move (cposition first, cposition second );
Void drawsolid (CDC * PDC, int drawmode); // draw a circle
Bool picksolid (cposition & Pos, float dis );
Void drawrect (bool Br, cposition & Pos, cposition * BPOs = NULL );
Csolid * Mirror (cposition & first, cposition & second );
PRIVATE:
Cposition m_begin, m_end;
};
Cline: Cline ()
{
}
Cline: Cline (cposition & pos1, cposition & pos2)
{
M_begin = pos1;
M_end = pos2;
M_style = ps_solid;
M_width = 0;
M_color = RGB (1, 255,255,255 );
}
Cline ::~ Cline ()
{
}
Void Cline: drawsolid (CDC * PDC, int drawmode)
{
Cpoint point1, point2;
G_pview-> wptodp (m_begin, point1 );
G_pview-> wptodp (m_end, point2 );
Cpen pen;
If (drawmode = normal) // creates a paint brush based on the input mode.
{
Pen. createpen (m_style, m_width, m_color );
}
Else
{
Gsetdrawmode (PDC, drawmode, & pen );
}
Int n = PDC-> getrop2 ();
Cpen * oldpen = NULL;
Oldpen = PDC-> SelectObject (& pen );
PDC-> moveTo (point1.x, point1.y );
PDC-> lineto (point2.x, point2.y );
PDC-> setrop2 (N );
PDC-> SelectObject (oldpen );
}
Bool Cline: picksolid (cposition & Pos, float dis)
{
Cbox2d box;
Getbox (box );
Box. getexbox2d (DIS); // obtain the expanded box. Consider the horizontal or vertical line.
If (! POs. isbox (box ))
{
Return false;
}
Else
{
Return (Pos. verdistance (m_begin, m_end) <= dis); // smaller than the given distance
}
}
Void Cline: getbox (cbox2d & box)
{
Box. m_min.m_x = min (m_begin.m_x, m_end.m_x );
Box. m_min.m_y = min (m_begin.m_y, m_end.m_y );
Box. m_max.m_x = max (m_begin.m_x, m_end.m_x );
Box. m_max.m_y = max (m_begin.m_y, m_end.m_y );
}
Csolid * Cline: Rotate (const cposition & base, float angle )//
{
M_begin.rotate (base, angle );
M_end.rotate (base, angle );
Return (csolid *) This;
}
Csolid * Cline: explan (cposition POs, short zdelta)
{
Float size = 0.0;
If (zdelta> 0)
Scale = 0.7;
Else
Scale = 1.3;
M_begin.explan (Pos, scale );
M_end.explan (Pos, scale );
Return (csolid *) This;
}
Csolid * Cline: Move (cposition first, cposition second)
{
M_begin.move (first, second );
M_end.move (first, second );
Return (csolid *) This;
}
Csolid * Cline: Mirror (cposition & first, cposition & Second)
{
Cposition pos1 = m_begin.mirror (first, second );
Cposition pos2 = m_end.mirror (first, second );
Return new Cline (pos1, pos2 );
}
Void Cline: drawrect (bool Br, cposition & Pos, cposition * BPOs) // a straight line is labeled with three rectangles.
{
Cmyrect * rect1 = new cmyrect (m_begin );
Cmyrect * rect2 = new cmyrect (m_end );
Cmyrect * center = new cmytri (m_begin + m_end) * 0.5 );
CDC * PDC = g_pview-> getdc ();
Rect1-> drawrect (PDC, rect1-> pisrect (POS), 1, POs, BPOs );
Rect2-> drawrect (PDC, rect2-> pisrect (POS), 1, POs, BPOs );
Center-> drawrect (PDC, center-> pisrect (POS), 1, POs, BPOs );
G_pview-> releasedc (PDC );
Delete rect1, rect2, center;
}
Ccircle: ccircle (const cposition begin, const cposition end)
{
M_begin = begin;
M_end = end;
M_style = ps_solid;
M_width = 0;
M_color = RGB (1, 255,255,255 );
}
Bool ccircle: picksolid (cposition & Pos, float dis) // The circle is a line of width with a width of 6 pixels.
{
Dis = 3 * (g_pview-> m_scale );
Float r = m_begin.distance (m_end );
Float dis1 = r-DIS;
Float dis2 = R + DIS;
Float RO = m_begin.distance (POS );
If (Ro> = dis1 & Ro <= dis2)
{
Return true;
}
Else
{
Return false;
}
}
Csolid * ccircle: Rotate (const cposition & base, float angle )//
{
M_begin.rotate (base, angle );
M_end.rotate (base, angle );
Return (csolid *) This;
}
Csolid * ccircle: explan (cposition POs, short zdelta)
{
Float size = 0.0;
If (zdelta> 0)
Scale = 0.7;
Else
Scale = 1.3;
M_begin.explan (Pos, scale );
M_end.explan (Pos, scale );
Return (csolid *) This;
}
Csolid * ccircle: Move (cposition first, cposition second)
{
M_begin.move (first, second );
M_end.move (first, second );
Return (csolid *) This;
}
Csolid * ccircle: Mirror (cposition & first, cposition & Second)
{
Cposition pos1 = m_begin.mirror (first, second );
Cposition pos2 = m_end.mirror (first, second );
Return new ccircle (pos1, pos2 );
}
Class cmycircle;
Class ccros;
Void ccircle: drawrect (bool Br, cposition & Pos, cposition * BPOs) // The polygon is labeled with five rectangles.
{
Float Dis = m_begin.distance (m_end );
CDC * PDC = g_pview-> getdc ();
Cposition numpos [4];
Numpos [0] = (cposition (0, 1) * DIS + m_begin );
Numpos [1] = (cposition (0,-1) * DIS + m_begin );
Numpos [2] = (cposition (1, 0) * DIS + m_begin );
Numpos [3] = (cposition (-1, 0) * DIS + m_begin );
Cmyrect * Circle = new cmycircle (m_begin); // draw the center
Circle-> drawrect (PDC, circle-> pisrect (POS), 1, POs, BPOs );
Delete circle;
Cmyrect * rect = new ccros [4];
Cmyrect: drawmrect (PDC, 4, numpos, & Pos, BPOs, rect );
Delete [] rect;
G_pview-> releasedc (PDC );
}
Void ccircle: drawsolid (CDC * PDC, int drawmode)
{
Cposition POS [2];
Float Dis = m_begin.distance (m_end );
Pos [0] = cposition (-1, 0) * DIS + cposition (0, 1) * DIS + m_begin;
Pos [1] = m_begin * 2-pos [0];
Cpoint point1, point2;
G_pview-> wptodp (Pos [0], point1 );
G_pview-> wptodp (Pos [1], point2 );
Cpen pen;
If (drawmode = normal) // creates a paint brush based on the input mode.
{
Pen. createpen (m_style, m_width, m_color );
}
Else
{
Gsetdrawmode (PDC, drawmode, & pen );
}
Cbrush brush;
Logbrush;
Logbrush. lbstyle = bs_null;
Brush. createbrushindirect (& logbrush );
Int n = PDC-> getrop2 ();
Cpen * oldpen = NULL;
Cbrush * oldbrush = NULL;
Oldbrush = PDC-> SelectObject (& brush );
Oldpen = PDC-> SelectObject (& pen );
PDC-> ellipse (& crect (point1, point2 ));
PDC-> setrop2 (N );
PDC-> SelectObject (oldpen );
PDC-> SelectObject (oldbrush );
}
Ccrect: ccrect (const cposition begin, const cposition end)
{
M_begin = begin;
M_end = end;
M_style = ps_solid;
M_width = 0;
M_color = RGB (1, 255,255,255 );
}
Bool ccrect: picksolid (cposition & Pos, float dis) // you can directly select the four sides.
{
Cposition arraypos [5];
Arraypos [0] = m_begin;
Arraypos [1] = cposition (m_begin.m_x, m_end.m_y); // bottom left
Arraypos [2] = m_end;
Arraypos [3] = cposition (m_end.m_x, m_begin.m_y); // upper right
Arraypos [4] = m_begin;
For (INT I = 0; I <4; I ++)
{
Cline * line = new Cline (arraypos [I], arraypos [I + 1]);
If (line-> picksolid (Pos, DIS ))
{
Delete line;
Return true;
}
}
Return false;
}
Csolid * ccrect: Rotate (const cposition & base, float angle )//
{
M_begin.rotate (base, angle );
M_end.rotate (base, angle );
Return (csolid *) This;
}
Csolid * ccrect: explan (cposition POs, short zdelta)
{
Float size = 0.0;
If (zdelta> 0)
Scale = 0.7;
Else
Scale = 1.3;
M_begin.explan (Pos, scale );
M_end.explan (Pos, scale );
Return (csolid *) This;
}
Csolid * ccrect: Move (cposition first, cposition second)
{
M_begin.move (first, second );
M_end.move (first, second );
Return (csolid *) This;
}
Csolid * ccrect: Mirror (cposition & first, cposition & Second)
{
Cposition pos1 = m_begin.mirror (first, second );
Cposition pos2 = m_end.mirror (first, second );
Return new ccrect (pos1, pos2 );
}
Void ccrect: drawrect (bool Br, cposition & Pos, cposition * BPOs) // The rectangle has nine tags
{
CDC * PDC = g_pview-> getdc ();
Cposition arraypos [4];
Arraypos [0] = m_begin; // 0
Arraypos [1] = cposition (m_begin.m_x, m_end.m_y); // bottom left 1 // endpoint
Arraypos [2] = m_end; // 2
Arraypos [3] = cposition (m_end.m_x, m_begin.m_y); // upper right 3
Cposition ctrarraypos [4];
Ctrarraypos [0] = (arraypos [0] + arraypos [3]) * 0.5; // 03 // midpoint
Ctrarraypos [1] = (arraypos [0] + arraypos [1]) * 0.5; // 01
Ctrarraypos [2] = (arraypos [1] + arraypos [2]) * 0.5; // 12
Ctrarraypos [3] = (arraypos [2] + arraypos [3]) * 0.5; // 23
Cposition cenarraypos [1];
Cenarraypos [1] = (arraypos [0] + arraypos [2]) * 0.5; // 02 // center
Cmyrect * Circle = new cmycircle (cenarraypos [0]); // draw the center
Circle-> drawrect (PDC, circle-> pisrect (POS), 1, POs, BPOs );
Delete circle;
Cmyrect * myrect = new cmyrect [4]; // endpoint
Cmyrect: drawmrect (PDC, 4, arraypos, & Pos, BPOs, myrect );
Delete [] myrect;
Cmyrect * rect = new cmytri [4];
Cmyrect: drawmrect (PDC, 4, ctrarraypos, & Pos, BPOs, rect );
Delete [] rect;
G_pview-> releasedc (PDC );
}
Void ccrect: drawsolid (CDC * PDC, int drawmode)
{
Cpoint point1, point2;
G_pview-> wptodp (m_begin, point1 );
G_pview-> wptodp (m_end, point2 );
Cpen pen;
If (drawmode = normal) // creates a paint brush based on the input mode.
{
Pen. createpen (m_style, m_width, m_color );
}
Else
{
Gsetdrawmode (PDC, drawmode, & pen );
}
Cbrush brush;
Logbrush;
Logbrush. lbstyle = bs_null;
Brush. createbrushindirect (& logbrush );
Int n = PDC-> getrop2 ();
Cpen * oldpen = NULL;
Cbrush * oldbrush = NULL;
Oldbrush = PDC-> SelectObject (& brush );
Oldpen = PDC-> SelectObject (& pen );
PDC-> rectangle (& crect (point1, point2 ));
PDC-> setrop2 (N );
PDC-> SelectObject (oldpen );
PDC-> SelectObject (oldbrush );
}