Mildly Hurtful Sarcasm

Meaningless ranting, just like everybody else.

Tuesday, January 30, 2007

Quest for a nicer desktop III - Shadows

I've made my window transparent, and it's working fairly well. Shadow is what I'm after next. After a brief search on MSDN I found out about CS_DROPSHADOW class style - turns out in XP, you can add shadows to your windows right out of the box.

AfxRegisterWndClass(CS_DROPSHADOW, ...);

The result is actually pretty nice.



However nothing happens when I apply the same class style to my non-rectangular window. Perhaps it is because it is not a WS_OVERLAPPEDWINDOW. I need to implement shadow on the my own. I pick the easiest way: slide under the main window a top level window that resizes and relocates accordingly. I knew ahead of time a solid shadow like old times won't do it any more, but I didn't know it is going to look so bad, it even kills the transparency of my main window. So I reduce the opacity of my shadow window to 50%.



Transparent shadow works ok but looks pretty rigid. Windows' shadows are the fuzzy type, I need to add fuzziness. I create a GraphicsPath that outlines my shadow window's shape. Since my main window is see through, I need my shadow to be solid in the middle and fade out only at the edge.

INT num = 1;
Color clrSurround = Color::White;
PathGradientBrush brShadow(&path);
brShadow.SetSurroundColors(&clrSurround, &num);
brShadow.SetCenterColor(Color::Black);
REAL xScale = (nWidth - nEdgeWidth * 2) / nWidth;
REAL yScale = (nHeight - nEdgeWidth * 2) / nHeight;
brShadow.SetFocusScales(xScale, yScale);
graphics.FillPath(&brShadow, &path);


It looks okay at first, but when I take a closer look I realize this is really creating a white rim:


This sucks, I am so close...

Labels:

0 Comments:

Post a Comment

<< Home