the Drawing Room (paintoffice) can design individual drawing objects, each drawing object includes coordinate information, and graphical information can be initialized through constructors, each drawing object provides a draw () function, has completed its own drawing, and provides SetPos () member function to change the position of the member. The design of the graphic objects include lines, ellipses, rectangles three, if interested can add other graphics on their own. Each class provides initialization of the constructor completion information, no system energy applications within the class, and no destructors. The Draw (), SetPos () function can be considered a member function of a class. The coordinates of the line can be positioned using the coordinates of the start and end points, the coordinates of the rectangle are positioned with the upper-left and lower-right corners, and the coordinates of the ellipse can be positioned by the ellipse's bounding rectangle.
The following is a list of related programs for one of the graphic objects (lines), similar to other graphical objects.
1 //Line.cpp2#include"line.h"3 #include4 using namespacestd;5 6Cline::cline (intX1,intY1,intX2,inty2): CShape (x1,y1,x2,y2)7 {8m_x1=X1;9m_y1=Y1;TenM_x2=x2; OneM_y2=Y2; A } - - voidCline::D Raw () the { -cout<<"Draw a line"<<Endl; - } - + voidCline::setpos (intX1,intY1,intX2,inty2) - { +m_x1=X1; Am_y1=Y1; atM_x2=x2; -M_y2=Y2; - } - - //line.h - #pragmaOnce in#include"Shape.h" - classCline: PublicCShape to { + Public: -Cline (intX1,intY1,intX2,inty2); the voidDraw (); * voidSetPos (intX1,intY1,intX2,inty2); $ Private:Panax Notoginseng intm_x1;//start x coordinate - intm_y1; the intm_x2;//end X Coordinate + intM_y2; A};
each graphic class in a drawing room project has coordinate information and a draw (), SetPos () function, which can be placed in a base class as a commonality, with derived classes inheriting from it. Because different graphic class coordinate information is the same, the coordinate point and the SetPos () function fit into the parent class, but the draw () function parameters of the different graphics classes are the same, but the concrete implementation is not the same, so you can set the virtual function in the parent class.
The design of the base class Cshape related procedures are as follows:
1 //Shape.cpp2#include"Shape.h"3 4Cshape::cshape (intX1,intY1,intX2,inty2)5 {6m_x1=X1;7m_y1=Y1;8M_x2=x2;9M_y2=Y2;Ten } One A voidCshape::setpos (intX1,intY1,intX2,inty2) - { -m_x1=X1; them_y1=Y1; -M_x2=x2; -M_y2=Y2; - } + - //Shape.h + #pragmaOnce A classCShape at { - Public: -CShape (intX1,intY1,intX2,inty2); - Virtual voidDraw () =0; - voidSetPos (intX1,intY1,intX2,inty2); - protected: in intm_x1;//start x coordinate - intM_y1;//Start Y coordinate to intm_x2;//end X Coordinate + intM_y2;//End Y coordinate -};
Reprint please specify the source:
C + + Blog Park: godfrey_88
http://www.cnblogs.com/gaobaoru-articles/
Drawing Room (Paintoffice)