Question

Using this complete example I could draw text on Aero Glass. The rendering is perfectly fine, but there is a visual problem: the glow is clipped on the text-alignment side.

enter image description here

FYI, text format is defined like this:

  Dim uFormat As Integer = TextFormatFlags.NoPrefix Or TextFormatFlags.WordBreak Or _
            TextFormatFlags.TextBoxControl Or TextFormatFlags.EndEllipsis

Can this be fixed?

Was it helpful?

Solution

This example is used a middle-center alignment for the text by default. The format you using (NoPrefix|WordBreak|TextBoxControl|EndEllipsis) is left-aligned by default. So to fix glow clipping you should extend glow bounds.
Here is the corrected the sample:

public void DrawTextOnGlass(IntPtr hwnd, String text, Font font, Rectangle bounds, int glowSize){
//...
    RECT glowRect = new RECT();
    RECT textRect = new RECT();

    glowRect.left = bounds.Left - glowSize;
    glowRect.right = bounds.Right + glowSize;
    glowRect.top = bounds.Top - glowSize;
    glowRect.bottom = bounds.Bottom + glowSize;

    textRect.left = glowSize;
    textRect.top = glowSize;
    textRect.right = glowRect.right - glowRect.left;
    textRect.bottom = glowRect.bottom - glowRect.top;
//...
    int uFormat = (int)(TextFormatFlags.NoPrefix
    | TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.EndEllipsis);
//...
    DrawThemeTextEx(renderer.Handle, Memdc, 0, 0, text, -1, uFormat, ref textRect, ref dttOpts);
    BitBlt(destdc, glowRect.left, glowRect.top, 
        glowRect.right - glowRect.left, 
        glowRect.bottom - glowRect.top, 
        Memdc, 0, 0, SRCCOPY);
//...    
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top