Chapter 12 demonstrated how to create simple windows and display basic shapes: rectangle, circle, triangle, and ellipse. It showed how to manipulate such shapes: change colors and line style, add text, etc. Chapter 13 shows how these shapes and operations are implemented, and shows a few more examples. In Chapter 12, we were basically tool users; here we become tool builders. | Chapter 13 Graphics classes Bjarne Stroustrup Abstract Chapter 12 demonstrated how to create simple windows and display basic shapes: rectangle, circle, triangle, and ellipse. It showed how to manipulate such shapes: change colors and line style, add text, etc. Chapter 13 shows how these shapes and operations are implemented, and shows a few more examples. In Chapter 12, we were basically tool users; here we become tool builders. Stroustrup/Programming Overview Graphing Model Code organization Interface classes Point Line Lines Grid Open Polylines Closed Polylines Color Text Unnamed objects Stroustrup/Programming Display model Objects (such as graphs) are “attached to” (“placed in”) a window. The “display engine” invokes display commands (such as “draw line from x to y”) for the objects in a window Objects such as Rectangle add vectors of lines to the window to draw Open_polyline Rectangle “window” Display Engine attach() attach() draw() . | Chapter 13 Graphics classes Bjarne Stroustrup Abstract Chapter 12 demonstrated how to create simple windows and display basic shapes: rectangle, circle, triangle, and ellipse. It showed how to manipulate such shapes: change colors and line style, add text, etc. Chapter 13 shows how these shapes and operations are implemented, and shows a few more examples. In Chapter 12, we were basically tool users; here we become tool builders. Stroustrup/Programming Overview Graphing Model Code organization Interface classes Point Line Lines Grid Open Polylines Closed Polylines Color Text Unnamed objects Stroustrup/Programming Display model Objects (such as graphs) are “attached to” (“placed in”) a window. The “display engine” invokes display commands (such as “draw line from x to y”) for the objects in a window Objects such as Rectangle add vectors of lines to the window to draw Open_polyline Rectangle “window” Display Engine attach() attach() draw() draw() draw() Stroustrup/Programming Code organization // Graphing interface: struct Shape { }; // window interface: class Window { }; FLTK headers Graph code Window code FLTK code : : : #include "" #include "" int main() { } : : struct Point { }; // GUI interface: struct In_box { }; GUI code : : : Stroustrup/Programming Source files Header File that contains interface information (declarations) #include in user and implementer .cpp (“code file” / “implementation file”) File that contains code implementing interfaces defined in headers and/or uses such interfaces #includes headers Read the header And later the implementation file Don’t read the header or the implementation file Naturally, some of you will take a peek Beware: heavy use of yet unexplained C++ features Stroustrup/Programming Design note The ideal of program design is to represent .