GUI Window clipping

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Kamal123
Member
Member
Posts: 99
Joined: Fri Nov 01, 2019 1:17 am

GUI Window clipping

Post by Kamal123 »

Hello, I have confusion regarding window clipping, when an window is overlaped by another window, the overlapping window is drawn fully and from the overlapped window only those portion are redrawn which are visible, the confusion is here-- every window owns there own buffer where pixels are drawn by each application who owns that window and the compositor composites that buffer to final image, so the portion which are visible are calculated using rectangle clipping and those rectangles are in device coordinates how can I convert those same rects to window coordinate? So that I can only copy those visible portion of window buffer to final image? Or my method is wrong?

For example if the clip rect is in 100,100 as per screen coord, the same rect should be in 0,0 in window coord..
devc1
Member
Member
Posts: 439
Joined: Fri Feb 11, 2022 4:55 am
Location: behind the keyboard

Re: GUI Window clipping

Post by devc1 »

Kamal123 wrote: For example if the clip rect is in 100,100 as per screen coord, the same rect should be in 0,0 in window coord..
What are you talking about ? Shouldn't you just make a bitmap of the Window and process rects locally and draw them. Then the compositor will simply copy the window bitmap (or the modified portions only?)

I don't understand the rest of the question, can you provide more details and maybe a screenshot

Devc1,
User avatar
AndrewAPrice
Member
Member
Posts: 2300
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: GUI Window clipping

Post by AndrewAPrice »

For converting coordinates on the screen to coordinates on the window:

Position in window = position on screen - window's position
E.g. if your window is as 100,100 and you click at 150,150 on the screen, that will be 50,50 in the window.

For compositing window managers (where each window is drawn into its own buffer, and the window manager then combines them together), the easiest way is to draw them back-to-front, so overlapping buffers. All of this is drawn into the window manager's buffer, then once all the windows are drawn to it, this is the copied into the graphic device's framebuffer.

Now, you might have noticed there's a lot of overdrawn (pixels being copied from background windows that are covered up by foreground windows). If you are comfortable doing rectangle slicing, you can cut one rectangle out of another, that way you don't copy pixels that aren't shown, and you can avoid the need for a window manager's back buffer.

---

This is what I do: I iterate through the windows back-to-front, and call Draw on my window.
https://github.com/AndrewAPrice/Percept ... positor.cc

But the Draw function doesn't really draw, it calls the CopyTexture function adds a rectangle to copy to quad tree.

Here's my quad tree that slices up/removes rectangles behind it:
https://github.com/AndrewAPrice/Percept ... uad_tree.h

Then my window manager sends a collection of "copy rectangle from a to b" commands to the graphics driver.
My OS is Perception.
Post Reply