Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How to make GUI with Allegro?

This thread is locked; no one can reply to it. rss feed Print
How to make GUI with Allegro?
Zdravko
Member #6,994
March 2006
avatar

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.

miran
Member #2,407
June 2002

Code derived from exgui.c:

1#include <allegro.h>
2 
3char the_string[64] = "0.0";
4 
5DIALOG the_dialog[] =
6{
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 }
14};
15 
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;
29}
30END_OF_MAIN()

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

--
sig used to be here

Specter Phoenix
Member #1,425
July 2001
avatar

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
Member #210
April 2000
avatar

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:

http://www.allegro.cc/manual/api/gui-routines/d_text_proc

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

miran
Member #2,407
June 2002

Quote:

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...

--
sig used to be here

Johan Halmén
Member #1,550
September 2001

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.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

Neil Walker
Member #210
April 2000
avatar

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.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

miran
Member #2,407
June 2002

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.

--
sig used to be here

Specter Phoenix
Member #1,425
July 2001
avatar

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
Member #23
April 2000

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

Ceagon Xylas
Member #5,495
February 2005
avatar

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.

Quote:

The gui has always confused me.

Amen.

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

miran
Member #2,407
June 2002

Quote:

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...

--
sig used to be here

Corelian
Member #3,376
March 2003
avatar

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

Johan Halmén
Member #1,550
September 2001

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.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

Specter Phoenix
Member #1,425
July 2001
avatar

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).

Go to: