22
33(* ******************************************************************************
44* Author : Angus Johnson *
5- * Version : 3.0 *
6- * Date : 20 July 2021 *
5+ * Version : 3.1 *
6+ * Date : 15 August 2021 *
77* Website : http://www.angusj.com *
88* Copyright : Angus Johnson 2019-2021 *
99* *
@@ -92,11 +92,11 @@ procedure EraseOutsidePaths(img: TImage32; const paths: TPathsD;
9292procedure Draw3D (img: TImage32; const polygon: TPathD;
9393 fillRule: TFillRule; height, blurRadius: double;
9494 colorLt: TColor32 = $DDFFFFFF; colorDk: TColor32 = $80000000 ;
95- angleRads: double = angle45 ); overload;
95+ angleRads: double = angle225 ); overload;
9696procedure Draw3D (img: TImage32; const polygons: TPathsD;
9797 fillRule: TFillRule; height, blurRadius: double;
9898 colorLt: TColor32 = $DDFFFFFF; colorDk: TColor32 = $80000000 ;
99- angleRads: double = angle45 ); overload;
99+ angleRads: double = angle225 ); overload;
100100
101101function RainbowColor (fraction: double): TColor32;
102102function GradientColor (color1, color2: TColor32; frac: single): TColor32;
@@ -265,6 +265,7 @@ procedure DrawShadow(img: TImage32; const polygons: TPathsD;
265265 rec := GetBounds(polygons);
266266 if IsEmptyRect(rec) or (depth < 1 ) then Exit;
267267 if not ClockwiseRotationIsAnglePositive then angleRads := -angleRads;
268+ NormalizeAngle(angleRads);
268269 GetSinCos(angleRads, y, x);
269270 x := depth * x;
270271 y := depth * y;
@@ -605,37 +606,35 @@ procedure Draw3D(img: TImage32; const polygons: TPathsD;
605606 colorLt: TColor32; colorDk: TColor32; angleRads: double);
606607var
607608 tmp: TImage32;
608- recI: TRect;
609- recD: TRectD;
609+ rec: TRect;
610610 paths, paths2: TPathsD;
611611 x,y: double;
612612begin
613+ rec := GetBounds(polygons);
614+ if IsEmptyRect(rec) then Exit;
613615 if not ClockwiseRotationIsAnglePositive then angleRads := -angleRads;
614616 GetSinCos(angleRads, y, x);
615- recD := GetBoundsD(polygons);
616- if recD.IsEmpty then Exit;
617- recI := Rect(recD);
618- paths := OffsetPath(polygons, -recI.Left, -recI.Top);
619- tmp := TImage32.Create(rectWidth(recI), rectHeight(recI));
617+ paths := OffsetPath(polygons, -rec.Left, -rec.Top);
618+ tmp := TImage32.Create(rectWidth(rec), rectHeight(rec));
620619 try
621620 if colorLt shr 24 > 0 then
622621 begin
623622 tmp.Clear(colorLt);
624- paths2 := OffsetPath(paths, height*x, height*y);
623+ paths2 := OffsetPath(paths, - height*x, - height*y);
625624 EraseInsidePaths(tmp, paths2, fillRule);
626625 FastGaussianBlur(tmp, tmp.Bounds, Round(blurRadius), 0 );
627626 EraseOutsidePaths(tmp, paths, fillRule, tmp.Bounds);
628- img.CopyBlend(tmp, tmp.Bounds, recI , BlendToAlpha);
627+ img.CopyBlend(tmp, tmp.Bounds, rec , BlendToAlpha);
629628 end ;
630629
631630 if colorDk shr 24 > 0 then
632631 begin
633632 tmp.Clear(colorDk);
634- paths2 := OffsetPath(paths, - height*x, - height*y);
633+ paths2 := OffsetPath(paths, height*x, height*y);
635634 EraseInsidePaths(tmp, paths2, fillRule);
636635 FastGaussianBlur(tmp, tmp.Bounds, Round(blurRadius), 0 );
637636 EraseOutsidePaths(tmp, paths, fillRule, tmp.Bounds);
638- img.CopyBlend(tmp, tmp.Bounds, recI , BlendToAlpha);
637+ img.CopyBlend(tmp, tmp.Bounds, rec , BlendToAlpha);
639638 end ;
640639 finally
641640 tmp.Free;
@@ -701,12 +700,12 @@ function DrawButton(img: TImage32; const pt: TPointD;
701700 i: integer;
702701 radius: double;
703702 rec: TRectD;
704- shadowSize, shadowAngle : double;
703+ lightSize, lightAngle : double;
705704begin
706705 img.Clear;
707706 if (size < 5 ) then Exit;
708707 radius := size * 0.5 ;
709- shadowSize := radius * 0.25 ;
708+ lightSize := radius * 0.25 ;
710709
711710 rec := RectD(pt.X -radius, pt.Y -radius, pt.X +radius, pt.Y +radius);
712711
@@ -728,23 +727,23 @@ function DrawButton(img: TImage32; const pt: TPointD;
728727 else
729728 Result := Ellipse(rec);
730729 end ;
731- shadowAngle := angle45 ;
730+ lightAngle := angle225 ;
732731
733732 img.BeginUpdate;
734733 try
735734
736735 // nb: only need to cutout the inside shadow if
737736 // the pending color fill is semi-transparent
738737 if baShadow in buttonAttributes then
739- DrawShadow(img, Result, frNonZero, shadowSize ,
740- shadowAngle , $AA000000, color shr 24 < 254 );
738+ DrawShadow(img, Result, frNonZero, lightSize ,
739+ (lightAngle + angle180) , $AA000000, color shr 24 < 254 );
741740
742741 if color shr 24 > 2 then
743742 DrawPolygon(img, Result, frNonZero, color);
744743
745744 if ba3D in buttonAttributes then
746- Draw3D(img, Result, frNonZero, shadowSize *2 ,
747- Ceil(shadowSize ), $CCFFFFFF, $AA000000, shadowAngle );
745+ Draw3D(img, Result, frNonZero, lightSize *2 ,
746+ Ceil(lightSize ), $CCFFFFFF, $AA000000, lightAngle );
748747 DrawLine(img, Result, DpiAwareI, clBlack32, esPolygon);
749748 finally
750749 img.EndUpdate;
@@ -1768,20 +1767,6 @@ function Vectorize(img: TImage32; compareColor: TColor32;
17681767// RamerDouglasPeucker - and support functions
17691768// ------------------------------------------------------------------------------
17701769
1771- function PerpendicularDistSqrd (const pt, line1, line2: TPointD): double;
1772- var
1773- a,b,c,d: double;
1774- begin
1775- a := pt.X - line1.X;
1776- b := pt.Y - line1.Y;
1777- c := line2.X - line1.X;
1778- d := line2.Y - line1.Y;
1779- if (c = 0 ) and (d = 0 ) then
1780- result := 0 else
1781- result := Sqr(a * d - c * b) / (c * c + d * d);
1782- end ;
1783- // ------------------------------------------------------------------------------
1784-
17851770procedure RDP (const path: TPathD; startIdx, endIdx: integer;
17861771 epsilonSqrd: double; const flags: TArrayOfInteger);
17871772var
0 commit comments