snowdev
snowdev

Reputation: 29

"Blur behind" like effect for TPanel

I want to make a TPanel with a blur effect which is like a glass effect that Windows 7 (Aero) had.

The goal is to be a visual component that shows what is behind it but blurred, which is common in web/mobile design.

I saw something similar, but to forms (which does not apply to me), like in this other post or this blog.

Researching, I also found a Lazarus component on the lazarus forum (later comments) which does the exact effect I need. I tried to learn how they do this, but fail.

I don't even know how to start into this. Hope someone can help so I can at least start.

Upvotes: 1

Views: 257

Answers (1)

skamradt
skamradt

Reputation: 15538

The answer https://stackoverflow.com/a/33064611/9217 might also provide a clue as it uses an undocumented windows API to provide the glass look for a VCL application. The BlendColors routine can be replaced with the ColorBlendRGB from GraphUtil in Delphi 11+. This approach does appear to still work for Windows 11. Some controls may need to be "double buffered" to render properly.

Otherwise ...

the components at https://www.almdev.com/prods/smarteffects/smarteffects.html might offer some help, I recall a demo from them a while back that had a glass like layered effect, but it might have been just layered opacity.

If you go the route of adding a blur manually, you will need to first "screen capture" the rect behind your form, apply the blur to the captured bitmap (box blur is likely the simplest to implement) and then paint it to your form background.

If I recall correctly, you won't be able to grab all windows (some might be protected via a flag set to the windows manager see SetWindowDisplayAffinity), so using the undocumented call might be your best option if you don't want parts of windows to "vanish" when your hovering over them.

Upvotes: 0

Related Questions