#include <Graphics.h>
Inheritance diagram for prapi::graphics::Graphics< T >:

This is a superclass for classes that are able to draw on various devices. A graphics device must contain a rectangular area of pixels. The upper left corner of the area is used as an origin by default, with the positive y axis running down and the positive x axis to the right. By default, the Graphics class takes care of high-level drawing primitives, and delegates only the setting of pixels to the actual graphics device. It is however possible the override the drawing functions. This way it is possible to create, for example, PostScript graphics etc.
The template parameter T defines the type of a pixel in the graphics context. In a memory buffer, pixels may be represented as chars or ints. For color graphics, the type may be Color.
Public Methods | |
| void | setDrawMode (DrawMode mode) |
| Set the drawing mode. | |
| DrawMode | getDrawMode () const |
| Get the current drawing mode. | |
| void | setColor (T color) |
| Set the current drawing "color" to a value. | |
| T | getColor () const |
| Get the current drawing color. | |
| void | setOpacity (double opacity) |
| Set the opacity of the drawing operations. | |
| double | getOpacity () |
| Get the current opacity. | |
| void | translate (int x, int y) |
| Shift the origin of this graphics context to the given coordinates. | |
| Point< int > | getOrigin () const |
| Get the current origin of the coordinate system. | |
| void | setClip (const Shape *shape) |
| Set the clipping region. | |
| void | drawPixel (int x, int y) |
| Set a pixel in a graphics context with no interpolation (anti-aliasing). | |
| virtual void | drawPixel (double x, double y) |
| Draw a pixel in a graphics context. | |
| template<class modifier> void | modifyPixel (double x, double y) |
| Modify a pixel. | |
| template<class modifier> void | modifyPixel (int x, int y) |
| Modify a pixel in an image without interpolation (anti-aliasing). | |
| virtual void | drawCircle (double centerX, double centerY, double radius) |
| Draw an anti-alised circle. | |
| virtual void | drawArc (double centerX, double centerY, double radius, double startAngle, double endAngle) |
| Draw an anti-alised arc. | |
| virtual void | drawLine (double startX, double startY, double endX, double endY) |
| Draw an interpolated (anti-aliased) line. | |
| virtual void | drawLine (int startX, int startY, int endX, int endY) |
| Draw a non-interpolated line. | |
| virtual void | drawRect (int x, int y, int width, int height) |
| Draw a rectangle with non-interpolated borders. | |
| virtual void | drawRect (double x, double y, double width, double height) |
| Draw a rectangle with interpolated (anti-alised) borders. | |
| virtual | ~Graphics () |
Protected Methods | |
| Graphics (int width=0, int height=0) | |
| Create a new graphics context. | |
| virtual T | getPixel (int x, int y) const=0 |
| Get a pixel in a graphics context. | |
| virtual T & | pixel (int x, int y)=0 |
| Get a pixel in a graphics context. | |
| virtual void | setPixel (int x, int y, T value)=0 |
| Set a pixel in a graphics context. | |
Protected Attributes | |
| Dimension< int > | _dimBounds |
| The dimensions of the graphics context. | |
| int | _iOriginX |
| The coordinates of the current origin. | |
| int | _iOriginY |
| The coordinates of the current origin. | |
| const Shape * | _pClipShape |
| The current clipping region. | |
| T | _color |
| The current drawing color. | |
| double | _dOpacity |
| The current opacity. | |
| DrawMode | _drawMode |
| The current drawing mode. | |
|
||||||||||||||||
|
Create a new graphics context. Subclasses should provide the bounds of their device/buffer at initialization.
|
|
||||||||||||||||||||||||||||
|
Draw an anti-alised arc. Angles are represented as radians in counter-clockwise direction. Zero angle is at the direction of the horizontal x-axis.
|
|
||||||||||||||||||||
|
Draw an anti-alised circle.
|
|
||||||||||||||||||||||||
|
Draw a non-interpolated line.
|
|
||||||||||||||||||||||||
|
Draw an interpolated (anti-aliased) line.
|
|
||||||||||||||||
|
Draw a pixel in a graphics context. This method uses bilinear interpolation to draw anti-aliased pixels. Up to four neighboring pixels closest to the given floating-point image coordinates may be affected.
|
|
||||||||||||||||
|
Set a pixel in a graphics context with no interpolation (anti-aliasing). It is not possible to override this method. Instead, subclasses should override the protected get/setPixel() methods.
|
|
||||||||||||||||||||||||
|
Draw a rectangle with interpolated (anti-alised) borders.
|
|
||||||||||||||||||||||||
|
Draw a rectangle with non-interpolated borders.
|
|
||||||||||||||||
|
Get a pixel in a graphics context. Subclasses must implement this method to get the contents of the graphics device/buffer. Boundary checking has been done before calling this method. Thus, assuming _dimBounds has been set correctly, subclasses never need to check whether the given coordinates are within the allowed range. Implemented in prapi::graphics::MemoryGraphics< T >. |
|
||||||||||||||||||||
|
Modify a pixel in an image without interpolation (anti-aliasing).
|
|
||||||||||||||||||||
|
Modify a pixel. This method works in a similar way as drawPixel(), but instead of overwriting a pixel it modifies the old value. The current opacity is used to control the "strength" of the modification. 0 means no change, and 1 means the old value will be modified with exactly the given value. The current drawing mode does not affect pixel modifications. Therefore, this method allows one to alter the pixel data in many customized ways. The modifier template parameter can be any class with the T operator() (T,T) defined. An example:
class MyModifier
{
public:
int operator() (int a, int b) { return b-a; }
};
...
//Subtract the value of the pixel at (2.3, 3.5) from three (with anti-aliasing)
graphics.setColor(3);
graphics.modifyPixel<MyModifier>(2.3, 3.5);
//Subtract the value of the pixel at (3, 4) from two (without anti-aliasing)
graphics.setColor(4);
graphics.setOpacity(0.5);
graphics.modifyPixel<MyModifier>(3,4);
|
|
||||||||||||||||
|
Get a pixel in a graphics context. Subclasses must implement this method to get the contents of the graphics device/buffer. Boundary checking has been done before calling this method. Thus, assuming _dimBounds has been set correctly, subclasses never need to check whether the given coordinates are within the allowed range. Implemented in prapi::graphics::MemoryGraphics< T >. |
|
||||||||||
|
Set the clipping region. The clipping region determines the drawable area in a graphics context. All graphics primitives that fall outside of the clipping region, as determined by the Shape::contains(x,y) method, are not drawn. The clipping region is always interpreted relative to the current origin of the coordinate system. That is, moving the origin also moves the clipping region. |
|
||||||||||
|
Set the current drawing "color" to a value. All subsequent drawing operations will use this color. For gray-scale graphics, for example integer valued memory buffers, the "color" is actually a scalar. |
|
||||||||||
|
Set the drawing mode. All subsequent drawing operations will be performed in the indicated mode. |
|
||||||||||
|
Set the opacity of the drawing operations. Opacity determines how much newly drawn pixels affect those under it. If opacity is set to one, the old pixel value is totally overwritten. If opacity is set to zero, drawing operations have no visible effect. The default value is one. |
|
||||||||||||||||||||
|
Set a pixel in a graphics context. Subclasses must implement this method to alter the graphics device/buffer. Boundary checking has been done before calling this method. Thus, assuming _dimBounds has been set correctly, subclasses never need to check whether the given coordinates are within the allowed range. Implemented in prapi::graphics::MemoryGraphics< T >. |
|
||||||||||||||||
|
Shift the origin of this graphics context to the given coordinates. The coordinates of all subsequent drawing operations will be interpreted relative to this position. The origin can lie outside of the boundaried of the graphics context. An example:
//To move the origin to (30,20): graphics.translate(30,20); //To move the origin back: graphics.translate(-30,-20); In addition to the origin, this method also moves the current clipping region. |
|
|||||
|
The current drawing color. Set initially to zero. |
|
|||||
|
The dimensions of the graphics context. Subclasses must fill this class with the dimensions of the graphics device/buffer. |
|
|||||
|
The current opacity. Initially set to one. |
|
|||||
|
The current drawing mode. Set initially to DRAWMODE_NORMAL. |