Sign in to follow this  
CTar

Help with GUI

Recommended Posts

Hi, in the last couple of days I have been thinking about how to implent my own GUI. I know have a good idea about how everything is going to be, but there is one thing I still doesn't have a glue about how to implent, "Dirty areas". Because of speed I wont draw everything each frame, but instead each window will have a vector of areas that needs to be redrawn. My problem with these areas is not to figure out how to find out which areas needs repainting, but repainting it. How would you go about only repaint a little area of the window? I would love to see some open source GUIs, if anyone knows any, to see how they have done all this. BTW I have searched google, couldn't find anything, all I found was articles about WIN32, WGL or something like that. I also found 4 articles here on GDNet(Developing a GUI in C++ and DirectX 1-4), but in the last article the author says it might be a good idea to implent these dirty areas, but does not provide any code or resources.

Share this post


Link to post
Share on other sites
I guess I need to provide some information about the GUI I'm thinking about right now, if I want some answers to the "dirty area" question.

Here comes a high-level explanation of the GUI I thought of, I'm sorry it's a little long:

Everything in the GUI will be managed by a class, maybe called Desktop, GUIManager or something like that. It'll contain a double-linked list(if that's the name) with all the windows and will then call the windows drawing routines, starting at the bottom of the double-linked list. The windows will be in order so that the first element in the linked list will be the window under all other windows, and the last element will be the current active window. The reason I choose a double-linked list was so that you can iterate through the list both ways (and still run in more than 1 FPS).

The GUI will contain a base class for all elements, probably called IGUIElement or something like that. Windows, text boxes, buttons etc. will inhert from this class.

The IGUIElement class will contain a render function which as parameters take an x- and y-element. These will indicate where it should be drawn, so if the name of the IGUIElement are TextBox1 it will be called like this:
TextBox1.Render(XOffset + TextBox1.XPos(),YOffset + TextBox1.YPos());
Remember that the window also is a member of IGUIElement and it also got a x and y coordinate, here called XOffset and YOffset.

Then if the TextBox1 got another IGUIElement on it it would call it like this:
Element.Render(XOffset + Element.XPos(),YOffset + Element.YPos());
As you can see here and in the previous example the IGUIElement alsp contains an "unsigned int XPos()" and "unsigned int YPos()" function.

Every IGUIElement will have a container of children, probably a std::vector, then in the render function all of these children's Render function will be called.

The manager of all the GUI element will have a function called: GetWindow() which takes a x and y coordinate and then by going through the double-linked list from the back it'll find the window that are at top at those coordinates.

The window class will have a "bool Move(int XMovement,int YMovement)" function which moves the window, it'll also find out which windows are at the now empty areas and send them a message, via a "void AddDirtyArea(RECT DirtyArea)" function call the window class will have.

Each window will have a vector (or other container) of dirty areas, I still have to figure out how to render only those. When the dirty areas are rendered they are removed.

Well if you have more questions or suggestions, please reply.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
http://www.cegui.org.uk
Crazy Eddie's GUI System

Awesome open-source GUI system, you should try it. It's also located on SourceForge.net, which is where you should search when you want to find open-source things - not Google. Freshmeat.net is another great open-source site, too. Anyway, try this. Hope it helps.

Ricky28269

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