## Drawing blurred rectangle Topic is solved

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Pelle
In need of some credit
Posts: 8
Joined: Sun Jun 25, 2023 9:59 am

### Drawing blurred rectangle

I'm doing painting of a custom control and need some blur. I have a feeling this is impossible to do without doing "pixel math" (I hope I'm wrong).

The control is a node diagram with draws nodes as rectangles, and it should look something like the following:
Nodes.png (6.07 KiB) Viewed 622 times
I'm avoiding bitmaps, as the nodes can be of variable sizes. Is there an easy way to accomplish this?
doublemax
Moderator
Posts: 18704
Joined: Fri Apr 21, 2006 8:03 pm
Location: \$FCE2

### Re: Drawing blurred rectangle

There is no built-in function that could blur the background, but i think a grey-to-transparent gradient should do the trick. But you'll have to use wxGraphicsContext for it.

https://docs.wxwidgets.org/trunk/classw ... 713ec29d93

BTW: In order to give the effect of a shadow, you'd usually have the dark areas only on two sides, e.g. right and bottom.
Use the source, Luke!
Pelle
In need of some credit
Posts: 8
Joined: Sun Jun 25, 2023 9:59 am

### Re: Drawing blurred rectangle

Thank you for the answer. I'm unsure on how to do the corners of the rectangle if I'm going for this solution. I did some testing in Inkscape with both linear and radial gradient, but can't get it to look right.
doublemax
Moderator
Posts: 18704
Joined: Fri Apr 21, 2006 8:03 pm
Location: \$FCE2

### Re: Drawing blurred rectangle

Using a CreateRadialGradientBrush() for the corners should work.
Use the source, Luke!
Pelle
In need of some credit
Posts: 8
Joined: Sun Jun 25, 2023 9:59 am

### Re: Drawing blurred rectangle

I am very certain a radiant brush for the corners will end up looking like this:
Corner.png (6.11 KiB) Viewed 605 times
This is made in Inkscape, but if I can't get it right there, I certainly can't code it. I might be misunderstanding you, however.
doublemax
Moderator
Posts: 18704
Joined: Fri Apr 21, 2006 8:03 pm
Location: \$FCE2

### Re: Drawing blurred rectangle

I am very certain a radiant brush for the corners will end up looking like this:
The colors are just wrong. In principle that should work.

If the color and width of the "shadow" is always the same, there is another option: Create a bitmap of how it's supposed to look in Photoshop (or similar) and in your app, stretch-blit the 4 corners and 4 edges of that bitmap onto your graphic.
Use the source, Luke!
Pelle
In need of some credit
Posts: 8
Joined: Sun Jun 25, 2023 9:59 am

### Re: Drawing blurred rectangle

I will give it a go. Thank you for the help.