Is it just me, or does everyone's GUI code look like spaghetti?

Originally the code did more than swap a boolean, I just never went back to clean it up. :wink:

Yeah, I might try out the rectangles and intersects, that sounds like a pretty good idea because you only have to specify coordinates in one single place, then just see if the mouse is intersecting, if it is, do whatever is under the button.

I’ve written a “simple” (1) panel-based UI system for OpenGL that operates somewhat like Swing except its painted 60 fps.

It has mouse (move, drag, press, release, enter, exit, click, etc.) and key events (press, release) that are dispatched to the panels which in turn dispatches events to any child components.

I’ve really come to appreciate the amount of effort required to write any UI library. I’ve probably spent close to 30 working days in total on it and each time I revisit it to add functionality I find new bugs and new ways to do things.

Recently I’ve added some more complicated UI controls such as auto-paginating text areas, single-selection lists, and drop-down selection lists.

Overall the code is clean and manageable but wowsers, it took considerable effort.

(1) “Simple” in functionality but not simple in code.

To reduce the redundancy and verbosity:
[icode]modeBlood ^= true;[/icode] (it might look obscure, but your brain will soon recognize this as ‘toggle’)

On topic:
Just add support for panels, in which components have an offset relative to their parent. Then pump events through the root, and let the panel deliver the events to the descendants, making the coordinates relative to each component you pass them through - just like AWT, Swing, HTML, etc.

true. Just learned this @ school :slight_smile: Makes life so much easier.

Aka a scene graph! :smiley: I don’t think they are listening though.

Yeah, I explicitly described a scene-graph, because I felt it would otherwise be ignored :point: