Home   About   Contact   Log in

Archive for January 2nd, 2007

Working GUI!

January 2nd, 2007 | No Comments | Filed in 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

GUI Message Passing

January 2nd, 2007 | 1 Comment | Filed in Programming, Projects

OK, I have a button class. We’ll call it GUIButton. It has an “OnClick()” member that gets called when the button is clicked. Currently this just prints “Clicked!” on the screen.

Imagine I want to put five buttons on the screen to do various things. Where do I put the OnClick() code for each button?

I was thinking of making an instance of GUIButton for each real button I want (QuitButton, LoadButton … etc) and overriding the OnClick() in each one. What I can’t work out now is how to link that to the GUI XML I’ve just created.

Take this line:

Code:
<BUTTON x=0, y=0, name=”btnQuit” type=”1″ />

How, in my code, do I make that button link to the “QuitButton” class without having messy code that does this:

Code:
switch (buttontype) {
case 1:
widget = new QuitButton(x,y,z,blah);
break;
case 2:
widget = new OKButton(x,y,z);
break;
}

Since by doing this I’m hardcoding the class types into code that will later be rolled up into a library. Also it doesn’t work very well if I have two OK buttons that do different things.

It feels like I need some sort of table that I register each class with so I can ask for a class by name.

This is the bit I never got to see when writing MFC code. All I did was click on a button, press Ctrl-W and choose “WM_CLICKED” and hit “Edit code”. *something* happened and I got a function to put code in.

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

Working Layout Manager

January 2nd, 2007 | No Comments | Filed in Programming, Projects

It works Smile I can turn an XML file that looks like this

Code:
<?xml version=”1.0″ ?>
<GUI version=”0.1″>
<WINDOW x=”0″ y=”400″ z=”0″ w=”800″ h=”200″ caption=”MainWindow”>
<WINDOW x=”10″ y=”10″ z=”0″ w=”50″ h=”50″ caption=”MainWindow2″>
</WINDOW>
<WINDOW x=”70″ y=”10″ z=”0″ w=”50″ h=”50″ caption=”MainWindow3″>
</WINDOW>
<WINDOW x=”130″ y=”10″ z=”0″ w=”50″ h=”50″ caption=”MainWindow4″>
</WINDOW>
<WINDOW x=”10″ y=”60″ z=”0″ w=”740″ h=”120″ caption=”MainWindow5″>
<WINDOW x=”5″ y=”5″ z=”0″ w=”50″ h=”50″ caption=”MainWindow6″>
</WINDOW>
<WINDOW x=”60″ y=”5″ z=”0″ w=”50″ h=”50″ caption=”MainWindow7″>
</WINDOW>
<WINDOW x=”120″ y=”5″ z=”0″ w=”50″ h=”50″ caption=”MainWindow8″>
</WINDOW>
</WINDOW>
</WINDOW>
</GUI>

Into something like this

*goes off to commit it to SVN and make backups*

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

Test post with geo info

January 2nd, 2007 | No Comments | Filed in Test

This is a test to see if geo info is recorded…

And it does :)

I have installed the Plug-n-play-google-map plugin on my site. I can now provide links on a fancy Google Map to relevant places. I’m off to Wales on Thursday so I’ll use that as a test.

This site is good for finding lat,lon positions to put in your posts.

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