# WoopsiUI::GraphicsPort Class Reference

`#include <graphicsport.h>`

List of all members.

## Public Member Functions
| GraphicsPort (const s16 x, const s16 y, const u16 width, const u16 height, const bool isEnabled, FrameBuffer *bitmap, const WoopsiArray< Rect > *clipRectList, const Rect *clipRect)
virtual | ~GraphicsPort ()
void | setClipRect (const Rect &clipRect)
void | getClipRect (Rect &rect) const
const s16 | getX () const
const s16 | getY () const
void | drawPixel (s16 x, s16 y, u16 colour)
void | drawFilledRect (s16 x, s16 y, u16 width, u16 height, u16 colour)
void | drawHorizLine (s16 x, s16 y, s16 width, u16 colour)
void | drawVertLine (s16 x, s16 y, s16 height, u16 colour)
void | drawRect (s16 x, s16 y, u16 width, u16 height, u16 colour)
void | drawBevelledRect (s16 x, s16 y, u16 width, u16 height, u16 shineColour, u16 shadowColour)
virtual void | drawCircle (s16 x0, s16 y0, u16 radius, u16 colour)
void | drawFilledCircle (s16 x0, s16 y0, u16 radius, u16 colour)
virtual void | drawXORPixel (s16 x, s16 y, u16 colour)
virtual void | drawXORHorizLine (s16 x, s16 y, u16 width, u16 colour)
virtual void | drawXORVertLine (s16 x, s16 y, u16 height, u16 colour)
virtual void | drawXORRect (s16 x, s16 y, u16 width, u16 height, u16 colour)
virtual void | drawFilledXORRect (s16 x, s16 y, u16 width, u16 height, u16 colour)
virtual void | drawXORPixel (s16 x, s16 y)
void | drawXORHorizLine (s16 x, s16 y, u16 width)
void | drawXORVertLine (s16 x, s16 y, u16 height)
void | drawXORRect (s16 x, s16 y, u16 width, u16 height)
void | drawFilledXORRect (s16 x, s16 y, u16 width, u16 height)
void | drawText (s16 x, s16 y, FontBase *font, const WoopsiString &string)
void | drawText (s16 x, s16 y, FontBase *font, const WoopsiString &string, s32 startIndex, s32 length, u16 colour)
void | drawText (s16 x, s16 y, FontBase *font, const WoopsiString &string, s32 startIndex, s32 length)
void | drawBitmap (s16 x, s16 y, u16 width, u16 height, const BitmapBase *bitmap, s16 bitmapX, s16 bitmapY)
void | drawBitmap (s16 x, s16 y, u16 width, u16 height, const BitmapBase *bitmap, s16 bitmapX, s16 bitmapY, u16 transparentColour)
virtual void | drawBitmapGreyScale (s16 x, s16 y, u16 width, u16 height, const BitmapBase *bitmap, s16 bitmapX, s16 bitmapY)
void | drawLine (s16 x1, s16 y1, s16 x2, s16 y2, u16 colour)
void | copy (s16 sourceX, s16 sourceY, s16 destX, s16 destY, u16 width, u16 height)
void | scroll (s16 x, s16 y, s16 xDistance, s16 yDistance, u16 width, u16 height, WoopsiArray< Rect > *revealedRects)
void | dim (s16 x, s16 y, u16 width, u16 height)
void | greyScale (s16 x, s16 y, u16 width, u16 height)
virtual void | drawEllipse (s16 xCentre, s16 yCentre, s16 horizRadius, s16 vertRadius, u16 colour)
virtual void | drawFilledEllipse (s16 xCentre, s16 yCentre, s16 horizRadius, s16 vertRadius, u16 colour)

## Detailed Description

GraphicsPort is the interface between a gadget and the framebuffer. It provides drawing tools that are clipped to the visible regions of a gadget.

All drawing co-ordinates should be submitted in GraphicsPort space. GraphicsPort space is relative to the x and y co-ordinates given to an instance of the GraphicsPort class via its constructor. The width and height parameters define the size of that space. The x and y co-ordinates submitted to the constructor should be relative to the gadget. The getClipRect() method returns the rect in GraphicsPort space.

