• 12
• 14
• 13
• 10
• 11
• entries
557
1237
• views
422716

# Widgets galore

67 views

So, I started work on my GUI system yesterday, and it's coming along quite well. Everyone seems to be doing GUI stuff just now, such as Programmer16 and ravuya.

My GUI system isn't really anything special. The highest level element is a window, and all windows are managed by the GUI manager. A window contains several widgets, and input is handled by the GUI managager, which is ticked once per frame.

I'm also going to have the ability to load a window from a schema, which I've semi-decided is going to be an ini-like file (since I have code for that already). So a sample GUI schema would look something like:
[Text]X = 0Y = 0Alignment = LeftText = I am a sample test string[Button]X = 0Y = 20Width = 30Text = I R Teh Button

Width and Height will default to the size of the object (Size of the text, for instance). Now I think about this, I might be better off with XML, so I can nest stuff. Hrm...

I'm currently doing text stuff, which is a lot neater than I thought. There's a SOText scene object, which you create and add to the scene as normal. You can set the text string, the font, the colour, etc here. When you change the font, it allocates a new CFont from the font manager. A CFont is really just a wrapper around ID3DXFont, but the D3D device manages a list of them and resets them when the device gets lost. The font manager caches fonts, so two requests for the same font won't allocate two objects. It also keeps hold of an ID3DXSprite for font rendering.
When the scene graph comes to render everything, because it sorts the objects, I can just call ID3DXSprite::Begin() in FirstRender(), using the font manager's sprite, draw the text for all objects, and then call ID3DXSprite::End() in LastRender().

So, the text is set on the scene object, meaning it can be set once and forgotten about, and everything is cached, sorted and rendered nicely. Hooray!

All of that is untested of course (I'll give it a go during my lunch break, it's nearly compilable). So far only text is done (And the GUI manager and window classes).

Shit, man. I could only tell you how much time I've wasted writing my own fucking config loader when I could've just dropped in TinyXML.

Seriously, Freezer 2 and Glow and CSRPG2 -- all of 'em would have been out a month earlier if it weren't for my damnable configuration file format. It's gone in my next game.

TinyXML: flawless parser, vetted by several people in and out of industry writing many different projects.
Ravuya's Big Fun Configuration Loader: pure shit.

I agree with Rad. Use the XML. Not only will it save you time, it makes it easier to structure. Good luck.

Yeah, I used TinyXML briefly before and thought it was pretty neat. I'll use it I think.