Home   About   Contact   Log in

Working GUI!

January 2nd, 2007 | Filed under Programming, Projects.

Shocked It works…

I create an instance of each delegator at the beginning of my code, then “register” them with a name. This is the same name as what goes in the XML file.

So you do this:

(first subclass the “Delegator” class, adding the functionality needed for each widget that needs it)

Code:
QuitDelegator d_quitBtn;
LoadDelegator d_loadBtn;

manager.RegisterDelegator (”QuitBtn”, &d_quitBtn);
manager.RegisterDelegator (”LoadBtn”, &d_loadBtn);
manager.LoadGUIDef (”gui-def.xml”);

manager.Run();

And then have XML that looks like this:

Code:
<BUTTON x=”10″ y=”10″ caption=”Quit” name=”QuitBtn” />
<BUTTON x=”40″ y=”10″ caption=”Load” name=”LoadBtn” />

The “name” is looked up in the delegator map and the appropriate delegator pulled out. The newly created instance of the GUIButton class responsible for drawing the “Quit” button gets this delegator then assigned to it.

Code:
switch (type_of_widget) {
case WIDGET_TEXTBOX:

break;
case WIDGET_BUTTON:
newButton->Create (x, y);
newButton->SetCaption (caption);
newButton->SetName (name);
newButton->SetDelegator (GetDelegator(newButton->name));
break;
case WIDGET_WINDOW:

}

I was trying to avoid the mapping part, but there’s no way around it, and at least it’s at the top of the code right where the XML file is loaded in the main() function, not buried deep within some class as a load of if-then-else statements.

Visit my other sites: Photo Gallery | Insane in the Membrane | Main website

Tags:

Share Your Thoughts