Internally, all co-ordinates are converted to Woopsi-space for manipulation. However, when drawing all co-ordinates are converted from Woopsi-space to framebuffer-space.

This class can only draw to one of the DS' framebuffers. This means that a gadget cannot span both of the DS' screens. If a gadget attempts to span both screens (as in the case of the Woopsi gadget), any drawing will be done to the bottom display only. Drawing commands that should take effect on the top display will simply be clipped out. This is why the Woopsi class creates two blank screens as backgrounds in its constructor and does not include any drawing commands.

A workaround for this limitation is to manually create a new graphicsport in your gadget's draw methods and force it to use the top display's framebuffer. You can then direct drawing commands to the upper display.

## Constructor & Destructor Documentation

WoopsiUI::GraphicsPort::GraphicsPort | ( | const s16 | x,
|  | const s16 | y,
|  | const u16 | width,
|  | const u16 | height,
|  | const bool | isEnabled,
|  | FrameBuffer * | bitmap,
|  | const WoopsiArray< Rect > * | clipRectList,
|  | const Rect * | clipRect |
| ) |  |  |

Constructor.

The x, y, width and height parameters define the area within which the GraphicsPort can draw. These should represent the co-ordinates of the gadget, or an area within the gadget, expressed in Woopsi-space co-ordinates. A gadget's co-ordinates in Woopsi-space are given by its getX() and getY() methods. The width and height parameters are given by the getWidth() and getHeight() methods of the gadget.

To limit drawing to an area within a gadget, add the co-ordinates of the area to the values returned by getX() and getY(). For example, to create a GraphicsPort that will not draw within any of the pixels from co-ordinates (0,0) to (0,12), the x parameter should be:

getX() + 12

When the co-ordinates are increased, the width must decrease. The appropriate width for the above situation is:

getWidth() - 12

In most circumstances, x/y/width/height should reflect either the dimensions and co-ordinates of the gadget or the area inside its border.

Parameters:

  | x | The x co-ordinate of the region into which the graphics port can draw.
  | y | The y co-ordinate of the region into which the graphics port can draw.
  | width | The width of the region into which the graphics port can draw.
  | height | The height of the region into which the graphics port can draw.
  | isEnabled | Set this to false to disable all drawing commands.
  | bitmap | The bitmap that the port will draw to.
  | clipRectList | An array of clipping regions within which the class must draw. If set, clipRect must be NULL.
  | clipRect | The clipping region within which the class must draw. If set, clipRectList must be NULL.

virtual WoopsiUI::GraphicsPort::~GraphicsPort | ( |  | ) | `[inline, virtual]`

Destructor.

## Member Function Documentation

void WoopsiUI::GraphicsPort::copy | ( | s16 | sourceX,
|  | s16 | sourceY,
|  | s16 | destX,
|  | s16 | destY,
|  | u16 | width,
|  | u16 | height |
| ) |  |  |

Copy a rectangular region from the source co-ordinates to the destination co-ordinates. Uses the DMA for speed. Worst-case scenario uses an off-screen buffer for situations wherein there is no vertical movement and the source and destination overlap, in which case two copies are performed for each row (source to buffer and buffer to destination). Does not clip.

Parameters:

  | sourceX | Source x co-ord.
  | sourceY | Source y co-ord.
  | destX | Destination x co-ord.
  | destY | Destination y co-ord.
  | width | Width of the rectangle to copy.
  | height | Height of the rectangle to copy.

void WoopsiUI::GraphicsPort::dim | ( | s16 | x,
|  | s16 | y,
|  | u16 | width,
|  | u16 | height |
| ) |  |  |

Halve the brightness of a specified region.

Parameters:

  | x | X co-ord of the region to dim.
  | y | Y co-ord of the region to dim.
  | width | Width of the region to dim.
  | height | Height of the region to dim.

void WoopsiUI::GraphicsPort::drawBevelledRect | ( | s16 | x,
|  | s16 | y,
|  | u16 | width,
|  | u16 | height,
|  | u16 | shineColour,
|  | u16 | shadowColour |
| ) |  |  |

