An alpha-aware TCanvas-like class that allows you to compose and draw blended transparent shapes, text, etc. It also makes drawing to glass parts of a form much easier. Uses pure GDI – not GDI+, so no external libraries required. MPL license.
A standard VCL application running on Windows Vista or 7 can have glass areas of a form – the transparent sections showing a blurred view of the background. This includes the title bar. Suppose you want to draw on glass, and you’re using a version of Delphi without good (or any!) transparency support in the TCanvas class. What do you do?
- Drop back to GDI, and, through use of AlphaBlend, BLENDFUNCTION, premultiplied alpha, upside-down (reverse-ordered) bitmaps, checking DWM composition and using DrawThemeTextEx, write code to draw Aero-style text successfully to glass. It’s interesting stuff, but a lot of effort for a small feature. Or…
- You can drop this unit into your application, and use TCanvas-like methods to output text, draw shapes, etc and compose the result straight onto the glass area of your form in a few lines of code.
- Does not pull in any external libraries (such as GDI+) – it’s implemented purely using GDI
- Lets you draw transparent text and shapes to a normal TCanvas (eg, to blend transparent shapes and text onto a TBitmap.) It’s useful for implementing, say, an Explorer-like transparent selection rectangle or a closed-caption-style text label with a transparent background.
Draws Aero text (with a fuzzy background), including changing the white background color to something else – something with no support in the Windows API. This gracefully falls back to standard text if Aero is not available, including if you call the methods on Windows XP.
- Includes an example of drawing on the non-client area – that is, drawing on the title bar.
It’s free and licensed under the commercial-use-friendly MPL. Being open source, contributions adding more drawing functionality are gratefully accepted.
- GitHub page
- Blog posts: