How to make GUI with Allegro?

I am sorry if my questions sound too repetetive. But I am in a hurry. My program must have a very simple gui - just to input a few double numbers. These must be read and then the actual graphical processing should begin. I read in the manual for the GUI routines, but I don't understand it yet. How do I create an input field? How do I create a button, that triggers "parsing" from the field?
I will be extremely thankful to those who help me.


Code derived from exgui.c:

1#include <allegro.h>
3char the_string[64] = "0.0";
5DIALOG the_dialog[] =
7 /* (dialog proc) (x) (y) (w) (h) (fg)(bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
8 { d_clear_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
9 { d_text_proc, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, (void*)"enter number", NULL, NULL },
10 { d_edit_proc, 160, 10, 160, 8, 0, 0, 0, D_EXIT, 64, 0, (void*)the_string, NULL, NULL },
11 { d_button_proc, 328, 6, 160, 16, 0, 0, 0, D_EXIT, 0, 0, (void*)"OK", NULL, NULL },
12 { d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
16int main() {
17 allegro_init();
18 set_color_depth(32);
19 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
20 install_keyboard();
21 install_mouse();
22 gui_fg_color = makecol(0, 0, 0);
23 gui_mg_color = makecol(128, 128, 128);
24 gui_bg_color = makecol(230, 220, 210);
25 set_dialog_color (the_dialog, gui_fg_color, gui_bg_color);
26 do_dialog(the_dialog, 2);
27 allegro_message("You entered %f.", uatof(the_string));
28 return 0;

Note to Allegro developers: that GUI example is waaaay too complex.

Specter Phoenix

That example you gave is easier but still way too complex for just showing how to use Allegro's lame GUI. If only they would make a tut that shows how to extend AlGUI to make it say skinable so you can do stuff you want with it. Or maybe make your own GUI. I've been wanting to toy with making one of my own but didn't know where to start.

Neil Walker

The gui has always confused me. Is it yours or allegro's built in one that is non-blocking? i.e. lets you happily use controls within a timer loop to display as part of a screen rather than a modal type window.

on a different not, is there any reason why the online manual for d_text_proc is empty:


Is it yours or allegro's built in one that is non-blocking?

Is that directed at me? Both Allegro GUI and MASkinG can be used in blocking and non-blocking mode but both are primarily meant to be used in blocking mode. In Allegro GUI you call do_dialog() and wait for it to return. In MASkinG you call you main dialog's Execute() method and wait for it to return. Getting both GUIs to work in non-blocking mode alongside your other code requires a bit of extra work...

Johan Halmén

So far I've managed to do everything I want with Allegro GUI. Guess I don't want very much. I use Julien Cugniere's dlg.exe to shape the basics. If I have procs of my own, I simply draw boxes or something similar in dlg, then I edit the code when I've imported it to my project. If I ever edit the dialog again with dlg, dlg finds it in my cpp file and does the changes there, showing my own procs as boxes with the proc name. Perhaps one could hack the dlg code to actually import one's own procs in it.

Neil Walker

thanks miran. Yes, it was directed at you :)

I always thought the best use of a gui in an allegro game would be non-blocking not blocking so that you can add stuff to a running game alongside your game timer logic/drawing loop, e.g. menu options for changing values using a slider, text input for entering your name, etc.


There are two ways to make more or less GUI heavy games. Either add a GUI to your game, or add a game to your GUI. People who prefer option #1 probably outnumber people who prefer option #2 but I think that's mostly because people tend to code their tilemaps, collision detection, physics, AI and everything else first, and then add menus and stuff like that. IMHO once you have a solid GUI framework the development process becomes a lot quicker than when you're just throwing random pieces of code together...

Btw, for an example of how a GUI can be effectively used as a foundation for a game, take a look at my TINS '06 entry Dodger. I think it's still in the recent threads list. It uses MASkinG and it doesn't just add bits of GUI to an existing engine, instead it is written around and inside the GUI.

Specter Phoenix

Allegro's GUI routines don't let me do anything like the attached image. That is why I've wanted to make my own GUI, I've never really cared about the skinning stuff I just want to make art that I can add to the side of the menu with the little icons and have my art go the length of the menu like the KDE art does (arrow points to it).

Peter Wang

Why do you think the Allegro GUI won't allow that?

Ceagon Xylas

Maybe they just figured the GUI was a little less important than the platform... So they didn't spend a whole lot of time on it. I still want to get CGUI to work for me one day, it seems pretty useful.


The gui has always confused me.


Further note to all: the default GUI can look a million times better if you just load a diffrent font to the default


Further note to all: the default GUI can look a million times better if you just load a diffrent font to the default

That, and change the colours. If you also spend some time drawing some nicer pseudo 3D panels with linear gradients and stuff, it will look so different no one will even recognize it's Allegro GUI...


I take it that everyone is familiar with AGUP, right?

Johan Halmén

Allegro GUI lets you do anything! It doesn't provide much, but it certainly doesn't prevent you from doing anything. If I got you right, you want a drop down menu with small icons along the menu items. I'd look at the menu procs of Allegro and do my own proc that mostly would call the Allegro menu proc, but for drawing it would first draw my icon, then the text. You can do this. But on the other hand it might be easier to use another gui library. Like Masking.

Personally I prefer Allegro's GUI. Not that I don't know that Masking is great! But I enjoy the challenge of twisting Allegro's GUI procs or writing my own Allegro style procs. It's the fun that counts for me.

Specter Phoenix

Well I wasn't referring to the icons I was referring to the KDE 3.3 Limited Edition 2005 image runing the length of the menu. I want to do stuff like that (don't ask why I have a few secret things going that I want to make that way only with character art running the length).

Thread #572856. Printed from