Bitmap Blitting with Transparency and Proportional Fonts

Another hefty set of updates today.

Following on from the requests made in the forum, I’ve added a new “drawBitmap()” method to the GraphicsPort class that will treat a specified colour as transparent. Any pixels of that colour won’t get drawn. This is a lot slower than the usual method, as it involves drawing the bitmap pixel-by-pixel instead of using the DMA hardware, so it should only be used when necessary.

In the same thread, Jeff asked for some improvements to the font system. I have moved the “drawChar()” function out of the TextWriter class and into the font classes, which means each font is now responsible for blitting itself. It offers a much more flexible system. In addition to this, I’ve split the FontBase class in two and added a new “FixedWidthFontBase”. Woopsi is now set up to handle proportional fonts. I just need someone to write a proportional font class (hint hint).

As part of the proportional font changes I re-wrote the “Text::wrap()” function. It’s a lot neater, faster and more efficient now. However, the change seems to have broken the scrollbars again (gnnk) so I’ll need to spend some time debugging it.

EDIT: Scrollbars fixed (or as fixed as they ever have been), plus I’ve fixed some other scrollbar problems I found.


Jeff on 2008-04-09 at 23:11 said:

Well, that was fast. I’ll take a look at it as soon as I can - I’m stuck trying to get wifi working at the moment. God that stuff is a mess - I have no idea why its 98% beautiful and then they stick arbitrary hex constants like 0x12345678 into boiler-plate code that gets copied around.

Jeff on 2008-04-14 at 05:11 said:

Ok, done.


contains an implementation of “packed” fonts which uses a different encoding scheme, that allows efficient proportional font support. There’s a Woopsi.nds in there that shows the code in action.

The encoding is done with a self-contained Python script so it should work on all platforms that devkitpro works on.

There are a number of things that still need to change in the Woopsi FontBase class since it isn’t as abstract as it needs to be, and it has one inline method that needs to be virtual.

Jeff on 2008-04-14 at 05:14 said:

There is no need for a different ‘fixed width’ font class - you simply pass in a ‘desired width’ to the packed font constructor - if its specified, its obeyed. If its not big enough, its automatically extended.

I’ve done 16-bit and 1-bit fonts already. It should be trivial to add 8-bit fonts though git’s support for shared palettes isn’t fabulous so I’m less excited about that. But extending the packing script and writing another subclass to do 8-bit would take about an hour, I believe, so I’ll leave it till someone that will test it wants it.

ant on 2008-04-14 at 15:57 said:

Excellent, great stuff. I’ve added the classes into the Woopsi codebase, tidied up the FontBase so that it’s more abstract, and tidied up your classes a little.