2008-01-11

Woopsi 0.29

Another release of Woopsi for those who aren’t syncing with the SVN repositories. All the latest changes are included, plus the XCode version is now available as a separate archive. All available from the SourceForge page.

There are a few new changes to the code. The ScreenFlipButton and ScreenDepthButton gadgets (and skinned versions) now raise release events instead of calling functions within their parents, which should help make subclassing easier. This makes the ScreenFlipButton and ScreenDepthButton classes identical in everything but name, so I’m also going to see if it’s worth scrapping those gadgets and any similar buttons and merge them into a single GlyphButton class.

In order to achieve this event-based relationship between gadgets, the Gadget class inherits from EventHandler. Any gadget can now be set as the event handler for any other. In the case of the flip/depth swap decoration gadgets, their containing AmigaScreen or SkinnedScreen gadget is set as the event handler when the decorations are created. Their events are handled in the XXXScreen::handleEvent() function.

I’m going to work out where I can implement event handling in the rest of the code (ie. window close button, etc) and tidy those things up too.

Comments

Jeff on 2008-01-11 at 20:28 said:

Why does Gadget need to inherit from EventHandler?

Just make Window/Screen inherit from both Gadget and EventHandler and it will work fine?

In a ram-light world like the DS, growing the vtable (by adding mostly unused methods) is a bit wasteful. Yes, its only a few bytes for every method per class, but still, its a slippery slope and poor oo design to boot.

Is this some sort of ‘I don’t like multiple inheritance’ thing?

Ah, or is it that you are sending the event to the _parent of the screen flip button? Because thats not the right thing to do, you should be sending it to the registered event handler for that button. Which the screen/window should have set itself as when it created the button.

I’m expecting that I’ll set the screen depth/flip buttons to some common ‘screen manager’ that will handle flipping in a different fashion - that can’t be left to any one screen, or rather it shouldn’t be.

Jeff on 2008-01-12 at 06:57 said:

Looks to me like debug.cpp is missing

Jeff on 2008-01-12 at 06:58 said:

HTML - <stdarg.h> is missing

Jeff on 2008-01-12 at 09:52 said:

Ok, I’ve seen now that EventHandler really only adds ONE extra event method, rather than a hundred. However, I think the point remains - for good oo design, you shouldn’t keep heaping extra functionality into the one base class, when inheritance would serve just as well…

ant on 2008-01-12 at 11:07 said:

debug.cpp is definitely in the repository, I’m looking at it now:

http://woopsi.svn.sourceforge.net/viewvc/woopsi/woopsi/trunk/Woopsi/woopsi/debug.cpp?view=markup

stdarg.h is built into C++, isn’t it? It’s not a Woopsi header.

Or has WordPress mangled your comment, and you mean to say that debug.cpp isn’t including stdarg.h when it should be?

The thinking behind adding EventHandler to the Gadget class is that it keeps all gadgets uniform. What works with one gadget will generally work with any gadget. There’s definitely an argument for removing it from Gadget and just adding it where it’s needed, though. If you’re setting a gadget as an event handler you’re undoubtedly subclassing that gadget, so responsibility for making a gadget an event handler can fall to the developer. I’ll switch that around.

Buttons do use the standard raiseXXXEvent() functions to send the events to their event handlers. I briefly considered raising it to the parent instead, but as you say, that causes problems when you want to set the event handler to something else.

One thing that’s missing at the moment is a way of setting the decoration gadgets’ event handlers to something other than the containing screen. I’ll need to add that in.

Jeff on 2008-01-13 at 05:00 said:

Yes, the html filter got me again, as you worked out. Sorry for the brevity of the previous comments, my head wasn’t really working all that well.

ant on 2008-01-13 at 13:12 said:

No prob, I’ve already added stdarg.h to the debug.cpp file.