Yet another update. Any functions that need to check _flags.visible are, where possible, now using isVisible() instead. There are one or two functions that do need direct access to the struct, which defeats my plan to hide away some of the internals of the Gadget class.
The Gadget::focus() function, and any that override it, now check to see if the gadget is already active before running the function. This results in less redraws and less flicker. One more minor change - all resize() functions now respect the parent’s isPermeable() property.
The brief discussion in the comments about C versus C++ reminded me of another basic C++ feature I re-invented the other day. I wanted to add the floodfill code into the SuperBitmap but, at the same time, I didn’t want the popStack(), eraseStack() and pushStack() code bundled into the class - it made more sense to move that into its own class. So, I thought to myself, I need a class that can push values onto a stack and pop them off again. I started designing it in my head, but then: Hang on a mo, that sounds oddly familiar… In the end, I did use the vector class, but kept the pushStack() and popStack() functions within SuperBitmap because they do some processing before adding values into the vector.
Anyway. Another good suggestion from Jeff on SourceForge - VBL events shouldn’t be sent through the whole hierarchy, especially as that would make a complex hierarchy an unnecessary drain on CPU time. Woopsi now implements static registerForVBL() and unregisterFromVBL() methods. Passing a gadget pointer into the first function will make it receive VBL events. Passing a gadget pointer into the second will, naturally enough, prevent it from receiving VBL events. Gadgets are automatically unregistered when they are deleted if the developer has forgotten to unregister them manually, but otherwise all responsibility lies with the developer. I don’t want to automatically unregister them when a gadget is hidden, for example, in case the developer intends the gadget to continue processing in the background.
The Woopsi class now has a static getVBLCount() member, which will return a u32 containing the number of VBLs that have occurred since Woopsi began running. This will eventually wrap around, of course, so it’s down to the app coder to take this into account.
Switching VBL control around caused a bit of a problem, as the deletion queue was processed by each gadget during the VBL. I’ve moved that into static members and functions in the Woopsi class. The method for deleting gadgets remains the same for developers, though - gadget->close(). I’ve refactored gadget->closeChild(gadget), too, so that can now be used as expected to delete a child. Along side those changes, I’ve added gadget->hideChild(gadget) to complement gadget->hide(). Hopefully nothing has broken as a result of these changes.
These changes exposed one stupid bug - the closeChild() and hideChild() functions were setting the _activeGadget pointer to the highest gadget in the stack. This was usually the gadget being closed, so the _activeGadget pointer got trashed as soon as the next VBL ran. Whilst making these changes, I noticed that the GraphicsPort class would happily draw to deleted or invisible gadgets, so I’ve fixed that.
(Oh, and I discovered that F7 in VC++ Express does a make instead of make clean - that’s saving me loads of time.)
EDIT: Last thing today - split Window class into WindowBase, AmigaWindow and SimpleWindow classes.