Draw a bevelled rectangle to the bitmap.

Parameters:

  | x | The x co-ordinate of the rectangle.
  | y | The y co-ordinate of the rectangle.
  | width | The width of the rectangle.
  | height | The height of the rectangle.
  | shineColour | The colour of the top/left sides.
  | shadowColour | The colour of the bottom/right sides.

void WoopsiUI::GraphicsPort::drawBitmap | ( | s16 | x,
|  | s16 | y,
|  | u16 | width,
|  | u16 | height,
|  | const BitmapBase * | bitmap,
|  | s16 | bitmapX,
|  | s16 | bitmapY,
|  | u16 | transparentColour |
| ) |  |  |

Draw a bitmap to the port's bitmap, using the supplied transparent colour as an invisible colour. This is considerably slower than the standard bitmap drawing routine as it plots pixel-by-pixel instead of using a scanline DMA copy.

Parameters:

  | x | The x co-ordinate to draw the bitmap to.
  | y | The y co-ordinate to draw the bitmap to.
  | width | The width of the bitmap to draw.
  | height | The height of the bitmap to draw.
  | bitmap | Pointer to the bitmap to draw.
  | bitmapX | The x co-ordinate within the supplied bitmap to use as the origin.
  | bitmapY | The y co-ordinate within the supplied bitmap to use as the origin.
  | transparentColour | The transparent colour used in the bitmap.

void WoopsiUI::GraphicsPort::drawBitmap | ( | s16 | x,
|  | s16 | y,
|  | u16 | width,
|  | u16 | height,
|  | const BitmapBase * | bitmap,
|  | s16 | bitmapX,
|  | s16 | bitmapY |
| ) |  |  |

Draw a bitmap to the port's bitmap.

Parameters:

  | x | The x co-ordinate to draw the bitmap to.
  | y | The y co-ordinate to draw the bitmap to.
  | width | The width of the bitmap to draw.
  | height | The height of the bitmap to draw.
  | bitmap | Pointer to the bitmap to draw.
  | bitmapX | The x co-ordinate within the supplied bitmap to use as the origin.
  | bitmapY | The y co-ordinate within the supplied bitmap to use as the origin.

virtual void WoopsiUI::GraphicsPort::drawBitmapGreyScale | ( | s16 | x,
|  | s16 | y,
|  | u16 | width,
|  | u16 | height,
|  | const BitmapBase * | bitmap,
|  | s16 | bitmapX,
|  | s16 | bitmapY |
| ) |  |  | `[virtual]`

Draw a bitmap to the port in greyscale. This is considerably slower than the standard bitmap drawing routine as it plots pixel-by-pixel instead of using a scanline DMA copy.

Parameters:

  | x | The x co-ordinate to draw the bitmap to.
  | y | The y co-ordinate to draw the bitmap to.
  | width | The width of the bitmap to draw.
  | height | The height of the bitmap to draw.
  | bitmap | Pointer to the bitmap to draw.
  | bitmapX | The x co-ordinate within the supplied bitmap to use as the origin.
  | bitmapY | The y co-ordinate within the supplied bitmap to use as the origin.

virtual void WoopsiUI::GraphicsPort::drawCircle | ( | s16 | x0,
|  | s16 | y0,
|  | u16 | radius,
|  | u16 | colour |
| ) |  |  | `[virtual]`

Draw an unfilled circle to the internal bitmap.

Parameters:

  | x0 | The x co-ordinate of the circle.
  | y0 | The y co-ordinate of the circle.
  | radius | The radius of the circle.
  | colour | The colour of the circle.

virtual void WoopsiUI::GraphicsPort::drawEllipse | ( | s16 | xCentre,
|  | s16 | yCentre,
|  | s16 | horizRadius,
|  | s16 | vertRadius,
|  | u16 | colour |
| ) |  |  | `[virtual]`

Draw an unfilled ellipse to the bitmap.

