2013-09-01 05:11:20 +00:00
|
|
|
unit SpkGUITools;
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-18 01:46:25 +00:00
|
|
|
{$mode ObjFpc}
|
|
|
|
{$H+}
|
2011-06-17 20:53:01 +00:00
|
|
|
{$DEFINE SPKGUITOOLS}
|
2011-06-18 01:46:25 +00:00
|
|
|
{.$define EnhancedRecordSupport}
|
2011-06-20 20:35:07 +00:00
|
|
|
//the fpcbugworkaround is only necessary when using inline for DrawRoundRect
|
|
|
|
{.$define FpcBugWorkAround}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
interface
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
{$MESSAGE HINT 'W tym module konsekwentnie ka¿dy rect opisuje dok³adny prostok¹t (a nie, jak w przypadku WINAPI - bez dolnej i prawej krawêdzi)'}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-18 01:46:25 +00:00
|
|
|
uses
|
2012-06-04 00:49:51 +00:00
|
|
|
LCLType, Graphics, SysUtils, Classes, Controls, StdCtrls, SpkGraphTools, SpkMath;
|
2011-06-18 01:46:25 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
TCornerPos = (cpLeftTop, cpRightTop, cpLeftBottom, cpRightBottom);
|
|
|
|
TCornerKind = (cpRound, cpNormal);
|
|
|
|
TBackgroundKind = (bkSolid, bkVerticalGradient, bkHorizontalGradient,
|
|
|
|
bkConcave);
|
|
|
|
|
2012-06-04 00:49:51 +00:00
|
|
|
TSpkCheckboxStyle = (cbsCheckbox, cbsRadioButton);
|
|
|
|
TSpkCheckboxState = (cbsIdle, cbsHotTrack, cbsPressed, cbsDisabled);
|
|
|
|
|
2011-06-18 01:46:25 +00:00
|
|
|
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);
|
|
|
|
public
|
|
|
|
// *** Lines ***
|
|
|
|
|
|
|
|
// Performance:
|
|
|
|
// w/ClipRect: Bitmap is faster (2x)
|
|
|
|
// wo/ClipRect: Canvas is faster (a little)
|
|
|
|
class procedure DrawHLine(ABitmap : TBitmap;
|
|
|
|
x1, x2 : integer;
|
|
|
|
y : integer;
|
2011-06-20 20:35:07 +00:00
|
|
|
Color : TColor); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawHLine(ABitmap : TBitmap;
|
|
|
|
x1, x2 : integer;
|
|
|
|
y : integer;
|
|
|
|
Color : TColor;
|
2011-06-20 20:35:07 +00:00
|
|
|
ClipRect : T2DIntRect); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawHLine(ACanvas : TCanvas;
|
|
|
|
x1, x2 : integer;
|
|
|
|
y : integer;
|
2011-06-20 20:35:07 +00:00
|
|
|
Color : TColor); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawHLine(ACanvas : TCanvas;
|
|
|
|
x1, x2 : integer;
|
|
|
|
y : integer;
|
|
|
|
Color : TColor;
|
2011-06-20 20:35:07 +00:00
|
|
|
ClipRect : T2DIntRect); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Performance:
|
|
|
|
// w/ClipRect: Bitmap is faster (2x)
|
|
|
|
// wo/ClipRect: Canvas is faster (a little)
|
|
|
|
class procedure DrawVLine(ABitmap : TBitmap;
|
|
|
|
x : integer;
|
|
|
|
y1, y2 : integer;
|
2011-06-20 20:35:07 +00:00
|
|
|
Color : TColor); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawVLine(ABitmap : TBitmap;
|
|
|
|
x : integer;
|
|
|
|
y1, y2 : integer;
|
|
|
|
Color : TColor;
|
2011-06-20 20:35:07 +00:00
|
|
|
ClipRect : T2DIntRect); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawVLine(ACanvas : TCanvas;
|
|
|
|
x : integer;
|
|
|
|
y1, y2 : integer;
|
2011-06-20 20:35:07 +00:00
|
|
|
Color : TColor); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawVLine(ACanvas : TCanvas;
|
|
|
|
x : integer;
|
|
|
|
y1, y2 : integer;
|
|
|
|
Color : TColor;
|
2011-06-20 20:35:07 +00:00
|
|
|
ClipRect : T2DIntRect); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
|
|
|
|
// *** Background and frame tools ***
|
|
|
|
|
|
|
|
// Performance:
|
|
|
|
// w/ClipRect: Bitmap is faster (extremely)
|
|
|
|
// wo/ClipRect: Bitmap is faster (extremely)
|
|
|
|
class procedure DrawAARoundCorner(ABitmap : TBitmap;
|
|
|
|
Point : T2DIntVector;
|
|
|
|
Radius : integer;
|
|
|
|
CornerPos : TCornerPos;
|
2011-06-20 20:35:07 +00:00
|
|
|
Color : TColor); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawAARoundCorner(ABitmap : TBitmap;
|
|
|
|
Point : T2DIntVector;
|
|
|
|
Radius : integer;
|
|
|
|
CornerPos : TCornerPos;
|
|
|
|
Color : TColor;
|
2011-06-20 20:35:07 +00:00
|
|
|
ClipRect : T2DIntRect); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawAARoundCorner(ACanvas : TCanvas;
|
|
|
|
Point : T2DIntVector;
|
|
|
|
Radius : integer;
|
|
|
|
CornerPos : TCornerPos;
|
2011-06-20 20:35:07 +00:00
|
|
|
Color : TColor); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawAARoundCorner(ACanvas : TCanvas;
|
|
|
|
Point : T2DIntVector;
|
|
|
|
Radius : integer;
|
|
|
|
CornerPos : TCornerPos;
|
|
|
|
Color : TColor;
|
2011-06-20 20:35:07 +00:00
|
|
|
ClipRect : T2DIntRect); overload;
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-18 01:46:25 +00:00
|
|
|
// Performance:
|
|
|
|
// w/ClipRect: Bitmap is faster (extremely)
|
|
|
|
// wo/ClipRect: Bitmap is faster (extremely)
|
|
|
|
class procedure DrawAARoundFrame(ABitmap : TBitmap;
|
|
|
|
Rect : T2DIntRect;
|
|
|
|
Radius : integer;
|
2011-06-20 20:35:07 +00:00
|
|
|
Color : TColor); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawAARoundFrame(ABitmap : TBitmap;
|
|
|
|
Rect : T2DIntRect;
|
|
|
|
Radius : integer;
|
|
|
|
Color : TColor;
|
2011-06-20 20:35:07 +00:00
|
|
|
ClipRect : T2DIntRect); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawAARoundFrame(ACanvas : TCanvas;
|
|
|
|
Rect : T2DIntRect;
|
|
|
|
Radius : integer;
|
2011-06-20 20:35:07 +00:00
|
|
|
Color : TColor); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawAARoundFrame(ACanvas : TCanvas;
|
|
|
|
Rect : T2DIntRect;
|
|
|
|
Radius : integer;
|
|
|
|
Color : TColor;
|
2011-06-20 20:35:07 +00:00
|
|
|
ClipRect : T2DIntRect); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
|
|
|
|
class procedure RenderBackground(ABuffer : TBitmap;
|
|
|
|
Rect : T2DIntRect;
|
|
|
|
Color1, Color2 : TColor;
|
2011-06-20 20:35:07 +00:00
|
|
|
BackgroundKind : TBackgroundKind);
|
2011-06-18 01:46:25 +00:00
|
|
|
|
|
|
|
class procedure CopyRoundCorner(ABuffer : TBitmap;
|
|
|
|
ABitmap : TBitmap;
|
|
|
|
SrcPoint : T2DIntVector;
|
|
|
|
DstPoint : T2DIntVector;
|
|
|
|
Radius : integer;
|
|
|
|
CornerPos : TCornerPos;
|
2011-06-20 20:35:07 +00:00
|
|
|
Convex : boolean = true); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure CopyRoundCorner(ABuffer : TBitmap;
|
|
|
|
ABitmap : TBitmap;
|
|
|
|
SrcPoint : T2DIntVector;
|
|
|
|
DstPoint : T2DIntVector;
|
|
|
|
Radius : integer;
|
|
|
|
CornerPos : TCornerPos;
|
|
|
|
ClipRect : T2DIntRect;
|
2011-06-20 20:35:07 +00:00
|
|
|
Convex : boolean = true); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
|
|
|
|
class procedure CopyCorner(ABuffer : TBitmap;
|
|
|
|
ABitmap: TBitmap;
|
|
|
|
SrcPoint : T2DIntVector;
|
|
|
|
DstPoint: T2DIntVector;
|
|
|
|
Radius: integer); overload; inline;
|
|
|
|
class procedure CopyCorner(ABuffer : TBitmap;
|
|
|
|
ABitmap: TBitmap;
|
|
|
|
SrcPoint : T2DIntVector;
|
|
|
|
DstPoint: T2DIntVector;
|
|
|
|
Radius: integer;
|
|
|
|
ClipRect : T2DIntRect); overload; inline;
|
|
|
|
|
|
|
|
class procedure CopyRectangle(ABuffer : TBitmap;
|
|
|
|
ABitmap: TBitmap;
|
|
|
|
SrcPoint : T2DIntVector;
|
|
|
|
DstPoint: T2DIntVector;
|
|
|
|
Width: integer;
|
2011-06-20 20:35:07 +00:00
|
|
|
Height : integer); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure CopyRectangle(ABuffer : TBitmap;
|
|
|
|
ABitmap : TBitmap;
|
|
|
|
SrcPoint : T2DIntVector;
|
|
|
|
DstPoint : T2DIntVector;
|
|
|
|
Width : integer;
|
|
|
|
Height : integer;
|
2011-06-20 20:35:07 +00:00
|
|
|
ClipRect : T2DIntRect); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure CopyMaskRectangle(ABuffer : TBitmap;
|
|
|
|
AMask : TBitmap;
|
|
|
|
ABitmap : TBitmap;
|
2011-06-17 20:53:01 +00:00
|
|
|
SrcPoint : T2DIntVector;
|
2011-06-18 01:46:25 +00:00
|
|
|
DstPoint : T2DIntVector;
|
|
|
|
Width : integer;
|
2011-06-20 20:35:07 +00:00
|
|
|
Height : integer); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure CopyMaskRectangle(ABuffer : TBitmap;
|
|
|
|
AMask : TBitmap;
|
2011-06-17 20:53:01 +00:00
|
|
|
ABitmap : TBitmap;
|
|
|
|
SrcPoint : T2DIntVector;
|
|
|
|
DstPoint : T2DIntVector;
|
|
|
|
Width : integer;
|
|
|
|
Height : integer;
|
2011-06-20 20:35:07 +00:00
|
|
|
ClipRect : T2DIntRect); overload;
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-18 01:46:25 +00:00
|
|
|
// Performance (RenderBackground + CopyRoundRect vs DrawRoundRect):
|
|
|
|
// w/ClipRect : Bitmap faster for smaller radiuses, Canvas faster for larger
|
|
|
|
// wo/ClipRect : Bitmap faster for smaller radiuses, Canvas faster for larger
|
|
|
|
class procedure CopyRoundRect(ABuffer : TBitmap;
|
|
|
|
ABitmap : TBitmap;
|
|
|
|
SrcPoint : T2DIntVector;
|
|
|
|
DstPoint : T2DIntVector;
|
|
|
|
Width, Height : integer;
|
|
|
|
Radius : integer;
|
|
|
|
LeftTopRound : boolean = true;
|
|
|
|
RightTopRound : boolean = true;
|
|
|
|
LeftBottomRound : boolean = true;
|
2011-06-20 20:35:07 +00:00
|
|
|
RightBottomRound : boolean = true); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure CopyRoundRect(ABuffer : TBitmap;
|
|
|
|
ABitmap : TBitmap;
|
|
|
|
SrcPoint : T2DIntVector;
|
|
|
|
DstPoint : T2DIntVector;
|
|
|
|
Width, Height : integer;
|
|
|
|
Radius : integer;
|
|
|
|
ClipRect : T2DIntRect;
|
|
|
|
LeftTopRound : boolean = true;
|
|
|
|
RightTopRound : boolean = true;
|
|
|
|
LeftBottomRound : boolean = true;
|
2011-06-20 20:35:07 +00:00
|
|
|
RightBottomRound : boolean = true); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
class procedure DrawRoundRect(ACanvas : TCanvas;
|
|
|
|
Rect : T2DIntRect;
|
|
|
|
Radius : integer;
|
|
|
|
ColorFrom : TColor;
|
|
|
|
ColorTo : TColor;
|
|
|
|
GradientKind : TBackgroundKind;
|
|
|
|
LeftTopRound : boolean = true;
|
|
|
|
RightTopRound : boolean = true;
|
|
|
|
LeftBottomRound : boolean = true;
|
2011-06-20 20:35:07 +00:00
|
|
|
RightBottomRound : boolean = true); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawRoundRect(ACanvas : TCanvas;
|
|
|
|
Rect : T2DIntRect;
|
|
|
|
Radius : integer;
|
|
|
|
ColorFrom : TColor;
|
|
|
|
ColorTo : TColor;
|
|
|
|
GradientKind : TBackgroundKind;
|
|
|
|
ClipRect : T2DIntRect;
|
|
|
|
LeftTopRound : boolean = true;
|
|
|
|
RightTopRound : boolean = true;
|
|
|
|
LeftBottomRound : boolean = true;
|
2011-06-20 20:35:07 +00:00
|
|
|
RightBottomRound : boolean = true); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
|
|
|
|
class procedure DrawRegion(ACanvas : TCanvas;
|
|
|
|
Region : HRGN;
|
|
|
|
Rect : T2DIntRect;
|
|
|
|
ColorFrom : TColor;
|
|
|
|
ColorTo : TColor;
|
2011-06-20 20:35:07 +00:00
|
|
|
GradientKind : TBackgroundKind); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawRegion(ACanvas : TCanvas;
|
|
|
|
Region : HRGN;
|
|
|
|
Rect : T2DIntRect;
|
|
|
|
ColorFrom : TColor;
|
|
|
|
ColorTo : TColor;
|
|
|
|
GradientKind : TBackgroundKind;
|
2011-06-20 20:35:07 +00:00
|
|
|
ClipRect : T2DIntRect); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
|
|
|
|
// Imagelist tools
|
|
|
|
class procedure DrawImage(ABitmap : TBitmap;
|
|
|
|
Imagelist : TImageList;
|
|
|
|
ImageIndex : integer;
|
|
|
|
Point : T2DIntVector); overload; inline;
|
|
|
|
class procedure DrawImage(ABitmap : TBitmap;
|
|
|
|
Imagelist : TImageList;
|
|
|
|
ImageIndex : integer;
|
|
|
|
Point : T2DIntVector;
|
|
|
|
ClipRect : T2DIntRect); overload; inline;
|
|
|
|
class procedure DrawImage(ACanvas : TCanvas;
|
|
|
|
Imagelist : TImageList;
|
|
|
|
ImageIndex : integer;
|
|
|
|
Point : T2DIntVector); overload; inline;
|
|
|
|
class procedure DrawImage(ACanvas : TCanvas;
|
|
|
|
Imagelist : TImageList;
|
|
|
|
ImageIndex : integer;
|
|
|
|
Point : T2DIntVector;
|
2011-06-20 20:35:07 +00:00
|
|
|
ClipRect : T2DIntRect); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
|
|
|
|
class procedure DrawDisabledImage(ABitmap : TBitmap;
|
|
|
|
Imagelist : TImageList;
|
|
|
|
ImageIndex : integer;
|
|
|
|
Point : T2DIntVector); overload; inline;
|
|
|
|
class procedure DrawDisabledImage(ABitmap : TBitmap;
|
|
|
|
Imagelist : TImageList;
|
|
|
|
ImageIndex : integer;
|
|
|
|
Point : T2DIntVector;
|
|
|
|
ClipRect : T2DIntRect); overload; inline;
|
|
|
|
class procedure DrawDisabledImage(ACanvas : TCanvas;
|
|
|
|
Imagelist : TImageList;
|
|
|
|
ImageIndex : integer;
|
2011-06-20 20:35:07 +00:00
|
|
|
Point : T2DIntVector); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawDisabledImage(ACanvas : TCanvas;
|
|
|
|
Imagelist : TImageList;
|
|
|
|
ImageIndex : integer;
|
|
|
|
Point : T2DIntVector;
|
|
|
|
ClipRect : T2DIntRect); overload; inline;
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2012-06-04 00:49:51 +00:00
|
|
|
// Checkbox
|
|
|
|
class procedure DrawCheckbox(ACanvas: TCanvas;
|
|
|
|
x,y: Integer;
|
|
|
|
AState: TCheckboxState;
|
|
|
|
ACheckboxState: TSpkCheckboxState;
|
|
|
|
AStyle: TSpkCheckboxStyle); overload;
|
|
|
|
class procedure DrawCheckbox(ACanvas: TCanvas;
|
|
|
|
x,y: Integer;
|
|
|
|
AState: TCheckboxState;
|
|
|
|
ACheckboxState: TSpkCheckboxState;
|
|
|
|
AStyle: TSpkCheckboxStyle;
|
|
|
|
ClipRect: T2DIntRect); overload;
|
|
|
|
|
2011-06-18 01:46:25 +00:00
|
|
|
// Text tools
|
|
|
|
class procedure DrawText(ABitmap : TBitmap;
|
|
|
|
x, y : integer;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText : string;
|
|
|
|
TextColor: TColor); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawText(ABitmap : TBitmap;
|
|
|
|
x, y : integer;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText : string;
|
2011-06-18 01:46:25 +00:00
|
|
|
TextColor : TColor;
|
2011-06-21 02:04:04 +00:00
|
|
|
ClipRect: T2DIntRect); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawMarkedText(ACanvas : TCanvas;
|
|
|
|
x, y : integer;
|
2011-06-18 13:46:52 +00:00
|
|
|
const AText, AMarkPhrase : string;
|
2011-06-18 01:46:25 +00:00
|
|
|
TextColor : TColor;
|
2011-06-20 20:35:07 +00:00
|
|
|
CaseSensitive : boolean = false); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawMarkedText(ACanvas : TCanvas;
|
|
|
|
x, y : integer;
|
2011-06-18 13:46:52 +00:00
|
|
|
const AText, AMarkPhrase : string;
|
2011-06-18 01:46:25 +00:00
|
|
|
TextColor : TColor;
|
|
|
|
ClipRect : T2DIntRect;
|
2011-06-20 20:35:07 +00:00
|
|
|
CaseSensitive : boolean = false); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawText(ACanvas : TCanvas;
|
|
|
|
x, y : integer;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText : string;
|
2011-06-20 20:35:07 +00:00
|
|
|
TextColor : TColor); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawText(ACanvas : TCanvas;
|
|
|
|
x, y : integer;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText : string;
|
2011-06-18 01:46:25 +00:00
|
|
|
TextColor : TColor;
|
2011-06-20 20:35:07 +00:00
|
|
|
ClipRect : T2DIntRect); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawFitWText(ABitmap : TBitmap;
|
|
|
|
x1, x2 : integer;
|
|
|
|
y : integer;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText : string;
|
2011-06-18 01:46:25 +00:00
|
|
|
TextColor : TColor;
|
2011-06-20 20:35:07 +00:00
|
|
|
Align : TAlignment); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawFitWText(ACanvas : TCanvas;
|
|
|
|
x1, x2 : integer;
|
|
|
|
y : integer;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText : string;
|
2011-06-18 01:46:25 +00:00
|
|
|
TextColor : TColor;
|
2011-06-20 20:35:07 +00:00
|
|
|
Align : TAlignment); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
|
|
|
|
class procedure DrawOutlinedText(ABitmap : TBitmap;
|
|
|
|
x, y : integer;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText : string;
|
2011-06-17 20:53:01 +00:00
|
|
|
TextColor : TColor;
|
2011-06-20 20:35:07 +00:00
|
|
|
OutlineColor : TColor); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawOutlinedText(ABitmap : TBitmap;
|
|
|
|
x, y : integer;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText : string;
|
2011-06-17 20:53:01 +00:00
|
|
|
TextColor : TColor;
|
2011-06-18 01:46:25 +00:00
|
|
|
OutlineColor : TColor;
|
2011-06-20 20:35:07 +00:00
|
|
|
ClipRect : T2DIntRect); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawOutlinedText(ACanvas : TCanvas;
|
|
|
|
x, y : integer;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText : string;
|
2011-06-18 01:46:25 +00:00
|
|
|
TextColor : TColor;
|
2011-06-20 20:35:07 +00:00
|
|
|
OutlineColor : TColor); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawOutlinedText(ACanvas : TCanvas;
|
|
|
|
x, y : integer;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText : string;
|
2011-06-18 01:46:25 +00:00
|
|
|
TextColor : TColor;
|
|
|
|
OutlineColor : TColor;
|
2011-06-20 20:35:07 +00:00
|
|
|
ClipRect : T2DIntRect); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawFitWOutlinedText(ABitmap: TBitmap;
|
|
|
|
x1, x2 : integer;
|
|
|
|
y: integer;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText: string;
|
2011-06-18 01:46:25 +00:00
|
|
|
TextColor,
|
|
|
|
OutlineColor: TColor;
|
2011-06-20 20:35:07 +00:00
|
|
|
Align: TAlignment); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
class procedure DrawFitWOutlinedText(ACanvas: TCanvas;
|
|
|
|
x1, x2 : integer;
|
|
|
|
y: integer;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText: string;
|
2011-06-18 01:46:25 +00:00
|
|
|
TextColor,
|
|
|
|
OutlineColor: TColor;
|
2011-06-20 20:35:07 +00:00
|
|
|
Align: TAlignment); overload;
|
2011-06-18 01:46:25 +00:00
|
|
|
end;
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2011-06-18 12:34:17 +00:00
|
|
|
uses
|
2014-10-13 19:04:19 +00:00
|
|
|
types, LCLIntf, IntfGraphics, Math, Themes;
|
2011-06-18 12:34:17 +00:00
|
|
|
|
2011-06-17 20:53:01 +00:00
|
|
|
{ TSpkGUITools }
|
|
|
|
|
|
|
|
class procedure TGUITools.CopyRoundCorner(ABuffer, ABitmap: TBitmap; SrcPoint,
|
|
|
|
DstPoint: T2DIntVector; Radius: integer; CornerPos: TCornerPos;
|
|
|
|
ClipRect: T2DIntRect; Convex: boolean);
|
|
|
|
|
2011-06-18 01:46:25 +00:00
|
|
|
var BufferRect, BitmapRect, TempRect : T2DIntRect;
|
2011-06-17 20:53:01 +00:00
|
|
|
OrgSrcRect, UnClippedDstRect, OrgDstRect : T2DIntRect;
|
2011-06-18 12:34:17 +00:00
|
|
|
SrcRect: T2DIntRect;
|
|
|
|
Offset: T2DIntVector;
|
2011-06-17 20:53:01 +00:00
|
|
|
Center: T2DIntVector;
|
|
|
|
y: Integer;
|
|
|
|
SrcLine: Pointer;
|
|
|
|
DstLine: Pointer;
|
|
|
|
SrcPtr, DstPtr : PByte;
|
|
|
|
x: Integer;
|
|
|
|
Dist : double;
|
2011-06-18 12:34:17 +00:00
|
|
|
SrcImg, DestImg: TLazIntfImage;
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
if (ABuffer.PixelFormat<>pf24bit) or (ABitmap.PixelFormat<>pf24bit) then
|
2011-06-17 21:12:21 +00:00
|
|
|
raise exception.create('TSpkGUITools.CopyRoundCorner: Tylko 24-bitowe bitmapy s¹ akceptowane!');
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Sprawdzanie poprawnoœci
|
2011-06-17 20:53:01 +00:00
|
|
|
if Radius<1 then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
if (ABuffer.width=0) or (ABuffer.height=0) or
|
|
|
|
(ABitmap.width=0) or (ABitmap.height=0) then exit;
|
|
|
|
|
2011-06-18 01:46:25 +00:00
|
|
|
//todo minimize use of temps here
|
|
|
|
{$ifdef EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
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;
|
2011-06-18 01:46:25 +00:00
|
|
|
{$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}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-18 01:46:25 +00:00
|
|
|
{$ifdef EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
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;
|
2011-06-18 01:46:25 +00:00
|
|
|
{$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}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
if not(ClipRect.IntersectsWith(UnClippedDstRect, OrgDstRect)) then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
Offset:=DstPoint - SrcPoint;
|
|
|
|
|
|
|
|
if not(OrgSrcRect.IntersectsWith(OrgDstRect - Offset, SrcRect)) then exit;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Ustalamy pozycjê œrodka ³uku
|
2011-06-18 01:46:25 +00:00
|
|
|
{$ifdef EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
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;
|
2011-06-18 01:46:25 +00:00
|
|
|
{$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}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
// Czy jest cokolwiek do przetworzenia?
|
|
|
|
if Convex then
|
|
|
|
begin
|
2011-06-18 12:34:17 +00:00
|
|
|
//todo: remove the check since is not necessary
|
2011-06-17 20:53:01 +00:00
|
|
|
if (SrcRect.left<=SrcRect.right) and (SrcRect.top<=SrcRect.bottom) then
|
2011-06-18 12:34:17 +00:00
|
|
|
begin
|
|
|
|
SrcImg := ABuffer.CreateIntfImage;
|
|
|
|
DestImg := ABitmap.CreateIntfImage;
|
2011-06-17 20:53:01 +00:00
|
|
|
for y := SrcRect.top to SrcRect.bottom do
|
|
|
|
begin
|
2011-06-18 12:34:17 +00:00
|
|
|
SrcLine:=SrcImg.GetDataLineStart(y);
|
|
|
|
DstLine:=DestImg.GetDataLineStart(y+Offset.y);
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2013-02-05 01:37:55 +00:00
|
|
|
SrcPtr:=pointer(PtrInt(SrcLine) + 3*SrcRect.left);
|
|
|
|
DstPtr:=pointer(PtrInt(DstLine) + 3*(SrcRect.left + Offset.x));
|
2011-06-17 20:53:01 +00:00
|
|
|
for x := SrcRect.left to SrcRect.right do
|
|
|
|
begin
|
2011-06-18 12:34:17 +00:00
|
|
|
{$ifdef EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
Dist:=Center.DistanceTo(T2DIntVector.create(x, y));
|
2011-06-18 12:34:17 +00:00
|
|
|
{$else}
|
|
|
|
Dist:=Center.DistanceTo(x, y);
|
|
|
|
{$endif}
|
2011-06-17 20:53:01 +00:00
|
|
|
if Dist <= (Radius-1) then
|
|
|
|
Move(SrcPtr^,DstPtr^,3);
|
|
|
|
|
|
|
|
inc(SrcPtr,3);
|
|
|
|
inc(DstPtr,3);
|
|
|
|
end;
|
|
|
|
end;
|
2011-06-18 12:34:17 +00:00
|
|
|
ABitmap.LoadFromIntfImage(DestImg);
|
|
|
|
SrcImg.Destroy;
|
|
|
|
DestImg.Destroy;
|
|
|
|
end;
|
2011-06-17 20:53:01 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
if (SrcRect.left<=SrcRect.right) and (SrcRect.top<=SrcRect.bottom) then
|
2011-06-18 12:34:17 +00:00
|
|
|
begin
|
|
|
|
SrcImg := ABuffer.CreateIntfImage;
|
|
|
|
DestImg := ABitmap.CreateIntfImage;
|
2011-06-17 20:53:01 +00:00
|
|
|
for y := SrcRect.top to SrcRect.bottom do
|
|
|
|
begin
|
2011-06-18 12:34:17 +00:00
|
|
|
SrcLine:=SrcImg.GetDataLineStart(y);
|
|
|
|
DstLine:=DestImg.GetDataLineStart(y+Offset.y);
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2013-02-05 01:37:55 +00:00
|
|
|
SrcPtr:=pointer(PtrInt(SrcLine) + 3*SrcRect.left);
|
|
|
|
DstPtr:=pointer(PtrInt(DstLine) + 3*(SrcRect.left + Offset.x));
|
2011-06-17 20:53:01 +00:00
|
|
|
for x := SrcRect.left to SrcRect.right do
|
|
|
|
begin
|
2011-06-18 12:34:17 +00:00
|
|
|
{$ifdef EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
Dist:=Center.DistanceTo(T2DIntVector.create(x, y));
|
2011-06-18 12:34:17 +00:00
|
|
|
{$else}
|
|
|
|
Dist:=Center.DistanceTo(x, y);
|
|
|
|
{$endif}
|
2011-06-17 20:53:01 +00:00
|
|
|
if Dist >= (Radius-1) then
|
|
|
|
Move(SrcPtr^,DstPtr^,3);
|
|
|
|
|
|
|
|
inc(SrcPtr,3);
|
|
|
|
inc(DstPtr,3);
|
|
|
|
end;
|
|
|
|
end;
|
2011-06-18 12:34:17 +00:00
|
|
|
ABitmap.LoadFromIntfImage(DestImg);
|
|
|
|
SrcImg.Destroy;
|
|
|
|
DestImg.Destroy;
|
|
|
|
end;
|
2011-06-17 20:53:01 +00:00
|
|
|
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
|
2011-06-17 21:12:21 +00:00
|
|
|
raise exception.create('TSpkGUITools.CopyBackground: Tylko 24-bitowe bitmapy s¹ akceptowane!');
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Sprawdzamy poprawnoϾ
|
2011-06-17 20:53:01 +00:00
|
|
|
if Radius<0 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;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
{$REGION 'Wype³niamy prostok¹ty'}
|
|
|
|
// Góra
|
2011-06-17 20:53:01 +00:00
|
|
|
CopyRectangle(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ifdef EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.create(SrcPoint.x + radius, SrcPoint.y),
|
|
|
|
T2DIntPoint.create(DstPoint.x + radius, DstPoint.y),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$else}
|
|
|
|
Create2DIntPoint(SrcPoint.x + radius, SrcPoint.y),
|
|
|
|
Create2DIntPoint(DstPoint.x + radius, DstPoint.y),
|
|
|
|
{$endif}
|
2011-06-17 20:53:01 +00:00
|
|
|
width - 2*radius,
|
|
|
|
radius,
|
|
|
|
ClipRect);
|
2011-06-17 21:12:21 +00:00
|
|
|
// Dó³
|
2011-06-17 20:53:01 +00:00
|
|
|
CopyRectangle(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.create(SrcPoint.x + radius, SrcPoint.y + height - radius),
|
|
|
|
T2DIntPoint.create(DstPoint.x + radius, DstPoint.y + height - radius),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Create2DIntPoint(SrcPoint.x + radius, SrcPoint.y + height - radius),
|
|
|
|
Create2DIntPoint(DstPoint.x + radius, DstPoint.y + height - radius),
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
width - 2*radius,
|
|
|
|
radius,
|
|
|
|
ClipRect);
|
2011-06-17 21:12:21 +00:00
|
|
|
// Œrodek
|
2011-06-17 20:53:01 +00:00
|
|
|
CopyRectangle(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.create(SrcPoint.x, SrcPoint.y + radius),
|
|
|
|
T2DIntPoint.create(DstPoint.x, DstPoint.y + radius),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Create2DIntPoint(SrcPoint.x, SrcPoint.y + radius),
|
|
|
|
Create2DIntPoint(DstPoint.x, DstPoint.y + radius),
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
width,
|
|
|
|
height - 2*radius,
|
|
|
|
ClipRect);
|
|
|
|
{$ENDREGION}
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Wype³niamy naro¿niki
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
{$REGION 'Lewy górny'}
|
2011-06-17 20:53:01 +00:00
|
|
|
if LeftTopRound then
|
|
|
|
TGUITools.CopyRoundCorner(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.Create(SrcPoint.x, SrcPoint.y),
|
|
|
|
T2DIntPoint.Create(DstPoint.x, DstPoint.y),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Create2DIntPoint(SrcPoint.x, SrcPoint.y),
|
|
|
|
Create2DIntPoint(DstPoint.x, DstPoint.y),
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
Radius,
|
|
|
|
cpLeftTop,
|
|
|
|
ClipRect,
|
|
|
|
true)
|
|
|
|
else
|
|
|
|
TGUITools.CopyCorner(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.Create(SrcPoint.x, SrcPoint.y),
|
|
|
|
T2DIntPoint.Create(DstPoint.x, DstPoint.y),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Create2DIntPoint(SrcPoint.x, SrcPoint.y),
|
|
|
|
Create2DIntPoint(DstPoint.x, DstPoint.y),
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
Radius,
|
|
|
|
ClipRect);
|
|
|
|
{$ENDREGION}
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
{$REGION 'Prawy górny'}
|
2011-06-17 20:53:01 +00:00
|
|
|
if RightTopRound then
|
|
|
|
TGUITools.CopyRoundCorner(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y),
|
|
|
|
T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y),
|
|
|
|
Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y),
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
Radius,
|
|
|
|
cpRightTop,
|
|
|
|
ClipRect,
|
|
|
|
true)
|
|
|
|
else
|
|
|
|
TGUITools.CopyCorner(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y),
|
|
|
|
T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y),
|
|
|
|
Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y),
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
Radius,
|
|
|
|
ClipRect);
|
|
|
|
{$ENDREGION}
|
|
|
|
|
|
|
|
{$REGION 'Lewy dolny'}
|
|
|
|
if LeftBottomRound then
|
|
|
|
TGUITools.CopyRoundCorner(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.Create(SrcPoint.x, SrcPoint.y + Height - Radius),
|
|
|
|
T2DIntPoint.Create(DstPoint.x, DstPoint.y + Height - Radius),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Create2DIntPoint(SrcPoint.x, SrcPoint.y + Height - Radius),
|
|
|
|
Create2DIntPoint(DstPoint.x, DstPoint.y + Height - Radius),
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
Radius,
|
|
|
|
cpLeftBottom,
|
|
|
|
ClipRect,
|
|
|
|
true)
|
|
|
|
else
|
|
|
|
TGUITools.CopyCorner(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.Create(SrcPoint.x, SrcPoint.y + Height - Radius),
|
|
|
|
T2DIntPoint.Create(DstPoint.x, DstPoint.y + Height - Radius),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Create2DIntPoint(SrcPoint.x, SrcPoint.y + Height - Radius),
|
|
|
|
Create2DIntPoint(DstPoint.x, DstPoint.y + Height - Radius),
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
Radius,
|
|
|
|
ClipRect);
|
|
|
|
{$ENDREGION}
|
|
|
|
|
|
|
|
{$REGION 'Prawy dolny'}
|
|
|
|
if RightBottomRound then
|
|
|
|
TGUITools.CopyRoundCorner(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius),
|
|
|
|
T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius),
|
|
|
|
Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius),
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
Radius,
|
|
|
|
cpRightBottom,
|
|
|
|
ClipRect,
|
|
|
|
true)
|
|
|
|
else
|
|
|
|
TGUITools.CopyCorner(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius),
|
|
|
|
T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius),
|
|
|
|
Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius),
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
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
|
2011-06-17 21:12:21 +00:00
|
|
|
raise exception.create('TSpkGUITools.CopyBackground: Tylko 24-bitowe bitmapy s¹ akceptowane!');
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Sprawdzamy poprawnoϾ
|
2011-06-17 20:53:01 +00:00
|
|
|
if Radius<0 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;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
{$REGION 'Wype³niamy prostok¹ty'}
|
|
|
|
// Góra
|
2011-06-17 20:53:01 +00:00
|
|
|
CopyRectangle(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.create(SrcPoint.x + radius, SrcPoint.y),
|
|
|
|
T2DIntPoint.create(DstPoint.x + radius, DstPoint.y),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Create2DIntPoint(SrcPoint.x + radius, SrcPoint.y),
|
|
|
|
Create2DIntPoint(DstPoint.x + radius, DstPoint.y),
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
width - 2*radius,
|
|
|
|
radius);
|
2011-06-17 21:12:21 +00:00
|
|
|
// Dó³
|
2011-06-17 20:53:01 +00:00
|
|
|
CopyRectangle(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.create(SrcPoint.x + radius, SrcPoint.y + height - radius),
|
|
|
|
T2DIntPoint.create(DstPoint.x + radius, DstPoint.y + height - radius),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Create2DIntPoint(SrcPoint.x + radius, SrcPoint.y + height - radius),
|
|
|
|
Create2DIntPoint(DstPoint.x + radius, DstPoint.y + height - radius),
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
width - 2*radius,
|
|
|
|
radius);
|
2011-06-17 21:12:21 +00:00
|
|
|
// Œrodek
|
2011-06-17 20:53:01 +00:00
|
|
|
CopyRectangle(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.create(SrcPoint.x, SrcPoint.y + radius),
|
|
|
|
T2DIntPoint.create(DstPoint.x, DstPoint.y + radius),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Create2DIntPoint(SrcPoint.x, SrcPoint.y + radius),
|
|
|
|
Create2DIntPoint(DstPoint.x, DstPoint.y + radius),
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
width,
|
|
|
|
height - 2*radius);
|
|
|
|
{$ENDREGION}
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Wype³niamy naro¿niki
|
|
|
|
{$REGION 'Lewy górny'}
|
2011-06-17 20:53:01 +00:00
|
|
|
if LeftTopRound then
|
|
|
|
TGUITools.CopyRoundCorner(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.Create(SrcPoint.x, SrcPoint.y),
|
|
|
|
T2DIntPoint.Create(DstPoint.x, DstPoint.y),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Create2DIntPoint(SrcPoint.x, SrcPoint.y),
|
|
|
|
Create2DIntPoint(DstPoint.x, DstPoint.y),
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
Radius,
|
|
|
|
cpLeftTop,
|
|
|
|
true)
|
|
|
|
else
|
|
|
|
TGUITools.CopyCorner(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.Create(SrcPoint.x, SrcPoint.y),
|
|
|
|
T2DIntPoint.Create(DstPoint.x, DstPoint.y),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Create2DIntPoint(SrcPoint.x, SrcPoint.y),
|
|
|
|
Create2DIntPoint(DstPoint.x, DstPoint.y),
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
Radius);
|
|
|
|
{$ENDREGION}
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
{$REGION 'Prawy górny'}
|
2011-06-17 20:53:01 +00:00
|
|
|
if RightTopRound then
|
|
|
|
TGUITools.CopyRoundCorner(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y),
|
|
|
|
T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y),
|
|
|
|
Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y),
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
Radius,
|
|
|
|
cpRightTop,
|
|
|
|
true)
|
|
|
|
else
|
|
|
|
TGUITools.CopyCorner(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y),
|
|
|
|
T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y),
|
|
|
|
Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y),
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
Radius);
|
|
|
|
{$ENDREGION}
|
|
|
|
|
|
|
|
{$REGION 'Lewy dolny'}
|
|
|
|
if LeftBottomRound then
|
|
|
|
TGUITools.CopyRoundCorner(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.Create(SrcPoint.x, SrcPoint.y + Height - Radius),
|
|
|
|
T2DIntPoint.Create(DstPoint.x, DstPoint.y + Height - Radius),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Create2DIntPoint(SrcPoint.x, SrcPoint.y + Height - Radius),
|
|
|
|
Create2DIntPoint(DstPoint.x, DstPoint.y + Height - Radius),
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
Radius,
|
|
|
|
cpLeftBottom,
|
|
|
|
true)
|
|
|
|
else
|
|
|
|
TGUITools.CopyCorner(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.Create(SrcPoint.x, SrcPoint.y + Height - Radius),
|
|
|
|
T2DIntPoint.Create(DstPoint.x, DstPoint.y + Height - Radius),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Create2DIntPoint(SrcPoint.x, SrcPoint.y + Height - Radius),
|
|
|
|
Create2DIntPoint(DstPoint.x, DstPoint.y + Height - Radius),
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
Radius);
|
|
|
|
{$ENDREGION}
|
|
|
|
|
|
|
|
{$REGION 'Prawy dolny'}
|
|
|
|
if RightBottomRound then
|
|
|
|
TGUITools.CopyRoundCorner(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius),
|
|
|
|
T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius),
|
|
|
|
Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius),
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
Radius,
|
|
|
|
cpRightBottom,
|
|
|
|
true)
|
|
|
|
else
|
|
|
|
TGUITools.CopyCorner(ABuffer,
|
|
|
|
ABitmap,
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
T2DIntPoint.Create(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius),
|
|
|
|
T2DIntPoint.Create(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius),
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Create2DIntPoint(SrcPoint.x + Width - Radius, SrcPoint.y + Height - Radius),
|
|
|
|
Create2DIntPoint(DstPoint.x + Width - Radius, DstPoint.y + Height - Radius),
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
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;
|
2011-06-18 12:34:17 +00:00
|
|
|
SrcImg: TLazIntfImage;
|
|
|
|
DestImg: TLazIntfImage;
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
if (ABuffer.PixelFormat<>pf24bit) or (ABitmap.PixelFormat<>pf24bit) then
|
2011-06-17 21:12:21 +00:00
|
|
|
raise exception.create('TSpkGUITools.CopyRoundCorner: Tylko 24-bitowe bitmapy s¹ akceptowane!');
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Sprawdzanie poprawnoœci
|
2011-06-17 20:53:01 +00:00
|
|
|
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;
|
|
|
|
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 21:12:21 +00:00
|
|
|
// Przycinamy Ÿród³owy rect do obszaru Ÿród³owej bitmapy
|
2011-06-17 20:53:01 +00:00
|
|
|
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);
|
|
|
|
if not(BitmapRect.IntersectsWith(T2DIntRect.create(DstPoint.x,
|
|
|
|
DstPoint.y,
|
|
|
|
DstPoint.x+Width-1,
|
|
|
|
DstPoint.y+Height-1),
|
|
|
|
DstRect)) then exit;
|
2011-06-18 13:46:52 +00:00
|
|
|
{$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;
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Liczymy offset Ÿród³owego do docelowego recta
|
2011-06-17 20:53:01 +00:00
|
|
|
Offset:=DstPoint - SrcPoint;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Sprawdzamy, czy na³o¿one na siebie recty: Ÿród³owy i docelowy przesuniêty o
|
|
|
|
// offset maj¹ jak¹œ czêœæ wspóln¹
|
2011-06-17 20:53:01 +00:00
|
|
|
if not(SrcRect.IntersectsWith(DstRect - Offset, ClippedSrcRect)) then exit;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Jeœli jest cokolwiek do przetworzenia, wykonaj operacjê
|
2011-06-18 12:34:17 +00:00
|
|
|
if (ClippedSrcRect.left<=ClippedSrcRect.right) and (ClippedSrcRect.top<=ClippedSrcRect.bottom) then
|
|
|
|
begin
|
|
|
|
SrcImg := ABuffer.CreateIntfImage;
|
|
|
|
DestImg := ABitmap.CreateIntfImage;
|
2011-06-17 20:53:01 +00:00
|
|
|
for y := ClippedSrcRect.top to ClippedSrcRect.bottom do
|
|
|
|
begin
|
2011-06-18 12:34:17 +00:00
|
|
|
SrcLine:=SrcImg.GetDataLineStart(y);
|
|
|
|
DstLine:=DestImg.GetDataLineStart(y+Offset.y);
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2013-02-05 01:37:55 +00:00
|
|
|
Move(pointer(PtrInt(SrcLine) + 3*ClippedSrcRect.left)^,
|
|
|
|
pointer(PtrInt(DstLine) + 3*(ClippedSrcRect.left + Offset.x))^,
|
2011-06-17 20:53:01 +00:00
|
|
|
3*ClippedSrcRect.Width);
|
2011-06-18 12:34:17 +00:00
|
|
|
end;
|
|
|
|
ABitmap.LoadFromIntfImage(DestImg);
|
|
|
|
SrcImg.Destroy;
|
|
|
|
DestImg.Destroy;
|
|
|
|
end;
|
2011-06-17 20:53:01 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.CopyCorner(ABuffer : TBitmap; ABitmap: TBitmap;
|
|
|
|
SrcPoint, DstPoint: T2DIntVector; Radius: integer);
|
|
|
|
|
|
|
|
begin
|
|
|
|
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);
|
|
|
|
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;
|
2011-06-18 12:34:17 +00:00
|
|
|
SrcImg: TLazIntfImage;
|
|
|
|
MaskImg: TLazIntfImage;
|
|
|
|
DestImg: TLazIntfImage;
|
|
|
|
i: Integer;
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
if (ABuffer.PixelFormat<>pf24bit) or (ABitmap.PixelFormat<>pf24bit) then
|
2011-06-17 21:12:21 +00:00
|
|
|
raise exception.create('TSpkGUITools.CopyRoundCorner: Tylko 24-bitowe bitmapy s¹ akceptowane!');
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
if (AMask.PixelFormat<>pf8bit) then
|
2011-06-17 21:12:21 +00:00
|
|
|
raise exception.create('TSpkGUITools.CopyRoundCorner: Tylko 8-bitowe maski s¹ akceptowane!');
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Sprawdzanie poprawnoœci
|
2011-06-17 20:53:01 +00:00
|
|
|
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<>AMask.Width) or
|
|
|
|
(ABuffer.Height<>AMask.Height) then exit;
|
|
|
|
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 21:12:21 +00:00
|
|
|
// Przycinamy Ÿród³owy rect do obszaru Ÿród³owej bitmapy
|
2011-06-17 20:53:01 +00:00
|
|
|
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);
|
|
|
|
if not(BitmapRect.IntersectsWith(T2DIntRect.create(DstPoint.x,
|
|
|
|
DstPoint.y,
|
|
|
|
DstPoint.x+Width-1,
|
|
|
|
DstPoint.y+Height-1),
|
|
|
|
DstRect)) then exit;
|
2011-06-18 13:46:52 +00:00
|
|
|
{$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;
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Liczymy offset Ÿród³owego do docelowego recta
|
2011-06-17 20:53:01 +00:00
|
|
|
Offset:=DstPoint - SrcPoint;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Sprawdzamy, czy na³o¿one na siebie recty: Ÿród³owy i docelowy przesuniêty o
|
|
|
|
// offset maj¹ jak¹œ czêœæ wspóln¹
|
2011-06-17 20:53:01 +00:00
|
|
|
if not(SrcRect.IntersectsWith(DstRect - Offset, ClippedSrcRect)) then exit;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Jeœli jest cokolwiek do przetworzenia, wykonaj operacjê
|
2011-06-17 20:53:01 +00:00
|
|
|
if (ClippedSrcRect.left<=ClippedSrcRect.right) and (ClippedSrcRect.top<=ClippedSrcRect.bottom) then
|
2011-06-18 12:34:17 +00:00
|
|
|
begin
|
|
|
|
SrcImg := ABuffer.CreateIntfImage;
|
|
|
|
DestImg := ABitmap.CreateIntfImage;
|
|
|
|
MaskImg := AMask.CreateIntfImage;
|
2011-06-17 20:53:01 +00:00
|
|
|
for y := ClippedSrcRect.top to ClippedSrcRect.bottom do
|
|
|
|
begin
|
2011-06-18 12:34:17 +00:00
|
|
|
SrcLine:=SrcImg.GetDataLineStart(y);
|
2013-02-05 01:37:55 +00:00
|
|
|
SrcLine:=pointer(PtrInt(SrcLine) + 3 * ClippedSrcRect.left);
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-18 12:34:17 +00:00
|
|
|
MaskLine:=MaskImg.GetDataLineStart(y);
|
2013-02-05 01:37:55 +00:00
|
|
|
MaskLine:=pointer(PtrInt(MaskLine) + ClippedSrcRect.left);
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-18 12:34:17 +00:00
|
|
|
DstLine:=DestImg.GetDataLineStart(y+Offset.y);
|
2013-02-05 01:37:55 +00:00
|
|
|
DstLine:=pointer(PtrInt(DstLine) + 3 * (ClippedSrcRect.left + Offset.x));
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
for i := 0 to ClippedSrcRect.Width - 1 do
|
|
|
|
begin
|
|
|
|
if PByte(MaskLine)^<128 then
|
|
|
|
Move(SrcLine^,DstLine^,3);
|
|
|
|
|
2013-02-05 01:37:55 +00:00
|
|
|
SrcLine:=pointer(PtrInt(SrcLine)+3);
|
|
|
|
DstLine:=pointer(PtrInt(DstLine)+3);
|
|
|
|
MaskLine:=pointer(PtrInt(MaskLine)+1);
|
2011-06-17 20:53:01 +00:00
|
|
|
end;
|
|
|
|
end;
|
2011-06-18 12:34:17 +00:00
|
|
|
ABitmap.LoadFromIntfImage(DestImg);
|
|
|
|
DestImg.Destroy;
|
|
|
|
SrcImg.Destroy;
|
|
|
|
MaskImg.Destroy;
|
|
|
|
end;
|
2011-06-17 20:53:01 +00:00
|
|
|
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;
|
2011-06-18 12:34:17 +00:00
|
|
|
SrcImg: TLazIntfImage;
|
|
|
|
MaskImg: TLazIntfImage;
|
|
|
|
DestImg: TLazIntfImage;
|
2011-06-17 20:53:01 +00:00
|
|
|
SrcLine: Pointer;
|
|
|
|
DstLine: Pointer;
|
|
|
|
i: Integer;
|
|
|
|
MaskLine: Pointer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if (ABuffer.PixelFormat<>pf24bit) or (ABitmap.PixelFormat<>pf24bit) then
|
2011-06-17 21:12:21 +00:00
|
|
|
raise exception.create('TSpkGUITools.CopyMaskRectangle: Tylko 24-bitowe bitmapy s¹ akceptowane!');
|
2011-06-17 20:53:01 +00:00
|
|
|
if AMask.PixelFormat<>pf8bit then
|
2011-06-17 21:12:21 +00:00
|
|
|
raise exception.create('TSpkGUITools.CopyMaskRectangle: Tylko 8-bitowe maski s¹ akceptowane!');
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Sprawdzanie poprawnoœci
|
2011-06-17 20:53:01 +00:00
|
|
|
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<>AMask.Width) or
|
|
|
|
(ABuffer.Height<>AMask.Height) then
|
2011-06-17 21:12:21 +00:00
|
|
|
raise exception.create('TSpkGUITools.CopyMaskRectangle: Maska ma nieprawid³owe rozmiary!');
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 21:12:21 +00:00
|
|
|
// Przycinamy Ÿród³owy rect do obszaru Ÿród³owej bitmapy
|
2011-06-17 20:53:01 +00:00
|
|
|
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);
|
|
|
|
if not(BitmapRect.IntersectsWith(T2DIntRect.create(DstPoint.x,
|
|
|
|
DstPoint.y,
|
|
|
|
DstPoint.x+Width-1,
|
|
|
|
DstPoint.y+Height-1),
|
|
|
|
DstRect)) then exit;
|
2011-06-18 13:46:52 +00:00
|
|
|
{$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;
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
// Dodatkowo przycinamy docelowy rect
|
|
|
|
if not(DstRect.IntersectsWith(ClipRect, ClippedDstRect)) then
|
|
|
|
Exit;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Liczymy offset Ÿród³owego do docelowego recta
|
2011-06-17 20:53:01 +00:00
|
|
|
Offset:=DstPoint - SrcPoint;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Sprawdzamy, czy na³o¿one na siebie recty: Ÿród³owy i docelowy przesuniêty o
|
|
|
|
// offset maj¹ jak¹œ czêœæ wspóln¹
|
2011-06-17 20:53:01 +00:00
|
|
|
if not(SrcRect.IntersectsWith(ClippedDstRect - Offset, ClippedSrcRect)) then exit;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Jeœli jest cokolwiek do przetworzenia, wykonaj operacjê
|
2011-06-17 20:53:01 +00:00
|
|
|
if (ClippedSrcRect.left<=ClippedSrcRect.right) and (ClippedSrcRect.top<=ClippedSrcRect.bottom) then
|
2011-06-18 12:34:17 +00:00
|
|
|
begin
|
|
|
|
SrcImg := ABuffer.CreateIntfImage;
|
|
|
|
DestImg := ABitmap.CreateIntfImage;
|
|
|
|
MaskImg := ABitmap.CreateIntfImage;
|
2011-06-17 20:53:01 +00:00
|
|
|
for y := ClippedSrcRect.top to ClippedSrcRect.bottom do
|
|
|
|
begin
|
2011-06-18 12:34:17 +00:00
|
|
|
SrcLine:=SrcImg.GetDataLineStart(y);
|
2013-02-05 01:37:55 +00:00
|
|
|
SrcLine:=pointer(PtrInt(SrcLine) + 3 * ClippedSrcRect.left);
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-18 13:46:52 +00:00
|
|
|
MaskLine:=MaskImg.GetDataLineStart(y);
|
2013-02-05 01:37:55 +00:00
|
|
|
MaskLine:=pointer(PtrInt(MaskLine) + ClippedSrcRect.left);
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-18 12:34:17 +00:00
|
|
|
DstLine:=DestImg.GetDataLineStart(y+Offset.y);
|
2013-02-05 01:37:55 +00:00
|
|
|
DstLine:=pointer(PtrInt(DstLine) + 3 * (ClippedSrcRect.left + Offset.x));
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
for i := 0 to ClippedSrcRect.width - 1 do
|
|
|
|
begin
|
|
|
|
if PByte(MaskLine)^<128 then
|
|
|
|
Move(SrcLine^, DstLine^, 3);
|
|
|
|
|
2013-02-05 01:37:55 +00:00
|
|
|
SrcLine:=pointer(PtrInt(SrcLine)+3);
|
|
|
|
DstLine:=pointer(PtrInt(DstLine)+3);
|
|
|
|
MaskLine:=pointer(PtrInt(MaskLine)+1);
|
2011-06-17 20:53:01 +00:00
|
|
|
end;
|
|
|
|
end;
|
2011-06-18 12:34:17 +00:00
|
|
|
ABitmap.LoadFromIntfImage(DestImg);
|
|
|
|
SrcImg.Destroy;
|
|
|
|
DestImg.Destroy;
|
|
|
|
MaskImg.Destroy;
|
|
|
|
end;
|
2011-06-17 20:53:01 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.CopyRectangle(ABuffer, ABitmap: TBitmap; SrcPoint,
|
|
|
|
DstPoint: T2DIntVector; Width, Height: integer; ClipRect: T2DIntRect);
|
|
|
|
|
|
|
|
var BufferRect, BitmapRect : T2DIntRect;
|
|
|
|
SrcRect, DstRect : T2DIntRect;
|
|
|
|
ClippedSrcRect, ClippedDstRect : T2DIntRect;
|
|
|
|
Offset : T2DIntVector;
|
|
|
|
y: Integer;
|
2011-06-18 12:34:17 +00:00
|
|
|
DestImg: TLazIntfImage;
|
|
|
|
SrcImg: TLazIntfImage;
|
2011-06-17 20:53:01 +00:00
|
|
|
SrcLine: Pointer;
|
|
|
|
DstLine: Pointer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if (ABuffer.PixelFormat<>pf24bit) or (ABitmap.PixelFormat<>pf24bit) then
|
2011-06-17 21:12:21 +00:00
|
|
|
raise exception.create('TSpkGUITools.CopyRoundCorner: Tylko 24-bitowe bitmapy s¹ akceptowane!');
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Sprawdzanie poprawnoœci
|
2011-06-17 20:53:01 +00:00
|
|
|
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;
|
|
|
|
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 21:12:21 +00:00
|
|
|
// Przycinamy Ÿród³owy rect do obszaru Ÿród³owej bitmapy
|
2011-06-17 20:53:01 +00:00
|
|
|
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);
|
|
|
|
if not(BitmapRect.IntersectsWith(T2DIntRect.create(DstPoint.x,
|
|
|
|
DstPoint.y,
|
|
|
|
DstPoint.x+Width-1,
|
|
|
|
DstPoint.y+Height-1),
|
|
|
|
DstRect)) then exit;
|
2011-06-18 13:46:52 +00:00
|
|
|
{$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;
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
// Dodatkowo przycinamy docelowy rect
|
|
|
|
if not(DstRect.IntersectsWith(ClipRect, ClippedDstRect)) then
|
|
|
|
Exit;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Liczymy offset Ÿród³owego do docelowego recta
|
2011-06-17 20:53:01 +00:00
|
|
|
Offset:=DstPoint - SrcPoint;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Sprawdzamy, czy na³o¿one na siebie recty: Ÿród³owy i docelowy przesuniêty o
|
|
|
|
// offset maj¹ jak¹œ czêœæ wspóln¹
|
2011-06-17 20:53:01 +00:00
|
|
|
if not(SrcRect.IntersectsWith(ClippedDstRect - Offset, ClippedSrcRect)) then exit;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Jeœli jest cokolwiek do przetworzenia, wykonaj operacjê
|
2011-06-17 20:53:01 +00:00
|
|
|
if (ClippedSrcRect.left<=ClippedSrcRect.right) and (ClippedSrcRect.top<=ClippedSrcRect.bottom) then
|
2011-06-18 12:34:17 +00:00
|
|
|
begin
|
|
|
|
SrcImg := ABuffer.CreateIntfImage;
|
|
|
|
DestImg := ABitmap.CreateIntfImage;
|
2011-06-17 20:53:01 +00:00
|
|
|
for y := ClippedSrcRect.top to ClippedSrcRect.bottom do
|
|
|
|
begin
|
2011-06-18 12:34:17 +00:00
|
|
|
SrcLine:=SrcImg.GetDataLineStart(y);
|
|
|
|
DstLine:=DestImg.GetDataLineStart(y+Offset.y);
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2013-02-05 01:37:55 +00:00
|
|
|
Move(pointer(PtrInt(SrcLine) + 3*ClippedSrcRect.left)^,
|
|
|
|
pointer(PtrInt(DstLine) + 3*(ClippedSrcRect.left + Offset.x))^,
|
2011-06-17 20:53:01 +00:00
|
|
|
3*ClippedSrcRect.Width);
|
|
|
|
end;
|
2011-06-18 12:34:17 +00:00
|
|
|
ABitmap.LoadFromIntfImage(DestImg);
|
|
|
|
DestImg.Destroy;
|
|
|
|
SrcImg.Destroy;
|
|
|
|
end;
|
2011-06-17 20:53:01 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.CopyRoundCorner(ABuffer: TBitmap; ABitmap: TBitmap;
|
|
|
|
SrcPoint, DstPoint: T2DIntVector; Radius: integer; CornerPos: TCornerPos;
|
|
|
|
Convex: boolean);
|
|
|
|
|
|
|
|
var BufferRect, BitmapRect : T2DIntRect;
|
|
|
|
OrgSrcRect, OrgDstRect : T2DIntRect;
|
|
|
|
SrcRect : T2DIntRect;
|
|
|
|
Offset : T2DIntVector;
|
|
|
|
Center: T2DIntVector;
|
|
|
|
y: Integer;
|
2011-06-18 12:34:17 +00:00
|
|
|
SrcImg: TLazIntfImage;
|
|
|
|
DestImg: TLazIntfImage;
|
2011-06-17 20:53:01 +00:00
|
|
|
SrcLine: Pointer;
|
|
|
|
DstLine: Pointer;
|
|
|
|
SrcPtr, DstPtr : PByte;
|
|
|
|
x: Integer;
|
|
|
|
Dist : double;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if (ABuffer.PixelFormat<>pf24bit) or (ABitmap.PixelFormat<>pf24bit) then
|
2011-06-17 21:12:21 +00:00
|
|
|
raise exception.create('TSpkGUITools.CopyRoundCorner: Tylko 24-bitowe bitmapy s¹ akceptowane!');
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Sprawdzanie poprawnoœci
|
2011-06-17 20:53:01 +00:00
|
|
|
if Radius<1 then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
if (ABuffer.width=0) or (ABuffer.height=0) or
|
|
|
|
(ABitmap.width=0) or (ABitmap.height=0) then exit;
|
|
|
|
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
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),
|
|
|
|
OrgDstRect)) then exit;
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
BufferRect.create(0, 0, ABuffer.width-1, ABuffer.height-1);
|
|
|
|
if not(BufferRect.IntersectsWith(Create2DIntRect(SrcPoint.x,
|
|
|
|
SrcPoint.y,
|
|
|
|
SrcPoint.x+Radius-1,
|
|
|
|
SrcPoint.y+Radius-1),
|
|
|
|
OrgSrcRect)) then exit;
|
|
|
|
|
|
|
|
BitmapRect.create(0, 0, ABitmap.width-1, ABitmap.height-1);
|
|
|
|
if not(BitmapRect.IntersectsWith(Create2DIntRect(DstPoint.x,
|
|
|
|
DstPoint.y,
|
|
|
|
DstPoint.x+Radius-1,
|
|
|
|
DstPoint.y+Radius-1),
|
|
|
|
OrgDstRect)) then exit;
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
Offset:=DstPoint - SrcPoint;
|
|
|
|
|
|
|
|
if not(OrgSrcRect.IntersectsWith(OrgDstRect - Offset, SrcRect)) then exit;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Ustalamy pozycjê œrodka ³uku
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
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;
|
2011-06-18 13:46:52 +00:00
|
|
|
{$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}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
// Czy jest cokolwiek do przetworzenia?
|
|
|
|
if Convex then
|
|
|
|
begin
|
|
|
|
if (SrcRect.left<=SrcRect.right) and (SrcRect.top<=SrcRect.bottom) then
|
2011-06-18 12:34:17 +00:00
|
|
|
begin
|
|
|
|
SrcImg := ABuffer.CreateIntfImage;
|
|
|
|
DestImg := ABitmap.CreateIntfImage;
|
2011-06-17 20:53:01 +00:00
|
|
|
for y := SrcRect.top to SrcRect.bottom do
|
|
|
|
begin
|
2011-06-18 12:34:17 +00:00
|
|
|
SrcLine:=SrcImg.GetDataLineStart(y);
|
|
|
|
DstLine:=DestImg.GetDataLineStart(y+Offset.y);
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2013-02-05 01:37:55 +00:00
|
|
|
SrcPtr:=pointer(PtrInt(SrcLine) + 3*SrcRect.left);
|
|
|
|
DstPtr:=pointer(PtrInt(DstLine) + 3*(SrcRect.left + Offset.x));
|
2011-06-17 20:53:01 +00:00
|
|
|
for x := SrcRect.left to SrcRect.right do
|
|
|
|
begin
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
Dist:=Center.DistanceTo(T2DVector.create(x, y));
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Dist:=Center.DistanceTo(x, y);
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
if Dist <= (Radius-1) then
|
|
|
|
Move(SrcPtr^,DstPtr^,3);
|
|
|
|
|
|
|
|
inc(SrcPtr,3);
|
|
|
|
inc(DstPtr,3);
|
|
|
|
end;
|
|
|
|
end;
|
2011-06-18 12:34:17 +00:00
|
|
|
ABitmap.LoadFromIntfImage(DestImg);
|
|
|
|
SrcImg.Destroy;
|
|
|
|
DestImg.Destroy;
|
|
|
|
end;
|
2011-06-17 20:53:01 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
if (SrcRect.left<=SrcRect.right) and (SrcRect.top<=SrcRect.bottom) then
|
2011-06-18 12:34:17 +00:00
|
|
|
begin
|
|
|
|
SrcImg := ABuffer.CreateIntfImage;
|
|
|
|
DestImg := ABitmap.CreateIntfImage;
|
2011-06-17 20:53:01 +00:00
|
|
|
for y := SrcRect.top to SrcRect.bottom do
|
|
|
|
begin
|
2011-06-18 12:34:17 +00:00
|
|
|
SrcLine:=SrcImg.GetDataLineStart(y);
|
|
|
|
DstLine:=DestImg.GetDataLineStart(y+Offset.y);
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2013-02-05 01:37:55 +00:00
|
|
|
SrcPtr:=pointer(PtrInt(SrcLine) + 3*SrcRect.left);
|
|
|
|
DstPtr:=pointer(PtrInt(DstLine) + 3*(SrcRect.left + Offset.x));
|
2011-06-17 20:53:01 +00:00
|
|
|
for x := SrcRect.left to SrcRect.right do
|
|
|
|
begin
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
Dist:=Center.DistanceTo(T2DVector.create(x, y));
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
Dist:=Center.DistanceTo(x, y);
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
if Dist >= (Radius-1) then
|
|
|
|
Move(SrcPtr^,DstPtr^,3);
|
|
|
|
|
|
|
|
inc(SrcPtr,3);
|
|
|
|
inc(DstPtr,3);
|
|
|
|
end;
|
|
|
|
end;
|
2011-06-18 12:34:17 +00:00
|
|
|
ABitmap.LoadFromIntfImage(DestImg);
|
|
|
|
SrcImg.Destroy;
|
|
|
|
DestImg.Destroy;
|
|
|
|
end;
|
2011-06-17 20:53:01 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawAARoundCorner(ABitmap: TBitmap; Point: T2DIntVector;
|
|
|
|
Radius: integer; CornerPos: TCornerPos; Color: TColor);
|
|
|
|
|
|
|
|
var CornerRect : T2DIntRect;
|
|
|
|
Center : T2DIntVector;
|
|
|
|
Line : PByte;
|
|
|
|
Ptr : PByte;
|
|
|
|
colorR, colorG, colorB : byte;
|
|
|
|
x, y : integer;
|
|
|
|
RadiusDist : double;
|
|
|
|
OrgCornerRect: T2DIntRect;
|
|
|
|
BitmapRect: T2DIntRect;
|
2011-06-18 12:34:17 +00:00
|
|
|
DestImg: TLazIntfImage;
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
if ABitmap.PixelFormat<>pf24bit then
|
2011-06-17 21:12:21 +00:00
|
|
|
raise exception.create('TSpkGUITools.DrawAARoundCorner: Bitmapa musi byæ w trybie 24-bitowym!');
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Sprawdzamy poprawnoϾ
|
2011-06-17 20:53:01 +00:00
|
|
|
if Radius<1 then
|
|
|
|
exit;
|
|
|
|
if (ABitmap.width=0) or (ABitmap.height=0) then
|
|
|
|
exit;
|
|
|
|
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2013-02-05 01:37:55 +00:00
|
|
|
// �?ród³owy rect...
|
2011-06-17 20:53:01 +00:00
|
|
|
OrgCornerRect:=T2DIntRect.create(Point.x,
|
|
|
|
Point.y,
|
|
|
|
Point.x + radius - 1,
|
|
|
|
Point.y + radius - 1);
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// ...przycinamy do rozmiarów bitmapy
|
2011-06-17 20:53:01 +00:00
|
|
|
BitmapRect:=T2DIntRect.create(0, 0, ABitmap.width-1, ABitmap.height-1);
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
2013-02-05 01:37:55 +00:00
|
|
|
// �?ród³owy rect...
|
2011-06-18 13:46:52 +00:00
|
|
|
OrgCornerRect.create(Point.x,
|
|
|
|
Point.y,
|
|
|
|
Point.x + radius - 1,
|
|
|
|
Point.y + radius - 1);
|
|
|
|
|
|
|
|
// ...przycinamy do rozmiarów bitmapy
|
|
|
|
BitmapRect.create(0, 0, ABitmap.width-1, ABitmap.height-1);
|
|
|
|
{$ENDIF}
|
|
|
|
|
2011-06-17 20:53:01 +00:00
|
|
|
if not(BitmapRect.intersectsWith(OrgCornerRect, CornerRect)) then
|
|
|
|
exit;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Jeœli nie ma czego rysowaæ, wychodzimy
|
2011-06-17 20:53:01 +00:00
|
|
|
if (CornerRect.left>CornerRect.right) or (CornerRect.top>CornerRect.bottom) then
|
|
|
|
exit;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Szukamy œrodka ³uku - zale¿nie od rodzaju naro¿nika
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
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;
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
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}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
Color:=ColorToRGB(Color);
|
|
|
|
|
|
|
|
colorR:=GetRValue(Color);
|
|
|
|
colorG:=GetGValue(Color);
|
|
|
|
ColorB:=GetBValue(Color);
|
2011-06-18 12:34:17 +00:00
|
|
|
DestImg := ABitmap.CreateIntfImage;
|
2011-06-17 20:53:01 +00:00
|
|
|
for y := CornerRect.top to CornerRect.bottom do
|
|
|
|
begin
|
2011-06-18 12:34:17 +00:00
|
|
|
Line:=DestImg.GetDataLineStart(y);
|
2011-06-17 20:53:01 +00:00
|
|
|
for x := CornerRect.left to CornerRect.right do
|
|
|
|
begin
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
RadiusDist:=1 - abs((Radius - 1) - Center.DistanceTo(T2DIntVector.create(x, y)));
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
RadiusDist:=1 - abs((Radius - 1) - Center.DistanceTo(x, y));
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
if RadiusDist>0 then
|
|
|
|
begin
|
2013-02-05 01:37:55 +00:00
|
|
|
Ptr:=pointer(PtrInt(Line) + 3*x);
|
2011-06-17 20:53:01 +00:00
|
|
|
Ptr^:=round(Ptr^ + (ColorB - Ptr^) * RadiusDist); inc(Ptr);
|
|
|
|
Ptr^:=round(Ptr^ + (ColorG - Ptr^) * RadiusDist); inc(Ptr);
|
|
|
|
Ptr^:=round(Ptr^ + (ColorR - Ptr^) * RadiusDist);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
2011-06-18 12:34:17 +00:00
|
|
|
ABitmap.LoadFromIntfImage(DestImg);
|
|
|
|
DestImg.Destroy;
|
2011-06-17 20:53:01 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawAARoundCorner(ABitmap: TBitmap;
|
|
|
|
Point: T2DIntVector; Radius: integer; CornerPos: TCornerPos; Color: TColor;
|
|
|
|
ClipRect: T2DIntRect);
|
|
|
|
|
|
|
|
var CornerRect : T2DIntRect;
|
|
|
|
Center : T2DIntVector;
|
|
|
|
Line : PByte;
|
|
|
|
Ptr : PByte;
|
|
|
|
colorR, colorG, colorB : byte;
|
|
|
|
x, y : integer;
|
|
|
|
RadiusDist : double;
|
|
|
|
OrgCornerRect: T2DIntRect;
|
|
|
|
UnClippedCornerRect : T2DIntRect;
|
|
|
|
BitmapRect: T2DIntRect;
|
2011-06-18 12:34:17 +00:00
|
|
|
DestImg: TLazIntfImage;
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
if ABitmap.PixelFormat<>pf24bit then
|
2011-06-17 21:12:21 +00:00
|
|
|
raise exception.create('TSpkGUITools.DrawAARoundCorner: Bitmapa musi byæ w trybie 24-bitowym!');
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Sprawdzamy poprawnoϾ
|
2011-06-17 20:53:01 +00:00
|
|
|
if Radius<1 then
|
|
|
|
exit;
|
|
|
|
if (ABitmap.width=0) or (ABitmap.height=0) then
|
|
|
|
exit;
|
|
|
|
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2013-02-05 01:37:55 +00:00
|
|
|
// �?ród³owy rect...
|
2011-06-17 20:53:01 +00:00
|
|
|
OrgCornerRect:=T2DIntRect.create(Point.x,
|
|
|
|
Point.y,
|
|
|
|
Point.x + radius - 1,
|
|
|
|
Point.y + radius - 1);
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// ...przycinamy do rozmiarów bitmapy
|
2011-06-17 20:53:01 +00:00
|
|
|
BitmapRect:=T2DIntRect.create(0, 0, ABitmap.width-1, ABitmap.height-1);
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
2013-02-05 01:37:55 +00:00
|
|
|
// �?ród³owy rect...
|
2011-06-18 13:46:52 +00:00
|
|
|
OrgCornerRect.create(Point.x,
|
|
|
|
Point.y,
|
|
|
|
Point.x + radius - 1,
|
|
|
|
Point.y + radius - 1);
|
|
|
|
|
|
|
|
// ...przycinamy do rozmiarów bitmapy
|
|
|
|
BitmapRect.create(0, 0, ABitmap.width-1, ABitmap.height-1);
|
|
|
|
{$ENDIF}
|
|
|
|
|
2011-06-17 20:53:01 +00:00
|
|
|
if not(BitmapRect.intersectsWith(OrgCornerRect, UnClippedCornerRect)) then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
// ClipRect
|
|
|
|
if not(UnClippedCornerRect.IntersectsWith(ClipRect, CornerRect)) then
|
|
|
|
exit;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Jeœli nie ma czego rysowaæ, wychodzimy
|
2011-06-17 20:53:01 +00:00
|
|
|
if (CornerRect.left>CornerRect.right) or (CornerRect.top>CornerRect.bottom) then
|
|
|
|
exit;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Szukamy œrodka ³uku - zale¿nie od rodzaju naro¿nika
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
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;
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
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}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
Color:=ColorToRGB(Color);
|
|
|
|
|
|
|
|
colorR:=GetRValue(Color);
|
|
|
|
colorG:=GetGValue(Color);
|
|
|
|
ColorB:=GetBValue(Color);
|
|
|
|
|
2011-06-18 12:34:17 +00:00
|
|
|
DestImg := ABitmap.CreateIntfImage;
|
2011-06-17 20:53:01 +00:00
|
|
|
for y := CornerRect.top to CornerRect.bottom do
|
|
|
|
begin
|
2011-06-18 12:34:17 +00:00
|
|
|
Line:=DestImg.GetDataLineStart(y);
|
2011-06-17 20:53:01 +00:00
|
|
|
for x := CornerRect.left to CornerRect.right do
|
|
|
|
begin
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
RadiusDist:=1 - abs((Radius - 1) - Center.DistanceTo(T2DIntVector.create(x, y)));
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
RadiusDist:=1 - abs((Radius - 1) - Center.DistanceTo(x, y));
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
if RadiusDist>0 then
|
|
|
|
begin
|
2013-02-05 01:37:55 +00:00
|
|
|
Ptr:=pointer(PtrInt(Line) + 3*x);
|
2011-06-17 20:53:01 +00:00
|
|
|
Ptr^:=round(Ptr^ + (ColorB - Ptr^) * RadiusDist); inc(Ptr);
|
|
|
|
Ptr^:=round(Ptr^ + (ColorG - Ptr^) * RadiusDist); inc(Ptr);
|
|
|
|
Ptr^:=round(Ptr^ + (ColorR - Ptr^) * RadiusDist);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
2011-06-18 12:34:17 +00:00
|
|
|
ABitmap.LoadFromIntfImage(DestImg);
|
|
|
|
DestImg.Destroy;
|
2011-06-17 20:53:01 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
begin
|
2011-06-17 21:12:21 +00:00
|
|
|
// Sprawdzamy poprawnoϾ
|
2011-06-17 20:53:01 +00:00
|
|
|
if Radius<1 then
|
|
|
|
exit;
|
|
|
|
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2013-02-05 01:37:55 +00:00
|
|
|
// �?ród³owy rect...
|
2011-06-17 20:53:01 +00:00
|
|
|
CornerRect:=T2DIntRect.create(Point.x,
|
|
|
|
Point.y,
|
|
|
|
Point.x + radius - 1,
|
|
|
|
Point.y + radius - 1);
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Szukamy œrodka ³uku - zale¿nie od rodzaju naro¿nika
|
2011-06-17 20:53:01 +00:00
|
|
|
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;
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
2013-02-05 01:37:55 +00:00
|
|
|
// �?ród³owy rect...
|
2011-06-18 13:46:52 +00:00
|
|
|
CornerRect.create(Point.x,
|
|
|
|
Point.y,
|
|
|
|
Point.x + radius - 1,
|
|
|
|
Point.y + radius - 1);
|
|
|
|
|
|
|
|
// 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}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
Color:=ColorToRGB(Color);
|
|
|
|
|
|
|
|
for y := CornerRect.top to CornerRect.bottom do
|
|
|
|
begin
|
|
|
|
for x := CornerRect.left to CornerRect.right do
|
|
|
|
begin
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
RadiusDist:=1 - abs((Radius - 1) - Center.DistanceTo(T2DIntVector.create(x, y)));
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
RadiusDist:=1 - abs((Radius - 1) - Center.DistanceTo(x, y));
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
begin
|
2011-06-17 21:12:21 +00:00
|
|
|
// Zapamiêtywanie oryginalnego ClipRgn i ustawianie nowego
|
2011-06-17 20:53:01 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
SelectClipRgn(ACanvas.Handle, ClipRgn);
|
|
|
|
|
|
|
|
DrawAARoundCorner(ACanvas, Point, Radius, CornerPos, Color);
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Przywracanie poprzedniego ClipRgn i usuwanie wykorzystanych regionów
|
2011-06-17 20:53:01 +00:00
|
|
|
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
|
2011-06-17 21:12:21 +00:00
|
|
|
raise exception.create('TGUITools.DrawAARoundFrame: Bitmapa musi byæ w trybie 24-bitowym!');
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
if (Radius<1) then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
if (Radius>Rect.width div 2) or (Radius>Rect.height div 2) then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
// DrawAARoundCorner jest zabezpieczony przed rysowaniem poza obszarem
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
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);
|
2011-06-18 13:46:52 +00:00
|
|
|
{$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}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
ABitmap.Canvas.Pen.color:=Color;
|
|
|
|
ABitmap.Canvas.pen.style:=psSolid;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Draw*Line s¹ zabezpieczone przed rysowaniem poza obszarem
|
2011-06-17 20:53:01 +00:00
|
|
|
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
|
2011-06-17 21:12:21 +00:00
|
|
|
raise exception.create('TGUITools.DrawAARoundFrame: Bitmapa musi byæ w trybie 24-bitowym!');
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
if (Radius<1) then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
if (Radius>Rect.width div 2) or (Radius>Rect.height div 2) then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
// DrawAARoundCorner jest zabezpieczony przed rysowaniem poza obszarem
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
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);
|
2011-06-18 13:46:52 +00:00
|
|
|
{$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}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
ABitmap.canvas.Pen.color:=Color;
|
|
|
|
ABitmap.canvas.pen.style:=psSolid;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Draw*Line s¹ zabezpieczone przed rysowaniem poza obszarem
|
2011-06-17 20:53:01 +00:00
|
|
|
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;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText: string; TextColor: TColor; Align : TAlignment);
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
var tw : integer;
|
|
|
|
s : string;
|
|
|
|
|
|
|
|
begin
|
|
|
|
with ABitmap.Canvas do
|
|
|
|
begin
|
|
|
|
s:=AText;
|
|
|
|
tw:=TextWidth(s);
|
2011-06-17 21:12:21 +00:00
|
|
|
// Jeœli tekst siê zmieœci, rysujemy
|
2011-06-17 20:53:01 +00:00
|
|
|
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 x2<x1 then
|
|
|
|
begin
|
|
|
|
tmp:=x1;
|
|
|
|
x1:=x2;
|
|
|
|
x2:=tmp;
|
|
|
|
end;
|
|
|
|
|
|
|
|
ACanvas.pen.color:=Color;
|
|
|
|
ACanvas.moveto(x1, y);
|
|
|
|
ACanvas.lineto(x2+1,y);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawHLine(ACanvas: TCanvas; x1, x2, y: integer;
|
|
|
|
Color: TColor; ClipRect: T2DIntRect);
|
|
|
|
|
|
|
|
var UseOrgClipRgn : boolean;
|
|
|
|
ClipRgn : HRGN;
|
|
|
|
OrgRgn : HRGN;
|
|
|
|
|
|
|
|
begin
|
2011-06-17 21:12:21 +00:00
|
|
|
// Zapamiêtywanie oryginalnego ClipRgn i ustawianie nowego
|
2011-06-17 20:53:01 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
SelectClipRgn(ACanvas.Handle, ClipRgn);
|
|
|
|
|
|
|
|
DrawHLine(ACanvas, x1, x2, y, Color);
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Przywracanie poprzedniego ClipRgn i usuwanie wykorzystanych regionów
|
2011-06-17 20:53:01 +00:00
|
|
|
RestoreClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn);
|
|
|
|
DeleteObject(ClipRgn);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawImage(ABitmap: TBitmap; Imagelist: TImageList;
|
|
|
|
ImageIndex: integer; Point : T2DIntVector; ClipRect: T2DIntRect);
|
|
|
|
|
|
|
|
begin
|
|
|
|
DrawImage(ABitmap.Canvas, ImageList, ImageIndex, Point, ClipRect);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawImage(ABitmap: TBitmap; Imagelist: TImageList;
|
|
|
|
ImageIndex: integer; Point: T2DIntVector);
|
|
|
|
begin
|
|
|
|
DrawImage(ABitmap.Canvas, ImageList, ImageIndex, Point);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawImage(ACanvas: TCanvas; Imagelist: TImageList;
|
|
|
|
ImageIndex: integer; Point : T2DIntVector; ClipRect: T2DIntRect);
|
|
|
|
|
|
|
|
var UseOrgClipRgn: Boolean;
|
|
|
|
OrgRgn: HRGN;
|
|
|
|
ClipRgn: HRGN;
|
|
|
|
|
|
|
|
begin
|
2011-06-17 21:12:21 +00:00
|
|
|
// Zapamiêtywanie oryginalnego ClipRgn i ustawianie nowego
|
2011-06-17 20:53:01 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
SelectClipRgn(ACanvas.Handle, ClipRgn);
|
|
|
|
|
|
|
|
ImageList.Draw(ACanvas, Point.x, Point.y, ImageIndex);
|
|
|
|
|
|
|
|
RestoreClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn);
|
|
|
|
DeleteObject(ClipRgn);
|
|
|
|
end;
|
|
|
|
|
2011-06-18 13:46:52 +00:00
|
|
|
class procedure TGUITools.DrawMarkedText(ACanvas: TCanvas; x, y: integer; const AText,
|
2011-06-17 20:53:01 +00:00
|
|
|
AMarkPhrase: string; TextColor : TColor; ClipRect: T2DIntRect; CaseSensitive: boolean);
|
|
|
|
|
|
|
|
var UseOrgClipRgn: Boolean;
|
|
|
|
OrgRgn: HRGN;
|
|
|
|
ClipRgn: HRGN;
|
|
|
|
|
|
|
|
begin
|
2011-06-17 21:12:21 +00:00
|
|
|
// Zapamiêtywanie oryginalnego ClipRgn i ustawianie nowego
|
2011-06-17 20:53:01 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
SelectClipRgn(ACanvas.Handle, ClipRgn);
|
|
|
|
|
|
|
|
DrawMarkedText(ACanvas, x, y, AText, AMarkPhrase, TextColor, CaseSensitive);
|
|
|
|
|
|
|
|
RestoreClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn);
|
|
|
|
DeleteObject(ClipRgn);
|
|
|
|
end;
|
|
|
|
|
2011-06-18 13:46:52 +00:00
|
|
|
class procedure TGUITools.DrawMarkedText(ACanvas: TCanvas; x, y: integer; const AText,
|
2011-06-17 20:53:01 +00:00
|
|
|
AMarkPhrase: string; TextColor : TColor; CaseSensitive : boolean);
|
|
|
|
|
2011-06-18 13:46:52 +00:00
|
|
|
var TextToDraw : string;
|
2011-06-17 20:53:01 +00:00
|
|
|
BaseText : string;
|
|
|
|
MarkText : string;
|
|
|
|
MarkPos: Integer;
|
|
|
|
x1 : integer;
|
|
|
|
s: string;
|
|
|
|
MarkTextLength: Integer;
|
|
|
|
|
|
|
|
begin
|
2011-06-18 13:46:52 +00:00
|
|
|
TextToDraw:=AText;
|
2011-06-17 20:53:01 +00:00
|
|
|
if CaseSensitive then
|
|
|
|
begin
|
|
|
|
BaseText:=AText;
|
|
|
|
MarkText:=AMarkPhrase;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
BaseText:=AnsiUpperCase(AText);
|
|
|
|
MarkText:=AnsiUpperCase(AMarkPhrase);
|
|
|
|
end;
|
|
|
|
|
|
|
|
x1:=x;
|
|
|
|
MarkTextLength:=length(MarkText);
|
|
|
|
|
|
|
|
ACanvas.Font.Color:=TextColor;
|
|
|
|
ACanvas.Brush.Style:=bsClear;
|
|
|
|
|
|
|
|
MarkPos:=pos(MarkText, BaseText);
|
|
|
|
while MarkPos>0 do
|
|
|
|
begin
|
|
|
|
if MarkPos>1 then
|
|
|
|
begin
|
2011-06-17 21:12:21 +00:00
|
|
|
// Rysowanie tekstu przed wyró¿nionym
|
2011-06-17 20:53:01 +00:00
|
|
|
ACanvas.Font.Style:=ACanvas.Font.Style - [fsBold];
|
2011-06-18 13:46:52 +00:00
|
|
|
s:=copy(TextToDraw, 1, MarkPos-1);
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
ACanvas.TextOut(x1, y, s);
|
|
|
|
inc(x1, ACanvas.TextWidth(s)+1);
|
|
|
|
|
2011-06-18 13:46:52 +00:00
|
|
|
delete(TextToDraw, 1, MarkPos-1);
|
2011-06-17 20:53:01 +00:00
|
|
|
delete(BaseText, 1, MarkPos-1);
|
|
|
|
end;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Rysowanie wyró¿nionego tekstu
|
2011-06-17 20:53:01 +00:00
|
|
|
ACanvas.Font.Style:=ACanvas.Font.Style + [fsBold];
|
2011-06-18 13:46:52 +00:00
|
|
|
s:=copy(TextToDraw, 1, MarkTextLength);
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
ACanvas.TextOut(x1, y, s);
|
|
|
|
inc(x1, ACanvas.TextWidth(s)+1);
|
|
|
|
|
2011-06-18 13:46:52 +00:00
|
|
|
delete(TextToDraw, 1, MarkTextLength);
|
2011-06-17 20:53:01 +00:00
|
|
|
delete(BaseText, 1, MarkTextLength);
|
|
|
|
|
|
|
|
MarkPos:=pos(MarkText, BaseText);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if Length(BaseText)>0 then
|
|
|
|
begin
|
|
|
|
ACanvas.Font.Style:=ACanvas.Font.Style - [fsBold];
|
2011-06-18 13:46:52 +00:00
|
|
|
ACanvas.TextOut(x1, y, TextToDraw);
|
2011-06-17 20:53:01 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawImage(ACanvas: TCanvas; Imagelist: TImageList;
|
|
|
|
ImageIndex: integer; Point: T2DIntVector);
|
|
|
|
begin
|
|
|
|
ImageList.Draw(ACanvas, Point.x, Point.y, ImageIndex);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawOutlinedText(ACanvas: TCanvas; x, y: integer;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText: string; TextColor, OutlineColor: TColor);
|
2011-06-17 20:53:01 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
font.color:=TextColor;
|
|
|
|
TextOut(x, y, AText);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawOutlinedText(ACanvas: TCanvas; x, y: integer;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText: string; TextColor, OutlineColor: TColor; ClipRect: T2DIntRect);
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if ABitmap.PixelFormat<>pf24bit then
|
2011-06-17 21:12:21 +00:00
|
|
|
raise exception.create('TGUITools.DrawHLine: Bitmapa musi byæ w trybie 24-bitowym!');
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
if x2<x1 then
|
|
|
|
begin
|
|
|
|
tmp:=x1;
|
|
|
|
x1:=x2;
|
|
|
|
x2:=tmp;
|
|
|
|
end;
|
|
|
|
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
BitmapRect:=T2DIntRect.create(0, 0, ABitmap.width-1, ABitmap.height-1);
|
|
|
|
if not(BitmapRect.IntersectsWith(T2DIntRect.create(x1, y, x2, y), LineRect)) then
|
|
|
|
exit;
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
BitmapRect.create(0, 0, ABitmap.width-1, ABitmap.height-1);
|
|
|
|
if not(BitmapRect.IntersectsWith(Create2DIntRect(x1, y, x2, y), LineRect)) then
|
|
|
|
exit;
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
ABitmap.canvas.pen.color:=Color;
|
|
|
|
ABitmap.canvas.pen.style:=psSolid;
|
|
|
|
ABitmap.canvas.moveto(LineRect.left, LineRect.Top);
|
|
|
|
ABitmap.canvas.lineto(LineRect.right+1, Linerect.top);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawHLine(ABitmap: TBitmap; x1, x2, y: integer;
|
|
|
|
Color: TColor; ClipRect: T2DIntRect);
|
|
|
|
|
|
|
|
var OrgLineRect : T2DIntRect;
|
|
|
|
LineRect : T2DIntRect;
|
|
|
|
BitmapRect : T2DIntRect;
|
|
|
|
tmp: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if ABitmap.PixelFormat<>pf24bit then
|
2011-06-17 21:12:21 +00:00
|
|
|
raise exception.create('TGUITools.DrawHLine: Bitmapa musi byæ w trybie 24-bitowym!');
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
if x2<x1 then
|
|
|
|
begin
|
|
|
|
tmp:=x1;
|
|
|
|
x1:=x2;
|
|
|
|
x2:=tmp;
|
|
|
|
end;
|
|
|
|
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
BitmapRect:=T2DIntRect.create(0, 0, ABitmap.width-1, ABitmap.height-1);
|
|
|
|
if not(BitmapRect.IntersectsWith(T2DIntRect.create(x1, y, x2, y), OrgLineRect)) then
|
|
|
|
exit;
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
BitmapRect.create(0, 0, ABitmap.width-1, ABitmap.height-1);
|
|
|
|
if not(BitmapRect.IntersectsWith(Create2DIntRect(x1, y, x2, y), OrgLineRect)) then
|
|
|
|
exit;
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
if not(OrgLineRect.IntersectsWith(ClipRect, LineRect)) then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
ABitmap.canvas.pen.color:=Color;
|
|
|
|
ABitmap.canvas.pen.style:=psSolid;
|
|
|
|
ABitmap.canvas.moveto(LineRect.left, LineRect.Top);
|
|
|
|
ABitmap.canvas.lineto(LineRect.right+1, Linerect.top);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawOutlinedText(ABitmap: TBitmap; x, y: integer;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText: string; TextColor, OutlineColor: TColor; ClipRect: T2DIntRect);
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
var WinAPIClipRect : TRect;
|
|
|
|
|
|
|
|
begin
|
|
|
|
WinAPIClipRect:=ClipRect.ForWinAPI;
|
|
|
|
with ABitmap.canvas 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;
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawRegion(ACanvas: TCanvas; Region: HRGN; Rect : T2DIntRect; ColorFrom,
|
|
|
|
ColorTo: TColor; GradientKind: TBackgroundKind);
|
|
|
|
|
|
|
|
var UseOrgClipRgn: Boolean;
|
|
|
|
OrgRgn: HRGN;
|
|
|
|
|
|
|
|
begin
|
2011-06-17 21:12:21 +00:00
|
|
|
// Zapamiêtywanie oryginalnego ClipRgn i ustawianie nowego
|
2011-06-17 20:53:01 +00:00
|
|
|
SaveClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn);
|
|
|
|
SelectClipRgn(ACanvas.Handle, Region);
|
|
|
|
|
|
|
|
FillGradientRectangle(ACanvas, Rect, ColorFrom, ColorTo, GradientKind);
|
|
|
|
|
|
|
|
RestoreClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawRegion(ACanvas: TCanvas; Region: HRGN; Rect : T2DIntRect; ColorFrom,
|
|
|
|
ColorTo: TColor; GradientKind: TBackgroundKind; ClipRect: T2DIntRect);
|
|
|
|
|
|
|
|
var UseOrgClipRgn : boolean;
|
|
|
|
ClipRgn : HRGN;
|
|
|
|
OrgRgn : HRGN;
|
|
|
|
|
|
|
|
begin
|
2011-06-17 21:12:21 +00:00
|
|
|
// Zapamiêtywanie oryginalnego ClipRgn i ustawianie nowego
|
2011-06-17 20:53:01 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
SelectClipRgn(ACanvas.Handle, ClipRgn);
|
|
|
|
|
|
|
|
DrawRegion(ACanvas, Region, Rect, ColorFrom, ColorTo, GradientKind);
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Przywracanie poprzedniego ClipRgn i usuwanie wykorzystanych regionów
|
2011-06-17 20:53:01 +00:00
|
|
|
RestoreClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn);
|
|
|
|
DeleteObject(ClipRgn);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawRoundRect(ACanvas: TCanvas; Rect: T2DIntRect;
|
|
|
|
Radius: integer; ColorFrom, ColorTo: TColor; GradientKind: TBackgroundKind;
|
|
|
|
ClipRect: T2DIntRect; LeftTopRound, RightTopRound, LeftBottomRound,
|
|
|
|
RightBottomRound: boolean);
|
|
|
|
|
|
|
|
var UseOrgClipRgn : boolean;
|
|
|
|
ClipRgn : HRGN;
|
|
|
|
OrgRgn : HRGN;
|
|
|
|
|
|
|
|
begin
|
2011-06-17 21:12:21 +00:00
|
|
|
// Zapamiêtywanie oryginalnego ClipRgn i ustawianie nowego
|
2011-06-17 20:53:01 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
SelectClipRgn(ACanvas.Handle, ClipRgn);
|
|
|
|
|
|
|
|
DrawRoundRect(ACanvas, Rect, Radius, ColorFrom, ColorTo, GradientKind, LeftTopRound, RightTopRound, LeftBottomRound, RightBottomRound);
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Przywracanie poprzedniego ClipRgn i usuwanie wykorzystanych regionów
|
2011-06-17 20:53:01 +00:00
|
|
|
RestoreClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn);
|
|
|
|
DeleteObject(ClipRgn);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawText(ACanvas: TCanvas; x, y: integer;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText: string; TextColor: TColor);
|
2011-06-17 20:53:01 +00:00
|
|
|
begin
|
|
|
|
with Acanvas do
|
|
|
|
begin
|
|
|
|
brush.style:=bsClear;
|
|
|
|
font.color:=TextColor;
|
|
|
|
TextOut(x, y, AText);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawText(ACanvas: TCanvas; x, y: integer;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText: string; TextColor: TColor; ClipRect: T2DIntRect);
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
var WinAPIClipRect : TRect;
|
|
|
|
|
|
|
|
begin
|
|
|
|
WinAPIClipRect:=ClipRect.ForWinAPI;
|
|
|
|
with Acanvas do
|
|
|
|
begin
|
|
|
|
brush.style:=bsClear;
|
|
|
|
font.color:=TextColor;
|
|
|
|
TextRect(WinAPIClipRect, x, y, AText);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawRoundRect(ACanvas: TCanvas; Rect: T2DIntRect;
|
|
|
|
Radius: integer; ColorFrom, ColorTo: TColor; GradientKind: TBackgroundKind;
|
|
|
|
LeftTopRound, RightTopRound, LeftBottomRound, RightBottomRound: boolean);
|
|
|
|
|
|
|
|
var RoundRgn : HRGN;
|
|
|
|
TmpRgn : HRGN;
|
|
|
|
OrgRgn : HRGN;
|
|
|
|
UseOrgClipRgn: Boolean;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if Radius<1 then
|
|
|
|
exit;
|
|
|
|
|
2011-06-20 20:35:07 +00:00
|
|
|
//WriteLn('Radius: ', Radius, ' Rect.Width: ', Rect.Width, ' Rect.Height: ', Rect.Height);
|
|
|
|
|
|
|
|
//there's a bug in fpc that evaluates the expression below erroneous when using inline
|
|
|
|
// Radius = 3 and Rect.Width >=128 and <= 261 will evaluate to true
|
|
|
|
{$ifdef FpcBugWorkAround}
|
|
|
|
if (CompareValue(Radius*2, Rect.width) > 0) and (CompareValue(Radius*2, Rect.Height) > 0) then
|
|
|
|
exit;
|
|
|
|
{$else}
|
2011-06-17 20:53:01 +00:00
|
|
|
if (Radius*2>Rect.width) or (Radius*2>Rect.height) then
|
|
|
|
exit;
|
2011-06-20 20:35:07 +00:00
|
|
|
{$endif}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Zapamiêtywanie oryginalnego ClipRgn i ustawianie nowego
|
2011-06-17 20:53:01 +00:00
|
|
|
SaveClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn);
|
|
|
|
|
|
|
|
if not(LeftTopRound) and not(RightTopRound) and not(LeftBottomRound) and not (RightBottomRound) then
|
|
|
|
begin
|
|
|
|
RoundRgn:=CreateRectRgn(Rect.Left, Rect.Top, Rect.Right + 1, Rect.Bottom + 1);
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
RoundRgn:=CreateRoundRectRgn(Rect.Left, Rect.Top, Rect.Right +2, Rect.Bottom + 2, Radius*2, Radius*2);
|
|
|
|
|
|
|
|
if not(LeftTopRound) then
|
|
|
|
begin
|
|
|
|
TmpRgn:=CreateRectRgn(Rect.left, Rect.Top, Rect.left + Radius, Rect.Top + Radius);
|
|
|
|
CombineRgn(RoundRgn, RoundRgn, TmpRgn, RGN_OR);
|
|
|
|
DeleteObject(TmpRgn);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if not(RightTopRound) then
|
|
|
|
begin
|
|
|
|
TmpRgn:=CreateRectRgn(Rect.right - Radius + 1, Rect.Top, Rect.Right + 1, Rect.Top + Radius);
|
|
|
|
CombineRgn(RoundRgn, RoundRgn, TmpRgn, RGN_OR);
|
|
|
|
DeleteObject(TmpRgn);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if not(LeftBottomRound) then
|
|
|
|
begin
|
|
|
|
TmpRgn:=CreateRectRgn(Rect.left, Rect.Bottom - Radius + 1, Rect.Left + Radius, Rect.Bottom + 1);
|
|
|
|
CombineRgn(RoundRgn, RoundRgn, TmpRgn, RGN_OR);
|
|
|
|
DeleteObject(TmpRgn);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if not(RightBottomRound) then
|
|
|
|
begin
|
|
|
|
TmpRgn:=CreateRectRgn(Rect.right - Radius + 1, Rect.Bottom - Radius + 1, Rect.Right + 1, Rect.Bottom + 1);
|
|
|
|
CombineRgn(RoundRgn, RoundRgn, TmpRgn, RGN_OR);
|
|
|
|
DeleteObject(TmpRgn);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if UseOrgClipRgn then
|
|
|
|
CombineRgn(RoundRgn, RoundRgn, OrgRgn, RGN_AND);
|
|
|
|
|
|
|
|
SelectClipRgn(ACanvas.Handle, RoundRgn);
|
|
|
|
|
|
|
|
ColorFrom:=ColorToRGB(ColorFrom);
|
|
|
|
ColorTo:=ColorToRGB(ColorTo);
|
|
|
|
|
|
|
|
FillGradientRectangle(ACanvas, Rect, ColorFrom, ColorTo, GradientKind);
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Przywracanie poprzedniego ClipRgn i usuwanie wykorzystanych regionów
|
2011-06-17 20:53:01 +00:00
|
|
|
RestoreClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn);
|
|
|
|
DeleteObject(RoundRgn);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawOutlinedText(ABitmap: TBitmap; x, y: integer;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText: string; TextColor, OutlineColor: TColor);
|
2011-06-17 20:53:01 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
font.color:=TextColor;
|
|
|
|
TextOut(x, y, AText);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawText(ABitmap: TBitmap; x, y: integer;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText: string; TextColor: TColor; ClipRect: T2DIntRect);
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
var WinAPIClipRect : TRect;
|
|
|
|
|
|
|
|
begin
|
|
|
|
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;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText: string; TextColor, OutlineColor: TColor; Align : TAlignment);
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
var tw : integer;
|
|
|
|
s : string;
|
|
|
|
|
|
|
|
begin
|
|
|
|
with ABitmap.Canvas do
|
|
|
|
begin
|
|
|
|
s:=AText;
|
|
|
|
tw:=TextWidth(s) + 2;
|
2011-06-17 21:12:21 +00:00
|
|
|
// Jeœli tekst siê zmieœci, rysujemy
|
2011-06-17 20:53:01 +00:00
|
|
|
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,
|
2011-06-21 02:04:04 +00:00
|
|
|
y: integer; const AText: string; TextColor, OutlineColor: TColor;
|
2011-06-17 20:53:01 +00:00
|
|
|
Align: TAlignment);
|
|
|
|
|
|
|
|
var tw : integer;
|
|
|
|
s : string;
|
|
|
|
|
|
|
|
begin
|
|
|
|
with ACanvas do
|
|
|
|
begin
|
|
|
|
s:=AText;
|
|
|
|
tw:=TextWidth(s) + 2;
|
2011-06-17 21:12:21 +00:00
|
|
|
// Jeœli tekst siê zmieœci, rysujemy
|
2011-06-17 20:53:01 +00:00
|
|
|
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
|
2011-06-18 13:46:52 +00:00
|
|
|
Mesh: array of GRADIENTRECT;
|
|
|
|
GradientVertice: array of TRIVERTEX;
|
2011-06-17 20:53:01 +00:00
|
|
|
ConcaveColor: TColor;
|
|
|
|
begin
|
|
|
|
case GradientKind of
|
|
|
|
bkSolid:
|
|
|
|
begin
|
2011-06-20 18:49:36 +00:00
|
|
|
ACanvas.Brush.Style := bsSolid;
|
2011-06-17 20:53:01 +00:00
|
|
|
ACanvas.brush.color := ColorFrom;
|
|
|
|
ACanvas.fillrect(Rect.ForWinAPI);
|
|
|
|
end;
|
|
|
|
bkVerticalGradient, bkHorizontalGradient:
|
|
|
|
begin
|
|
|
|
setlength(GradientVertice, 2);
|
|
|
|
with GradientVertice[0] do
|
|
|
|
begin
|
|
|
|
x := Rect.left;
|
|
|
|
y := Rect.top;
|
|
|
|
Red := GetRValue(ColorFrom) shl 8;
|
|
|
|
Green := GetGValue(ColorFrom) shl 8;
|
|
|
|
Blue := GetBValue(ColorFrom) shl 8;
|
|
|
|
Alpha := 255 shl 8;
|
|
|
|
end;
|
|
|
|
with GradientVertice[1] do
|
|
|
|
begin
|
|
|
|
x := Rect.Right + 1;
|
|
|
|
y := Rect.bottom + 1;
|
|
|
|
Red := GetRValue(ColorTo) shl 8;
|
|
|
|
Green := GetGValue(ColorTo) shl 8;
|
|
|
|
Blue := GetBValue(ColorTo) shl 8;
|
|
|
|
Alpha := 255 shl 8;
|
|
|
|
end;
|
|
|
|
setlength(Mesh, 1);
|
|
|
|
Mesh[0].UpperLeft := 0;
|
|
|
|
Mesh[0].LowerRight := 1;
|
|
|
|
if GradientKind = bkVerticalGradient then
|
|
|
|
GradientFill(ACanvas.Handle, @GradientVertice[0], 2, @Mesh[0], 1, GRADIENT_FILL_RECT_V)
|
|
|
|
else
|
|
|
|
GradientFill(ACanvas.Handle, @GradientVertice[0], 2, @Mesh[0], 1, GRADIENT_FILL_RECT_H);
|
|
|
|
end;
|
|
|
|
bkConcave:
|
|
|
|
begin
|
|
|
|
ConcaveColor:=TColorTools.Brighten(ColorFrom, 20);
|
|
|
|
|
|
|
|
setlength(GradientVertice, 4);
|
|
|
|
with GradientVertice[0] do
|
|
|
|
begin
|
|
|
|
x := Rect.left;
|
|
|
|
y := Rect.top;
|
|
|
|
Red := GetRValue(ColorFrom) shl 8;
|
|
|
|
Green := GetGValue(ColorFrom) shl 8;
|
|
|
|
Blue := GetBValue(ColorFrom) shl 8;
|
|
|
|
Alpha := 255 shl 8;
|
|
|
|
end;
|
|
|
|
with GradientVertice[1] do
|
|
|
|
begin
|
|
|
|
x := Rect.Right + 1;
|
|
|
|
y := Rect.Top + (Rect.height) div 4;
|
|
|
|
Red := GetRValue(ConcaveColor) shl 8;
|
|
|
|
Green := GetGValue(ConcaveColor) shl 8;
|
|
|
|
Blue := GetBValue(ConcaveColor) shl 8;
|
|
|
|
Alpha := 255 shl 8;
|
|
|
|
end;
|
|
|
|
with GradientVertice[2] do
|
|
|
|
begin
|
|
|
|
x := Rect.left;
|
|
|
|
y := Rect.Top + (Rect.height) div 4;
|
|
|
|
Red := GetRValue(ColorTo) shl 8;
|
|
|
|
Green := GetGValue(ColorTo) shl 8;
|
|
|
|
Blue := GetBValue(ColorTo) shl 8;
|
|
|
|
Alpha := 255 shl 8;
|
|
|
|
end;
|
|
|
|
with GradientVertice[3] do
|
|
|
|
begin
|
|
|
|
x := Rect.Right + 1;
|
|
|
|
y := Rect.bottom + 1;
|
|
|
|
Red := GetRValue(ColorFrom) shl 8;
|
|
|
|
Green := GetGValue(ColorFrom) shl 8;
|
|
|
|
Blue := GetBValue(ColorFrom) shl 8;
|
|
|
|
Alpha := 255 shl 8;
|
|
|
|
end;
|
|
|
|
setlength(Mesh, 2);
|
|
|
|
Mesh[0].UpperLeft := 0;
|
|
|
|
Mesh[0].LowerRight := 1;
|
|
|
|
Mesh[1].UpperLeft := 2;
|
|
|
|
Mesh[1].LowerRight := 3;
|
|
|
|
GradientFill(ACanvas.Handle, @GradientVertice[0], 4, @Mesh[0], 2, GRADIENT_FILL_RECT_V);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawFitWText(ACanvas: TCanvas; x1, x2, y: integer;
|
2011-06-21 02:04:04 +00:00
|
|
|
const AText: string; TextColor: TColor; Align: TAlignment);
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
var tw : integer;
|
|
|
|
s : string;
|
|
|
|
|
|
|
|
begin
|
|
|
|
with ACanvas do
|
|
|
|
begin
|
|
|
|
s:=AText;
|
|
|
|
tw:=TextWidth(s);
|
2011-06-17 21:12:21 +00:00
|
|
|
// Jeœli tekst siê zmieœci, rysujemy
|
2011-06-17 20:53:01 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if ABuffer.PixelFormat<>pf24bit then
|
2011-06-17 21:12:21 +00:00
|
|
|
raise exception.create('TGUITools.RenderBackground: Bitmapa musi byæ w trybie 24-bitowym!');
|
2011-06-17 20:53:01 +00:00
|
|
|
if (rect.left>rect.right) or (rect.top>rect.bottom) then
|
|
|
|
exit;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Zarówno metoda FillRect jak i WinAPI'owe rysowanie gradientów jest
|
|
|
|
// zabezpieczone przed rysowaniem poza obszarem p³ótna.
|
2011-06-17 20:53:01 +00:00
|
|
|
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
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
TempRect:=T2DIntRect.create(rect.Left,
|
|
|
|
rect.top,
|
|
|
|
rect.right,
|
|
|
|
rect.Top + (rect.bottom - rect.top) div 4);
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
TempRect.create(rect.Left,
|
|
|
|
rect.top,
|
|
|
|
rect.right,
|
|
|
|
rect.Top + (rect.bottom - rect.top) div 4);
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
TGradientTools.VGradient(ABuffer.Canvas,
|
|
|
|
Color1,
|
|
|
|
TColorTools.Shade(Color1, Color2, 20),
|
|
|
|
TempRect.ForWinAPI
|
|
|
|
);
|
|
|
|
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
TempRect:=T2DIntRect.create(rect.Left,
|
|
|
|
rect.top + (rect.bottom - rect.top) div 4 + 1,
|
|
|
|
rect.right,
|
|
|
|
rect.bottom);
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
TempRect.create(rect.Left,
|
|
|
|
rect.top + (rect.bottom - rect.top) div 4 + 1,
|
|
|
|
rect.right,
|
|
|
|
rect.bottom);
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
TGradientTools.VGradient(ABuffer.Canvas,
|
|
|
|
Color2,
|
|
|
|
Color1,
|
|
|
|
TempRect.ForWinAPI
|
|
|
|
);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
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);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.SaveClipRgn(DC: HDC; var OrgRgnExists: boolean;
|
|
|
|
var OrgRgn: HRGN);
|
|
|
|
|
|
|
|
var i : integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
OrgRgn:=CreateRectRgn(0, 0, 1, 1);
|
|
|
|
i:=GetClipRgn(DC, OrgRgn);
|
|
|
|
OrgRgnExists:=(i=1);
|
|
|
|
end;
|
|
|
|
|
2011-06-21 02:04:04 +00:00
|
|
|
class procedure TGUITools.DrawText(ABitmap: TBitmap; x, y: integer; const AText: string;
|
2011-06-17 20:53:01 +00:00
|
|
|
TextColor: TColor);
|
|
|
|
begin
|
|
|
|
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;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if ABitmap.PixelFormat<>pf24bit then
|
2011-06-17 21:12:21 +00:00
|
|
|
raise exception.create('TGUITools.DrawHLine: Bitmapa musi byæ w trybie 24-bitowym!');
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
if y2<y1 then
|
|
|
|
begin
|
|
|
|
tmp:=y1;
|
|
|
|
y1:=y2;
|
|
|
|
y2:=tmp;
|
|
|
|
end;
|
|
|
|
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
BitmapRect:=T2DIntRect.create(0, 0, ABitmap.width-1, ABitmap.height-1);
|
|
|
|
if not(BitmapRect.IntersectsWith(T2DIntRect.create(x, y1, x, y2), LineRect)) then
|
|
|
|
exit;
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
BitmapRect.create(0, 0, ABitmap.width-1, ABitmap.height-1);
|
|
|
|
if not(BitmapRect.IntersectsWith(Create2DIntRect(x, y1, x, y2), LineRect)) then
|
|
|
|
exit;
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
ABitmap.canvas.pen.color:=Color;
|
|
|
|
ABitmap.canvas.pen.style:=psSolid;
|
|
|
|
ABitmap.canvas.moveto(LineRect.left, LineRect.Top);
|
|
|
|
ABitmap.canvas.lineto(LineRect.left, Linerect.bottom+1);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawVLine(ABitmap: TBitmap; x, y1, y2: integer;
|
|
|
|
Color: TColor; ClipRect: T2DIntRect);
|
|
|
|
|
|
|
|
var OrgLineRect : T2DIntRect;
|
|
|
|
LineRect : T2DIntRect;
|
|
|
|
BitmapRect : T2DIntRect;
|
|
|
|
tmp: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if ABitmap.PixelFormat<>pf24bit then
|
2011-06-17 21:12:21 +00:00
|
|
|
raise exception.create('TGUITools.DrawHLine: Bitmapa musi byæ w trybie 24-bitowym!');
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
if y2<y1 then
|
|
|
|
begin
|
|
|
|
tmp:=y1;
|
|
|
|
y1:=y2;
|
|
|
|
y2:=tmp;
|
|
|
|
end;
|
|
|
|
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
BitmapRect:=T2DIntRect.create(0, 0, ABitmap.width-1, ABitmap.height-1);
|
|
|
|
if not(BitmapRect.IntersectsWith(T2DIntRect.create(x, y1, x, y2), OrgLineRect)) then
|
|
|
|
exit;
|
2011-06-18 13:46:52 +00:00
|
|
|
{$ELSE}
|
|
|
|
BitmapRect.create(0, 0, ABitmap.width-1, ABitmap.height-1);
|
|
|
|
if not(BitmapRect.IntersectsWith(Create2DIntRect(x, y1, x, y2), OrgLineRect)) then
|
|
|
|
exit;
|
|
|
|
{$ENDIF}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
if not(OrgLineRect.IntersectsWith(ClipRect, LineRect)) then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
ABitmap.canvas.pen.color:=Color;
|
|
|
|
ABitmap.canvas.pen.style:=psSolid;
|
|
|
|
ABitmap.canvas.moveto(LineRect.left, LineRect.Top);
|
|
|
|
ABitmap.canvas.lineto(LineRect.left, Linerect.bottom+1);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawVLine(ACanvas: TCanvas; x, y1, y2: integer;
|
|
|
|
Color: TColor);
|
|
|
|
|
|
|
|
var tmp : integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if y2<y1 then
|
|
|
|
begin
|
|
|
|
tmp:=y1;
|
|
|
|
y1:=y2;
|
|
|
|
y2:=tmp;
|
|
|
|
end;
|
|
|
|
|
|
|
|
ACanvas.pen.color:=Color;
|
|
|
|
ACanvas.moveto(x, y1);
|
|
|
|
ACanvas.lineto(x, y2+1);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawVLine(ACanvas: TCanvas; x, y1, y2: integer;
|
|
|
|
Color: TColor; ClipRect: T2DIntRect);
|
|
|
|
|
|
|
|
var UseOrgClipRgn : boolean;
|
|
|
|
ClipRgn : HRGN;
|
|
|
|
OrgRgn : HRGN;
|
|
|
|
|
|
|
|
begin
|
2011-06-17 21:12:21 +00:00
|
|
|
// Zapamiêtywanie oryginalnego ClipRgn i ustawianie nowego
|
2011-06-17 20:53:01 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
SelectClipRgn(ACanvas.Handle, ClipRgn);
|
|
|
|
|
|
|
|
DrawVLine(ACanvas, x, y1, y2, Color);
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Przywracanie poprzedniego ClipRgn i usuwanie wykorzystanych regionów
|
2011-06-17 20:53:01 +00:00
|
|
|
RestoreClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn);
|
|
|
|
DeleteObject(ClipRgn);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawAARoundFrame(ACanvas: TCanvas; Rect: T2DIntRect;
|
|
|
|
Radius: integer; Color: TColor);
|
|
|
|
|
|
|
|
begin
|
|
|
|
if (Radius<1) then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
if (Radius>Rect.width div 2) or (Radius>Rect.height div 2) then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
// DrawAARoundCorner jest zabezpieczony przed rysowaniem poza obszarem
|
2011-06-18 13:46:52 +00:00
|
|
|
{$IFDEF EnhancedRecordSupport}
|
2011-06-17 20:53:01 +00:00
|
|
|
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);
|
2011-06-18 13:46:52 +00:00
|
|
|
{$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}
|
2011-06-17 20:53:01 +00:00
|
|
|
|
|
|
|
ACanvas.Pen.color:=Color;
|
|
|
|
ACanvas.pen.style:=psSolid;
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Draw*Line s¹ zabezpieczone przed rysowaniem poza obszarem
|
2011-06-17 20:53:01 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
begin
|
2011-06-17 21:12:21 +00:00
|
|
|
// Zapamiêtywanie oryginalnego ClipRgn i ustawianie nowego
|
2011-06-17 20:53:01 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
SelectClipRgn(ACanvas.Handle, ClipRgn);
|
|
|
|
|
|
|
|
DrawAARoundFrame(ACanvas, Rect, Radius, Color);
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Przywracanie poprzedniego ClipRgn i usuwanie wykorzystanych regionów
|
2011-06-17 20:53:01 +00:00
|
|
|
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);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawDisabledImage(ABitmap: TBitmap;
|
|
|
|
Imagelist: TImageList; ImageIndex: integer; Point: T2DIntVector);
|
|
|
|
begin
|
|
|
|
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;
|
|
|
|
|
|
|
|
begin
|
2011-06-17 21:12:21 +00:00
|
|
|
// Zapamiêtywanie oryginalnego ClipRgn i ustawianie nowego
|
2011-06-17 20:53:01 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
SelectClipRgn(ACanvas.Handle, ClipRgn);
|
|
|
|
|
2011-06-17 21:12:21 +00:00
|
|
|
// Hack poprawiaj¹cy b³¹d w ImageList.Draw, który nie przywraca poprzedniego
|
|
|
|
// koloru czcionki dla p³ótna
|
2011-06-17 20:53:01 +00:00
|
|
|
DcStackPos:=SaveDC(ACanvas.Handle);
|
|
|
|
ImageList.Draw(ACanvas, Point.x, Point.y, ImageIndex, false);
|
|
|
|
RestoreDC(ACanvas.Handle, DcStackPos);
|
|
|
|
|
|
|
|
RestoreClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn);
|
|
|
|
|
|
|
|
DeleteObject(ClipRgn);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawDisabledImage(ACanvas: TCanvas;
|
|
|
|
Imagelist: TImageList; ImageIndex: integer; Point: T2DIntVector);
|
|
|
|
|
|
|
|
var DCStackPos : integer;
|
|
|
|
|
|
|
|
begin
|
2011-06-20 20:35:07 +00:00
|
|
|
//todo: see if is necessary to save the DC
|
2011-06-17 20:53:01 +00:00
|
|
|
DcStackPos:=SaveDC(ACanvas.Handle);
|
|
|
|
ImageList.Draw(ACanvas, Point.x, Point.y, ImageIndex, false);
|
|
|
|
RestoreDC(ACanvas.Handle, DcStackPos);
|
|
|
|
end;
|
|
|
|
|
2012-06-04 00:49:51 +00:00
|
|
|
class procedure TGUITools.DrawCheckbox(ACanvas:TCanvas; x,y: Integer;
|
|
|
|
AState: TCheckboxState; ACheckboxState:TSpkCheckboxState;
|
|
|
|
AStyle: TSpkCheckboxStyle; ClipRect:T2DIntRect);
|
|
|
|
var
|
|
|
|
UseOrgClipRgn: Boolean;
|
|
|
|
OrgRgn: HRGN;
|
|
|
|
ClipRgn: HRGN;
|
|
|
|
te: TThemedElementDetails;
|
|
|
|
Rect: TRect;
|
|
|
|
begin
|
|
|
|
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);
|
|
|
|
SelectClipRgn(ACanvas.Handle, ClipRgn);
|
|
|
|
DrawCheckbox(ACanvas, x,y, AState, ACheckboxState, AStyle);
|
|
|
|
RestoreClipRgn(ACanvas.Handle, UseOrgClipRgn, OrgRgn);
|
|
|
|
DeleteObject(ClipRgn);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TGUITools.DrawCheckbox(ACanvas: TCanvas; x,y: Integer;
|
|
|
|
AState: TCheckboxState; ACheckboxState: TSpkCheckboxState;
|
|
|
|
AStyle:TSpkCheckboxStyle);
|
|
|
|
const
|
|
|
|
UNTHEMED_FLAGS: array [TSpkCheckboxStyle, TCheckboxState] of Integer = (
|
|
|
|
(DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED, DFCS_BUTTONCHECK or DFCS_BUTTON3STATE),
|
|
|
|
(DFCS_BUTTONRADIO, DFCS_BUTTONRADIO or DFCS_CHECKED, DFCS_BUTTONRADIO or DFCS_BUTTON3STATE)
|
|
|
|
);
|
|
|
|
THEMED_FLAGS: array [TSpkCheckboxStyle, TCheckboxState, TSpkCheckboxState] of TThemedButton = (
|
|
|
|
( (tbCheckboxUncheckedNormal, tbCheckboxUncheckedHot, tbCheckboxUncheckedPressed, tbCheckboxUncheckedDisabled),
|
|
|
|
(tbCheckboxCheckedNormal, tbCheckboxCheckedHot, tbCheckboxCheckedPressed, tbCheckboxCheckedDisabled),
|
|
|
|
(tbCheckboxMixedNormal, tbCheckboxMixedHot, tbCheckboxMixedPressed, tbCheckboxMixedDisabled)
|
|
|
|
),
|
|
|
|
( (tbRadioButtonUncheckedNormal, tbRadioButtonUncheckedHot, tbRadioButtonUncheckedPressed, tbRadioButtonUncheckedDisabled),
|
|
|
|
(tbRadioButtonCheckedNormal, tbRadioButtonCheckedHot, tbRadioButtonCheckedPressed, tbRadioButtonCheckedDisabled),
|
|
|
|
(tbRadioButtonCheckedNormal, tbRadioButtonCheckedHot, tbRadioButtonCheckedPressed, tbRadioButtonCheckedDisabled)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
var
|
|
|
|
R: TRect;
|
|
|
|
w: Integer;
|
2014-10-13 19:04:19 +00:00
|
|
|
sz: TSize;
|
2012-06-04 00:49:51 +00:00
|
|
|
te: TThemedElementDetails;
|
|
|
|
begin
|
|
|
|
if ThemeServices.ThemesEnabled then begin
|
|
|
|
te := ThemeServices.GetElementDetails(THEMED_FLAGS[AStyle, AState, ACheckboxState]);
|
2014-10-13 19:04:19 +00:00
|
|
|
sz := ThemeServices.GetDetailSize(te);
|
|
|
|
R := Bounds(x, y, sz.cx, sz.cy);
|
|
|
|
InflateRect(R, 1, 1);
|
2012-06-04 00:49:51 +00:00
|
|
|
ThemeServices.DrawElement(ACanvas.Handle, te, R);
|
2014-10-13 19:04:19 +00:00
|
|
|
end else begin
|
|
|
|
w := GetSystemMetrics(SM_CYMENUCHECK);
|
|
|
|
R := Bounds(x, y, w, w);
|
2012-06-04 00:49:51 +00:00
|
|
|
DrawFrameControl(
|
|
|
|
ACanvas.Handle, R, DFC_BUTTON, UNTHEMED_FLAGS[AStyle, AState]);
|
2014-10-13 19:04:19 +00:00
|
|
|
end;
|
2012-06-04 00:49:51 +00:00
|
|
|
end;
|
|
|
|
|
2011-06-17 20:53:01 +00:00
|
|
|
end.
|