From aa07232678e5e6b40e46d1a2544d863c347b6802 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Thu, 12 Oct 2017 17:48:39 +0000 Subject: [PATCH] spktoolbar: More conventional code formatting of unit SpkGUITools git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6038 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../spktoolbar/SpkGUITools/SpkGUITools.pas | 2789 ++++++++--------- components/spktoolbar/SpkMath/SpkMath.pas | 13 + .../spktoolbar/demos/actions/project1.lpr | 5 +- 3 files changed, 1371 insertions(+), 1436 deletions(-) diff --git a/components/spktoolbar/SpkGUITools/SpkGUITools.pas b/components/spktoolbar/SpkGUITools/SpkGUITools.pas index 30d37d497..f48dde500 100644 --- a/components/spktoolbar/SpkGUITools/SpkGUITools.pas +++ b/components/spktoolbar/SpkGUITools/SpkGUITools.pas @@ -25,10 +25,10 @@ type TGUITools = class(TObject) protected - class procedure FillGradientRectangle(ACanvas: TCanvas; Rect: T2DIntRect; ColorFrom: TColor; - ColorTo: TColor; GradientKind: TBackgroundKind); - class procedure SaveClipRgn(DC : HDC; var OrgRgnExists : boolean; var OrgRgn : HRGN); - class procedure RestoreClipRgn(DC : HDC; OrgRgnExists : boolean; var OrgRgn : HRGN); + class procedure FillGradientRectangle(ACanvas: TCanvas; Rect: T2DIntRect; + ColorFrom, ColorTo: TColor; GradientKind: TBackgroundKind); + class procedure SaveClipRgn(DC: HDC; var OrgRgnExists: boolean; var OrgRgn: HRGN); + class procedure RestoreClipRgn(DC: HDC; OrgRgnExists: boolean; var OrgRgn: HRGN); public // *** Lines *** @@ -394,747 +394,754 @@ uses class procedure TGUITools.CopyRoundCorner(ABuffer, ABitmap: TBitmap; SrcPoint, DstPoint: T2DIntVector; Radius: integer; CornerPos: TCornerPos; ClipRect: T2DIntRect; Convex: boolean); - -var BufferRect, BitmapRect, TempRect : T2DIntRect; - OrgSrcRect, UnClippedDstRect, OrgDstRect : T2DIntRect; - SrcRect: T2DIntRect; - Offset: T2DIntVector; - Center: T2DIntVector; - y: Integer; - SrcLine: Pointer; - DstLine: Pointer; - SrcPtr, DstPtr : PByte; - x: Integer; - Dist : double; - SrcImg, DestImg: TLazIntfImage; - +var + BufferRect, BitmapRect, TempRect: T2DIntRect; + OrgSrcRect, UnClippedDstRect, OrgDstRect: T2DIntRect; + SrcRect: T2DIntRect; + Offset: T2DIntVector; + Center: T2DIntVector; + y: Integer; + SrcLine: Pointer; + DstLine: Pointer; + SrcPtr, DstPtr : PByte; + x: Integer; + Dist : double; + SrcImg, DestImg: TLazIntfImage; begin -if (ABuffer.PixelFormat<>pf24bit) or (ABitmap.PixelFormat<>pf24bit) then - raise exception.create('TSpkGUITools.CopyRoundCorner: Tylko 24-bitowe bitmapy s¹ akceptowane!'); + if (ABuffer.PixelFormat <> pf24Bit) or (ABitmap.PixelFormat <> pf24Bit) then + raise Exception.Create('TSpkGUITools.CopyRoundCorner: Only 24-bit bitmaps are accepted!'); -// Sprawdzanie poprawnoœci -if Radius<1 then - exit; + // Validation + if Radius < 1 then + exit; -if (ABuffer.width=0) or (ABuffer.height=0) or - (ABitmap.width=0) or (ABitmap.height=0) then exit; + if (ABuffer.Width = 0) or (ABuffer.Height = 0) or + (ABitmap.Width = 0) or (ABitmap.Height = 0) then exit; -//todo minimize use of temps here -{$ifdef EnhancedRecordSupport} -BufferRect:=T2DIntRect.create(0, 0, ABuffer.width-1, ABuffer.height-1); -if not(BufferRect.IntersectsWith(T2DIntRect.create(SrcPoint.x, - SrcPoint.y, - SrcPoint.x+Radius-1, - SrcPoint.y+Radius-1), - OrgSrcRect)) then exit; -{$else} -BufferRect.create(0, 0, ABuffer.width-1, ABuffer.height-1); -TempRect.Create(SrcPoint.x, SrcPoint.y, SrcPoint.x+Radius-1, SrcPoint.y+Radius-1); -if not(BufferRect.IntersectsWith(TempRect, OrgSrcRect)) then exit; -{$endif} + //todo minimize use of temps here + {$ifdef EnhancedRecordSupport} + BufferRect := T2DIntRect.Create(0, 0, ABuffer.width-1, ABuffer.height-1); + if not BufferRect.IntersectsWith( + T2DIntRect.Create(SrcPoint.x, SrcPoint.y, SrcPoint.x+Radius-1, SrcPoint.y+Radius-1), + OrgSrcRect + ) + then + exit; + {$else} + BufferRect.Create(0, 0, ABuffer.Width-1, ABuffer.Height-1); + TempRect.Create(SrcPoint.x, SrcPoint.y, SrcPoint.x+Radius-1, SrcPoint.y+Radius-1); + if not BufferRect.IntersectsWith(TempRect, OrgSrcRect) then + exit; + {$endif} -{$ifdef EnhancedRecordSupport} -BitmapRect:=T2DIntRect.create(0, 0, ABitmap.width-1, ABitmap.height-1); -if not(BitmapRect.IntersectsWith(T2DIntRect.create(DstPoint.x, - DstPoint.y, - DstPoint.x+Radius-1, - DstPoint.y+Radius-1), - UnClippedDstRect)) then exit; -{$else} -BitmapRect.create(0, 0, ABitmap.width-1, ABitmap.height-1); -//todo: calling create twice -TempRect.Create(DstPoint.x, DstPoint.y, DstPoint.x+Radius-1, DstPoint.y+Radius-1); -if not(BitmapRect.IntersectsWith(TempRect, UnClippedDstRect)) then exit; -{$endif} + {$ifdef EnhancedRecordSupport} + BitmapRect := T2DIntRect.Create(0, 0, ABitmap.Width-1, ABitmap.Height-1); + if not BitmapRect.IntersectsWith( + T2DIntRect.Create(DstPoint.x, DstPoint.y, DstPoint.x+Radius-1, DstPoint.y+Radius-1), + UnClippedDstRect + ) + then + exit; + {$else} + BitmapRect.Create(0, 0, ABitmap.Width-1, ABitmap.Height-1); + //todo: calling create twice + TempRect.Create(DstPoint.x, DstPoint.y, DstPoint.x+Radius-1, DstPoint.y+Radius-1); + if not(BitmapRect.IntersectsWith(TempRect, UnClippedDstRect)) then + exit; + {$endif} -if not(ClipRect.IntersectsWith(UnClippedDstRect, OrgDstRect)) then - exit; + if not(ClipRect.IntersectsWith(UnClippedDstRect, OrgDstRect)) then + exit; -Offset:=DstPoint - SrcPoint; + Offset := DstPoint - SrcPoint; -if not(OrgSrcRect.IntersectsWith(OrgDstRect - Offset, SrcRect)) then exit; + if not(OrgSrcRect.IntersectsWith(OrgDstRect - Offset, SrcRect)) then + exit; -// Ustalamy pozycjê œrodka ³uku -{$ifdef EnhancedRecordSupport} -case CornerPos of - cpLeftTop: Center:=T2DIntVector.create(SrcPoint.x + radius - 1, SrcPoint.y + Radius - 1); - cpRightTop: Center:=T2DIntVector.create(SrcPoint.x, SrcPoint.y + Radius - 1); - cpLeftBottom: Center:=T2DIntVector.Create(SrcPoint.x + radius - 1, SrcPoint.y); - cpRightBottom: Center:=T2DIntVector.Create(SrcPoint.x, SrcPoint.y); -end; -{$else} -case CornerPos of - cpLeftTop: Center.create(SrcPoint.x + radius - 1, SrcPoint.y + Radius - 1); - cpRightTop: Center.create(SrcPoint.x, SrcPoint.y + Radius - 1); - cpLeftBottom: Center.Create(SrcPoint.x + radius - 1, SrcPoint.y); - cpRightBottom: Center.Create(SrcPoint.x, SrcPoint.y); -end; -{$endif} + // We position the center of the arc + {$ifdef EnhancedRecordSupport} + case CornerPos of + cpLeftTop: + Center := T2DIntVector.Create(SrcPoint.x + Radius - 1, SrcPoint.y + Radius - 1); + cpRightTop: + Center := T2DIntVector.Create(SrcPoint.x, SrcPoint.y + Radius - 1); + cpLeftBottom: + Center := T2DIntVector.Create(SrcPoint.x + Radius - 1, SrcPoint.y); + cpRightBottom: + Center := T2DIntVector.Create(SrcPoint.x, SrcPoint.y); + end; + {$else} + case CornerPos of + cpLeftTop: + Center.Create(SrcPoint.x + Radius - 1, SrcPoint.y + Radius - 1); + cpRightTop: + Center.Create(SrcPoint.x, SrcPoint.y + Radius - 1); + cpLeftBottom: + Center.Create(SrcPoint.x + Radius - 1, SrcPoint.y); + cpRightBottom: + Center.Create(SrcPoint.x, SrcPoint.y); + end; + {$endif} -// Czy jest cokolwiek do przetworzenia? -if Convex then - begin - //todo: remove the check since is not necessary - if (SrcRect.left<=SrcRect.right) and (SrcRect.top<=SrcRect.bottom) then - begin - SrcImg := ABuffer.CreateIntfImage; - DestImg := ABitmap.CreateIntfImage; - for y := SrcRect.top to SrcRect.bottom do - begin - SrcLine:=SrcImg.GetDataLineStart(y); - DstLine:=DestImg.GetDataLineStart(y+Offset.y); - - SrcPtr:=pointer(PtrInt(SrcLine) + 3*SrcRect.left); - DstPtr:=pointer(PtrInt(DstLine) + 3*(SrcRect.left + Offset.x)); - for x := SrcRect.left to SrcRect.right do - begin - {$ifdef EnhancedRecordSupport} - Dist:=Center.DistanceTo(T2DIntVector.create(x, y)); - {$else} - Dist:=Center.DistanceTo(x, y); - {$endif} - if Dist <= (Radius-1) then - Move(SrcPtr^,DstPtr^,3); - - inc(SrcPtr,3); - inc(DstPtr,3); - end; - end; + // Is there anything to be processed? + if Convex then + begin + //todo: remove the check since is not necessary + if (SrcRect.Left <= SrcRect.right) and (SrcRect.Top <= SrcRect.Bottom) then + begin + SrcImg := ABuffer.CreateIntfImage; + DestImg := ABitmap.CreateIntfImage; + for y := SrcRect.Top to SrcRect.Bottom do + begin + SrcLine := SrcImg.GetDataLineStart(y); + DstLine := DestImg.GetDataLineStart(y+Offset.y); + SrcPtr := pointer(PtrInt(SrcLine) + 3*SrcRect.Left); + DstPtr := pointer(PtrInt(DstLine) + 3*(SrcRect.Left + Offset.x)); + for x := SrcRect.Left to SrcRect.Right do + begin + {$ifdef EnhancedRecordSupport} + Dist := Center.DistanceTo(T2DIntVector.Create(x, y)); + {$else} + Dist := Center.DistanceTo(x, y); + {$endif} + if Dist <= (Radius-1) then + Move(SrcPtr^, DstPtr^, 3); + inc(SrcPtr, 3); + inc(DstPtr, 3); + end; + end; ABitmap.LoadFromIntfImage(DestImg); SrcImg.Destroy; DestImg.Destroy; - end; - end -else - begin - if (SrcRect.left<=SrcRect.right) and (SrcRect.top<=SrcRect.bottom) then - begin - SrcImg := ABuffer.CreateIntfImage; - DestImg := ABitmap.CreateIntfImage; - for y := SrcRect.top to SrcRect.bottom do - begin - SrcLine:=SrcImg.GetDataLineStart(y); - DstLine:=DestImg.GetDataLineStart(y+Offset.y); - - SrcPtr:=pointer(PtrInt(SrcLine) + 3*SrcRect.left); - DstPtr:=pointer(PtrInt(DstLine) + 3*(SrcRect.left + Offset.x)); - for x := SrcRect.left to SrcRect.right do - begin - {$ifdef EnhancedRecordSupport} - Dist:=Center.DistanceTo(T2DIntVector.create(x, y)); - {$else} - Dist:=Center.DistanceTo(x, y); - {$endif} - if Dist >= (Radius-1) then - Move(SrcPtr^,DstPtr^,3); - - inc(SrcPtr,3); - inc(DstPtr,3); - end; - end; + end; + end else + begin + if (SrcRect.Left <= SrcRect.Right) and (SrcRect.Top <= SrcRect.Bottom) then + begin + SrcImg := ABuffer.CreateIntfImage; + DestImg := ABitmap.CreateIntfImage; + for y := SrcRect.Top to SrcRect.Bottom do + begin + SrcLine := SrcImg.GetDataLineStart(y); + DstLine := DestImg.GetDataLineStart(y+Offset.y); + SrcPtr := pointer(PtrInt(SrcLine) + 3*SrcRect.Left); + DstPtr := pointer(PtrInt(DstLine) + 3*(SrcRect.Left + Offset.x)); + for x := SrcRect.Left to SrcRect.Right do + begin + {$ifdef EnhancedRecordSupport} + Dist := Center.DistanceTo(T2DIntVector.Create(x, y)); + {$else} + Dist := Center.DistanceTo(x, y); + {$endif} + if Dist >= (Radius-1) then + Move(SrcPtr^, DstPtr^, 3); + inc(SrcPtr,3); + inc(DstPtr,3); + end; + end; ABitmap.LoadFromIntfImage(DestImg); SrcImg.Destroy; DestImg.Destroy; - end; - end; + end; + end; end; class procedure TGUITools.CopyRoundRect(ABuffer, ABitmap: TBitmap; SrcPoint, DstPoint: T2DIntVector; Width, Height, Radius: integer; ClipRect: T2DIntRect; LeftTopRound, RightTopRound, LeftBottomRound, RightBottomRound: boolean); - begin -if (ABuffer.PixelFormat<>pf24bit) or (ABitmap.PixelFormat<>pf24bit) then - raise exception.create('TSpkGUITools.CopyBackground: Tylko 24-bitowe bitmapy s¹ akceptowane!'); + if (ABuffer.PixelFormat <> pf24Bit) or (ABitmap.PixelFormat <> pf24Bit) then + raise Exception.Create('TSpkGUITools.CopyBackground: Only 24 bit bitmaps are accepted!'); -// Sprawdzamy poprawnoœæ -if Radius<0 then - exit; + if Radius < 0 then + exit; -if (Radius>Width div 2) or (Radius>Height div 2) then exit; + if (Radius > Width div 2) or (Radius > Height div 2) then + exit; -if (ABuffer.width=0) or (ABuffer.height=0) or - (ABitmap.width=0) or (ABitmap.height=0) then exit; + if (ABuffer.Width = 0) or (ABuffer.Height = 0) or + (ABitmap.Width = 0) or (ABitmap.Height = 0) then exit; -{$REGION 'Wype³niamy prostok¹ty'} -// Góra -CopyRectangle(ABuffer, - ABitmap, - {$ifdef EnhancedRecordSupport} - T2DIntPoint.create(SrcPoint.x + radius, SrcPoint.y), - T2DIntPoint.create(DstPoint.x + radius, DstPoint.y), - {$else} - Create2DIntPoint(SrcPoint.x + radius, SrcPoint.y), - Create2DIntPoint(DstPoint.x + radius, DstPoint.y), - {$endif} - width - 2*radius, - radius, - ClipRect); -// Dó³ -CopyRectangle(ABuffer, - ABitmap, - {$IFDEF EnhancedRecordSupport} - T2DIntPoint.create(SrcPoint.x + radius, SrcPoint.y + height - radius), - T2DIntPoint.create(DstPoint.x + radius, DstPoint.y + height - radius), - {$ELSE} - Create2DIntPoint(SrcPoint.x + radius, SrcPoint.y + height - radius), - Create2DIntPoint(DstPoint.x + radius, DstPoint.y + height - radius), - {$ENDIF} - width - 2*radius, - radius, - ClipRect); -// Œrodek -CopyRectangle(ABuffer, - ABitmap, - {$IFDEF EnhancedRecordSupport} - T2DIntPoint.create(SrcPoint.x, SrcPoint.y + radius), - T2DIntPoint.create(DstPoint.x, DstPoint.y + radius), - {$ELSE} - Create2DIntPoint(SrcPoint.x, SrcPoint.y + radius), - Create2DIntPoint(DstPoint.x, DstPoint.y + radius), - {$ENDIF} - width, - height - 2*radius, - ClipRect); + {$REGION 'We fill the rectangles'} + // Mountain /???? + // Góra + CopyRectangle(ABuffer, + ABitmap, + {$ifdef EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x + Radius, SrcPoint.y), + T2DIntPoint.Create(DstPoint.x + Radius, DstPoint.y), + {$else} + Create2DIntPoint(SrcPoint.x + Radius, SrcPoint.y), + Create2DIntPoint(DstPoint.x + Radius, DstPoint.y), + {$endif} + Width - 2*Radius, + Radius, + ClipRect); + // Down + // Dó³ + CopyRectangle(ABuffer, + ABitmap, + {$IFDEF EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x + Radius, SrcPoint.y + Height - Radius), + T2DIntPoint.Create(DstPoint.x + Radius, DstPoint.y + Height - Radius), + {$ELSE} + Create2DIntPoint(SrcPoint.x + Radius, SrcPoint.y + Height - Radius), + Create2DIntPoint(DstPoint.x + Radius, DstPoint.y + Height - Radius), + {$ENDIF} + Width - 2*Radius, + Radius, + ClipRect); + // Agent (???) + // Œrodek + CopyRectangle(ABuffer, + ABitmap, + {$IFDEF EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x, SrcPoint.y + Radius), + T2DIntPoint.Create(DstPoint.x, DstPoint.y + Radius), + {$ELSE} + Create2DIntPoint(SrcPoint.x, SrcPoint.y + Radius), + Create2DIntPoint(DstPoint.x, DstPoint.y + Radius), + {$ENDIF} + Width, + Height - 2*Radius, + ClipRect); {$ENDREGION} -// Wype³niamy naro¿niki - -{$REGION 'Lewy górny'} -if LeftTopRound then - TGUITools.CopyRoundCorner(ABuffer, - ABitmap, - {$IFDEF EnhancedRecordSupport} - T2DIntPoint.Create(SrcPoint.x, SrcPoint.y), - T2DIntPoint.Create(DstPoint.x, DstPoint.y), - {$ELSE} - Create2DIntPoint(SrcPoint.x, SrcPoint.y), - Create2DIntPoint(DstPoint.x, DstPoint.y), - {$ENDIF} - Radius, - cpLeftTop, - ClipRect, - true) -else - TGUITools.CopyCorner(ABuffer, - ABitmap, - {$IFDEF EnhancedRecordSupport} - T2DIntPoint.Create(SrcPoint.x, SrcPoint.y), - T2DIntPoint.Create(DstPoint.x, DstPoint.y), - {$ELSE} - Create2DIntPoint(SrcPoint.x, SrcPoint.y), - Create2DIntPoint(DstPoint.x, DstPoint.y), - {$ENDIF} - Radius, - ClipRect); + // We fill the corners +{$REGION 'Left upper'} + if LeftTopRound then + TGUITools.CopyRoundCorner(ABuffer, + ABitmap, + {$IFDEF EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x, SrcPoint.y), + T2DIntPoint.Create(DstPoint.x, DstPoint.y), + {$ELSE} + Create2DIntPoint(SrcPoint.x, SrcPoint.y), + Create2DIntPoint(DstPoint.x, DstPoint.y), + {$ENDIF} + Radius, + cpLeftTop, + ClipRect, + true) + else + TGUITools.CopyCorner(ABuffer, + ABitmap, + {$IFDEF EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x, SrcPoint.y), + T2DIntPoint.Create(DstPoint.x, DstPoint.y), + {$ELSE} + Create2DIntPoint(SrcPoint.x, SrcPoint.y), + Create2DIntPoint(DstPoint.x, DstPoint.y), + {$ENDIF} + Radius, + ClipRect); {$ENDREGION} -{$REGION 'Prawy górny'} -if RightTopRound then - TGUITools.CopyRoundCorner(ABuffer, - ABitmap, - {$IFDEF EnhancedRecordSupport} - T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y), - T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y), - {$ELSE} - Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y), - Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y), - {$ENDIF} - Radius, - cpRightTop, - ClipRect, - true) -else - TGUITools.CopyCorner(ABuffer, - ABitmap, - {$IFDEF EnhancedRecordSupport} - T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y), - T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y), - {$ELSE} - Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y), - Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y), - {$ENDIF} - Radius, - ClipRect); +{$REGION 'Right upper'} + if RightTopRound then + TGUITools.CopyRoundCorner(ABuffer, + ABitmap, + {$IFDEF EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y), + T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y), + {$ELSE} + Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y), + Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y), + {$ENDIF} + Radius, + cpRightTop, + ClipRect, + true) + else + TGUITools.CopyCorner(ABuffer, + ABitmap, + {$IFDEF EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y), + T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y), + {$ELSE} + Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y), + Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y), + {$ENDIF} + Radius, + ClipRect); {$ENDREGION} -{$REGION 'Lewy dolny'} -if LeftBottomRound then - TGUITools.CopyRoundCorner(ABuffer, - ABitmap, - {$IFDEF EnhancedRecordSupport} - T2DIntPoint.Create(SrcPoint.x, SrcPoint.y + Height - Radius), - T2DIntPoint.Create(DstPoint.x, DstPoint.y + Height - Radius), - {$ELSE} - Create2DIntPoint(SrcPoint.x, SrcPoint.y + Height - Radius), - Create2DIntPoint(DstPoint.x, DstPoint.y + Height - Radius), - {$ENDIF} - Radius, - cpLeftBottom, - ClipRect, - true) -else - TGUITools.CopyCorner(ABuffer, - ABitmap, - {$IFDEF EnhancedRecordSupport} - T2DIntPoint.Create(SrcPoint.x, SrcPoint.y + Height - Radius), - T2DIntPoint.Create(DstPoint.x, DstPoint.y + Height - Radius), - {$ELSE} - Create2DIntPoint(SrcPoint.x, SrcPoint.y + Height - Radius), - Create2DIntPoint(DstPoint.x, DstPoint.y + Height - Radius), - {$ENDIF} - Radius, - ClipRect); +{$REGION 'Left bottom'} + if LeftBottomRound then + TGUITools.CopyRoundCorner(ABuffer, + ABitmap, + {$IFDEF EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x, SrcPoint.y + Height - Radius), + T2DIntPoint.Create(DstPoint.x, DstPoint.y + Height - Radius), + {$ELSE} + Create2DIntPoint(SrcPoint.x, SrcPoint.y + Height - Radius), + Create2DIntPoint(DstPoint.x, DstPoint.y + Height - Radius), + {$ENDIF} + Radius, + cpLeftBottom, + ClipRect, + true) + else + TGUITools.CopyCorner(ABuffer, + ABitmap, + {$IFDEF EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x, SrcPoint.y + Height - Radius), + T2DIntPoint.Create(DstPoint.x, DstPoint.y + Height - Radius), + {$ELSE} + Create2DIntPoint(SrcPoint.x, SrcPoint.y + Height - Radius), + Create2DIntPoint(DstPoint.x, DstPoint.y + Height - Radius), + {$ENDIF} + Radius, + ClipRect); {$ENDREGION} -{$REGION 'Prawy dolny'} -if RightBottomRound then - TGUITools.CopyRoundCorner(ABuffer, - ABitmap, - {$IFDEF EnhancedRecordSupport} - T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius), - T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius), - {$ELSE} - Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius), - Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius), - {$ENDIF} - Radius, - cpRightBottom, - ClipRect, - true) -else - TGUITools.CopyCorner(ABuffer, - ABitmap, - {$IFDEF EnhancedRecordSupport} - T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius), - T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius), - {$ELSE} - Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius), - Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius), - {$ENDIF} - Radius, - ClipRect); +{$REGION 'Right bottom'} + if RightBottomRound then + TGUITools.CopyRoundCorner(ABuffer, + ABitmap, + {$IFDEF EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius), + T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius), + {$ELSE} + Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius), + Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius), + {$ENDIF} + Radius, + cpRightBottom, + ClipRect, + true) + else + TGUITools.CopyCorner(ABuffer, + ABitmap, + {$IFDEF EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius), + T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius), + {$ELSE} + Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius), + Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius), + {$ENDIF} + Radius, + ClipRect); {$ENDREGION'} end; class procedure TGUITools.CopyRoundRect(ABuffer : TBitmap; ABitmap: TBitmap; SrcPoint, DstPoint: T2DIntVector; Width, Height, Radius: integer; LeftTopRound, RightTopRound, LeftBottomRound, RightBottomRound: boolean); - begin -if (ABuffer.PixelFormat<>pf24bit) or (ABitmap.PixelFormat<>pf24bit) then - raise exception.create('TSpkGUITools.CopyBackground: Tylko 24-bitowe bitmapy s¹ akceptowane!'); + if (ABuffer.PixelFormat <> pf24bit) or (ABitmap.PixelFormat <> pf24bit) then + raise exception.create('TSpkGUITools.CopyBackground: Only 24 bit bitmaps are accepted!'); -// Sprawdzamy poprawnoœæ -if Radius<0 then - exit; + if Radius < 0 then + exit; -if (Radius>Width div 2) or (Radius>Height div 2) then exit; + if (Radius > Width div 2) or (Radius > Height div 2) then + exit; -if (ABuffer.width=0) or (ABuffer.height=0) or - (ABitmap.width=0) or (ABitmap.height=0) then exit; + if (ABuffer.Width = 0) or (ABuffer.Height = 0) or + (ABitmap.Width = 0) or (ABitmap.Height = 0) then exit; -{$REGION 'Wype³niamy prostok¹ty'} -// Góra -CopyRectangle(ABuffer, - ABitmap, - {$IFDEF EnhancedRecordSupport} - T2DIntPoint.create(SrcPoint.x + radius, SrcPoint.y), - T2DIntPoint.create(DstPoint.x + radius, DstPoint.y), - {$ELSE} - Create2DIntPoint(SrcPoint.x + radius, SrcPoint.y), - Create2DIntPoint(DstPoint.x + radius, DstPoint.y), - {$ENDIF} - width - 2*radius, - radius); -// Dó³ -CopyRectangle(ABuffer, - ABitmap, - {$IFDEF EnhancedRecordSupport} - T2DIntPoint.create(SrcPoint.x + radius, SrcPoint.y + height - radius), - T2DIntPoint.create(DstPoint.x + radius, DstPoint.y + height - radius), - {$ELSE} - Create2DIntPoint(SrcPoint.x + radius, SrcPoint.y + height - radius), - Create2DIntPoint(DstPoint.x + radius, DstPoint.y + height - radius), - {$ENDIF} - width - 2*radius, - radius); -// Œrodek -CopyRectangle(ABuffer, - ABitmap, - {$IFDEF EnhancedRecordSupport} - T2DIntPoint.create(SrcPoint.x, SrcPoint.y + radius), - T2DIntPoint.create(DstPoint.x, DstPoint.y + radius), - {$ELSE} - Create2DIntPoint(SrcPoint.x, SrcPoint.y + radius), - Create2DIntPoint(DstPoint.x, DstPoint.y + radius), - {$ENDIF} - width, - height - 2*radius); +{$REGION 'We fill the rectangles'} + // Góra + CopyRectangle(ABuffer, + ABitmap, + {$IFDEF EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x + Radius, SrcPoint.y), + T2DIntPoint.Create(DstPoint.x + Radius, DstPoint.y), + {$ELSE} + Create2DIntPoint(SrcPoint.x + Radius, SrcPoint.y), + Create2DIntPoint(DstPoint.x + Radius, DstPoint.y), + {$ENDIF} + Width - 2*Radius, + Radius); + // Dó³ + CopyRectangle(ABuffer, + ABitmap, + {$IFDEF EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x + Radius, SrcPoint.y + Height - radius), + T2DIntPoint.Create(DstPoint.x + Radius, DstPoint.y + Height - radius), + {$ELSE} + Create2DIntPoint(SrcPoint.x + Radius, SrcPoint.y + Height - radius), + Create2DIntPoint(DstPoint.x + Radius, DstPoint.y + Height - radius), + {$ENDIF} + Width - 2*Radius, + Radius); + // Œrodek + CopyRectangle(ABuffer, + ABitmap, + {$IFDEF EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x, SrcPoint.y + Radius), + T2DIntPoint.Create(DstPoint.x, DstPoint.y + Radius), + {$ELSE} + Create2DIntPoint(SrcPoint.x, SrcPoint.y + Radius), + Create2DIntPoint(DstPoint.x, DstPoint.y + Radius), + {$ENDIF} + Width, + Height - 2*Radius); {$ENDREGION} -// Wype³niamy naro¿niki -{$REGION 'Lewy górny'} -if LeftTopRound then - TGUITools.CopyRoundCorner(ABuffer, - ABitmap, - {$IFDEF EnhancedRecordSupport} - T2DIntPoint.Create(SrcPoint.x, SrcPoint.y), - T2DIntPoint.Create(DstPoint.x, DstPoint.y), - {$ELSE} - Create2DIntPoint(SrcPoint.x, SrcPoint.y), - Create2DIntPoint(DstPoint.x, DstPoint.y), - {$ENDIF} - Radius, - cpLeftTop, - true) -else - TGUITools.CopyCorner(ABuffer, - ABitmap, - {$IFDEF EnhancedRecordSupport} - T2DIntPoint.Create(SrcPoint.x, SrcPoint.y), - T2DIntPoint.Create(DstPoint.x, DstPoint.y), - {$ELSE} - Create2DIntPoint(SrcPoint.x, SrcPoint.y), - Create2DIntPoint(DstPoint.x, DstPoint.y), - {$ENDIF} - Radius); + // We fill the corners +{$REGION 'Left upper'} + if LeftTopRound then + TGUITools.CopyRoundCorner(ABuffer, + ABitmap, + {$IFDEF EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x, SrcPoint.y), + T2DIntPoint.Create(DstPoint.x, DstPoint.y), + {$ELSE} + Create2DIntPoint(SrcPoint.x, SrcPoint.y), + Create2DIntPoint(DstPoint.x, DstPoint.y), + {$ENDIF} + Radius, + cpLeftTop, + true) + else + TGUITools.CopyCorner(ABuffer, + ABitmap, + {$IFDEF EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x, SrcPoint.y), + T2DIntPoint.Create(DstPoint.x, DstPoint.y), + {$ELSE} + Create2DIntPoint(SrcPoint.x, SrcPoint.y), + Create2DIntPoint(DstPoint.x, DstPoint.y), + {$ENDIF} + Radius); {$ENDREGION} -{$REGION 'Prawy górny'} -if RightTopRound then - TGUITools.CopyRoundCorner(ABuffer, - ABitmap, - {$IFDEF EnhancedRecordSupport} - T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y), - T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y), - {$ELSE} - Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y), - Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y), - {$ENDIF} - Radius, - cpRightTop, - true) -else - TGUITools.CopyCorner(ABuffer, - ABitmap, - {$IFDEF EnhancedRecordSupport} - T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y), - T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y), - {$ELSE} - Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y), - Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y), - {$ENDIF} - Radius); +{$REGION 'Right upper'} + if RightTopRound then + TGUITools.CopyRoundCorner(ABuffer, + ABitmap, + {$IFDEF EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y), + T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y), + {$ELSE} + Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y), + Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y), + {$ENDIF} + Radius, + cpRightTop, + true) + else + TGUITools.CopyCorner(ABuffer, + ABitmap, + {$IFDEF EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y), + T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y), + {$ELSE} + Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y), + Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y), + {$ENDIF} + Radius); {$ENDREGION} -{$REGION 'Lewy dolny'} -if LeftBottomRound then - TGUITools.CopyRoundCorner(ABuffer, - ABitmap, - {$IFDEF EnhancedRecordSupport} - T2DIntPoint.Create(SrcPoint.x, SrcPoint.y + Height - Radius), - T2DIntPoint.Create(DstPoint.x, DstPoint.y + Height - Radius), - {$ELSE} - Create2DIntPoint(SrcPoint.x, SrcPoint.y + Height - Radius), - Create2DIntPoint(DstPoint.x, DstPoint.y + Height - Radius), - {$ENDIF} - Radius, - cpLeftBottom, - true) -else - TGUITools.CopyCorner(ABuffer, - ABitmap, - {$IFDEF EnhancedRecordSupport} - T2DIntPoint.Create(SrcPoint.x, SrcPoint.y + Height - Radius), - T2DIntPoint.Create(DstPoint.x, DstPoint.y + Height - Radius), - {$ELSE} - Create2DIntPoint(SrcPoint.x, SrcPoint.y + Height - Radius), - Create2DIntPoint(DstPoint.x, DstPoint.y + Height - Radius), - {$ENDIF} - Radius); +{$REGION 'Left bottom'} + if LeftBottomRound then + TGUITools.CopyRoundCorner(ABuffer, + ABitmap, + {$IFDEF EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x, SrcPoint.y + Height - Radius), + T2DIntPoint.Create(DstPoint.x, DstPoint.y + Height - Radius), + {$ELSE} + Create2DIntPoint(SrcPoint.x, SrcPoint.y + Height - Radius), + Create2DIntPoint(DstPoint.x, DstPoint.y + Height - Radius), + {$ENDIF} + Radius, + cpLeftBottom, + true) + else + TGUITools.CopyCorner(ABuffer, + ABitmap, + {$IFDEF EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x, SrcPoint.y + Height - Radius), + T2DIntPoint.Create(DstPoint.x, DstPoint.y + Height - Radius), + {$ELSE} + Create2DIntPoint(SrcPoint.x, SrcPoint.y + Height - Radius), + Create2DIntPoint(DstPoint.x, DstPoint.y + Height - Radius), + {$ENDIF} + Radius); {$ENDREGION} -{$REGION 'Prawy dolny'} -if RightBottomRound then - TGUITools.CopyRoundCorner(ABuffer, - ABitmap, - {$IFDEF EnhancedRecordSupport} - T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius), - T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius), - {$ELSE} - Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius), - Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius), - {$ENDIF} - Radius, - cpRightBottom, - true) -else - TGUITools.CopyCorner(ABuffer, - ABitmap, - {$IFDEF EnhancedRecordSupport} - T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius), - T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius), - {$ELSE} - Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius), - Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius), - {$ENDIF} - Radius); -{$ENDREGION'} +{$REGION 'Right bottom'} + if RightBottomRound then + TGUITools.CopyRoundCorner(ABuffer, + ABitmap, + {$IFDEF EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius), + T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius), + {$ELSE} + Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius), + Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius), + {$ENDIF} + Radius, + cpRightBottom, + true) + else + TGUITools.CopyCorner(ABuffer, + ABitmap, + {$IFDEF EnhancedRecordSupport} + T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius), + T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius), + {$ELSE} + Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius), + Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius), + {$ENDIF} + Radius); +{$ENDREGION} end; class procedure TGUITools.CopyRectangle(ABuffer, ABitmap: TBitmap; SrcPoint, DstPoint: T2DIntVector; Width, Height: integer); - -var BufferRect, BitmapRect : T2DIntRect; - SrcRect, DstRect : T2DIntRect; - ClippedSrcRect : T2DIntRect; - Offset : T2DIntVector; - y: Integer; - SrcLine: Pointer; - DstLine: Pointer; - SrcImg: TLazIntfImage; - DestImg: TLazIntfImage; - +var + BufferRect, BitmapRect: T2DIntRect; + SrcRect, DstRect: T2DIntRect; + ClippedSrcRect: T2DIntRect; + Offset: T2DIntVector; + y: Integer; + SrcLine: Pointer; + DstLine: Pointer; + SrcImg: TLazIntfImage; + DestImg: TLazIntfImage; begin -if (ABuffer.PixelFormat<>pf24bit) or (ABitmap.PixelFormat<>pf24bit) then - raise exception.create('TSpkGUITools.CopyRoundCorner: Tylko 24-bitowe bitmapy s¹ akceptowane!'); + if (ABuffer.PixelFormat <> pf24Bit) or (ABitmap.PixelFormat <> pf24Bit) then + raise exception.create('TSpkGUITools.CopyRoundCorner: Only 24 bit bitmaps are accepted!'); -// Sprawdzanie poprawnoœci -if (Width<1) or (Height<1) then - exit; + // Validation + if (Width < 1) or (Height < 1) then + exit; -if (ABuffer.width=0) or (ABuffer.height=0) or - (ABitmap.width=0) or (ABitmap.height=0) then exit; + if (ABuffer.Width = 0) or (ABuffer.Height = 0) or + (ABitmap.Width = 0) or (ABitmap.Height = 0) then exit; -{$IFDEF EnhancedRecordSupport} -// Przycinamy Ÿród³owy rect do obszaru Ÿród³owej bitmapy -BufferRect:=T2DIntRect.create(0, 0, ABuffer.width-1, ABuffer.height-1); + {$IFDEF EnhancedRecordSupport} + // Truncate the source rect to the source bitmap + BufferRect := T2DIntRect.Create(0, 0, ABuffer.Width-1, ABuffer.Height-1); + if not BufferRect.IntersectsWith( + T2DIntRect.Create(SrcPoint.x, SrcPoint.y, SrcPoint.x+Width-1, SrcPoint.y+Height-1), + SrcRect + ) + then + exit; -if not(BufferRect.IntersectsWith(T2DIntRect.create(SrcPoint.x, - SrcPoint.y, - SrcPoint.x+Width-1, - SrcPoint.y+Height-1), - SrcRect)) then exit; + // We cut the target rect to the target bitmap + BitmapRect := T2DIntRect.Create(0, 0, ABitmap.Width-1, ABitmap.Height-1); + if not BitmapRect.IntersectsWith( + T2DIntRect.Create(DstPoint.x, DstPoint.y, DstPoint.x+Width-1, DstPoint.y+Height-1), + DstRect + ) + then + exit; + {$ELSE} + // Truncate the source rect to the source bitmap + BufferRect.Create(0, 0, ABuffer.Width-1, ABuffer.Height-1); + if not BufferRect.IntersectsWith( + Create2DIntRect(SrcPoint.x, SrcPoint.y, SrcPoint.x+Width-1, SrcPoint.y+Height-1), + SrcRect + ) + then + exit; -// Przycinamy docelowy rect do obszaru docelowej bitmapy -BitmapRect:=T2DIntRect.create(0, 0, ABitmap.width-1, ABitmap.height-1); -if not(BitmapRect.IntersectsWith(T2DIntRect.create(DstPoint.x, - DstPoint.y, - DstPoint.x+Width-1, - DstPoint.y+Height-1), - DstRect)) then exit; -{$ELSE} -// Przycinamy Ÿród³owy rect do obszaru Ÿród³owej bitmapy -BufferRect.create(0, 0, ABuffer.width-1, ABuffer.height-1); - -if not(BufferRect.IntersectsWith(Create2DIntRect(SrcPoint.x, - SrcPoint.y, - SrcPoint.x+Width-1, - SrcPoint.y+Height-1), - SrcRect)) then exit; - -// Przycinamy docelowy rect do obszaru docelowej bitmapy -BitmapRect.create(0, 0, ABitmap.width-1, ABitmap.height-1); -if not(BitmapRect.IntersectsWith(Create2DIntRect(DstPoint.x, - DstPoint.y, - DstPoint.x+Width-1, - DstPoint.y+Height-1), - DstRect)) then exit; + // We cut the target rect to the target bitmap + BitmapRect.Create(0, 0, ABitmap.Width-1, ABitmap.Height-1); + if not BitmapRect.IntersectsWith( + Create2DIntRect(DstPoint.x, DstPoint.y, DstPoint.x+Width-1, DstPoint.y+Height-1), + DstRect + ) + then + exit; {$ENDIF} -// Liczymy offset Ÿród³owego do docelowego recta -Offset:=DstPoint - SrcPoint; + // We are counting the source offset to the target recta + Offset := DstPoint - SrcPoint; -// Sprawdzamy, czy na³o¿one na siebie recty: Ÿród³owy i docelowy przesuniêty o -// offset maj¹ jak¹œ czêœæ wspóln¹ -if not(SrcRect.IntersectsWith(DstRect - Offset, ClippedSrcRect)) then exit; + // Sprawdzamy, czy na³o¿one na siebie recty: Ÿród³owy i docelowy przesuniêty o + // offset maj¹ jak¹œ czêœæ wspóln¹ + // Google-translated: + // Verify that the rectangular overhead: source and target shifted by offset have some common + if not SrcRect.IntersectsWith(DstRect - Offset, ClippedSrcRect) then + exit; -// Jeœli jest cokolwiek do przetworzenia, wykonaj operacjê - if (ClippedSrcRect.left<=ClippedSrcRect.right) and (ClippedSrcRect.top<=ClippedSrcRect.bottom) then + // If there is anything to process, do the operation + if (ClippedSrcRect.Left <= ClippedSrcRect.Right) and + (ClippedSrcRect.Top <= ClippedSrcRect.Bottom) then begin SrcImg := ABuffer.CreateIntfImage; DestImg := ABitmap.CreateIntfImage; - for y := ClippedSrcRect.top to ClippedSrcRect.bottom do - begin - SrcLine:=SrcImg.GetDataLineStart(y); - DstLine:=DestImg.GetDataLineStart(y+Offset.y); - - Move(pointer(PtrInt(SrcLine) + 3*ClippedSrcRect.left)^, - pointer(PtrInt(DstLine) + 3*(ClippedSrcRect.left + Offset.x))^, - 3*ClippedSrcRect.Width); - end; - ABitmap.LoadFromIntfImage(DestImg); - SrcImg.Destroy; - DestImg.Destroy; + for y := ClippedSrcRect.Top to ClippedSrcRect.Bottom do + begin + SrcLine := SrcImg.GetDataLineStart(y); + DstLine := DestImg.GetDataLineStart(y+Offset.y); + Move(pointer(PtrInt(SrcLine) + 3*ClippedSrcRect.Left)^, + pointer(PtrInt(DstLine) + 3*(ClippedSrcRect.Left + Offset.x))^, + 3*ClippedSrcRect.Width); + end; + ABitmap.LoadFromIntfImage(DestImg); + SrcImg.Destroy; + DestImg.Destroy; end; end; -class procedure TGUITools.CopyCorner(ABuffer : TBitmap; ABitmap: TBitmap; +class procedure TGUITools.CopyCorner(ABuffer, ABitmap: TBitmap; SrcPoint, DstPoint: T2DIntVector; Radius: integer); - begin -CopyRectangle(ABuffer, ABitmap, SrcPoint, DstPoint, Radius, Radius); + CopyRectangle(ABuffer, ABitmap, SrcPoint, DstPoint, Radius, Radius); end; class procedure TGUITools.CopyCorner(ABuffer, ABitmap: TBitmap; SrcPoint, DstPoint: T2DIntVector; Radius: integer; ClipRect: T2DIntRect); begin -CopyRectangle(ABuffer, ABitmap, SrcPoint, DstPoint, Radius, Radius, ClipRect); + CopyRectangle(ABuffer, ABitmap, SrcPoint, DstPoint, Radius, Radius, ClipRect); end; class procedure TGUITools.CopyMaskRectangle(ABuffer, AMask, ABitmap: TBitmap; SrcPoint, DstPoint: T2DIntVector; Width, Height: integer); - -var BufferRect, BitmapRect : T2DIntRect; - SrcRect, DstRect : T2DIntRect; - ClippedSrcRect : T2DIntRect; - Offset : T2DIntVector; - y: Integer; - SrcLine: Pointer; - MaskLine: Pointer; - DstLine: Pointer; - SrcImg: TLazIntfImage; - MaskImg: TLazIntfImage; - DestImg: TLazIntfImage; - i: Integer; - +var + BufferRect, BitmapRect: T2DIntRect; + SrcRect, DstRect: T2DIntRect; + ClippedSrcRect: T2DIntRect; + Offset: T2DIntVector; + y: Integer; + SrcLine: Pointer; + MaskLine: Pointer; + DstLine: Pointer; + SrcImg: TLazIntfImage; + MaskImg: TLazIntfImage; + DestImg: TLazIntfImage; + i: Integer; begin -if (ABuffer.PixelFormat<>pf24bit) or (ABitmap.PixelFormat<>pf24bit) then - raise exception.create('TSpkGUITools.CopyRoundCorner: Tylko 24-bitowe bitmapy s¹ akceptowane!'); + if (ABuffer.PixelFormat <> pf24Bit) or (ABitmap.PixelFormat <> pf24Bit) then + raise Exception.Create('TSpkGUITools.CopyRoundCorner: Only 24 bit bitmaps are accepted!'); -if (AMask.PixelFormat<>pf8bit) then - raise exception.create('TSpkGUITools.CopyRoundCorner: Tylko 8-bitowe maski s¹ akceptowane!'); + if (AMask.PixelFormat <> pf8bit) then + raise Exception.Create('TSpkGUITools.CopyRoundCorner: Only 8-bit masks are accepted!'); -// Sprawdzanie poprawnoœci -if (Width<1) or (Height<1) then - exit; + // Validation + if (Width < 1) or (Height < 1) then + exit; -if (ABuffer.width=0) or (ABuffer.height=0) or - (ABitmap.width=0) or (ABitmap.height=0) then exit; + if (ABuffer.Width = 0) or (ABuffer.Height = 0) or + (ABitmap.Width = 0) or (ABitmap.Height = 0) then exit; -if (ABuffer.Width<>AMask.Width) or - (ABuffer.Height<>AMask.Height) then exit; + if (ABuffer.Width <> AMask.Width) or (ABuffer.Height <> AMask.Height) then + exit; -{$IFDEF EnhancedRecordSupport} -// Przycinamy Ÿród³owy rect do obszaru Ÿród³owej bitmapy -BufferRect:=T2DIntRect.create(0, 0, ABuffer.width-1, ABuffer.height-1); + {$IFDEF EnhancedRecordSupport} + // Truncate the source rect to the source bitmap + BufferRect := T2DIntRect.Create(0, 0, ABuffer.Width-1, ABuffer.Height-1); + if not BufferRect.IntersectsWith( + T2DIntRect.Create(SrcPoint.x, SrcPoint.y, SrcPoint.x+Width-1, SrcPoint.y+Height-1), + SrcRect + ) then + exit; + // We cut the target rect to the target bitmap + BitmapRect := T2DIntRect.Create(0, 0, ABitmap.Width-1, ABitmap.Height-1); + if not BitmapRect.IntersectsWith( + T2DIntRect.Create(DstPoint.x, DstPoint.y, DstPoint.x+Width-1, DstPoint.y+Height-1), + DstRect + ) then + exit; + {$ELSE} + // Truncate the source rect to the source bitmap + BufferRect.Create(0, 0, ABuffer.Width-1, ABuffer.Height-1); + if not BufferRect.IntersectsWith( + Create2DIntRect(SrcPoint.x, SrcPoint.y, SrcPoint.x+Width-1, SrcPoint.y+Height-1), + SrcRect + ) then + exit; + // Trim the target rect to the target bitmap + BitmapRect.Create(0, 0, ABitmap.Width-1, ABitmap.Height-1); + if not BitmapRect.IntersectsWith( + Create2DIntRect(DstPoint.x, DstPoint.y, DstPoint.x+Width-1, DstPoint.y+Height-1), + DstRect + ) then + exit; + {$ENDIF} -if not(BufferRect.IntersectsWith(T2DIntRect.create(SrcPoint.x, - SrcPoint.y, - SrcPoint.x+Width-1, - SrcPoint.y+Height-1), - SrcRect)) then exit; + // We are counting the source offset to the target recta + Offset := DstPoint - SrcPoint; -// Przycinamy docelowy rect do obszaru docelowej bitmapy -BitmapRect:=T2DIntRect.create(0, 0, ABitmap.width-1, ABitmap.height-1); -if not(BitmapRect.IntersectsWith(T2DIntRect.create(DstPoint.x, - DstPoint.y, - DstPoint.x+Width-1, - DstPoint.y+Height-1), - DstRect)) then exit; -{$ELSE} -// Przycinamy Ÿród³owy rect do obszaru Ÿród³owej bitmapy -BufferRect.create(0, 0, ABuffer.width-1, ABuffer.height-1); + // Sprawdzamy, czy na³o¿one na siebie recty: Ÿród³owy i docelowy przesuniêty o + // offset maj¹ jak¹œ czêœæ wspóln¹ + // Google-translated: + // We check that the rectangles that are superimposed on each other: + // source and target shifted by offset have some common + if not(SrcRect.IntersectsWith(DstRect - Offset, ClippedSrcRect)) then + exit; -if not(BufferRect.IntersectsWith(Create2DIntRect(SrcPoint.x, - SrcPoint.y, - SrcPoint.x+Width-1, - SrcPoint.y+Height-1), - SrcRect)) then exit; - -// Przycinamy docelowy rect do obszaru docelowej bitmapy -BitmapRect.create(0, 0, ABitmap.width-1, ABitmap.height-1); -if not(BitmapRect.IntersectsWith(Create2DIntRect(DstPoint.x, - DstPoint.y, - DstPoint.x+Width-1, - DstPoint.y+Height-1), - DstRect)) then exit; -{$ENDIF} - -// Liczymy offset Ÿród³owego do docelowego recta -Offset:=DstPoint - SrcPoint; - -// Sprawdzamy, czy na³o¿one na siebie recty: Ÿród³owy i docelowy przesuniêty o -// offset maj¹ jak¹œ czêœæ wspóln¹ -if not(SrcRect.IntersectsWith(DstRect - Offset, ClippedSrcRect)) then exit; - -// Jeœli jest cokolwiek do przetworzenia, wykonaj operacjê -if (ClippedSrcRect.left<=ClippedSrcRect.right) and (ClippedSrcRect.top<=ClippedSrcRect.bottom) then -begin - SrcImg := ABuffer.CreateIntfImage; - DestImg := ABitmap.CreateIntfImage; - MaskImg := AMask.CreateIntfImage; - for y := ClippedSrcRect.top to ClippedSrcRect.bottom do - begin - SrcLine:=SrcImg.GetDataLineStart(y); - SrcLine:=pointer(PtrInt(SrcLine) + 3 * ClippedSrcRect.left); - - MaskLine:=MaskImg.GetDataLineStart(y); - MaskLine:=pointer(PtrInt(MaskLine) + ClippedSrcRect.left); - - DstLine:=DestImg.GetDataLineStart(y+Offset.y); - DstLine:=pointer(PtrInt(DstLine) + 3 * (ClippedSrcRect.left + Offset.x)); - - for i := 0 to ClippedSrcRect.Width - 1 do - begin - if PByte(MaskLine)^<128 then - Move(SrcLine^,DstLine^,3); - - SrcLine:=pointer(PtrInt(SrcLine)+3); - DstLine:=pointer(PtrInt(DstLine)+3); - MaskLine:=pointer(PtrInt(MaskLine)+1); - end; - end; - ABitmap.LoadFromIntfImage(DestImg); - DestImg.Destroy; - SrcImg.Destroy; - MaskImg.Destroy; -end; + // If there is anything to process, do the operation + if (ClippedSrcRect.Left <= ClippedSrcRect.Right) and + (ClippedSrcRect.Top <= ClippedSrcRect.Bottom) then + begin + SrcImg := ABuffer.CreateIntfImage; + DestImg := ABitmap.CreateIntfImage; + MaskImg := AMask.CreateIntfImage; + for y := ClippedSrcRect.Top to ClippedSrcRect.Bottom do + begin + SrcLine := SrcImg.GetDataLineStart(y); + SrcLine := pointer(PtrInt(SrcLine) + 3 * ClippedSrcRect.left); + MaskLine := MaskImg.GetDataLineStart(y); + MaskLine := pointer(PtrInt(MaskLine) + ClippedSrcRect.left); + DstLine := DestImg.GetDataLineStart(y+Offset.y); + DstLine := pointer(PtrInt(DstLine) + 3 * (ClippedSrcRect.left + Offset.x)); + for i := 0 to ClippedSrcRect.Width - 1 do + begin + if PByte(MaskLine)^ < 128 then + Move(SrcLine^, DstLine^, 3); + SrcLine := pointer(PtrInt(SrcLine)+3); + DstLine := pointer(PtrInt(DstLine)+3); + MaskLine := pointer(PtrInt(MaskLine)+1); + end; + end; + ABitmap.LoadFromIntfImage(DestImg); + DestImg.Destroy; + SrcImg.Destroy; + MaskImg.Destroy; + end; end; class procedure TGUITools.CopyMaskRectangle(ABuffer, AMask, ABitmap: TBitmap; SrcPoint, DstPoint: T2DIntVector; Width, Height: integer; ClipRect: T2DIntRect); - -var BufferRect, BitmapRect : T2DIntRect; - SrcRect, DstRect : T2DIntRect; - ClippedSrcRect, ClippedDstRect : T2DIntRect; - Offset : T2DIntVector; - y: Integer; - SrcImg: TLazIntfImage; - MaskImg: TLazIntfImage; - DestImg: TLazIntfImage; - SrcLine: Pointer; - DstLine: Pointer; - i: Integer; - MaskLine: Pointer; - +var + BufferRect, BitmapRect: T2DIntRect; + SrcRect, DstRect: T2DIntRect; + ClippedSrcRect, ClippedDstRect: T2DIntRect; + Offset: T2DIntVector; + y: Integer; + SrcImg: TLazIntfImage; + MaskImg: TLazIntfImage; + DestImg: TLazIntfImage; + SrcLine: Pointer; + DstLine: Pointer; + i: Integer; + MaskLine: Pointer; begin -if (ABuffer.PixelFormat<>pf24bit) or (ABitmap.PixelFormat<>pf24bit) then - raise exception.create('TSpkGUITools.CopyMaskRectangle: Tylko 24-bitowe bitmapy s¹ akceptowane!'); -if AMask.PixelFormat<>pf8bit then - raise exception.create('TSpkGUITools.CopyMaskRectangle: Tylko 8-bitowe maski s¹ akceptowane!'); + if (ABuffer.PixelFormat <> pf24Bit) or (ABitmap.PixelFormat <> pf24Bit) then + raise Exception.Create('TSpkGUITools.CopyMaskRectangle: Only 24 bit bitmaps are accepted!'); + if AMask.PixelFormat<>pf8bit then + raise Exception.Create('TSpkGUITools.CopyMaskRectangle: Only 8-bit masks are accepted!'); -// Sprawdzanie poprawnoœci -if (Width<1) or (Height<1) then - exit; + // Validation + if (Width < 1) or (Height < 1) then + exit; -if (ABuffer.width=0) or (ABuffer.height=0) or - (ABitmap.width=0) or (ABitmap.height=0) then exit; + if (ABuffer.Width = 0) or (ABuffer.Height = 0) or + (ABitmap.Width = 0) or (ABitmap.Height = 0) then exit; -if (ABuffer.Width<>AMask.Width) or - (ABuffer.Height<>AMask.Height) then - raise exception.create('TSpkGUITools.CopyMaskRectangle: Maska ma nieprawid³owe rozmiary!'); + if (ABuffer.Width <> AMask.Width) or + (ABuffer.Height <> AMask.Height) + then + raise Exception.Create('TSpkGUITools.CopyMaskRectangle: The mask has incorrect dimensions!'); -{$IFDEF EnhancedRecordSupport} -// Przycinamy Ÿród³owy rect do obszaru Ÿród³owej bitmapy -BufferRect:=T2DIntRect.create(0, 0, ABuffer.width-1, ABuffer.height-1); -if not(BufferRect.IntersectsWith(T2DIntRect.create(SrcPoint.x, - SrcPoint.y, - SrcPoint.x+Width-1, - SrcPoint.y+Height-1), - SrcRect)) then exit; + {$IFDEF EnhancedRecordSupport} + // Truncate the source rect to the source bitmap + BufferRect := T2DIntRect.Create(0, 0, ABuffer.Width-1, ABuffer.Height-1); + if not BufferRect.IntersectsWith( + T2DIntRect.Create(SrcPoint.x, SrcPoint.y, SrcPoint.x+Width-1, SrcPoint.y+Height-1), + SrcRect + ) + then + exit; // Przycinamy docelowy rect do obszaru docelowej bitmapy BitmapRect:=T2DIntRect.create(0, 0, ABitmap.width-1, ABitmap.height-1); @@ -1562,31 +1569,29 @@ var cr,cb,cg: byte; begin if ABitmap.PixelFormat<>pf24bit then - raise exception.create('TSpkGUITools.DrawAARoundCorner: Bitmapa musi byæ w trybie 24-bitowym!'); + raise Exception.Create('TSpkGUITools.DrawAARoundCorner: Bitmap must be in 24-bit mode!'); - // Sprawdzamy poprawnoœæ if Radius < 1 then exit; - if (ABitmap.Width=0) or (ABitmap.Height=0) then + if (ABitmap.Width = 0) or (ABitmap.Height = 0) then exit; {$IFDEF EnhancedRecordSupport} - // �?ród³owy rect... - OrgCornerRect:=T2DIntRect.create(Point.x, - Point.y, - Point.x + radius - 1, - Point.y + radius - 1); - - // ...przycinamy do rozmiarów bitmapy - BitmapRect := T2DIntRect.create(0, 0, ABitmap.Width-1, ABitmap.Height-1); + // Source rect... + OrgCornerRect := T2DIntRect.Create( + Point.x, Point.y, Point.x + radius - 1, Point.y + radius - 1 + ); + // ... cut to size bitmap + BitmapRect := T2DIntRect.Create( + 0, 0, ABitmap.Width-1, ABitmap.Height-1); {$ELSE} - // �?ród³owy rect... + // Source rect... OrgCornerRect.Create(Point.x, Point.y, Point.x + radius - 1, Point.y + radius - 1); - // ...przycinamy do rozmiarów bitmapy + // ... cut to size bitmap BitmapRect.Create(0, 0, ABitmap.Width-1, ABitmap.Height-1); {$ENDIF} @@ -1597,11 +1602,13 @@ begin if not UnClippedCornerRect.IntersectsWith(ClipRect, CornerRect) then exit; - // Jeœli nie ma czego rysowaæ, wychodzimy - if (CornerRect.Left > CornerRect.Right) or (CornerRect.Top > CornerRect.Bottom) then + // If there is nothing to draw, we leave + if (CornerRect.Left > CornerRect.Right) or + (CornerRect.Top > CornerRect.Bottom) + then exit; - // Szukamy œrodka ³uku - zale¿nie od rodzaju naro¿nika + // We seek the center of the arc - depending on the type of corner {$IFDEF EnhancedRecordSupport} case CornerPos of cpLeftTop: @@ -1655,574 +1662,535 @@ end; class procedure TGUITools.DrawAARoundCorner(ACanvas: TCanvas; Point: T2DIntVector; Radius: integer; CornerPos: TCornerPos; Color: TColor); - -var Center : T2DIntVector; - OrgColor : TColor; - x, y : integer; - RadiusDist : double; - CornerRect: T2DIntRect; - +var + Center: T2DIntVector; + OrgColor: TColor; + x, y: integer; + RadiusDist: double; + CornerRect: T2DIntRect; begin -// Sprawdzamy poprawnoœæ -if Radius<1 then - exit; + if Radius<1 then + exit; -{$IFDEF EnhancedRecordSupport} -// �?ród³owy rect... -CornerRect:=T2DIntRect.create(Point.x, - Point.y, - Point.x + radius - 1, - Point.y + radius - 1); + {$IFDEF EnhancedRecordSupport} + // Source rect + CornerRect := T2DIntRect.Create( + Point.x, Point.y, Point.x + radius - 1, Point.y + radius - 1 + ); + // We seek the center of the arc - depending on the type of corner + case CornerPos of + cpLeftTop: + Center := T2DIntVector.Create(Point.x + radius - 1, Point.y + Radius - 1); + cpRightTop: + Center := T2DIntVector.Create(Point.x, Point.y + Radius - 1); + cpLeftBottom: + Center := T2DIntVector.Create(Point.x + radius - 1, Point.y); + cpRightBottom: + Center := T2DIntVector.Create(Point.x, Point.y); + end; + {$ELSE} + // Source rect + CornerRect.Create(Point.x, Point.y, Point.x + radius - 1, Point.y + radius - 1); + // We seek the center of the arc - depending on the type of corner + case CornerPos of + cpLeftTop: + Center.Create(Point.x + radius - 1, Point.y + Radius - 1); + cpRightTop: + Center.Create(Point.x, Point.y + Radius - 1); + cpLeftBottom: + Center.Create(Point.x + radius - 1, Point.y); + cpRightBottom: + Center.Create(Point.x, Point.y); + end; + {$ENDIF} -// Szukamy œrodka ³uku - zale¿nie od rodzaju naro¿nika -case CornerPos of - cpLeftTop: Center:=T2DIntVector.create(Point.x + radius - 1, Point.y + Radius - 1); - cpRightTop: Center:=T2DIntVector.create(Point.x, Point.y + Radius - 1); - cpLeftBottom: Center:=T2DIntVector.Create(Point.x + radius - 1, Point.y); - cpRightBottom: Center:=T2DIntVector.Create(Point.x, Point.y); -end; -{$ELSE} -// �?ród³owy rect... -CornerRect.create(Point.x, - Point.y, - Point.x + radius - 1, - Point.y + radius - 1); + Color := ColorToRGB(Color); -// Szukamy œrodka ³uku - zale¿nie od rodzaju naro¿nika -case CornerPos of - cpLeftTop: Center.create(Point.x + radius - 1, Point.y + Radius - 1); - cpRightTop: Center.create(Point.x, Point.y + Radius - 1); - cpLeftBottom: Center.Create(Point.x + radius - 1, Point.y); - cpRightBottom: Center.Create(Point.x, Point.y); -end; -{$ENDIF} - -Color:=ColorToRGB(Color); - -for y := CornerRect.top to CornerRect.bottom do + for y := CornerRect.Top to CornerRect.Bottom do + begin + for x := CornerRect.Left to CornerRect.Right do begin - for x := CornerRect.left to CornerRect.right do - begin - {$IFDEF EnhancedRecordSupport} - RadiusDist:=1 - abs((Radius - 1) - Center.DistanceTo(T2DIntVector.create(x, y))); - {$ELSE} - RadiusDist:=1 - abs((Radius - 1) - Center.DistanceTo(x, y)); - {$ENDIF} - if RadiusDist>0 then - begin - OrgColor:=ACanvas.Pixels[x, y]; - ACanvas.Pixels[x, y]:=TColorTools.Shade(OrgColor, Color, RadiusDist); - end; - end; + {$IFDEF EnhancedRecordSupport} + RadiusDist := 1 - abs((Radius - 1) - Center.DistanceTo(T2DIntVector.Create(x, y))); + {$ELSE} + RadiusDist := 1 - abs((Radius - 1) - Center.DistanceTo(x, y)); + {$ENDIF} + if RadiusDist > 0 then + begin + OrgColor := ACanvas.Pixels[x, y]; + ACanvas.Pixels[x, y] := TColorTools.Shade(OrgColor, Color, RadiusDist); + end; end; + end; end; class procedure TGUITools.DrawAARoundCorner(ACanvas: TCanvas; Point: T2DIntVector; Radius: integer; CornerPos: TCornerPos; Color: TColor; ClipRect: T2DIntRect); - -var UseOrgClipRgn : boolean; - ClipRgn : HRGN; - OrgRgn : HRGN; - +var + UseOrgClipRgn: boolean; + ClipRgn: HRGN; + OrgRgn: HRGN; begin -// Zapamiêtywanie oryginalnego ClipRgn i ustawianie nowego -SaveClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn); + // Store the original ClipRgn and set a new one + SaveClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn); -ClipRgn:=CreateRectRgn(ClipRect.left, ClipRect.Top, ClipRect.Right+1, ClipRect.Bottom+1); -if UseOrgClipRgn then - CombineRgn(ClipRgn, ClipRgn, OrgRgn, RGN_AND); + ClipRgn := CreateRectRgn(ClipRect.Left, ClipRect.Top, ClipRect.Right+1, ClipRect.Bottom+1); + if UseOrgClipRgn then + CombineRgn(ClipRgn, ClipRgn, OrgRgn, RGN_AND); -SelectClipRgn(ACanvas.Handle, ClipRgn); + SelectClipRgn(ACanvas.Handle, ClipRgn); -DrawAARoundCorner(ACanvas, Point, Radius, CornerPos, Color); + DrawAARoundCorner(ACanvas, Point, Radius, CornerPos, Color); -// Przywracanie poprzedniego ClipRgn i usuwanie wykorzystanych regionów -RestoreClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn); -DeleteObject(ClipRgn); + // Restores previous ClipRgn and removes used regions + RestoreClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn); + DeleteObject(ClipRgn); end; class procedure TGUITools.DrawAARoundFrame(ABitmap: TBitmap; Rect: T2DIntRect; Radius: integer; Color: TColor; ClipRect: T2DIntRect); begin -if ABitmap.PixelFormat<>pf24bit then - raise exception.create('TGUITools.DrawAARoundFrame: Bitmapa musi byæ w trybie 24-bitowym!'); + if ABitmap.PixelFormat <> pf24Bit then + raise Exception.Create('TGUITools.DrawAARoundFrame: Bitmap must be in 24-bit mode!'); -if (Radius<1) then - exit; + if Radius < 1 then + exit; -if (Radius>Rect.width div 2) or (Radius>Rect.height div 2) then - exit; + if (Radius > Rect.Width div 2) or (Radius > Rect.Height div 2) then + exit; -// DrawAARoundCorner jest zabezpieczony przed rysowaniem poza obszarem -{$IFDEF EnhancedRecordSupport} -DrawAARoundCorner(ABitmap, T2DIntVector.create(Rect.left, Rect.top), Radius, cpLeftTop, Color, ClipRect); -DrawAARoundCorner(ABitmap, T2DIntVector.create(Rect.right - Radius + 1, Rect.top), Radius, cpRightTop, Color, ClipRect); -DrawAARoundCorner(ABitmap, T2DIntVector.create(Rect.left, Rect.bottom - Radius + 1), Radius, cpLeftBottom, Color, ClipRect); -DrawAARoundCorner(ABitmap, T2DIntVector.create(Rect.Right - Radius + 1, Rect.Bottom - Radius + 1), Radius, cpRightBottom, Color, ClipRect); -{$ELSE} -DrawAARoundCorner(ABitmap, Create2DIntVector(Rect.left, Rect.top), Radius, cpLeftTop, Color, ClipRect); -DrawAARoundCorner(ABitmap, Create2DIntVector(Rect.right - Radius + 1, Rect.top), Radius, cpRightTop, Color, ClipRect); -DrawAARoundCorner(ABitmap, Create2DIntVector(Rect.left, Rect.bottom - Radius + 1), Radius, cpLeftBottom, Color, ClipRect); -DrawAARoundCorner(ABitmap, Create2DIntVector(Rect.Right - Radius + 1, Rect.Bottom - Radius + 1), Radius, cpRightBottom, Color, ClipRect); -{$ENDIF} + // DrawAARoundCorner is protected against drawing outside the area + {$IFDEF EnhancedRecordSupport} + DrawAARoundCorner(ABitmap, T2DIntVector.Create(Rect.Left, Rect.Top), Radius, cpLeftTop, Color, ClipRect); + DrawAARoundCorner(ABitmap, T2DIntVector.Create(Rect.Right - Radius + 1, Rect.Top), Radius, cpRightTop, Color, ClipRect); + DrawAARoundCorner(ABitmap, T2DIntVector.Create(Rect.Left, Rect.Bottom - Radius + 1), Radius, cpLeftBottom, Color, ClipRect); + DrawAARoundCorner(ABitmap, T2DIntVector.Create(Rect.Right - Radius + 1, Rect.Bottom - Radius + 1), Radius, cpRightBottom, Color, ClipRect); + {$ELSE} + DrawAARoundCorner(ABitmap, Create2DIntVector(Rect.Left, Rect.Top), Radius, cpLeftTop, Color, ClipRect); + DrawAARoundCorner(ABitmap, Create2DIntVector(Rect.Right - Radius + 1, Rect.Top), Radius, cpRightTop, Color, ClipRect); + DrawAARoundCorner(ABitmap, Create2DIntVector(Rect.Left, Rect.Bottom - Radius + 1), Radius, cpLeftBottom, Color, ClipRect); + DrawAARoundCorner(ABitmap, Create2DIntVector(Rect.Right - Radius + 1, Rect.Bottom - Radius + 1), Radius, cpRightBottom, Color, ClipRect); + {$ENDIF} -ABitmap.Canvas.Pen.color:=Color; -ABitmap.Canvas.pen.style:=psSolid; + ABitmap.Canvas.Pen.Color := Color; + ABitmap.Canvas.pen.Style := psSolid; -// Draw*Line s¹ zabezpieczone przed rysowaniem poza obszarem -DrawVLine(ABitmap, Rect.left, rect.top + Radius, rect.bottom - Radius, Color, ClipRect); -DrawVLine(ABitmap, Rect.right, rect.top + Radius, rect.bottom - Radius, Color, ClipRect); -DrawHLine(ABitmap, Rect.left + Radius, Rect.right - Radius, rect.top, Color, ClipRect); -DrawHLine(ABitmap, Rect.left + Radius, Rect.right - Radius, rect.bottom, Color, ClipRect); + // Draw*Line is protected against drawing outside the area + DrawVLine(ABitmap, Rect.Left, Rect.top + Radius, Rect.Bottom - Radius, Color, ClipRect); + DrawVLine(ABitmap, Rect.Right, Rect.top + Radius, Rect.Bottom - Radius, Color, ClipRect); + DrawHLine(ABitmap, Rect.Left + Radius, Rect.Right - Radius, Rect.Top, Color, ClipRect); + DrawHLine(ABitmap, Rect.Left + Radius, Rect.Right - Radius, Rect.Bottom, Color, ClipRect); end; class procedure TGUITools.DrawAARoundFrame(ABitmap: TBitmap; Rect: T2DIntRect; Radius: integer; Color: TColor); - begin -if ABitmap.PixelFormat<>pf24bit then - raise exception.create('TGUITools.DrawAARoundFrame: Bitmapa musi byæ w trybie 24-bitowym!'); + if ABitmap.PixelFormat <> pf24Bit then + raise Exception.Create('TGUITools.DrawAARoundFrame: Bitmap must be in 24-bit mode!'); -if (Radius<1) then - exit; + if Radius < 1 then + exit; -if (Radius>Rect.width div 2) or (Radius>Rect.height div 2) then - exit; + if (Radius > Rect.Width div 2) or (Radius > Rect.Height div 2) then + exit; -// DrawAARoundCorner jest zabezpieczony przed rysowaniem poza obszarem -{$IFDEF EnhancedRecordSupport} -DrawAARoundCorner(ABitmap, T2DIntVector.create(Rect.left, Rect.top), Radius, cpLeftTop, Color); -DrawAARoundCorner(ABitmap, T2DIntVector.create(Rect.right - Radius + 1, Rect.top), Radius, cpRightTop, Color); -DrawAARoundCorner(ABitmap, T2DIntVector.create(Rect.left, Rect.bottom - Radius + 1), Radius, cpLeftBottom, Color); -DrawAARoundCorner(ABitmap, T2DIntVector.create(Rect.Right - Radius + 1, Rect.Bottom - Radius + 1), Radius, cpRightBottom, Color); -{$ELSE} -DrawAARoundCorner(ABitmap, Create2DIntVector(Rect.left, Rect.top), Radius, cpLeftTop, Color); -DrawAARoundCorner(ABitmap, Create2DIntVector(Rect.right - Radius + 1, Rect.top), Radius, cpRightTop, Color); -DrawAARoundCorner(ABitmap, Create2DIntVector(Rect.left, Rect.bottom - Radius + 1), Radius, cpLeftBottom, Color); -DrawAARoundCorner(ABitmap, Create2DIntVector(Rect.Right - Radius + 1, Rect.Bottom - Radius + 1), Radius, cpRightBottom, Color); -{$ENDIF} + // DrawAARoundCorner is protected against drawing outside the area + {$IFDEF EnhancedRecordSupport} + DrawAARoundCorner(ABitmap, T2DIntVector.Create(Rect.Left, Rect.Top), Radius, cpLeftTop, Color); + DrawAARoundCorner(ABitmap, T2DIntVector.Create(Rect.Right - Radius + 1, Rect.Top), Radius, cpRightTop, Color); + DrawAARoundCorner(ABitmap, T2DIntVector.Create(Rect.Left, Rect.Bottom - Radius + 1), Radius, cpLeftBottom, Color); + DrawAARoundCorner(ABitmap, T2DIntVector.Create(Rect.Right - Radius + 1, Rect.Bottom - Radius + 1), Radius, cpRightBottom, Color); + {$ELSE} + DrawAARoundCorner(ABitmap, Create2DIntVector(Rect.Left, Rect.Top), Radius, cpLeftTop, Color); + DrawAARoundCorner(ABitmap, Create2DIntVector(Rect.Right - Radius + 1, Rect.top), Radius, cpRightTop, Color); + DrawAARoundCorner(ABitmap, Create2DIntVector(Rect.Left, Rect.Bottom - Radius + 1), Radius, cpLeftBottom, Color); + DrawAARoundCorner(ABitmap, Create2DIntVector(Rect.Right - Radius + 1, Rect.Bottom - Radius + 1), Radius, cpRightBottom, Color); + {$ENDIF} -ABitmap.canvas.Pen.color:=Color; -ABitmap.canvas.pen.style:=psSolid; + ABitmap.Canvas.Pen.Color := Color; + ABitmap.Canvas.pen.Style := psSolid; -// Draw*Line s¹ zabezpieczone przed rysowaniem poza obszarem -DrawVLine(ABitmap, Rect.left, rect.top + Radius, rect.bottom - Radius, Color); -DrawVLine(ABitmap, Rect.right, rect.top + Radius, rect.bottom - Radius, Color); -DrawHLine(ABitmap, Rect.left + Radius, Rect.right - Radius, rect.top, Color); -DrawHLine(ABitmap, Rect.left + Radius, Rect.right - Radius, rect.bottom, Color); + // Draw*Line is protected against drawing outside the area + DrawVLine(ABitmap, Rect.Left, Rect.Top + Radius, Rect.bottom - Radius, Color); + DrawVLine(ABitmap, Rect.Right, Rect.Top + Radius, Rect.bottom - Radius, Color); + DrawHLine(ABitmap, Rect.Left + Radius, Rect.Right - Radius, Rect.Top, Color); + DrawHLine(ABitmap, Rect.Left + Radius, Rect.Right - Radius, Rect.Bottom, Color); end; class procedure TGUITools.DrawFitWText(ABitmap: TBitmap; x1, x2, y: integer; const AText: string; TextColor: TColor; Align : TAlignment); - -var tw : integer; - s : string; - +var + tw: integer; + s: string; begin -with ABitmap.Canvas do - begin - s:=AText; - tw:=TextWidth(s); - // Jeœli tekst siê zmieœci, rysujemy - if tw<=(x2-x1+1) then - case Align of - taLeftJustify : TextOut(x1,y,AText); - taRightJustify : TextOut(x2-tw+1,y,AText); - taCenter : TextOut(x1 + ((x2-x1 - tw) div 2), y, AText); - end - else - begin - while (s<>'') and (tw>(x2-x1+1)) do - begin - delete(s,length(s),1); - tw:=TextWidth(s+'...'); - end; - if tw<=(x2-x1+1) then - TextOut(x1, y, s+'...'); - end; - end; + with ABitmap.Canvas do + begin + s := AText; + tw := TextWidth(s); + if tw <= x2-x1+1 then + case Align of + taLeftJustify : TextOut(x1,y,AText); + taRightJustify : TextOut(x2-tw+1,y,AText); + taCenter : TextOut(x1 + ((x2-x1 - tw) div 2), y, AText); + end else + begin + while (s <> '') and (tw > x2-x1+1) do + begin + Delete(s, Length(s), 1); + tw := TextWidth(s+'...'); + end; + if tw <= x2-x1+1 then + TextOut(x1, y, s+'...'); + end; + end; end; class procedure TGUITools.DrawHLine(ACanvas: TCanvas; x1, x2, y: integer; Color: TColor); - -var tmp : integer; - begin -if x20 do - begin - if MarkPos>1 then - begin - // Rysowanie tekstu przed wyró¿nionym - ACanvas.Font.Style:=ACanvas.Font.Style - [fsBold]; - s:=copy(TextToDraw, 1, MarkPos-1); - - ACanvas.TextOut(x1, y, s); - inc(x1, ACanvas.TextWidth(s)+1); - - delete(TextToDraw, 1, MarkPos-1); - delete(BaseText, 1, MarkPos-1); - end; - - // Rysowanie wyró¿nionego tekstu - ACanvas.Font.Style:=ACanvas.Font.Style + [fsBold]; - s:=copy(TextToDraw, 1, MarkTextLength); + MarkPos := pos(MarkText, BaseText); + while MarkPos > 0 do + begin + if MarkPos > 1 then + begin + // Drawing text before highlighted + ACanvas.Font.Style := ACanvas.Font.Style - [fsBold]; + s := copy(TextToDraw, 1, MarkPos-1); ACanvas.TextOut(x1, y, s); inc(x1, ACanvas.TextWidth(s)+1); - delete(TextToDraw, 1, MarkTextLength); - delete(BaseText, 1, MarkTextLength); + Delete(TextToDraw, 1, MarkPos-1); + Delete(BaseText, 1, MarkPos-1); + end; - MarkPos:=pos(MarkText, BaseText); - end; + // Drawing highlighted text + ACanvas.Font.Style := ACanvas.Font.Style + [fsBold]; + s := copy(TextToDraw, 1, MarkTextLength); -if Length(BaseText)>0 then - begin - ACanvas.Font.Style:=ACanvas.Font.Style - [fsBold]; - ACanvas.TextOut(x1, y, TextToDraw); - end; + ACanvas.TextOut(x1, y, s); + inc(x1, ACanvas.TextWidth(s)+1); + + Delete(TextToDraw, 1, MarkTextLength); + Delete(BaseText, 1, MarkTextLength); + + MarkPos := pos(MarkText, BaseText); + end; + + if Length(BaseText) > 0 then + begin + ACanvas.Font.Style := ACanvas.Font.Style - [fsBold]; + ACanvas.TextOut(x1, y, TextToDraw); + end; end; class procedure TGUITools.DrawImage(ACanvas: TCanvas; Imagelist: TImageList; ImageIndex: integer; Point: T2DIntVector); begin -ImageList.Draw(ACanvas, Point.x, Point.y, ImageIndex); + ImageList.Draw(ACanvas, Point.x, Point.y, ImageIndex); end; class procedure TGUITools.DrawOutlinedText(ACanvas: TCanvas; x, y: integer; const AText: string; TextColor, OutlineColor: TColor); begin -with Acanvas do - begin - brush.style:=bsClear; - font.color:=OutlineColor; - TextOut(x-1, y-1, AText); - TextOut(x, y-1, AText); - TextOut(x+1, y-1, AText); - TextOut(x-1, y, AText); - TextOut(x+1, y, AText); - TextOut(x-1, y+1, AText); - TextOut(x, y+1, AText); - TextOut(x+1, y+1, AText); + with ACanvas do + begin + Brush.Style := bsClear; + Font.Color := OutlineColor; + TextOut(x-1, y-1, AText); + TextOut(x, y-1, AText); + TextOut(x+1, y-1, AText); + TextOut(x-1, y, AText); + TextOut(x+1, y, AText); + TextOut(x-1, y+1, AText); + TextOut(x, y+1, AText); + TextOut(x+1, y+1, AText); - font.color:=TextColor; - TextOut(x, y, AText); - end; + Font.Color := TextColor; + TextOut(x, y, AText); + end; end; class procedure TGUITools.DrawOutlinedText(ACanvas: TCanvas; x, y: integer; const AText: string; TextColor, OutlineColor: TColor; ClipRect: T2DIntRect); - -var WinAPIClipRect : TRect; - +var + WinAPIClipRect: TRect; begin -WinAPIClipRect:=ClipRect.ForWinAPI; -with ACanvas do - begin - brush.style:=bsClear; - font.color:=OutlineColor; - TextRect(WinAPIClipRect, x-1, y-1, AText); - TextRect(WinAPIClipRect, x, y-1, AText); - TextRect(WinAPIClipRect, x+1, y-1, AText); - TextRect(WinAPIClipRect, x-1, y, AText); - TextRect(WinAPIClipRect, x+1, y, AText); - TextRect(WinAPIClipRect, x-1, y+1, AText); - TextRect(WinAPIClipRect, x, y+1, AText); - TextRect(WinAPIClipRect, x+1, y+1, AText); + WinAPIClipRect := ClipRect.ForWinAPI; + with ACanvas do + begin + Brush.Style := bsClear; + Font.Color := OutlineColor; + TextRect(WinAPIClipRect, x-1, y-1, AText); + TextRect(WinAPIClipRect, x, y-1, AText); + TextRect(WinAPIClipRect, x+1, y-1, AText); + TextRect(WinAPIClipRect, x-1, y, AText); + TextRect(WinAPIClipRect, x+1, y, AText); + TextRect(WinAPIClipRect, x-1, y+1, AText); + TextRect(WinAPIClipRect, x, y+1, AText); + TextRect(WinAPIClipRect, x+1, y+1, AText); - font.color:=TextColor; - TextRect(WinAPIClipRect, x, y, AText); - end; + Font.Color := TextColor; + TextRect(WinAPIClipRect, x, y, AText); + end; end; class procedure TGUITools.DrawHLine(ABitmap: TBitmap; x1, x2, y: integer; Color: TColor); - -var LineRect : T2DIntRect; - BitmapRect : T2DIntRect; - tmp: Integer; - +var + LineRect: T2DIntRect; + BitmapRect: T2DIntRect; begin -if ABitmap.PixelFormat<>pf24bit then - raise exception.create('TGUITools.DrawHLine: Bitmapa musi byæ w trybie 24-bitowym!'); + if ABitmap.PixelFormat <> pf24Bit then + raise Exception.Create('TGUITools.DrawHLine: Bitmap must be in 24-bit mode'); + EnsureOrder(x1, x2); -if x2pf24bit then - raise exception.create('TGUITools.DrawHLine: Bitmapa musi byæ w trybie 24-bitowym!'); + if ABitmap.PixelFormat<>pf24bit then + raise Exception.Create('TGUITools.DrawHLine: Bitmap must be in 24-bit mode!'); + EnsureOrder(x1, x2); -if x2 0 then begin - // Przywracanie poprzedniego ClipRgn i usuwanie wykorzystanych regionów + // Restores previous ClipRgn and removes used regions RestoreClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn); DeleteObject(RoundRgn); end; @@ -2367,103 +2337,107 @@ end; class procedure TGUITools.DrawOutlinedText(ABitmap: TBitmap; x, y: integer; const AText: string; TextColor, OutlineColor: TColor); begin -with ABitmap.canvas do - begin - brush.style:=bsClear; - font.color:=OutlineColor; - TextOut(x-1, y-1, AText); - TextOut(x, y-1, AText); - TextOut(x+1, y-1, AText); - TextOut(x-1, y, AText); - TextOut(x+1, y, AText); - TextOut(x-1, y+1, AText); - TextOut(x, y+1, AText); - TextOut(x+1, y+1, AText); + with ABitmap.Canvas do + begin + Brush.Style := bsClear; + Font.Color := OutlineColor; + TextOut(x-1, y-1, AText); + TextOut(x, y-1, AText); + TextOut(x+1, y-1, AText); + TextOut(x-1, y, AText); + TextOut(x+1, y, AText); + TextOut(x-1, y+1, AText); + TextOut(x, y+1, AText); + TextOut(x+1, y+1, AText); - font.color:=TextColor; - TextOut(x, y, AText); - end; + Font.Color := TextColor; + TextOut(x, y, AText); + end; end; class procedure TGUITools.DrawText(ABitmap: TBitmap; x, y: integer; const AText: string; TextColor: TColor; ClipRect: T2DIntRect); - -var WinAPIClipRect : TRect; - +var + WinAPIClipRect : TRect; begin -WinAPIClipRect:=ClipRect.ForWinAPI; -with ABitmap.canvas do - begin - brush.style:=bsClear; - font.color:=TextColor; - TextRect(WinAPIClipRect, x, y, AText); - end; + WinAPIClipRect := ClipRect.ForWinAPI; + with ABitmap.Canvas do + begin + Brush.Style := bsClear; + Font.Color := TextColor; + TextRect(WinAPIClipRect, x, y, AText); + end; end; -class procedure TGUITools.DrawFitWOutlinedText(ABitmap: TBitmap; x1, x2, y: integer; - const AText: string; TextColor, OutlineColor: TColor; Align : TAlignment); - -var tw : integer; - s : string; - -begin -with ABitmap.Canvas do - begin - s:=AText; - tw:=TextWidth(s) + 2; - // Jeœli tekst siê zmieœci, rysujemy - if tw<=(x2-x1+1) then - case Align of - taLeftJustify : TGUITools.DrawOutlinedText(ABitmap,x1, y, AText, TextColor, OutlineColor); - taRightJustify : TGUITools.DrawOutlinedText(ABitmap,x2-tw+1, y, AText, TextColor, OutlineColor); - taCenter : TGUITools.DrawOutlinedText(ABitmap,x1 + ((x2-x1 - tw) div 2), y, AText, TextColor, OutlineColor); - end - else - begin - while (s<>'') and (tw>(x2-x1+1)) do - begin - delete(s,length(s),1); - tw:=TextWidth(s+'...')+2; - end; - if tw<=(x2-x1+1) then - TGUITools.DrawOutlinedText(ABitmap, x1, y, s+'...', TextColor, OutlineColor); - end; - end; -end; - -class procedure TGUITools.DrawFitWOutlinedText(ACanvas: TCanvas; x1, x2, - y: integer; const AText: string; TextColor, OutlineColor: TColor; +class procedure TGUITools.DrawFitWOutlinedText(ABitmap: TBitmap; + x1, x2, y: integer; const AText: string; TextColor, OutlineColor: TColor; Align: TAlignment); - -var tw : integer; - s : string; - +var + tw: integer; + s: string; begin -with ACanvas do - begin - s:=AText; - tw:=TextWidth(s) + 2; - // Jeœli tekst siê zmieœci, rysujemy - if tw<=(x2-x1+1) then - case Align of - taLeftJustify : TGUITools.DrawOutlinedText(ACanvas,x1, y, AText, TextColor, OutlineColor); - taRightJustify : TGUITools.DrawOutlinedText(ACanvas,x2-tw+1, y, AText, TextColor, OutlineColor); - taCenter : TGUITools.DrawOutlinedText(ACanvas,x1 + ((x2-x1 - tw) div 2), y, AText, TextColor, OutlineColor); - end - else - begin - while (s<>'') and (tw>(x2-x1+1)) do - begin - delete(s,length(s),1); - tw:=TextWidth(s+'...')+2; - end; - if tw<=(x2-x1+1) then - TGUITools.DrawOutlinedText(ACanvas, x1, y, s+'...', TextColor, OutlineColor); - end; - end; + with ABitmap.Canvas do + begin + s := AText; + tw := TextWidth(s) + 2; + if tw <= x2 - x1 + 1 then + case Align of + taLeftJustify: + TGUITools.DrawOutlinedText(ABitmap,x1, y, AText, TextColor, OutlineColor); + taRightJustify: + TGUITools.DrawOutlinedText(ABitmap,x2-tw+1, y, AText, TextColor, OutlineColor); + taCenter: + TGUITools.DrawOutlinedText(ABitmap,x1 + ((x2-x1 - tw) div 2), y, AText, TextColor, OutlineColor); + end + else + begin + while (s <> '') and (tw > x2 - x1 + 1) do + begin + Delete(s, Length(s), 1); + tw := TextWidth(s + '...') + 2; + end; + if tw <= x2 - x1 + 1 then + TGUITools.DrawOutlinedText(ABitmap, x1, y, s+'...', TextColor, OutlineColor); + end; + end; end; -class procedure TGUITools.FillGradientRectangle(ACanvas: TCanvas; Rect: T2DIntRect; ColorFrom: TColor; ColorTo: TColor; GradientKind: TBackgroundKind); +class procedure TGUITools.DrawFitWOutlinedText(ACanvas: TCanvas; + x1, x2, y: integer; const AText: string; TextColor, OutlineColor: TColor; + Align: TAlignment); +var + tw: integer; + s: string; +begin + with ACanvas do + begin + s := AText; + tw := TextWidth(s) + 2; + if tw <= x2 - x1 + 1 then + case Align of + taLeftJustify: + TGUITools.DrawOutlinedText(ACanvas,x1, y, AText, TextColor, OutlineColor); + taRightJustify: + TGUITools.DrawOutlinedText(ACanvas,x2-tw+1, y, AText, TextColor, OutlineColor); + taCenter: + TGUITools.DrawOutlinedText(ACanvas,x1 + (x2-x1 - tw) div 2, y, AText, TextColor, OutlineColor); + end + else + begin + while (s <> '') and (tw > x2 - x1 + 1) do + begin + Delete(s, Length(s), 1); + tw := TextWidth(s + '...') + 2; + end; + if tw <= x2 - x1 + 1 then + TGUITools.DrawOutlinedText(ACanvas, x1, y, s+'...', TextColor, OutlineColor); + end; + end; +end; + +class procedure TGUITools.FillGradientRectangle(ACanvas: TCanvas; + Rect: T2DIntRect; ColorFrom: TColor; ColorTo: TColor; + GradientKind: TBackgroundKind); var Mesh: array of GRADIENTRECT; GradientVertice: array of TRIVERTEX; @@ -2478,7 +2452,7 @@ begin end; bkVerticalGradient, bkHorizontalGradient: begin - setlength(GradientVertice, 2); + SetLength(GradientVertice, 2); with GradientVertice[0] do begin x := Rect.left; @@ -2497,7 +2471,7 @@ begin Blue := GetBValue(ColorTo) shl 8; Alpha := 255 shl 8; end; - setlength(Mesh, 1); + SetLength(Mesh, 1); Mesh[0].UpperLeft := 0; Mesh[0].LowerRight := 1; if GradientKind = bkVerticalGradient then @@ -2508,8 +2482,7 @@ begin bkConcave: begin ConcaveColor:=TColorTools.Brighten(ColorFrom, 20); - - setlength(GradientVertice, 4); + SetLength(GradientVertice, 4); with GradientVertice[0] do begin x := Rect.left; @@ -2546,7 +2519,7 @@ begin Blue := GetBValue(ColorFrom) shl 8; Alpha := 255 shl 8; end; - setlength(Mesh, 2); + SetLength(Mesh, 2); Mesh[0].UpperLeft := 0; Mesh[0].LowerRight := 1; Mesh[1].UpperLeft := 2; @@ -2558,355 +2531,305 @@ end; class procedure TGUITools.DrawFitWText(ACanvas: TCanvas; x1, x2, y: integer; const AText: string; TextColor: TColor; Align: TAlignment); - -var tw : integer; - s : string; - +var + tw: integer; + s: string; begin -with ACanvas do - begin - s:=AText; - tw:=TextWidth(s); - // Jeœli tekst siê zmieœci, rysujemy - if tw<=(x2-x1+1) then - case Align of - taLeftJustify : TextOut(x1,y,AText); - taRightJustify : TextOut(x2-tw+1,y,AText); - taCenter : TextOut(x1 + ((x2-x1 - tw) div 2), y, AText); - end - else - begin - while (s<>'') and (tw>(x2-x1+1)) do - begin - delete(s,length(s),1); - tw:=TextWidth(s+'...'); - end; - if tw<=(x2-x1+1) then - TextOut(x1, y, s+'...'); - end; - end; + with ACanvas do + begin + s := AText; + tw := TextWidth(s); + // We draw if the text is changed + if tw <= x2 - x1 + 1 then + case Align of + taLeftJustify : TextOut(x1, y, AText); + taRightJustify : TextOut(x2-tw+1, y, AText); + taCenter : TextOut(x1 + (x2-x1 - tw) div 2, y, AText); + end + else + begin + while (s <> '') and (tw > x2 - x1 + 1) do + begin + Delete(s, Length(s), 1); + tw := TextWidth(s + '...'); + end; + if tw <= x2 - x1 + 1 then + TextOut(x1, y, s + '...'); + end; + end; end; class procedure TGUITools.RenderBackground(ABuffer: TBitmap; Rect: T2DIntRect; Color1, Color2: TColor; BackgroundKind: TBackgroundKind); - -var TempRect : T2DIntRect; - +var + TempRect: T2DIntRect; begin -if ABuffer.PixelFormat<>pf24bit then - raise exception.create('TGUITools.RenderBackground: Bitmapa musi byæ w trybie 24-bitowym!'); -if (rect.left>rect.right) or (rect.top>rect.bottom) then - exit; - -// Zarówno metoda FillRect jak i WinAPI'owe rysowanie gradientów jest -// zabezpieczone przed rysowaniem poza obszarem p³ótna. -case BackgroundKind of - bkSolid: begin - ABuffer.Canvas.brush.Color:=Color1; - ABuffer.Canvas.brush.style:=bsSolid; - ABuffer.Canvas.Fillrect(Rect.ForWinAPI); - end; - bkVerticalGradient: begin - TGradientTools.VGradient(ABuffer.canvas, Color1, Color2, Rect.ForWinAPI); - end; - bkHorizontalGradient: begin - TGradientTools.HGradient(ABuffer.canvas, Color1, Color2, Rect.ForWinAPI); - end; - bkConcave: begin - {$IFDEF EnhancedRecordSupport} - TempRect:=T2DIntRect.create(rect.Left, - rect.top, - rect.right, - rect.Top + (rect.bottom - rect.top) div 4); - {$ELSE} - TempRect.create(rect.Left, - rect.top, - rect.right, - rect.Top + (rect.bottom - rect.top) div 4); - {$ENDIF} - TGradientTools.VGradient(ABuffer.Canvas, - Color1, - TColorTools.Shade(Color1, Color2, 20), - TempRect.ForWinAPI - ); - - {$IFDEF EnhancedRecordSupport} - TempRect:=T2DIntRect.create(rect.Left, - rect.top + (rect.bottom - rect.top) div 4 + 1, - rect.right, - rect.bottom); - {$ELSE} - TempRect.create(rect.Left, - rect.top + (rect.bottom - rect.top) div 4 + 1, - rect.right, - rect.bottom); - {$ENDIF} - TGradientTools.VGradient(ABuffer.Canvas, - Color2, - Color1, - TempRect.ForWinAPI - ); - end; -end; + if ABuffer.PixelFormat<>pf24bit then + raise Exception.Create('TGUITools.RenderBackground: Bitmap must be in 24-bit mode'); + if (Rect.Left > Rect.Right) or (Rect.Top > Rect.Bottom) then + exit; + // Both the FillRect method and the WinAPI gradient drawing are + // protected from drawing outside the canvas area. + case BackgroundKind of + bkSolid: + begin + ABuffer.Canvas.Brush.Color := Color1; + ABuffer.Canvas.Brush.Style := bsSolid; + ABuffer.Canvas.FillRect(Rect.ForWinAPI); + end; + bkVerticalGradient: + TGradientTools.VGradient(ABuffer.Canvas, Color1, Color2, Rect.ForWinAPI); + bkHorizontalGradient: + TGradientTools.HGradient(ABuffer.Canvas, Color1, Color2, Rect.ForWinAPI); + bkConcave: + begin + {$IFDEF EnhancedRecordSupport} + TempRect := T2DIntRect.Create( + {$ELSE} + TempRect.Create( + {$ENDIF} + Rect.Left, Rect.Top, Rect.Right, Rect.Top + (Rect.Bottom - Rect.Top) div 4 + ); + TGradientTools.VGradient(ABuffer.Canvas, Color1, TColorTools.Shade(Color1, Color2, 20), TempRect.ForWinAPI); + {$IFDEF EnhancedRecordSupport} + TempRect := T2DIntRect.Create( + {$ELSE} + TempRect.Create( + {$ENDIF} + Rect.Left, Rect.Top + (Rect.Bottom - Rect.Top) div 4 + 1, Rect.Right, Rect.Bottom + ); + TGradientTools.VGradient(ABuffer.Canvas, Color2, Color1, TempRect.ForWinAPI); + end; + end; // case end; class procedure TGUITools.RestoreClipRgn(DC: HDC; OrgRgnExists: boolean; var OrgRgn: HRGN); - begin -if OrgRgnExists then - SelectClipRgn(DC, OrgRgn) else - SelectClipRgn(DC, 0); -DeleteObject(OrgRgn); + if OrgRgnExists then + SelectClipRgn(DC, OrgRgn) else + SelectClipRgn(DC, 0); + DeleteObject(OrgRgn); end; class procedure TGUITools.SaveClipRgn(DC: HDC; var OrgRgnExists: boolean; var OrgRgn: HRGN); - -var i : integer; - +var + i: integer; begin -OrgRgn:=CreateRectRgn(0, 0, 1, 1); -i:=GetClipRgn(DC, OrgRgn); -OrgRgnExists:=(i=1); + OrgRgn := CreateRectRgn(0, 0, 1, 1); + i := GetClipRgn(DC, OrgRgn); + OrgRgnExists := (i=1); end; class procedure TGUITools.DrawText(ABitmap: TBitmap; x, y: integer; const AText: string; TextColor: TColor); begin -with ABitmap.canvas do - begin - brush.style:=bsClear; - font.color:=TextColor; - TextOut(x, y, AText); - end; + with ABitmap.Canvas do + begin + Brush.Style := bsClear; + Font.Color:= TextColor; + TextOut(x, y, AText); + end; end; class procedure TGUITools.DrawVLine(ABitmap: TBitmap; x, y1, y2: integer; Color: TColor); - -var LineRect : T2DIntRect; - BitmapRect : T2DIntRect; - tmp: Integer; - +var + LineRect: T2DIntRect; + BitmapRect: T2DIntRect; begin -if ABitmap.PixelFormat<>pf24bit then - raise exception.create('TGUITools.DrawHLine: Bitmapa musi byæ w trybie 24-bitowym!'); + if ABitmap.PixelFormat <> pf24bit then + raise Exception.Create('TGUITools.DrawHLine: Bitmap must be in 24-bit mode!'); -if y2pf24bit then - raise exception.create('TGUITools.DrawHLine: Bitmapa musi byæ w trybie 24-bitowym!'); + if ABitmap.PixelFormat <> pf24bit then + raise Exception.Create('TGUITools.DrawHLine: Bitmap must be in 24-bit mode!'); -if y2Rect.width div 2) or (Radius>Rect.height div 2) then - exit; + if (Radius > Rect.Width div 2) or (Radius > Rect.Height div 2) then + exit; -// DrawAARoundCorner jest zabezpieczony przed rysowaniem poza obszarem -{$IFDEF EnhancedRecordSupport} -DrawAARoundCorner(ACanvas, T2DIntVector.create(Rect.left, Rect.top), Radius, cpLeftTop, Color); -DrawAARoundCorner(ACanvas, T2DIntVector.create(Rect.right - Radius + 1, Rect.top), Radius, cpRightTop, Color); -DrawAARoundCorner(ACanvas, T2DIntVector.create(Rect.left, Rect.bottom - Radius + 1), Radius, cpLeftBottom, Color); -DrawAARoundCorner(ACanvas, T2DIntVector.create(Rect.Right - Radius + 1, Rect.Bottom - Radius + 1), Radius, cpRightBottom, Color); -{$ELSE} -DrawAARoundCorner(ACanvas, Create2DIntVector(Rect.left, Rect.top), Radius, cpLeftTop, Color); -DrawAARoundCorner(ACanvas, Create2DIntVector(Rect.right - Radius + 1, Rect.top), Radius, cpRightTop, Color); -DrawAARoundCorner(ACanvas, Create2DIntVector(Rect.left, Rect.bottom - Radius + 1), Radius, cpLeftBottom, Color); -DrawAARoundCorner(ACanvas, Create2DIntVector(Rect.Right - Radius + 1, Rect.Bottom - Radius + 1), Radius, cpRightBottom, Color); -{$ENDIF} + // DrawAARoundCorner is protected against drawing outside the area + {$IFDEF EnhancedRecordSupport} + DrawAARoundCorner(ACanvas, T2DIntVector.create(Rect.Left, Rect.Top), Radius, cpLeftTop, Color); + DrawAARoundCorner(ACanvas, T2DIntVector.create(Rect.Right - Radius + 1, Rect.Top), Radius, cpRightTop, Color); + DrawAARoundCorner(ACanvas, T2DIntVector.create(Rect.Left, Rect.Bottom - Radius + 1), Radius, cpLeftBottom, Color); + DrawAARoundCorner(ACanvas, T2DIntVector.create(Rect.Right - Radius + 1, Rect.Bottom - Radius + 1), Radius, cpRightBottom, Color); + {$ELSE} + DrawAARoundCorner(ACanvas, Create2DIntVector(Rect.Left, Rect.Top), Radius, cpLeftTop, Color); + DrawAARoundCorner(ACanvas, Create2DIntVector(Rect.Right - Radius + 1, Rect.Top), Radius, cpRightTop, Color); + DrawAARoundCorner(ACanvas, Create2DIntVector(Rect.Left, Rect.Bottom - Radius + 1), Radius, cpLeftBottom, Color); + DrawAARoundCorner(ACanvas, Create2DIntVector(Rect.Right - Radius + 1, Rect.Bottom - Radius + 1), Radius, cpRightBottom, Color); + {$ENDIF} -ACanvas.Pen.color:=Color; -ACanvas.pen.style:=psSolid; + ACanvas.Pen.color := Color; + ACanvas.pen.style := psSolid; -// Draw*Line s¹ zabezpieczone przed rysowaniem poza obszarem -DrawVLine(ACanvas, Rect.left, rect.top + Radius, rect.bottom - Radius, Color); -DrawVLine(ACanvas, Rect.right, rect.top + Radius, rect.bottom - Radius, Color); -DrawHLine(ACanvas, Rect.left + Radius, Rect.right - Radius, rect.top, Color); -DrawHLine(ACanvas, Rect.left + Radius, Rect.right - Radius, rect.bottom, Color); + // Draw * Line is protected against drawing outside the area + DrawVLine(ACanvas, Rect.Left, Rect.Top + Radius, Rect.Bottom - Radius, Color); + DrawVLine(ACanvas, Rect.Right, Rect.Top + Radius, Rect.Bottom - Radius, Color); + DrawHLine(ACanvas, Rect.Left + Radius, Rect.Right - Radius, Rect.Top, Color); + DrawHLine(ACanvas, Rect.Left + Radius, Rect.Right - Radius, Rect.Bottom, Color); end; class procedure TGUITools.DrawAARoundFrame(ACanvas: TCanvas; Rect: T2DIntRect; Radius: integer; Color: TColor; ClipRect: T2DIntRect); - -var UseOrgClipRgn : boolean; - ClipRgn : HRGN; - OrgRgn : HRGN; - +var + UseOrgClipRgn: boolean; + ClipRgn: HRGN; + OrgRgn: HRGN; begin -// Zapamiêtywanie oryginalnego ClipRgn i ustawianie nowego -SaveClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn); + // Store the original ClipRgn and set a new one + SaveClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn); -ClipRgn:=CreateRectRgn(ClipRect.left, ClipRect.Top, ClipRect.Right+1, ClipRect.Bottom+1); -if UseOrgClipRgn then - CombineRgn(ClipRgn, ClipRgn, OrgRgn, RGN_AND); + ClipRgn := CreateRectRgn(ClipRect.left, ClipRect.Top, ClipRect.Right+1, ClipRect.Bottom+1); + if UseOrgClipRgn then + CombineRgn(ClipRgn, ClipRgn, OrgRgn, RGN_AND); -SelectClipRgn(ACanvas.Handle, ClipRgn); + SelectClipRgn(ACanvas.Handle, ClipRgn); -DrawAARoundFrame(ACanvas, Rect, Radius, Color); + DrawAARoundFrame(ACanvas, Rect, Radius, Color); -// Przywracanie poprzedniego ClipRgn i usuwanie wykorzystanych regionów -RestoreClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn); -DeleteObject(ClipRgn); + // Restores previous ClipRgn and removes used regions + RestoreClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn); + DeleteObject(ClipRgn); end; class procedure TGUITools.DrawDisabledImage(ABitmap: TBitmap; Imagelist: TImageList; ImageIndex: integer; Point: T2DIntVector; ClipRect: T2DIntRect); begin -DrawDisabledImage(ABitmap.Canvas, ImageList, ImageIndex, Point, ClipRect); + DrawDisabledImage(ABitmap.Canvas, ImageList, ImageIndex, Point, ClipRect); end; class procedure TGUITools.DrawDisabledImage(ABitmap: TBitmap; Imagelist: TImageList; ImageIndex: integer; Point: T2DIntVector); begin -DrawDisabledImage(ABitmap.Canvas, ImageList, ImageIndex, Point); + DrawDisabledImage(ABitmap.Canvas, ImageList, ImageIndex, Point); end; class procedure TGUITools.DrawDisabledImage(ACanvas: TCanvas; Imagelist: TImageList; ImageIndex: integer; Point: T2DIntVector; ClipRect: T2DIntRect); - -var UseOrgClipRgn: Boolean; - OrgRgn: HRGN; - ClipRgn: HRGN; - DCStackPos : integer; - +var + UseOrgClipRgn: Boolean; + OrgRgn: HRGN; + ClipRgn: HRGN; + DCStackPos : integer; begin -// Zapamiêtywanie oryginalnego ClipRgn i ustawianie nowego -SaveClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn); + // Store the original ClipRgn and set a new one + SaveClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn); -ClipRgn:=CreateRectRgn(ClipRect.left, ClipRect.Top, ClipRect.Right+1, ClipRect.Bottom+1); -if UseOrgClipRgn then - CombineRgn(ClipRgn, ClipRgn, OrgRgn, RGN_AND); + ClipRgn := CreateRectRgn(ClipRect.left, ClipRect.Top, ClipRect.Right+1, ClipRect.Bottom+1); + if UseOrgClipRgn then + CombineRgn(ClipRgn, ClipRgn, OrgRgn, RGN_AND); -SelectClipRgn(ACanvas.Handle, ClipRgn); + SelectClipRgn(ACanvas.Handle, ClipRgn); -// Hack poprawiaj¹cy b³¹d w ImageList.Draw, który nie przywraca poprzedniego -// koloru czcionki dla p³ótna -DcStackPos:=SaveDC(ACanvas.Handle); -ImageList.Draw(ACanvas, Point.x, Point.y, ImageIndex, false); -RestoreDC(ACanvas.Handle, DcStackPos); + // Hack fixes the bug in ImageList.Draw which does not restore the previous one /??? + // Font color for canvas + DcStackPos := SaveDC(ACanvas.Handle); + ImageList.Draw(ACanvas, Point.x, Point.y, ImageIndex, false); + RestoreDC(ACanvas.Handle, DcStackPos); -RestoreClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn); + RestoreClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn); -DeleteObject(ClipRgn); + DeleteObject(ClipRgn); end; class procedure TGUITools.DrawDisabledImage(ACanvas: TCanvas; Imagelist: TImageList; ImageIndex: integer; Point: T2DIntVector); - -var DCStackPos : integer; - +var + DCStackPos : integer; begin -//todo: see if is necessary to save the DC -DcStackPos:=SaveDC(ACanvas.Handle); -ImageList.Draw(ACanvas, Point.x, Point.y, ImageIndex, false); -RestoreDC(ACanvas.Handle, DcStackPos); + //todo: see if is necessary to save the DC + DcStackPos := SaveDC(ACanvas.Handle); + ImageList.Draw(ACanvas, Point.x, Point.y, ImageIndex, false); + RestoreDC(ACanvas.Handle, DcStackPos); end; class procedure TGUITools.DrawCheckbox(ACanvas:TCanvas; x,y: Integer; diff --git a/components/spktoolbar/SpkMath/SpkMath.pas b/components/spktoolbar/SpkMath/SpkMath.pas index 8f9a51f4a..885d3e577 100644 --- a/components/spktoolbar/SpkMath/SpkMath.pas +++ b/components/spktoolbar/SpkMath/SpkMath.pas @@ -329,6 +329,8 @@ type operator - (Left: T3DVector; Right: T3DVector): T3DVector; {$endif} + procedure EnsureOrder(var a, b: Integer); + implementation {$ifndef EnhancedRecordSupport} @@ -1696,4 +1698,15 @@ end; {$endif} +procedure EnsureOrder(var a, b: Integer); +var + tmp: Integer; +begin + if a <= b then + exit; + tmp := a; + a := b; + b := tmp; +end; + end. diff --git a/components/spktoolbar/demos/actions/project1.lpr b/components/spktoolbar/demos/actions/project1.lpr index bc1c90651..284a86303 100644 --- a/components/spktoolbar/demos/actions/project1.lpr +++ b/components/spktoolbar/demos/actions/project1.lpr @@ -13,9 +13,8 @@ uses {$R *.res} begin - Application.Scaled := True; - {$IF lcl_fullversion >= 1080000} - Application.Scaled := True; + {$IF LCL_FullVersion >= 1080000} + Application.Scaled:=True; {$ENDIF} RequireDerivedFormResource := True; Application.Initialize;