cxgraphics.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,593 行 · 第 1/5 页
PAS
1,593 行
{********************************************************************}
{ }
{ Developer Express Visual Component Library }
{ Express Cross Platform Library graphics classes }
{ }
{ Copyright (c) 2000-2008 Developer Express Inc. }
{ ALL RIGHTS RESERVED }
{ }
{ The entire contents of this file is protected by U.S. and }
{ International Copyright Laws. Unauthorized reproduction, }
{ reverse-engineering, and distribution of all or any portion of }
{ the code contained in this file is strictly prohibited and may }
{ result in severe civil and criminal penalties and will be }
{ prosecuted to the maximum extent possible under the law. }
{ }
{ RESTRICTIONS }
{ }
{ THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES }
{ (DCU, OBJ, DLL, ETC.) ARE CONFIDENTIAL AND PROPRIETARY TRADE }
{ SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS }
{ LICENSED TO DISTRIBUTE THE EXPRESSCROSSPLATFORMLIBRARY AND ALL }
{ ACCOMPANYING VCL CONTROLS AS PART OF AN EXECUTABLE PROGRAM }
{ ONLY. }
{ }
{ THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED }
{ FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE }
{ COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE }
{ AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT }
{ AND PERMISSION FROM DEVELOPER EXPRESS INC. }
{ }
{ CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON }
{ ADDITIONAL RESTRICTIONS. }
{ }
{********************************************************************}
unit cxGraphics;
{$I cxVer.inc}
interface
uses
{$IFDEF DELPHI6}
Types,
{$ENDIF}
Windows,
Classes, SysUtils, Controls, Graphics, CommCtrl, ComCtrls, ImgList, cxClasses;
const
cxAlignLeft = 1;
cxAlignRight = 2;
cxAlignHCenter = 4;
cxAlignTop = 8;
cxAlignBottom = 16;
cxAlignVCenter = 32;
cxAlignCenter = 36;
cxSingleLine = 64;
cxDontClip = 128;
cxExpandTabs = 256;
cxShowPrefix = 512;
cxWordBreak = 1024;
cxShowEndEllipsis = 2048;
cxDontPrint = 4096;
cxShowPathEllipsis = 8192;
cxDontBreakChars = 16384;
SystemAlignmentsHorz: array[TAlignment] of Integer = (DT_LEFT, DT_RIGHT, DT_CENTER);
SystemAlignmentsVert: array[TcxAlignmentVert] of Integer = (DT_TOP, DT_BOTTOM, DT_VCENTER);
cxAlignmentsHorz: array[TAlignment] of Integer = (cxAlignLeft, cxAlignRight, cxAlignHCenter);
cxAlignmentsVert: array[TcxAlignmentVert] of Integer = (cxAlignTop, cxAlignBottom, cxAlignVCenter);
{$IFNDEF DELPHI6}
clMoneyGreen = TColor($C0DCC0);
clSkyBlue = TColor($F0CAA6);
clCream = TColor($F0FBFF);
clMedGray = TColor($A4A0A0);
{$ENDIF}
clcxLightGray = $CFCFCF;
cxEmptyRect: TRect = (Left: 0; Top: 0; Right: 0; Bottom: 0);
cxDesignSelectionWidth = 2;
cxDefaultAlphaValue = 200;
cxHalfToneBrush: TBrush = nil;
cxDoubleBufferedBitmapPixelFormat: TPixelFormat = pfDevice;
type
IcxFontListener = interface
['{B144DD7E-0B27-439A-B908-FC3ACFE6A2D3}']
procedure Changed(Sender: TObject; AFont: TFont);
end;
TcxBorder = (bLeft, bTop, bRight, bBottom);
TcxBorders = set of TcxBorder;
const
cxBordersAll = [bLeft, bTop, bRight, bBottom];
type
TBrushHandle = HBRUSH;
TPointArray = array of TPoint;
TRectArray = array of TRect;
TcxColorPart = -100..100;
TcxGridLines = (glBoth, glNone, glVertical, glHorizontal);
PcxViewParams = ^TcxViewParams;
TcxViewParams = record
Bitmap: TBitmap;
Color: TColor;
Font: TFont;
TextColor: TColor;
end;
{ TcxRegion }
TcxRegionHandle = HRGN;
TcxRegionOperation = (roSet, roAdd, roSubtract, roIntersect);
TcxRegion = class {6}
private
FHandle: TcxRegionHandle;
function GetBoundsRect: TRect;
function GetIsEmpty: Boolean;
protected
procedure DestroyHandle;
public
constructor Create(AHandle: TcxRegionHandle); overload;
constructor Create(const ABounds: TRect); overload;
constructor Create; overload;
constructor Create(ALeft, ATop, ARight, ABottom: Integer); overload;
constructor CreateRoundCorners(const ABounds: TRect; AWidthEllepse, AHeightEllepse: Integer); overload;
constructor CreateRoundCorners(ALeft, ATop, ARight, ABottom, AWidthEllepse, AHeightEllepse: Integer); overload;
destructor Destroy; override;
procedure Combine(ARegion: TcxRegion; AOperation: TcxRegionOperation;
ADestroyRegion: Boolean = True);
function IsEqual(ARegion: TcxRegion): Boolean; overload;
function IsEqual(ARegionHandle: TcxRegionHandle): Boolean; overload;
procedure Offset(DX, DY: Integer);
function PtInRegion(const Pt: TPoint): Boolean; overload;
function PtInRegion(X, Y: Integer): Boolean; overload;
function RectInRegion(const R: TRect): Boolean; overload;
function RectInRegion(ALeft, ATop, ARight, ABottom: Integer): Boolean; overload;
property BoundsRect: TRect read GetBoundsRect;
property Handle: TcxRegionHandle read FHandle write FHandle;
property IsEmpty: Boolean read GetIsEmpty;
end;
{ TcxCanvas }
TcxRotationAngle = (ra0, raPlus90, raMinus90, ra180);
TcxCanvasState = record
Font: TFont;
Brush: TBrush;
Pen: TPen;
end;
TcxCanvasStates = array of TcxCanvasState;
TcxCanvas = class
private
FCanvas: TCanvas;
FSavedDCs: TList;
FSavedRegions: TList;
FSavedStates: TcxCanvasStates;
function GetBrush: TBrush;
function GetCopyMode: TCopyMode;
function GetDCOrigin: TPoint;
function GetFont: TFont;
function GetHandle: HDC;
function GetPen: TPen;
function GetViewportOrg: TPoint;
function GetWindowOrg: TPoint;
procedure SetBrush(Value: TBrush);
procedure SetCopyMode(Value: TCopyMode);
procedure SetFont(Value: TFont);
procedure SetPen(Value: TPen);
procedure SetPixel(X, Y: Integer; Value: TColor);
procedure SetViewportOrg(const P: TPoint);
procedure SetWindowOrg(const P: TPoint);
protected
procedure SynchronizeObjects(ADC: THandle);
public
constructor Create(ACanvas: TCanvas); virtual;
destructor Destroy; override;
procedure AlignMultiLineTextRectVertically(var R: TRect; const AText: string;
AAlignmentVert: TcxAlignmentVert; AWordBreak, AShowPrefix: Boolean;
AEnabled: Boolean = True; ADontBreakChars: Boolean = False);
procedure CopyRect(const Dest: TRect; ACanvas: TCanvas; const Source: TRect);
procedure Draw(X, Y: Integer; Graphic: TGraphic);
procedure DrawComplexFrame(const R: TRect; ALeftTopColor, ARightBottomColor: TColor;
ABorders: TcxBorders = [bLeft, bTop, bRight, bBottom]; ABorderWidth: Integer = 1);
procedure DrawEdge(const R: TRect; ASunken, AOuter: Boolean;
ABorders: TcxBorders = [bLeft, bTop, bRight, bBottom]);
procedure DrawFocusRect(const R: TRect);
procedure DrawGlyph(X, Y: Integer; AGlyph: TBitmap; AEnabled: Boolean = True;
ABackgroundColor: TColor = clNone{; ATempCanvas: TCanvas = nil});
procedure DrawImage(Images: TCustomImageList; X, Y, Index: Integer;
Enabled: Boolean = True);
procedure DrawTexT(const Text: string; R: TRect; Flags: Integer;
Enabled: Boolean = True);
procedure FillRect(const R: TRect; AColor: TColor); overload;
procedure FillRect(const R: TRect; ABitmap: TBitmap = nil;
AExcludeRect: Boolean = False); overload;
procedure FillRect(R: TRect; const AParams: TcxViewParams;
ABorders: TcxBorders = []; ABorderColor: TColor = clDefault;
ALineWidth: Integer = 1; AExcludeRect: Boolean = False); overload;
procedure DrawDesignSelection(ARect: TRect; AWidth: Integer = cxDesignSelectionWidth);
procedure DrawRegion(ARegion: TcxRegion; AContentColor: TColor = clDefault;
ABorderColor: TColor = clDefault; ABorderWidth: Integer = 1; ABorderHeight: Integer = 1); overload;
procedure DrawRegion(ARegion: TcxRegionHandle; AContentColor: TColor = clDefault;
ABorderColor: TColor = clDefault; ABorderWidth: Integer = 1; ABorderHeight: Integer = 1); overload;
procedure FillRegion(ARegion: TcxRegion; AColor: TColor = clDefault); overload;
procedure FillRegion(ARegion: TcxRegionHandle; AColor: TColor = clDefault); overload;
procedure FlipHorizontally(ABitmap: TBitmap);
procedure FrameRegion(ARegion: TcxRegion; AColor: TColor = clDefault;
ABorderWidth: Integer = 1; ABorderHeight: Integer = 1); overload;
procedure FrameRegion(ARegion: TcxRegionHandle; AColor: TColor = clDefault;
ABorderWidth: Integer = 1; ABorderHeight: Integer = 1); overload;
procedure Pie(const R: TRect; const ARadial1, ARadial2: TPoint); overload;
procedure Pie(const R: TRect; AStartAngle, ASweepAngle: Integer); overload;
function FontHeight(AFont: TFont): Integer;
procedure FrameRect(const R: TRect; Color: TColor = clDefault;
ALineWidth: Integer = 1; ABorders: TcxBorders = cxBordersAll;
AExcludeFrame: Boolean = False);
procedure InvertFrame(const R: TRect; ABorderSize: Integer);
procedure InvertRect(const R: TRect);
procedure LineTo(X, Y: Integer);
procedure MoveTo(X, Y: Integer);
procedure Polygon(const Points: array of TPoint);
procedure Polyline(const Points: array of TPoint);
procedure RotateBitmap(ABitmap: TBitmap; ARotationAngle: TcxRotationAngle;
AFlipVertically: Boolean = False);
function TextExtent(const Text: string): TSize; overload;
procedure TextExtent(const Text: string; var R: TRect; Flags: Integer); overload;
function TextHeight(const Text: string): Integer;
function TextWidth(const Text: string): Integer;
procedure TransparentDraw(X, Y: Integer; ABitmap: TBitmap; AAlpha: Byte;
ABackground: TBitmap = nil);
procedure RestoreDC;
procedure SaveDC;
procedure RestoreClipRegion;
procedure SaveClipRegion;
procedure RestoreState;
procedure SaveState;
procedure GetParams(var AParams: TcxViewParams);
procedure SetParams(AParams: TcxViewParams);
procedure SetBrushColor(Value: TColor);
procedure SetFontAngle(Value: Integer);
procedure GetTextStringsBounds(Text: string; R: TRect; Flags: Integer;
Enabled: Boolean; var ABounds: TRectArray);
procedure BeginPath;
procedure EndPath;
function PathToRegion: TcxRegion;
procedure WidenPath;
// clipping
procedure ExcludeClipRect(const R: TRect);
procedure IntersectClipRect(const R: TRect);
function GetClipRegion(AConsiderOrigin: Boolean = True): TcxRegion;
procedure SetClipRegion(ARegion: TcxRegion; AOperation: TcxRegionOperation;
ADestroyRegion: Boolean = True; AConsiderOrigin: Boolean = True);
function RectFullyVisible(const R: TRect): Boolean;
function RectVisible(const R: TRect): Boolean;
property Brush: TBrush read GetBrush write SetBrush;
property Canvas: TCanvas read FCanvas write FCanvas;
property CopyMode: TCopyMode read GetCopyMode write SetCopyMode;
property DCOrigin: TPoint read GetDCOrigin;
property Font: TFont read GetFont write SetFont;
property Handle: HDC read GetHandle;
property Pen: TPen read GetPen write SetPen;
property Pixels[X, Y: Integer]: TColor write SetPixel;
property ViewportOrg: TPoint read GetViewportOrg write SetViewportOrg;
property WindowOrg: TPoint read GetWindowOrg write SetWindowOrg;
end;
{ TcxScreenCanvas }
TcxScreenCanvas = class(TcxCanvas)
public
constructor Create; reintroduce; virtual;
destructor Destroy; override;
end;
{ TcxCustomBitmap }
TcxCustomBitmap = class(TBitmap)
private
FCompressData: Boolean;
FcxCanvas: TcxCanvas;
FLockCount: Integer;
FModified: Boolean;
function GetClientRect: TRect;
procedure Compress(ASourceStream, ADestStream: TStream; ASize: Integer);
procedure Decompress(ASourceStream, ADestStream: TStream; ASize: Integer);
protected
procedure Changed(Sender: TObject); override;
function ChangeLocked: Boolean;
procedure Initialize(AWidth, AHeight: Integer; APixelFormat: TPixelFormat); virtual;
procedure Update; virtual;
procedure ReadData(Stream: TStream); override;
procedure WriteData(Stream: TStream); override;
public
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?