GuiApplication.Initialize

General help with the Ecere Cross Platform GUI toolkit: Window, common controls, events, etc.
Help with the 2D Graphics library: Surface, Display, Bitmap, Font and others.
Post Reply
jfbilodeau
Posts: 19
Joined: Wed Feb 09, 2011 11:47 am

GuiApplication.Initialize

Post by jfbilodeau »

Good day,

The GuiApplication.Initialize() method is called ~500 times at start up. :O

If you have a moment, could you explain the initalization process of an Ecere application? I'm a bit at a lost. Thanks!

J-F
Last edited by jfbilodeau on Thu Feb 10, 2011 6:56 am, edited 1 time in total.
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: GuiApplication.Initialize

Post by jerome »

Amazing that Ecere apps still fire up faster than anything else, eh?

If you take a closer look at GuiApplication::Initialize:

Code: Select all

void Initialize(bool switchMode)
{
   static bool initialized = false;
   if(!initialized)
You'll see it will only do something the first time it is called.
It's called from the Window constructor.

The initialization process of an Ecere app starts in the 'symbol loader' (code generated by 'ecs', eC's Symbol Loader generator). That is your [object directory]/[project name].main.ec. That's where your actual C main() or WinMain() function resides.

Inside that main() function is where your 'in use' Application class's Main() method gets called. If you don't derive any classes from Application, yet link with Ecere, it will use GuiApplication. This is how you can build a simple Gui app by simply deriving a class from Window and creating a global instance. Among other things, GuiApplication will automatically create all global window instances (unless their autoCreate property is set to false), and keep the application alive as long as one of those windows is still up.

You can also derive an Application class from GuiApplication if you are making a Gui application, but need to override stuff in there. If you do derive from GuiApplication, then instead of overriding Main() (GuiApplication has a default Main already), you're better off overriding Init(), Cycle() or Terminate().

Something else that might be informative to you is that the first time Initialize() gets called and it actually does something, that is where it creates a 'desktop' window (visible in full screen as a blue background, in windowed mode it represents the actual 'desktop' of the system). That's also where it selects which display driver to use and sets it up, and sets the graphics mode if you are in full screen mode (all done through GuiApplication::SwitchMode).
jfbilodeau
Posts: 19
Joined: Wed Feb 09, 2011 11:47 am

Re: GuiApplication.Initialize

Post by jfbilodeau »

Thanks. That clarifies things.

I noticed that Window.ec contains:

Code: Select all

   Window()
   {
     if(guiApp) guiApp.Initialize(true);
...
I think that explains why I see GuiApplication initialized ~500 times. I'm attempting to run the ide to test the cocoa interface driver, and I suspect that the ide creates a good number of windows at startup. Furthermore, since the cocoa driver is not functional yet, GuiApplication fails to initialize. From GuiApplication.ec:598

Code: Select all

            if(!interfaceDriver)
               initialized = false;
J-F
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: GuiApplication.Initialize

Post by jerome »

JF,

Yes, that's what I meant by "It's called from the Window constructor."

In your Initialize code, what do driver and defaultDriver end up being?

First make sure it has the proper driver name set (the one for the DISPLAY driver, e.g. "OpenGLCocoa").
Then step through SwitchMode, and make sure it finds the proper INTERFACE driver, initializes it properly, and then afterwards initializes the display driver properly.

If interfaceDriver is null it means SwitchMode() failed, so your interface or display driver is not being selected properly, or not initializing properly.
Post Reply