### 2D Graphics Overview

The 2D Graphics Framework is a self-contained collection of C++ classes within IBM Open Class which provide classes for creating, manipulating, and rendering 2-dimensional graphics. You can use 2D Graphics classes to build applications that create and manipulate 2-dimensional graphics and images. These classes are easy to use. You instantiate the classes you need and call their member functions. You do not need to know linear algebra or any other advanced mathematics to effectively use these classes. All advanced mathematics is implemented for you.

You can extend most of these classes to add your own functionality by deriving from the abstract base classes, implementing the pure virtual functions, and adding whatever behavior you need.

The 2D Graphics Framework classes can be used to perform the following:

- Creation of graphical user interface (GUI) elements and decorations
- Manipulation of pixel-base images, screen captures and so on
- Creation of complex 2D graphics composed of groups of simple graphics used for modeling

The 2D Graphics Framework is grouped into the following main categories:

- Geometry
- Graphics Attributes
- Transformation
- Rendering
- Modeling

The graphics and geometry classes provide functionality for different areas of graphics programming:

- Graphics classes are derived from IMGraphic. They can own a geometry class and can have functions to transform and otherwise manipulate the geometry.
- Geometry classes have no common parent class. They have functions that let you manipulate the geometry, but are not intended to be derived from.

You can use graphics and geometry classes together, or use the geometry classes by themselves. You can also extend the graphics classes by creating your own graphic class. You can design your own class to use as many geometry classes as you want.

The geometry classes provide many ways to construct a shape because you construct the geometry first and then use it to construct the graphic. The graphics classes constructors give you the option of including an attribute bundle to define characteristics of the graphic.

Transformation functions let you rotate, translate, scale, or apply a general transformation to the geometry without using matrix multiplication.

The graphic classes provide mechanisms to determine the bounds of a graphic as a rectangle enclosing the shape. This bounding box can be used, for example, to determine whether a user has selected a graphic (hit detection). The supported functions return a bounding box that does not have a tight fit.

When you use a graphic class to create a shape, you get the following:

- The ability to display the graphic with user-defined attributes state class such as an IGrafBundle.
- The ability to combine several graphics into a group for common operations.

### Geometry

The geometry classes serve as the foundation for creating graphics. Use these classes to describe pure geometric shapes.

The geometry classes are grouped into the following categories:

- Computational geometry: Computational geometry classes, including points and collections of points, are used for 2D geometric calculations and as building blocks for other 2D geometry classes.
- Path geometry: Path geometry classes describe shapes of open shapes that need not be filled.
- Area geometry: Area geometry classes let you perform operations on a set of basic 2D geometry to create an arbitrary 2D shape. Area geometry classes describe shapes of an enclosed path that can be filled.
  Some geometric shapes, such as point, line, and nonenclosing polyline and curves, are of path geometry. Enclosing geometric shapes such as rectangle, circle, ellipse, polygon, and enclosing curves (loops) can be both path and area geometry.
- Special area geometry: Special area geometry classes, used primarily for clipping, make area geometry by concatenating different geometric shapes. These classes let you perform constructive area geometric operations through boolean operations such as union, intersection, and subtraction.
- Image geometry: Image geometry classes let you handle and manipulate 2D images (bitmaps). These classes convert basic geometry from coordinate units to pixels. 2D attribute bundles have special properties for determining the color of an image (transfer modes) and for specifying filters to control the appearance of an image when it has been enlarged or shrunk.

NOTE: For immediate mode rendering, a user can create geometry and graphics attributes and render directly to the graphics rendering/display system, the rendering pipeline, without using the modeling classes. However, IMGraphic modeling classes are more convenient for retained mode rendering where a user needs to attach attributes and transformation functions to a geometry.

### Attributes and Bundles

Graphics attributes classes describe primitive attributes such as paint, pen, and image transfer mode. These classes collect combinations of such primitive attributes to use when rendering the geometry.

### Transformations

Transformation classes, specifically IGrafMatrix, define transformation matrices for manipulating graphics geometry and modeling.

### Modeling

Modeling classes associate geometries with graphic attributes, and transformations for simple graphics and hierarchical collections of graphics. IMGraphic is the abstract class of IGraphicGroup and its related classes. Use these classes to create complex graphics models (scenes), and extend these classes to enable graphics metadata storage. The virtual draw function lets you render the geometry of a drawable graphic with attributes and transforms applied.

### Rendering

The rendering pipeline, controlled through IGrafPort, performs imaging operations. You associate a graphic and its state information, including its attribute state, transformation matrix, and clipping state, with a grafport. The grafport renders the graphic from this state information.

IGrafPort is associated with IGrafDevice. For performance reasons, IGrafDevice is at the level of abstraction of platform/device-specific code. The concrete subclass of IGrafDevice is platform/device specific. IGrafDevice encapsulates the nonportable code: the device-dependent layer is completely hidden from the client.

### Prerequisite Information

For background information on graphics programming, refer to a dictionary of graphics terms or to the following books on graphics programming:

- Foley, James; vanDam, Andries; Feiner, Steven; Hughes, John. Computer Graphics. Reading, Massachusetts: Addison-Wesley Publishing Company, 1990.
- Bartels, Richard; Beatty, John; Barsky, Brian. An Introduction to Splines for use in Computer Graphics & Geometric Modeling. Los Altos, California: Morgan Kaufmann Publishers, Inc., 1987.
- Farin, Gerald. Curves and Surfaces for Computer Aided Design. Boston, Massachusetts: Academic Press, 1990.
- Wyszecki, Günter. Color Science: Concepts and Methods, Quantitative Data and Formulae. John Wiley & Sons, Inc., 1982.

### Useful Information

- See also IGraphicText in the text display classes to create and manipulate text as a graphic.

- See also the 2DCombo sample in the code samples directory.

- The Open Class graphics classes use the following naming conventions to help you distinguish graphics classes from geometry classes:
  - Graphics class names begin with the letter "I" followed by the name of the graphic
    (for example, ILine).
  - Geometry class names begin with the letters "IG" followed by the name of the geometry
    (for example, IGLine2D).

- This guide describes the classes and data types common to the graphics classes. Member functions throughout the framework use some terms to indicate a particular function's role in storage management. These terms are provided here for your convenience while reading this guide.

  Functions that allocate and take responsibility for storage, or return pointers to instances, have special names and abide by the following guidelines:

  - Create: When you see "Create" in the name, the function makes and returns a new instance that the caller must delete.
  - Copy: When you see "Copy" in the name, the function copies an existing instance and the caller must delete that copy.
  - Adopt: When you see "Adopt" in the name, the function accepts an instance and is responsible for deleting it. Adopt functions that cannot have "Adopt" in their names (for example, constructors) prefix it to the name of the formal parameter.
  - Orphan: When you see "Orphan" in the name, the function transfers responsibility for deleting an instance to the caller.
  - Get: When you see "Get" in the name, the function returns a pointer to an instance, and the caller is not responsible for deleting the instance.

Attributes and Bundles Overview
2D Graphics Geometry Overview
Modeling Overview
2D Graphics Rendering Pipeline Overview
2D Graphic Transformations Overview

Transitioning 2D Graphics to IBM Open Class