diff --git a/X2UtGraphics.pas b/X2UtGraphics.pas index 678602e..d323868 100644 --- a/X2UtGraphics.pas +++ b/X2UtGraphics.pas @@ -47,6 +47,16 @@ uses } procedure AAOwned(const AOwner: TComponent); + { + :$ Blends the two colors using the specified alpha value + + :: The alpha determines how much of the foreground color is applied to the + :: background color. The alpha value must be between 0 and 255 (where 0 + :: indicates full transparency and 255 an opaque foreground). + } + function BlendColors(const ABackground, AForeground: TColor; + const AAlpha: Byte): TColor; + implementation uses @@ -137,4 +147,24 @@ begin AAControl(TControl(AOwner.Components[iControl])); end; + +function BlendColors; +var + cBack: Cardinal; + cFore: Cardinal; + bBack: Byte; + +begin + cBack := ColorToRGB(ABackground); + cFore := ColorToRGB(AForeground); + bBack := 255 - AAlpha; + + Result := RGB(((GetRValue(cBack) * bBack) + + (GetRValue(cFore) * AAlpha)) shr 8, + ((GetGValue(cBack) * bBack) + + (GetGValue(cFore) * AAlpha)) shr 8, + ((GetBValue(cBack) * bBack) + + (GetBValue(cFore) * AAlpha)) shr 8); +end; + end.