Dialogs without global scope

Greetings allegro community :)

I've been having a bit of a problem with the whole RGB vs BGR issue, and have searched through many previous posts here. Generally what I learned was that the order was mostly a problem if you attempted to define colors before setting the video mode. From this I realized my problem was the fact that my dialogs are defined globally.

For example DIALOG DlgMainMenu[] is global, and when I expected a red button I got blue. However, if after the video mode is set I change the color:
DlgMainMenu[1].bg = makecol(255,0,0);

..it's properly red.

My question is how do I define a DIALOG outside of the global scope, or moreso, how do I manage them? Do I need to know exactly how many elements my DIALOG is going to hold? Once I've declared the dialog globally, how do I go about defining it cleanly? (Without having to set each argument of each dialog element one at a time)


You should really have a look at what makecol do.


I understand what makecol does. That is not my problem.

The problem is globally I have this:

DIALOG DlgMainMenu[] =
  /*       (dialog proc) (x) (y) (w) (h) (fg) (bg)
           (key) (flags) (d1) (d2) (dp) (dp2) (dp3)       */

  /* 0 */  { d_clear_proc, 0, 0, 0, 0, 255, 0, 
             0, 0, 0, 0, NULL, NULL, NULL },

  /* 1 */ { exit_button_proc, 300, 120, 100, 20, makecol(0,0,0), makecol(255,0,0), 
            0, D_EXIT, 0, 0, "Exit", NULL, (void*)Button_MainMenuExit },

          { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }

In which makecol is called before allegro is completely initialized, as my dialog is global. If "later on" (in a function called after allegro is initialized) I manually set the color, it shows up properly. Thus I need to define my dialog after allegro is initialized. That's what I'm not entirely sure how to do.

Thomas Fjellstrom

you can declare/define a DIALOG struct in a function to be local to it. or just setup the colors afterwards.

You can not call most allegro functions before allegro has been initialized. Many also require a proper color depth and graphics mode to be set as well.

Kitty Cat
DIALOG *DlgMainMenu = new DIALOG[x+1];
...set DlgMainMenu[0] through DlgMainMenu[x-1]...
DlgMainMenu[x].proc = NULL;
do_dialog(DlgMainMenu, -1);
delete[] DlgMainMenu;

Thread #589807. Printed from Allegro.cc