I just spent the last few nights working on the user-interface code of this SDL 2D strategy game that I'm working on. It's finally come together nicely now.

I had been under the philosophy much earlier on to just "do what it takes" to accomplish something without heavy regard for good design, etc. I now have paid the price for that a few times, since as the code has evolved, I've had to redesign/refactor significant sections of code.

Anyway, I totally reworked the component hierarchy so graphical components of the user interface includes base Components with subclasses of Containers, Labels, Images. All of these components can be bound to event handlers at run-time for the following mouse events: "onMouseEnter", "onMouseExit", "onMouseMove", "onMousePressed", "onMouseReleased" and "onMouseClicked". Each game state has a "desktop" container that contains the screen elements and components are added, initialized, positioned and sized and bound to events at run-time. Events are forwarded to the desktop container which handles routing the events down the hierarchy.

This is all pretty basic UI component hierarchy stuff, and I've done similar frameworks before (in DirectX, for instance). It's a shame that I couldn't reuse a lot of that stuff but it ends up being too specific (coordinate systems, pointers to surfaces, etc) that I end up re-inventing the wheel each time. I'll write another entry in a few days about that as I've been reading and practicing UML and OCL at work. [Editor's Note: This never happened, sorry]

I guess I could have gone with one of the several GUI packages out there for SDL but this one sort of evolved from the current code and now I'm growing to like it.

Anyway, now that I have the basic UI component hierarchy in place, I'm going back into game code and start to implement the map rendering function that displays where the characters are in the school. One of my first tasks once this is complete is to allow the user to scroll the map in any direction by dragging the map with the middle mouse button.

§55 · March 1, 2005 · C++, Entertainment, Games, SDL, Software, Technology · · [Print]

Comments are closed.