|
|
|
| GUI Clinic Home |
||
| What's a GUI? A Little About Allegro | Allegro GUI Paradigm | Preparing Your Application |
||
Previous: None Yes, it's a rather patronizing question. Who doesn't know what a GUI is? Skip this bit if you want. In fact, if you already know a little about Allegro and a little about its GUI system, you can probably skip this whole page. A GUI (pronounced "gooey") is a Graphical User Interface. I'm sure you've seen one. Microsoft Windows is one popular GUI. Somewhat less popular are MacOS, X Windows, IBM's OS/2, and so on. I'm not going to try to convince you about which one is best (X Windows) or which one is worst (Microsoft Windows). I will say that they are all variations on a theme. They all put graphical "controls" onto the screen, that, when manipulated by pressing keys or using the mouse or whatever, perform various actions. These GUIs all use buttons and scroll bars and menus and the like as their controls. Having such common controls helps standardize the look of applications written for a particular GUI. In theory, this means a user won't have to spend lots of time learning the interface for a new program.
Enough about that. This isn't about GUI theory; it's a tutorial for the GUI subsystem built into Allegro, a cool game programming library originally written for DJGPP. Actually, it was originally written for the Atari ST, but Shawn Hargreaves, the author, eventually ported it to DOS. Since then, it's grown and grown, and now the list of contributers is too long to list here (though it can be found in the Allegro source distribution). On the way, people found it to be cool enough to merit porting to other platforms. The two major efforts that I'm aware of are the X Windows port by Michael Bukin and the DirectX port by Stefan Schimanski, which allow Allegro programs to be built and run with minimal source change on X Windows and Microsoft Windows, respectively. Anyway, if you're reading this, you probably already know a bit about Allegro, since I doubt you'd read about its GUI before even knowing anything about the library itself. I won't go into any more detail. You can always look things up on the Allegro web site if you like.
Allegro's GUI works on an event-based model. This means that you don't just execute code one routine after another the same way that you do in a procedural program. Your program waits in an idle state until it receives a message. These messages describe certain events, like receiving the input focus or being clicked. Your program then acts on that event by executing whatever code you've connected to it. At the base of the GUI is a dialog player. It's a function that handles input and coordinates the various parts of the whole interface. It uses dialogs to display different controls on the screen. We'll get to all those later. Suffice it to say that you create a dialog. You tell that dialog what to do when it's clicked, moved, scrolled, stomped, mashed, and so on by supplying a handler for different messages that might get sent its way. You give this dialog to a dialog player, and it will handle all these actions. Eventually, the player returns control to your program, and then you can read information from your dialog to find out what happened. It might sound complicated at first, but it's really a pretty easy way of handling a graphical interface. It's much easier than writing for a full-fledged GUI environment like MacOS or Windows 98, because there just isn't a whole lot of excess baggage to handle. But that doesn't mean it's not powerful. It's quite a powerful, flexible system, given its simplicity.
Setting up an application to run under the Allegro GUI is fairly painless. First, you need to map out the design for your project. The more thoroughly you do this, the easier your program will be to write. Some programs I've created almost wrote themselves because I spent so much time in the design stage. If you draw out each dialog on paper and document the connections between each component, things will usually fall into place quite neatly. The key is to be thorough. As far as actual code preparation goes, there isn't much to say yet. Just remember that the GUI system won't work unless you install the timer module by calling install_timer(). We'll get to the rest later. Enough introduction. Let's get to work. |