Sign in to follow this  
FireNet

GUI within a game

Recommended Posts

The idea is simple, and it is to design a simple GUI system which can support windows, text boxes, choice boxes and buttons.The graphics api is OpenGL. The problem: I have no clear idea as to how to go about designing an event driven gui system. What I want: - A few pointers on the overall structure, or how I could start. - Tutorial links - Source examples (Some stuff I found) Developing a GUI Using C++ and DirectX Part 1 GLO - Game GUI Engine http://www.cegui.org.uk/modules/news/ http://www.gamedev.net/community/forums/topic.asp?topic_id=318580 http://www.gamedev.net/community/forums/topic.asp?topic_id=299432

Share this post


Link to post
Share on other sites
A simple way to go about this is to design a simple class hierarchy like so:


class Event
{
// stuff for different event types, e.g. mouse pos, mouse button clicked, key pressed, ..
};

class Widget
{
public:
virtual void draw() = 0;
virtual void handle(Event& e) = 0;
};

class Window: public Widget
{
Rect dimensions;
vector<Widget*> children;

public:

virtual void draw(){ draw self and my children ... }
virtual void handle(Event& e)
{
if (e.type==mouse_click)
{
check coords
if coords are in some special area then do something ...
else pass event to each child in order
}
else pass event to children..
}
};



Have fun..

Share this post


Link to post
Share on other sites
I used different approach with callbacks. Something like that:

Quote:


void ClickMe(component *sender)
{
//do something when button is clicked
}

Window form1;
Button button1;

gui.AddWindow(form1);
form1.AddComponent(button1);
button1.OnClick = &ClicMe



The idea is that there are many classes - base and derived that add additional properties to each object.

for example:

//base class
class Base
{
int width;
int height;
};

//button class
class Button : Base
{
Click();
}

// the whole processing is made in the general gui class, that stores all components and windows positions. So it is just deteremening what component has foucs and where mouse is. If any input is made then this action is passed to the component that has focus.

Share this post


Link to post
Share on other sites
I'm going to start designing one of these soon for DirectX and i am going to follow a similar approach, that was used for wxWidgets.

ace

Share this post


Link to post
Share on other sites
JavaCoolDude was working on an OpenGL GUI library a while ago: OpenGL GUI Anyone?

It was based off XML and generated quite the discussion. You might want to check it out. I've been having a horrible time looking for a GUI library for Managed DirectX as OgreDotNet's CeGuiDotNet doesn't have the devloper base, RealmForge's CEGUI# is slowly dying and there is a horrible lack of Microsoft.DirectX.Utility GUI tutorials available.

Share this post


Link to post
Share on other sites

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

Sign in to follow this