Dynamic dropshadow

BlitzMax Forums/BlitzMax Beginners Area/Dynamic dropshadow

Kistjes(Posted 2007) [#1]
I want to create a (non windows-like) popup menu with a drop shadow. The size of the popup can vary so it's no option of having a fixed size drop shadow png-file.
Furthermore, I want to have the blur amount of this drop shadow to be variable.
Any ideas?

O, and I'm happy to have a solution for rectangular popups, but it would be great to have a 'createDropShadow()' based on the alpha-channel of an image (for instance a rounded rectangle popup menu).


Derron(Posted 2007) [#2]
You can "blur" a second instance of your image...(if the menus are statically generated - grabimage/grabpixmap) and then use the blurimage-code out of the 'code archives' here on bm.com

This blurred image is then drawn before the menu ... set ShadeBlend - or how it is called - before. Setting Color to 50,50,50 and alpha 0.5 or so would do the same.

Just take attention of the image generated by the blur-function - it should use alpha-channel.


bye
MB


sswift(Posted 2007) [#3]
Set the drawing color to black, draw the window 8 pixels down and to the right, then set the drawing color back to white and draw it again at the normal location.

To make it blur, if you want it to be 3d accelerated, I don't think there is a way you can do a perfect gaussian or box blur without pixel shaders, but you can do a sort of approximation if you draw the shadow multiple times in different locations with a certain amount of alpha.

This code shows how to do this in Blitz3D:
http://www.blitzmax.com/codearcs/codearcs.php?code=754

Basically, just look at that to figure out what alpha you need to set and how to offset it.

The drawback of this method is you will tend to see circular indentations at the corners of the object.


tonyg(Posted 2007) [#4]
Is it worth using this for the blur? (the function should really be 'cheapblur' rather than createbloom)?


Grey Alien(Posted 2007) [#5]
I'd have initially suggested what sswift did, i.e. draw shadow several times with different alpha but I'm interest to see these other functions. Be nice if BMax had some of these built in.


Kistjes(Posted 2007) [#6]
Thanks for the replies.
It seems there is no 'out of the box' solution for this. Based on your suggestions, I will try to make a drop shadow code myself. If it's successful I'll post a demo.


Damien Sturdy(Posted 2007) [#7]
Hint:

Draw a box with an alpha of 0.5 in the same place twice and it will draw the equivalent of 0.75.

You do not even need to change the alpha value!

How about something like this (Pseudocode)

For rounded corners:
setalpha 0.5
for Dist:int=36 to 0 step -5
   drawimage Image,x+(sin(dist*10)*angle),y+(cos(dist*10)*angle)
next


For a basic alpha'd edge:
Setalpha 0.1
For add#=10 to 0 step -2
   drawimage image,x+add,y+add
next


Write these in proper Max code and you should be able to do those shadows pretty easily.


Kistjes(Posted 2007) [#8]
Here is my blurred drop shadow demo:
If any of you can make this routine run (much) faster, please let me know!
I tried to make a pixmap with PF_A8 format for the alphachannel only. But that did not work because readpixel returns a 32 bit integer.
Anyway, here is the code (don't know how to include source code in a seperate scrollable text field).