Parameters:

  | xCentre | The x co-ordinate of the ellipse's centre.
  | yCentre | The y co-ordinate of the ellipse's centre.
  | horizRadius | The size of the ellipse's horizontal radius.
  | vertRadius | The size of the ellipse's vertical radius.
  | colour | The colour of the ellipse.

void WoopsiUI::GraphicsPort::drawFilledCircle | ( | s16 | x0,
|  | s16 | y0,
|  | u16 | radius,
|  | u16 | colour |
| ) |  |  |

Draw a filled circle to the bitmap.

Parameters:

  | x0 | The x co-ordinate of the circle.
  | y0 | The y co-ordinate of the circle.
  | radius | The radius of the circle.
  | colour | The colour of the circle.

virtual void WoopsiUI::GraphicsPort::drawFilledEllipse | ( | s16 | xCentre,
|  | s16 | yCentre,
|  | s16 | horizRadius,
|  | s16 | vertRadius,
|  | u16 | colour |
| ) |  |  | `[virtual]`

Draw a filled ellipse to the bitmap.

Parameters:

  | xCentre | The x co-ordinate of the ellipse's centre.
  | yCentre | The y co-ordinate of the ellipse's centre.
  | horizRadius | The size of the ellipse's horizontal radius.
  | vertRadius | The size of the ellipse's vertical radius.
  | colour | The colour of the ellipse.

void WoopsiUI::GraphicsPort::drawFilledRect | ( | s16 | x,
|  | s16 | y,
|  | u16 | width,
|  | u16 | height,
|  | u16 | colour |
| ) |  |  |

Draw a filled rectangle to the bitmap.

Parameters:

  | x | The x co-ordinate of the rectangle.
  | y | The y co-ordinate of the rectangle.
  | width | The width of the rectangle.
  | height | The height of the rectangle.
  | colour | The colour of the rectangle.

void WoopsiUI::GraphicsPort::drawFilledXORRect | ( | s16 | x,
|  | s16 | y,
|  | u16 | width,
|  | u16 | height |
| ) |  |  |

Invert the colour of a filled rectangle of pixels.

Parameters:

  | x | The x co-ordinate of the rectangle.
  | y | The y co-ordinate of the rectangle.
  | width | The width of the rectangle.
  | height | The height of the rectangle.

virtual void WoopsiUI::GraphicsPort::drawFilledXORRect | ( | s16 | x,
|  | s16 | y,
|  | u16 | width,
|  | u16 | height,
|  | u16 | colour |
| ) |  |  | `[virtual]`

XOR the colour of a filled rectangle of pixels against the supplied colour.

Parameters:

  | x | The x co-ordinate of the rectangle.
  | y | The y co-ordinate of the rectangle.
  | width | The width of the rectangle.
  | height | The height of the rectangle.
  | colour | The colour to XOR against.

void WoopsiUI::GraphicsPort::drawHorizLine | ( | s16 | x,
|  | s16 | y,
|  | s16 | width,
|  | u16 | colour |
| ) |  |  |

Draw a horizontal line to the bitmap

Parameters:

  | x | The x co-ordinate of the line.
  | y | The y co-ordinate of the line.
  | width | The width of the line.
  | colour | The colour of the line.

void WoopsiUI::GraphicsPort::drawLine | ( | s16 | x1,
|  | s16 | y1,
|  | s16 | x2,
|  | s16 | y2,
|  | u16 | colour |
| ) |  |  |

Draw a line to the port's bitmap.

Parameters:

  | x1 | The x co-ordinate of the start point of the line.
  | y1 | The y co-ordinate of the start point of the line.
  | x2 | The x co-ordinate of the end point of the line.
  | y2 | The y co-ordinate of the end point of the line.
  | colour | The colour of the line.

void WoopsiUI::GraphicsPort::drawPixel | ( | s16 | x,
|  | s16 | y,
|  | u16 | colour |
| ) |  |  |

Draw a pixel to the bitmap.

Parameters:

  | x | The x co-ordinate of the pixel.
  | y | The y co-ordinate of the pixel.
  | colour | The colour of the pixel.

void WoopsiUI::GraphicsPort::drawRect | ( | s16 | x,
|  | s16 | y,
|  | u16 | width,
|  | u16 | height,
|  | u16 | colour |
| ) |  |  |

Draw an unfilled rectangle to the bitmap

Parameters:

  | x | The x co-ordinate of the rectangle.
  | y | The y co-ordinate of the rectangle.
  | width | The width of the rectangle.
  | height | The height of the rectangle.
  | colour | The colour of the rectangle.

void WoopsiUI::GraphicsPort::drawText | ( | s16 | x,
|  | s16 | y,
|  | FontBase * | font,
|  | const WoopsiString & | string,
|  | s32 | startIndex,
|  | s32 | length |
| ) |  |  |

Draw a portion of a string to the bitmap.

Parameters:

  | x | The x co-ordinate of the string.
  | y | The y co-ordinate of the string.
  | font | The font to draw with.
  | string | The string to output.
  | startIndex | The start index within the string from which drawing will commence.
  | length | The number of characters to draw.

void WoopsiUI::GraphicsPort::drawText | ( | s16 | x,
|  | s16 | y,
|  | FontBase * | font,
|  | const WoopsiString & | string,
|  | s32 | startIndex,
|  | s32 | length,
|  | u16 | colour |
| ) |  |  |

Draw a particular length of a string to the bitmap in a secific colour.

Parameters:

  | x | The x co-ordinate of the string.
  | y | The y co-ordinate of the string.
  | font | The font to draw with.
  | string | The string to output.
  | startIndex | The start index within the string from which drawing will commence.
  | length | The number of characters to draw.
  | colour | The colour of the string.

void WoopsiUI::GraphicsPort::drawText | ( | s16 | x,
|  | s16 | y,
|  | FontBase * | font,
|  | const WoopsiString & | string |
| ) |  |  |

Draw a string to the bitmap.

Parameters:

  | x | The x co-ordinate of the string.
  | y | The y co-ordinate of the string.
  | font | The font to draw with.
  | string | The string to output.

void WoopsiUI::GraphicsPort::drawVertLine | ( | s16 | x,
|  | s16 | y,
|  | s16 | height,
|  | u16 | colour |
| ) |  |  |

Draw a vertical line to the bitmap

Parameters:

  | x | The x co-ordinate of the line.
  | y | The y co-ordinate of the line.
  | height | The height of the line.
  | colour | The colour of the line.

void WoopsiUI::GraphicsPort::drawXORHorizLine | ( | s16 | x,
|  | s16 | y,
|  | u16 | width |
| ) |  |  |

Invert the colour of a horizontal line of pixels.

Parameters:

  | x | The x co-ordinate of the line.
  | y | The y co-ordinate of the line.
  | width | The width of the line.

virtual void WoopsiUI::GraphicsPort::drawXORHorizLine | ( | s16 | x,
|  | s16 | y,
|  | u16 | width,
|  | u16 | colour |
| ) |  |  | `[virtual]`

XOR the colour of a horizontal line of pixels against the supplied colour.

Parameters:

  | x | The x co-ordinate of the line.
  | y | The y co-ordinate of the line.
  | width | The width of the line.
  | colour | The colour to XOR against.

virtual void WoopsiUI::GraphicsPort::drawXORPixel | ( | s16 | x,
|  | s16 | y |
| ) |  |  | `[virtual]`

Invert the colour of the pixel at the specified co-ordinates.

Parameters:

  | x | The x co-ordinate of the pixel.
  | y | The y co-ordinate of the pixel.

virtual void WoopsiUI::GraphicsPort::drawXORPixel | ( | s16 | x,
|  | s16 | y,
|  | u16 | colour |
| ) |  |  | `[virtual]`

XOR the colour of the pixel at the specified co-ordinates against the supplied colour.

Parameters:

  | x | The x co-ordinate of the pixel.
  | y | The y co-ordinate of the pixel.
  | colour | The colour to XOR against.

