Programming a GUI

Started by
2 comments, last by snk_kid 19 years, 5 months ago
I have to make a GUI for my game and currently I already have the following classes for that (in C++): *GuiButton (returns values if you press it with the mouse or after releasing the mouse, on mouseover it changes to a different picture or different text) *GuiInputLine (allows you to enter text) *GuiMenu (a list that pops up that has different GuiButtons in it and returns which of those is pressed) And all of these classes have functions draw(), check() and handle(). However I also need a few more complex gui elements, such as scroll lists and windows that contain multiple GuiButtons, GuiInputLines, GuiMenus and other elements in them. What would be the best way to make such things?
Advertisement
I don't have any concrete advices, but if you want to do it in a very clean oo way, take a look at the structure of the .net api, and take that as an example.

I think it will be a good idea to start with a Window/Widget/Form base class which has it's own events (functor objects are nice for that), and can have child windows, and then you build everything up from there.
You can define basic windowed (abstract) control class and derive all controls from this. This window class will hold the list of all child controls so you can position them relative to parent and allow things like moving whole window in simple way.
For example you can create Button which will override only methods like OnClick, Draw() etc. You can also use messages (similar system to win32 api).
I used this method to write my own simple gui and it was prety easy to develop and simple to use. Each new control took about two hours to implement, so I wrote whole gui system in about a week.
Quote:Original post by b2b3
You can define basic windowed (abstract) control class and derive all controls from this. This window class will hold the list of all child controls so you can position them relative to parent and allow things like moving whole window in simple way.
For example you can create Button which will override only methods like OnClick, Draw() etc. You can also use messages (similar system to win32 api).
I used this method to write my own simple gui and it was prety easy to develop and simple to use. Each new control took about two hours to implement, so I wrote whole gui system in about a week.


What your essentially doing is implemenating the composite design pattern this is what Lode wants to be looking into.

This topic is closed to new replies.

Advertisement