Can we discuss GUIs please?

Started by
18 comments, last by silverphyre673 17 years, 6 months ago
I too have a (marginally unimpressive) UI system in place, also in my journal (link at bottom of post). I do something akin to hplus' description for layout, and some data binding spots. As he says, it is quite nice once done, and done well.

Some other major controls that I have and have found useful to a certain degree.

1. Timer. Some people's orginization would have this be more appropriate elsewhere, but I've found it useful to be able to tie an arbitrary timed trigger as a child control to another. Makes FPS displays, certain animations, blinking things much easier.

2. Sound. I hate when stuff isn't consistant. Ever see when you close a window playing a sound and the sound continues? Annoying. It's also fairly hackish to fix depending on how you have things designed. I have a UI control that wraps a sound resource and maps open/visible:close/invisible to play:stop. Makes things easier and consistant, and allows for easy expansion into other GUI sound interfaces; often overlooked in games outside of Options.

Non-Basic:

3. Containers (lists). In data heavy games, it's really nice to have a container that can do auto-arrangement/formatting for you. These are really hard to do right, but when they are... a godsend.

4. Canvas. Essentially a RenderToSurface which is constrained to a rectangle. It's not useful at first glance, but having a common class which does it makes things like screenshots, display caching, and thumbnailing consistant, repeatable, and flexible.


And as I touched upon earlier, I find inconsistantcy annoying in GUIs. Usually that includes things that look identical but have different behaviors (usually due to mouse input differences), or obvious keyboard control of the UI not existing. Wether that's a UI failing or the programmer's fault is debatable though...
Advertisement
You're GUI library should have a way of representing multiple document interfaces. The traditional MDI system seems to have been replaced with tabs - make such a control.

Also, no list controls? [sad]
Although i didnt state it, list controls and tabs will be the more advanced controls. I had thought of the timer, sounds like it should be included.
I am also unsure about whether to try and make this library cross platform, using OpenGL as the alternative rendering API.

Any thoughts on the ease of this?
Quote:Original post by Dave
I am also unsure about whether to try and make this library cross platform, using OpenGL as the alternative rendering API.

Any thoughts on the ease of this?


I've not actually done it, but if you build everything off of the API dependant parts ("image" and "text" mainly) and keep abstraction in mind, I can't imagine it'll be terribly difficult to drop in replacements for image/text which use differing APIs.
See, what's putting me off making it cross platform is that i would have to write image loaders or use another library, since i couldn't use either for loading the textures. I would also have to write a font system for text.

Do i hahve any other solutions to this?
IMO, a good way of abstracting out the platform-dependant drawing portions of the GUI would be to follow a sort of device context approach, where the base control class has a drawing context associated with it, and all drawing methods go through the context interface, where the implementation is platform dependant.

I don't know how *nix and X-windows, or Cocoa works, but I know this would make it easier to add support for Win32 and OpenGL (and possibly Direct-X) driven back-ends.
daerid@gmail.com
I did an OpenGL GUI Library for a university project a couple of semesters ago as well. I didn't get done with what I wanted to and I'm actually still working on it. If you are interested here are a few of the key features of my gui system;

• Every component such as the window and push button are derived off of a cComponent class.
• The cComponent class contains a singleton class to a texture repository that contains textures for the backgrounds, frames, fonts, etc.
• The cComponent class allows the component to be customized by allowing the user to select up to 9 textures: 4 for the frames, 4 for the corners, and one for the background.
• I use a virtual coordinate system and translate everything during rendering. The Screen is 10000x10000 units. The only thing that doesn’t use the virtual coordinates is the component frame set.
• Child controls don’t contain pointers to the parent, but have coordinates relative to the parent. When rendering, a control is called by its parent which sends the coordinate translation information.
• Everything is handled through the cWindowProcessor class which basically has two main functions: CreateMessages(void *data); ExecuteMessages(void *data);
• CreateMessages() basically takes the input information, find out which window is being targeted by the cursor and then find out which component inside window is being targeted by the cursor and then create the appropriate message to put in the message queue.
• ExecuteMessage() basically calls every message that is in the queue. Each window has a function pointer that the user sets to determine what happens when each control is pressed, dragged, etc.

-----------------------------Download my real time 3D RPG.
Some random thoughts:

- Make the renderer "pluggable". There should be rather few basic rendering functions necessary ("draw colored rectangle", "draw textured rectangle", "draw string of text", etc). Making these functions part of an easily replaceable "Renderer"-class (or similar) should make it fairly easy to implement a renderer for a different platform while keeping the rest of the code the same.

- Composable components. Yeah, ok, not the catchiest of names, but basically making it easy to create a new kind of "gadget"/"widget"/whatever by combining existing components is a near must-have capability.

- In my opinion the single most important part of a gui-library is making it easy to plug gui-component behavior into my own code. Preferrably something like

class Test {public: Test() {  fooButton.setText ( "Foo" );  barButton.setText ( "Bar" );  fooButton.onClick ( foo );  barButton.onClick ( bar ); } void foo(); void bar();private: Button fooButton; Button barButton;};

Something like Boost.Signal would fit the bill quite nicely.


Personally I'd make the Drop-down menu control a "non-basic" control composed of other components (a Label for the text, an Image for the "drop-down down arrow", both in a Frame. With another Frame with Labels in it shown when clicking, for instance.)
How does your GUI interact with the rest of an application? For example, if I wanted to have a window pop up, with a text box that allowed me to, say, input a username and password and click a "login" button, how would the GUI communicate to the application that we are ready to allow the player to attempt to log in, and how would the application find out what username and password the player entered was? This is where I keep getting stuck in my GUI design. I can't seem to think of a non-procedural solution to the problem.
my siteGenius is 1% inspiration and 99% perspiration

This topic is closed to new replies.

Advertisement