• Advertisement
  • entries
    1212
  • comments
    1738
  • views
    1143627

FYI, MY SDL GUI

Sign in to follow this  

300 views

Wow, something actually related to game programming? Wow!

I've been working diligently on a "new" Duck Tiles that's worthy of all of the great levels I got from the contest. Rather than make it a part of another game pack, I decided that I could make a version that's good enough to sell on its own. Heck, I've got 440 levels!

Anyway, I'm using SDL for the graphics because it's a Good Thing. I wrote a nice C++ abstraction and sprite engine a while back but had halfway abandoned it to start on the Duck Tiles project using the old library so I could get it out the door with another game pack. I decided to resurrect it with a Duck Tiles bent.

Biggest problem lately is that I needed some non-trivial GUI stuff, specifically a nice little browse-box to allow you to choose the level you want to play. My old games are based on traditional GDI calls, so doing things with ordinary dialog boxes would've worked fine. SDL, though, is a bitmap-only beast, so I couldn't do dialog boxes without abandoning some of the SDL niceties (cross-platform, full-screen).

Conclusion: I needed a GUI.

There are a couple of GUI libraries out there for SDL, but they're either so rudimentary that they're useless or so big that they're overkill for my simple needs.

Conclusion: I needed to roll my own GUI.

Thankfully, it's going together much quicker than I'd expected. I've got a DialogBox object, which is a collection of Control objects. Here's an example of a dialog box containing three StaticText objects, one EntryField object, and an OKButton object (similar to a Button object, but it kills the dialog when pressed).




One assumption I made that is making things much simpler than things would normally be with a GUI is that I did away with the concept of focus --every keyboard or mouse input is broadcast to every control on the dialog. For example, pressing "J" will send a keyboard event to all of the controls, and in this case all of them will ignore it except for the EntryField. This pretty severely limits what I can do with a dialog box, as you can't do things like have two EntryField objects up at once, but I didn't really think I'd need such things so I didn't bother.

The stuff's quite nice. Dunno if you can see it because of the JPEG artifacts, but the text is all antialiased against the bitmap background. The background is being stored as a PNG file in a resource-only ZIP file that I'm using to hold all of the bitmaps and fonts and levels and such. All I need to add now is MP3 playback, and it'll probably be all I need to write anything I want. We'll see.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement