by mlepage » Oct 6, 2003 @ 6:29pm
Sigslot works really nicely, I tried it and I like it.
For my widgets, I just send a paint event to all widgets during process frame, and don't bother painting them otherwise (e.g. no update, repaint, etc.). For a game which redraws constantly, and only has a few widgets, this is acceptable I think. If you don't want to redraw them, you could not send the event during process frame, but then you'd have to make sure your updates were all in the right places (e.g. button click).
Typically in a widget library, widget bounds are in the coordinate system of the parent. Hence, the find child behaviour I posted above in the mouse event dispatch code. This is fine, but when you get to painting, your widget needs to paint to the right area of the screen. This involves either another coordinate transform, or having a painting context that already has the origin set properly. The latter is common, but we don't have such contexts in GapiDraw.
I could implement the former, at some perfomance cost, but I think there is a better approach. Each widget should have a copy of its screen bounds in addition to its bounds in the parent coordinate system. A consequence is that when a widget moves, it has to update all of its children's screen bounds. On the other hand, looking for widgets by screen position is suddenly easier, and painting can use the screen bounds. Since in a game, moving widgets is uncommon and finding/painting widgets happens many times a second, I think this is a good approach. It requires a bit more memory per widget, but a game doesn't have many widgets anyways.