This is Part II of the GUI system baloney. We left off with a brief overview of the core components, IComponent and IContainer so lets move onto some other fun stuff.
BOOM HEADSHOT.
IWindow : public IContainer - this wonderful class is the first control which actually does something. Well, not really. It essentially is just a bin for managing WindowEvents, the real power is contained in the template class Window.
But first - IWindow methods
- addWindowListener( WindowListener* );
delWindowListener( WindowListener* );
Management of the window-specific events ( WINDOW_MOVE, WINDOW_RESIZE, WINDOW_CLOSE, etc ) which it sends out to listeners. Pretty boring really.
Now I'm still a little bit iffy on how the following pieces fit together, simply because Window (which derives from IWindow), IMO, contains some crap that should be in IWindow. But, at the same time, shouldn't. Its really weird, but the way it is now works for me - any fixes can easily be made by deriving a better class from IWindow. But I mean... bleh.
Okay, I'm getting tired of thinking. So we're going to take a short break.
"Now, Beakie, we'll just flip this switch and 60,000 refreshing
volts of electricity will surge through your body. Ready?"
Anyway. So Window.
I guess this is where some of the steaming evil comes in with templates and such. Essentially this is where the API abstraction comes in -
template < class GfxAdapter, class style = Defaultstyle< GfxAdapter > >
class Window : public IWindow, public style
GfxAdapter is the class that we're using to render the GUI. Each control should store a pointer to the adapter to use for drawing calls (because singletons/static methods are teh suck!) like so and initialize them in the constructor.
class Window {
GfxAdapter* _gfx;
explicit Window( GfxAdapter* gfx)
: _gfx( gfx ) { }
};
I just realized just now that it should really be an explicit constructor so nothing weird happens. So I added it in just now. Whee.
The style is a static policy class that allows you to create a unified style for all the controls. Basically, when you're writing your own controls you put the stuff you need in the style class.
The Defaultstyle is actually a parameterized template -
template < class GfxAdapter, int instance >
class Defaultstyle
First, we need the size/color typedefs from the GfxAdapter to store information. Secondly, if we want multiple style sets, we can instanciate multiple Defaultstyle classes. (Remember, they're filled with static data so we'd need a completely different class).
All of the functionality from Window comes through a listener injected into its own listener list. In fact, this is how almost all of control functionality is implemented.
It also implements IComponent's draw method, thus making it an instanciable class.
Err, pretty much all of the other control classes work the same way.
And now a word from our sponsors (EDI)~
POLL!
Do you think Ivy needs more cleavage? My suggestion was to have her wear a V-neck shirt like the picture on the right.