More progress with fonts. The system font is now called “sysfont”, and has been moved out of the “all_gfx” files into a separate “sysfont.h” include. It’s also been moved into the main woopsi folder.
I’ve scrapped the font inheritance idea - it caused more problems than it solved. Instead, the Woopsi class now has a static “getSystemFont()” method that will return a pointer to the default font. If a gadget’s font is not specified when it is constructed, the gadget will automatically fetch its own pointer to the system font and use that instead. The font parameter on all gadgets is, therefore, now optional, and has been set up as such in all of the constructors (this means that the parameter order has now changed on every single gadget). Gadgets that do not need a font (ie. window borders) no longer have the parameter in their constructors.
Gadgets that use the Text class for their text manipulation need to update that class’ font pointer too. I’ve added that functionality into the TextWriter and MultiLineTextBox classes, and added the “setFont()” function into the Text class.
There are a few fiddly changes - Woopsi uses a sensible value for its height, instead of an arbitrary number I made up to make the clipping work. Private class members are now set to protected where necessary - they were only set to private in the first place out of habit (I find that simple business apps rarely require clever subclassing, or cleverness in general, so I find myself using private by default).
I’ve removed the “removeGadget()” function I added a week or so ago. I don’t quite know why I didn’t see this at the time, but that function did little more than duplicate some of the functionality of the “close()” function. Unfortunately, it didn’t duplicate all of the functionality, so it was doing little more than causing problems.
One long-standing problem with window borders has been the way that they decide what colour their background should be. They were abusing the focus() system - when a window received or lost focus, it sent a focus() or blur() command to all of its border gadgets. This technically meant that the window had up to 7 active gadgets at any one time (6 border gadgets and one other gadget) but did not know that the borders were active. Nasty bodge, but it wasn’t a problem until I used border->close() to remove the border gadgets. The close() function tells the gadget’s parent that the gadget is losing focus (if it has focus), and that bubbles up the gadget tree. Thus, calling setBorderless(true) made the borders lose focus, which confused the window and lost focus there too.
Window borders now use the parent’s “isActive()” function to determine which colour they should be, and when a window gains or loses focus it just tells its borders to redraw. Much nicer.
Whilst tinkering with the border code, I noticed that making a gadget borderless didn’t invalidate its visible region cache. That’s now fixed.
Finally, the SuperBitmap class now includes the floodfill routine I wrote the other day. One more item knocked off the to-do list! It improves on the original routine by using the colour of its starting pixel as the “oldColour” parameter.
In unrelated news, I’ve found another bug in the devKitPro compiler. I documented a bug with arrays a while ago - trying to create an array with more than 32767 elements (ie. more than the upper bound of a signed short) causes overflow problems and crashes. The only way around it is to use malloc(). The new bug is the same kind of thing - trying to create a multidimensional array with more than 255 elements in the first array (ie. char arr) also causes overflow/crashing problems.