void WoopsiUI::GraphicsPort::drawXORRect | ( | s16 | x,
|  | s16 | y,
|  | u16 | width,
|  | u16 | height |
| ) |  |  |

Invert the colour of an unfilled rectangle of pixels.

Parameters:

  | x | The x co-ordinate of the rectangle.
  | y | The y co-ordinate of the rectangle.
  | width | The width of the rectangle.
  | height | The height of the rectangle.

virtual void WoopsiUI::GraphicsPort::drawXORRect | ( | s16 | x,
|  | s16 | y,
|  | u16 | width,
|  | u16 | height,
|  | u16 | colour |
| ) |  |  | `[virtual]`

XOR the colour of an unfilled rectangle of pixels against the supplied colour.

Parameters:

  | x | The x co-ordinate of the rectangle.
  | y | The y co-ordinate of the rectangle.
  | width | The width of the rectangle.
  | height | The height of the rectangle.
  | colour | The colour to XOR against.

void WoopsiUI::GraphicsPort::drawXORVertLine | ( | s16 | x,
|  | s16 | y,
|  | u16 | height |
| ) |  |  |

Invert the colour of a vertical line of pixels.

Parameters:

  | x | The x co-ordinate of the line.
  | y | The y co-ordinate of the line.
  | height | The height of the line.

virtual void WoopsiUI::GraphicsPort::drawXORVertLine | ( | s16 | x,
|  | s16 | y,
|  | u16 | height,
|  | u16 | colour |
| ) |  |  | `[virtual]`

XOR the colour of a vertical line of pixels against the supplied colour.

Parameters:

  | x | The x co-ordinate of the line.
  | y | The y co-ordinate of the line.
  | height | The height of the line.
  | colour | The colour to XOR against.

void WoopsiUI::GraphicsPort::getClipRect | ( | Rect & | rect | ) | const

Get the current clipping region. The rect is automatically converted to GraphicsPort-space so that it can be retrieved in gadget drawing code in order to optmise the drawing routines.

Parameters:

  | rect | A rect that will be populated with the current clipping region.

const s16 WoopsiUI::GraphicsPort::getX | ( |  | ) | const`[inline]`

Return the x co-ordinate of the graphics port.

Returns:
  The x co-ordinate of the graphics port.

const s16 WoopsiUI::GraphicsPort::getY | ( |  | ) | const`[inline]`

Return the y co-ordinate of the graphics port.

Returns:
  The y co-ordinate of the graphics port.

void WoopsiUI::GraphicsPort::greyScale | ( | s16 | x,
|  | s16 | y,
|  | u16 | width,
|  | u16 | height |
| ) |  |  |

Convert the region to greyscale.

Parameters:

  | x | X co-ord of the region to change.
  | y | Y co-ord of the region to change.
  | width | Width of the region to change.
  | height | Height of the region to change.

void WoopsiUI::GraphicsPort::scroll | ( | s16 | x,
|  | s16 | y,
|  | s16 | xDistance,
|  | s16 | yDistance,
|  | u16 | width,
|  | u16 | height,
|  | WoopsiArray< Rect > * | revealedRects |
| ) |  |  |

Scroll a region by a specified distance in two dimensions. Performs a clipped copy to achieve scroll effect.

Parameters:

  | x | X co-ord of the area to scroll.
  | y | Y co-ord of the area to scroll.
  | xDistance | Horizontal distance to scroll.
  | yDistance | Vertical distance to scroll.
  | width | Width of the area to scroll.
  | height | Height of the area to scroll.
  | revealedRects | Populated with rects representing the region uncovered by the scroll method. This should be empty when passed, and the regions should be drawn to once the scroll has finished.

void WoopsiUI::GraphicsPort::setClipRect | ( | const Rect & | clipRect | ) |

Sets the clip rect. Attempts to draw outside of this region will be clipped out. The rect's co-ordinates must be in Woopsi-space relative to the entire Woopsi system.

User code should not interfere with the clipping rects inside the GraphicsPort. Doing so will result in graphical glitches.

Parameters:

  | clipRect | The new clipping region.

The documentation for this class was generated from the following file:

- graphicsport.h