Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Dialogs without global scope

This thread is locked; no one can reply to it. rss feed Print
Dialogs without global scope
cpayette
Member #7,348
June 2006

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)

GullRaDriel
Member #3,861
September 2003
avatar

You should really have a look at what makecol do.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

cpayette
Member #7,348
June 2006

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
Member #476
June 2000
avatar

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.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Kitty Cat
Member #2,815
October 2002
avatar

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

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Go to: