• Advertisement
Sign in to follow this  
  • entries
    11
  • comments
    11
  • views
    12911

Something Else

Sign in to follow this  

255 views

Well today I've been doing some work on a C++ GUI library I'm writing. I ended up spending several hours trying to fix a bug and as always when I spend a long time trying to fix a bug the solution is stupidly easy (in this case I forgot GL textures had to have dimensions that were a power of two[grin]). The GUI in question is in shown in the picture below looking throughly unimpressive [smile]. Though at the moment it is in the very early stages.

A little bit more background on the GUI: It's completely platform independant. This is achieved by having every control using a pointer to an abstract graphics interface to do it's drawing. You can then implement this class however you want. Currently I've only got a implementation done in OpenGL but it'd be easy enough to do in any API used for drawing to the screen. When events happen (e.g. the mouse moves, a keyboard button is pressed etc) it is the applications responsibility to report the event to the GUI root window so it can be handled. Incidently you could use this GUI system to render the GUI to a texture, which you could then put on a surface somewhere in a game, and then when the player clicks on it pipe in the click event. This means you could have a fully interactive GUI on any surface in a game engine, kinda like Doom 3. The GUI will also be fully skinable using XML files so hopefully when it's done it'll be highly flexable and rather useful.

In terms of the way you actually use the GUI in C++ I copied a concept from WinForms in .Net. In WinForms when you want something to happen when an event happens to a control you write code like this:


Control.event += new System.EventHandler(HandlerFunction);


I've replicated this in C++ by overloading the += operator so you can do things like this:


void Quit(const GUI::MouseEventData &evData)
{
running = 0;
}

Button->MouseClick += new GUI::EventFunctor(&Quit);

//or if you want to use a function in a class

class Foo
{
public:
void Bar(const GUI::MouseEventData &evData)
{
//do something on a mouse click
}
};

Foo* FooThing = new Foo;
Button->MouseClick += new GUI::ClassEventFunctor(FooThing, &Foo::Bar);




I thought it was rather nice.

Sign in to follow this  


1 Comment


Recommended Comments

Nice coding trick...

I usually go crosseyed when I see templates, pointers, functions addresses and lists used together within a 5 line proximity.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement