Skip to content
Ant edited this page Dec 27, 2013 · 1 revision

As a user interface framework, Woopsi deals extensively with graphics. To make this easier, the framework includes a wealth of classes designed to simplify working with bitmaps, drawing to bitmaps, working with fonts and working with animations. These classes are available for Woopsi developers to use in their own applications.

BitmapBase

The BitmapBase class is the most fundamental class for working with bitmaps in Woopsi. It contains the most basic information necessary to describe an immutable bitmap – width, height, and a way to retrieve a pointer to its internal array of u16 data. It also provides a way to retrieve the colour of a pixel at a given set of co-ordinates.

The class itself does not implement these last two methods – they are pure virtual functions - so it must be subclassed in order for an instance to be created. This means that the class can store its bitmap data in any way that it needs to. Although any bitmap must expose its data as a 16-bit array, internally it can store the data in 8-bit or 32-bit formats, or even as an SDL surface. This possibility is used by the FrameBuffer class.

Any class that inherits from BitmapBase can be used anywhere within Woopsi as a standard bitmap.

BitmapWrapper

The BitmapWrapper class inherits from BitmapBase and provides an immutable bitmap class that can be instantiated. It does not allocate any internal memory on which to store a bitmap. Instead, it expects to be given a pointer to a pre-existing raw u16 array in its constructor. Thus, any bitmaps converted to C code and included in a project can be wrapped inside a bitmap object and treated like any other bitmap.

The destructor for the BitmapWrapper does not automatically delete the data it is told to wrap around. This ensures that no attempt will be made to data marked const, such as that included by converting a bitmap to C code.

Hereʼs an example of the BitmapWrapper in use:

// Allocate an array of shorts that will be used as the bitmap data
u16* myData = new u16[100];

// Wrap the short array inside a BitmapWrapper object
BitmapWrapper* wrapper = new BitmapWrapper(10, 10, myData);

// Delete the wrapper
delete wrapper;
	
// Delete the data array
delete myData;

MutableBitmapBase

Neither the BitmapBase nor the BitmapWrapper classes provide a way to store mutable bitmap data. If a bitmap needs to be altered, by drawing to it, these classes are of limited use.

Woopsi provides the MutableBitmapBase class as a way of defining bitmaps that can be drawn to. It extends the BitmapBase with a set of methods designed to change the internal bitmap data:

  • setPixel(), for setting an individual pixel;
  • blit(), for copying from one bitmap to another;
  • blitFill(), for setting a range of pixels in one command.

MutableBitmapBase is an abstract class and must be subclassed. Any class that inherits from this class can be used throughout Woopsi as a mutable bitmap.

FrameBuffer

The FrameBuffer class is a subclass of MutableBitmapBase intended for a single purpose. It forms a wrapper around the DSʼ framebuffers and allows them to be used in the same way as any other mutable bitmap.

All Woopsi interaction with the DSʼ framebuffers occurs through instances of the FrameBuffer class. Since all framebuffer interaction is therefore entirely centralised, the FrameBuffer class can be modified to allow Woopsi to be ported to other platforms. The standard class includes conditional compilation directives that allow it to work with an SDL surface instead of the DSʼ framebuffers.

Bitmap

The Bitmap class is the most generally useful of Woopsiʼs bitmap classes. It provides a mutable bitmap that creates its own internal data array.

Hereʼs an example:

// Create bitmap
Bitmap* bitmap = new Bitmap(100, 100);

// Draw a blue line to the from the left to the right at row 10
bitmap->blitFill(0, 10, woopsiRGB(0, 0, 31), 100);

// Delete the bitmap
delete bitmap;

Clone this wiki locally