2008-10-05

Timers Revisited

Following on from yesterday’s post, I’ve removed the existing VBL timing system and replaced it with a WoopsiTimer class. So, instead of adding your gadgets to the woopsiApplication’s VBL listener vector, you now create an instance of the WoopsiTimer class and handle its EVENT_ACTION event. The change has resulted in the removal of some nasty, counterintuitive code and cruft, and made VBL timing easier to work with. There’s a new “timer” example in the examples folder.

I’ve fiddled with a number of other things, too. The TinyFont bitmap now has all of the missing glyphs in place, and I’ve moved the at symbol to the correct location. Haven’t made the .c file yet, though.

SkinnedWindows move to the front when they are clicked. Not sure when I broke that.

All references to text position in any classes involved with text have been renamed to alignment. For example, TextBox::setTextPositionVert() is now TextBox::setTextAlignmentVert(), and TEXT_POSITION_VERT_CENTRE is now TEXT_ALIGNMENT_VERT_CENTRE. “Position” didn’t quite cut it. Similarly, all methods called “addText()” that were really appending text are now called “appendText()”.

I’ve made a few other changes and fixes to the TextBox, but the most significant is the addition of the concept of a cursor. This can be positioned anywhere within the string that the TextBox contains, and the new “insertTextAtCursor()” function allows text to be inserted at that location. The cursor isn’t drawn yet, as it’s a bit tricky. A rectangular XOR box the size and width of the character at the cursor position is probably the easiest option.

As soon as I get that done I think it’s about time for another release. I’d planned to release a new version on the 11th of this month, as that was (so I thought) the day when I first started Woopsi development. However, it appears I’ve been working on this for over a year; the first post about it on this blog was on September 9th last year. Nuts, a milestone missed.

2008-10-04

Key Repeating, Timers and Bugs

First of all, a bug. The Text class doesn’t seem to be wrapping text properly if the line of text doesn’t have a break in it.

I hate the Text class. If anyone wants to earn themselves a substantial number of Zombie Points*, debugging and fixing the Text class will earn you a bucketload.

Secondly, key repeating now works in the keyboard. Instead of registering the keyboard for VBLs, I’ve written a WoopsiTimer class. This works in more or less exactly the same way as a Javascript timer. Give it a number of frames to count and tell it to start, and it’ll count that many frames and then fire an EVENT_ACTION event. It can be paused, stopped and reset, the timeout (frames until an event is fired) can be changed, and it can either fire once and stop or continually loop. It registers itself automatically for VBLs. In short, it’s a much better solution than the existing VBL system. It is far simpler to set up and considerably more helpful.

This leaves me with a question to resolve. Do I change the Woopsi class so that only timers can register themselves for VBLs or do I leave it as it is with two methods of achieving the same thing? The former results in a tidier API; the latter gives the developer more options (ie. it means they have one less child gadget to create). I’m leaning towards stripping the old method out, but I’ll leave it as it is for now in case I think of a good reason to leave it.

*Zombie Points are exchangeable for Zombie Tokens. 10 Zombie Points earns 1 Zombie Token. Zombie Tokens are exchangeable for Zombie Points. 10 Zombie Tokens earns 1 Zombie Point.