Do you use zBuffer for 2D GUI?

Started by
6 comments, last by Gotanod 2 years, 6 months ago

I was using z coordinate to sort the entities before drawing them, but I have faced some situations where the z coordinate is not enough to solve the issues.
My issues:
- Dragging a window, I need that it comes to the front over the other windows. I can increase the z to the maximum z.
- Selecting a windows, needs to bring it also to the front. I can increase the z to the maximum z.
- All the children elements must be drawn in front of the window. I solved this adding the parent's z coordinate to children.

After those issues, I realized that what I need is a sorted list, the order is important, and not the z coordinate.

My question is:
Do you use the z coordinate in your GUIs?
In which situations?

I want to be prepared for future scenarios ?
Thanks!

None

Advertisement

Do you use the z coordinate in your GUIs?
In which situations?

For my editors GUI, I don't use z-coordinates at all, and instead use the “painters algorithm”. Meaning that elements are drawn without any z-testing, in breadth-first hierachical order, from the root down to the last children.

For my 2D-game, where UI is much simpler, I use an explicit z-coordinate (but there are only very basic elements, no windows or panels at all; it doesn't even use a gui-framework but just some sprites).

For the actual GUI-framework for more complex games, I also use painters-algorithm, with the ability to override the sort-order.

@Juliean Thanks for the answer. “Painters algorithm” using the windows hierarchy works fine.
I have also added methods to sort the children when I interact with the windows (bringToFront) and a reverse order list to consume the mouse events.

None

Gotanod said:
Thanks for the answer. “Painters algorithm” using the windows hierarchy works fine. I have also added methods to sort the children when I interact with the windows (bringToFront) and a reverse order list to consume the mouse events.

Glad to hear its working out. I'm also having variants of bring-to-front/bring-to-back, for exactly that reason (forgot to mention it).

Nothing to add except if you use a window management system, you may read through some resources of the Windows Desktop Manager or X11 Desktop Manager. They have the same problems and are doing the same thing probably

Gotanod said:
All the children elements must be drawn in front of the window. I solved this adding the parent's z coordinate to children.

I did this using the stencil buffer. Not as sophisticated, but it works.

let me share a short video showing the current GUI with the painter's algorithm, 9-patch windows, and animations (WIP).

None

This topic is closed to new replies.

Advertisement