procedure TForm2.DrawGradiantEllipse(
Handle: HDC; X, Y, Width, Height,
RingWidth: integer; OuterColor, InnerColor: cardinal; UseGradient: boolean);
var
g: TGPGraphics;
pBrush: TGPPathGradientBrush;
region,region2: TGPRegion;
pen: TGPPen;
OuterRect: TGPRect;
InnerRect: TGPRect;
InnerPath: TGPGraphicsPath;
OuterPath: TGPGraphicsPath;
Count: integer;
white:cardinal;
FocusScale: double;
begin
g := TGPGraphics.Create(
Handle);
region := TGPRegion.Create;
pBrush := TGPPathGradientBrush.Create;
pen := TGPPen.Create(OuterColor, RingWidth);
try
FocusScale := 1 - (RingWidth / Width);
g.SetSmoothingMode(SmoothingModeHighQuality);
//(SmoothingModeAntiAlias);
if UseGradient
then
begin
// Create Outer/Inner Rect
OuterRect := MakeRect(x,y,Width,Height);
InnerRect := MakeRect(OuterRect.X + RingWidth
div 2,
OuterRect.Y + RingWidth
div 2,
OuterRect.Width - RingWidth,
OuterRect.Height - RingWidth);
// Create Outer/Inner Ellipse Path
InnerPath := TGPGraphicsPath.Create;
OuterPath := TGPGraphicsPath.Create;
InnerPath.AddEllipse(InnerRect);
OuterPath.AddEllipse(OuterRect);
// Create PathGradientBrush
pBrush := TGPPathGradientBrush.Create(OuterPath);
pBrush.SetCenterColor(InnerColor);
// Always a single Color
count := 1;
pBrush.SetSurroundColors(@OuterColor,count);
pBrush.SetFocusScales(FocusScale,FocusScale);
pBrush.SetBlendTriangularShape(0.5,FocusScale);
// Create Region of InnerPath
region := TGPRegion.Create(OuterPath);
region2 := TGPRegion.Create(InnerPath);
region.Exclude(region2);
// "Erases" the Inner Ellipse
// g.SetClip(region,CombineModeExclude);
//g.FillEllipse(pBrush,OuterRect);
g.FillRegion(pbrush,region);
// Set PenWidth for Ellipse with AA
pen.SetWidth(1);
// pen.SetColor(MakeColor(225,0,255,0)); // Just for Debug
g.DrawEllipse(pen,x + Ringwidth
div 2,y + Ringwidth
div 2,Width - Ringwidth,Height - Ringwidth);
end;
pen.SetColor(MakeColor(225,255,0,0));
// Just for Debug
g.DrawEllipse(pen,x,y,Width,Height);
finally
region.Free;
region2.Free;
pBrush.Free;
g.Free;
pen.Free;
end;
end;