9 Patches to my heart

For the better part of this week and past weekend, I have been learing a whole lot about surfaces in ScummVM, in order to implement beautiful 9patch borders in the MacGUI code.

As I delved deeper and deeper into the graphics code, I found out that a lot of steps had to be made in order for the 9patch to initialize and blit correctly:

  1. Define the alpha color in a bitmap (a bright pink).
  2. Load the bitmap.
  3. Copy the loaded bitmap into a surface.
  4. Apply the colorkey into the surface (previously defined alpha color).
  5. Pass the surface to the 9patch.
  6. Define the surface in which you want to blit the border.
  7. Blit the border.
  8. Convert the border into the graphics format (I still don’t know how to do this).
  9. Draw the border into the surface you want.
  10. Tell sev that you finally got his code to work, and that it works wonders.

Between each of these steps there are several hours of figuring out which PixelFormats, Palettes, Surfaces and conversion functions I had to use, and several more hours in GDB and the IRC.

But, at last, besides that format conversion in step 8, 9patch is working correctly 🙂

Below are two images: The border bitmap rendered without going through the 9patch, and after passing it to the 9patch and then rendering (blit) it into surface twice as high and wide (4x size) before printing it to screen.

Edit: I just fixed a small bug, this is what it looks like now: