📄 dxdraws.pas
字号:
unit DXDraws;
interface
{$INCLUDE DelphiXcfg.inc}
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
DXClass, DIB, DXTexImg, DirectX;
type
{ EDirectDrawError }
EDirectDrawError = class(EDirectXError);
EDirectDrawPaletteError = class(EDirectDrawError);
EDirectDrawClipperError = class(EDirectDrawError);
EDirectDrawSurfaceError = class(EDirectDrawError);
{ TDirectDraw }
TDirectDrawClipper = class;
TDirectDrawPalette = class;
TDirectDrawSurface = class;
TDirectDraw = class(TDirectX)
private
FIDDraw: IDirectDraw;
FIDDraw4: IDirectDraw4;
FIDDraw7: IDirectDraw7;
FDriverCaps: TDDCaps;
FHELCaps: TDDCaps;
FClippers: TList;
FPalettes: TList;
FSurfaces: TList;
function GetClipper(Index: Integer): TDirectDrawClipper;
function GetClipperCount: Integer;
function GetDisplayMode: TDDSurfaceDesc;
function GetIDDraw: IDirectDraw;
function GetIDDraw4: IDirectDraw4;
function GetIDDraw7: IDirectDraw7;
function GetIDraw: IDirectDraw;
function GetIDraw4: IDirectDraw4;
function GetIDraw7: IDirectDraw7;
function GetPalette(Index: Integer): TDirectDrawPalette;
function GetPaletteCount: Integer;
function GetSurface(Index: Integer): TDirectDrawSurface;
function GetSurfaceCount: Integer;
public
constructor Create(GUID: PGUID);
constructor CreateEx(GUID: PGUID; DirectX7Mode: Boolean);
destructor Destroy; override;
class function Drivers: TDirectXDrivers;
property ClipperCount: Integer read GetClipperCount;
property Clippers[Index: Integer]: TDirectDrawClipper read GetClipper;
property DisplayMode: TDDSurfaceDesc read GetDisplayMode;
property DriverCaps: TDDCaps read FDriverCaps;
property HELCaps: TDDCaps read FHELCaps;
property IDDraw: IDirectDraw read GetIDDraw;
property IDDraw4: IDirectDraw4 read GetIDDraw4;
property IDDraw7: IDirectDraw7 read GetIDDraw7;
property IDraw: IDirectDraw read GetIDraw;
property IDraw4: IDirectDraw4 read GetIDraw4;
property IDraw7: IDirectDraw7 read GetIDraw7;
property PaletteCount: Integer read GetPaletteCount;
property Palettes[Index: Integer]: TDirectDrawPalette read GetPalette;
property SurfaceCount: Integer read GetSurfaceCount;
property Surfaces[Index: Integer]: TDirectDrawSurface read GetSurface;
end;
{ TDirectDrawClipper }
TDirectDrawClipper = class(TDirectX)
private
FDDraw: TDirectDraw;
FIDDClipper: IDirectDrawClipper;
function GetIDDClipper: IDirectDrawClipper;
function GetIClipper: IDirectDrawClipper;
procedure SetHandle(Value: THandle);
procedure SetIDDClipper(Value: IDirectDrawClipper);
property Handle: THandle write SetHandle;
public
constructor Create(ADirectDraw: TDirectDraw);
destructor Destroy; override;
procedure SetClipRects(const Rects: array of TRect);
property DDraw: TDirectDraw read FDDraw;
property IClipper: IDirectDrawClipper read GetIClipper;
property IDDClipper: IDirectDrawClipper read GetIDDClipper write SetIDDClipper;
end;
{ TDirectDrawPalette }
TDirectDrawPalette = class(TDirectX)
private
FDDraw: TDirectDraw;
FIDDPalette: IDirectDrawPalette;
function GetEntry(Index: Integer): TPaletteEntry;
function GetIDDPalette: IDirectDrawPalette;
function GetIPalette: IDirectDrawPalette;
procedure SetEntry(Index: Integer; Value: TPaletteEntry);
procedure SetIDDPalette(Value: IDirectDrawPalette);
public
constructor Create(ADirectDraw: TDirectDraw);
destructor Destroy; override;
function CreatePalette(Caps: DWORD; const Entries): Boolean;
function GetEntries(StartIndex, NumEntries: Integer; var Entries): Boolean;
procedure LoadFromDIB(DIB: TDIB);
procedure LoadFromFile(const FileName: string);
procedure LoadFromStream(Stream: TStream);
function SetEntries(StartIndex, NumEntries: Integer; const Entries): Boolean;
property DDraw: TDirectDraw read FDDraw;
property Entries[Index: Integer]: TPaletteEntry read GetEntry write SetEntry;
property IDDPalette: IDirectDrawPalette read GetIDDPalette write SetIDDPalette;
property IPalette: IDirectDrawPalette read GetIPalette;
end;
{ TDirectDrawSurfaceCanvas }
TDirectDrawSurfaceCanvas = class(TCanvas)
private
FDC: HDC;
FSurface: TDirectDrawSurface;
protected
procedure CreateHandle; override;
public
constructor Create(ASurface: TDirectDrawSurface);
destructor Destroy; override;
procedure Release;
end;
{ TDirectDrawSurface }
TDirectDrawSurface = class(TDirectX)
private
FCanvas: TDirectDrawSurfaceCanvas;
FHasClipper: Boolean;
FDDraw: TDirectDraw;
FIDDSurface: IDirectDrawSurface;
FIDDSurface4: IDirectDrawSurface4;
FIDDSurface7: IDirectDrawSurface7;
FSystemMemory: Boolean;
FStretchDrawClipper: IDirectDrawClipper;
FSurfaceDesc: TDDSurfaceDesc;
FGammaControl: IDirectDrawGammaControl;
FLockSurfaceDesc: TDDSurfaceDesc;
FLockCount: Integer;
function GetBitCount: Integer;
function GetCanvas: TDirectDrawSurfaceCanvas;
function GetClientRect: TRect;
function GetHeight: Integer;
function GetIDDSurface: IDirectDrawSurface;
function GetIDDSurface4: IDirectDrawSurface4;
function GetIDDSurface7: IDirectDrawSurface7;
function GetISurface: IDirectDrawSurface;
function GetISurface4: IDirectDrawSurface4;
function GetISurface7: IDirectDrawSurface7;
function GetPixel(X, Y: Integer): Longint;
function GetWidth: Integer;
procedure SetClipper(Value: TDirectDrawClipper);
procedure SetColorKey(Flags: DWORD; const Value: TDDColorKey);
procedure SetIDDSurface(Value: IDirectDrawSurface);
procedure SetIDDSurface4(Value: IDirectDrawSurface4);
procedure SetIDDSurface7(Value: IDirectDrawSurface7);
procedure SetPalette(Value: TDirectDrawPalette);
procedure SetPixel(X, Y: Integer; Value: Longint);
procedure SetTransparentColor(Col: Longint);
public
constructor Create(ADirectDraw: TDirectDraw);
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure AssignTo(Dest: TPersistent); override;
function Blt(const DestRect, SrcRect: TRect; Flags: DWORD;
const DF: TDDBltFX; Source: TDirectDrawSurface): Boolean;
function BltFast(X, Y: Integer; const SrcRect: TRect;
Flags: DWORD; Source: TDirectDrawSurface): Boolean;
function ColorMatch(Col: TColor): Integer;
{$IFDEF DelphiX_Spt4}
function CreateSurface(const SurfaceDesc: TDDSurfaceDesc): Boolean; overload;
function CreateSurface(const SurfaceDesc: TDDSurfaceDesc2): Boolean; overload;
{$ELSE}
function CreateSurface(const SurfaceDesc: TDDSurfaceDesc): Boolean;
{$ENDIF}
{$IFDEF DelphiX_Spt4}
procedure Draw(X, Y: Integer; SrcRect: TRect; Source: TDirectDrawSurface; Transparent: Boolean=True); overload;
procedure Draw(X, Y: Integer; Source: TDirectDrawSurface; Transparent: Boolean=True); overload;
procedure StretchDraw(const DestRect, SrcRect: TRect; Source: TDirectDrawSurface;
Transparent: Boolean=True); overload;
procedure StretchDraw(const DestRect: TRect; Source: TDirectDrawSurface;
Transparent: Boolean=True); overload;
{$ELSE}
procedure Draw(X, Y: Integer; SrcRect: TRect; Source: TDirectDrawSurface;
Transparent: Boolean);
procedure StretchDraw(const DestRect, SrcRect: TRect; Source: TDirectDrawSurface;
Transparent: Boolean);
{$ENDIF}
procedure DrawAdd(const DestRect, SrcRect: TRect; Source: TDirectDrawSurface;
Transparent: Boolean; Alpha: Integer{$IFDEF DelphiX_Spt4}=255{$ENDIF});
procedure DrawAlpha(const DestRect, SrcRect: TRect; Source: TDirectDrawSurface;
Transparent: Boolean; Alpha: Integer);
procedure DrawSub(const DestRect, SrcRect: TRect; Source: TDirectDrawSurface;
Transparent: Boolean; Alpha: Integer{$IFDEF DelphiX_Spt4}=255{$ENDIF});
procedure DrawRotate(X, Y, Width, Height: Integer; const SrcRect: TRect;
Source: TDirectDrawSurface; CenterX, CenterY: Double; Transparent: Boolean; Angle: Integer);
procedure DrawRotateAdd(X, Y, Width, Height: Integer; const SrcRect: TRect;
Source: TDirectDrawSurface; CenterX, CenterY: Double; Transparent: Boolean; Angle: Integer;
Alpha: Integer{$IFDEF DelphiX_Spt4}=255{$ENDIF});
procedure DrawRotateAlpha(X, Y, Width, Height: Integer; const SrcRect: TRect;
Source: TDirectDrawSurface; CenterX, CenterY: Double; Transparent: Boolean; Angle: Integer;
Alpha: Integer);
procedure DrawRotateSub(X, Y, Width, Height: Integer; const SrcRect: TRect;
Source: TDirectDrawSurface; CenterX, CenterY: Double; Transparent: Boolean; Angle: Integer;
Alpha: Integer{$IFDEF DelphiX_Spt4}=255{$ENDIF});
procedure DrawWaveX(X, Y, Width, Height: Integer; const SrcRect: TRect;
Source: TDirectDrawSurface; Transparent: Boolean; amp, Len, ph: Integer);
procedure DrawWaveXAdd(X, Y, Width, Height: Integer; const SrcRect: TRect;
Source: TDirectDrawSurface; Transparent: Boolean; amp, Len, ph: Integer;
Alpha: Integer{$IFDEF DelphiX_Spt4}=255{$ENDIF});
procedure DrawWaveXAlpha(X, Y, Width, Height: Integer; const SrcRect: TRect;
Source: TDirectDrawSurface; Transparent: Boolean; amp, Len, ph: Integer;
Alpha: Integer);
procedure DrawWaveXSub(X, Y, Width, Height: Integer; const SrcRect: TRect;
Source: TDirectDrawSurface; Transparent: Boolean; amp, Len, ph: Integer;
Alpha: Integer{$IFDEF DelphiX_Spt4}=255{$ENDIF});
procedure Fill(DevColor: Longint);
procedure FillRect(const Rect: TRect; DevColor: Longint);
procedure FillRectAdd(const DestRect: TRect; Color: TColor);
procedure FillRectAlpha(const DestRect: TRect; Color: TColor; Alpha: Integer);
procedure FillRectSub(const DestRect: TRect; Color: TColor);
procedure LoadFromDIB(DIB: TDIB);
procedure LoadFromDIBRect(DIB: TDIB; AWidth, AHeight: Integer; const SrcRect: TRect);
procedure LoadFromGraphic(Graphic: TGraphic);
procedure LoadFromGraphicRect(Graphic: TGraphic; AWidth, AHeight: Integer; const SrcRect: TRect);
procedure LoadFromFile(const FileName: string);
procedure LoadFromStream(Stream: TStream);
{$IFDEF DelphiX_Spt4}
function Lock(const Rect: TRect; var SurfaceDesc: TDDSurfaceDesc): Boolean; overload;
function Lock(var SurfaceDesc: TDDSurfaceDesc): Boolean; overload;
{$ELSE}
function Lock(const Rect: TRect; var SurfaceDesc: TDDSurfaceDesc): Boolean;
{$ENDIF}
procedure UnLock;
function Restore: Boolean;
procedure SetSize(AWidth, AHeight: Integer);
property BitCount: Integer read GetBitCount;
property Canvas: TDirectDrawSurfaceCanvas read GetCanvas;
property ClientRect: TRect read GetClientRect;
property Clipper: TDirectDrawClipper write SetClipper;
property ColorKey[Flags: DWORD]: TDDColorKey write SetColorKey;
property DDraw: TDirectDraw read FDDraw;
property GammaControl: IDirectDrawGammaControl read FGammaControl;
property Height: Integer read GetHeight;
property IDDSurface: IDirectDrawSurface read GetIDDSurface write SetIDDSurface;
property IDDSurface4: IDirectDrawSurface4 read GetIDDSurface4 write SetIDDSurface4;
property IDDSurface7: IDirectDrawSurface7 read GetIDDSurface7 write SetIDDSurface7;
property ISurface: IDirectDrawSurface read GetISurface;
property ISurface4: IDirectDrawSurface4 read GetISurface4;
property ISurface7: IDirectDrawSurface7 read GetISurface7;
property Palette: TDirectDrawPalette write SetPalette;
property Pixels[X, Y: Integer]: Longint read GetPixel write SetPixel;
property SurfaceDesc: TDDSurfaceDesc read FSurfaceDesc;
property SystemMemory: Boolean read FSystemMemory write FSystemMemory;
property TransparentColor: Longint write SetTransparentColor;
property Width: Integer read GetWidth;
end;
{ TDXDrawDisplay }
TCustomDXDraw = class;
TDXDrawDisplayMode = class(TCollectionItem)
private
FSurfaceDesc: TDDSurfaceDesc;
function GetBitCount: Integer;
function GetHeight: Integer;
function GetWidth: Integer;
public
property BitCount: Integer read GetBitCount;
property Height: Integer read GetHeight;
property SurfaceDesc: TDDSurfaceDesc read FSurfaceDesc;
property Width: Integer read GetWidth;
end;
TDXDrawDisplay = class(TPersistent)
private
FBitCount: Integer;
FDXDraw: TCustomDXDraw;
FHeight: Integer;
FModes: TCollection;
FWidth: Integer;
FFixedBitCount: Boolean;
FFixedRatio: Boolean;
FFixedSize: Boolean;
function GetCount: Integer;
function GetMode: TDXDrawDisplayMode;
function GetMode2(Index: Integer): TDXDrawDisplayMode;
procedure LoadDisplayModes;
procedure SetBitCount(Value: Integer);
procedure SetHeight(Value: Integer);
procedure SetWidth(Value: Integer);
function SetSize(AWidth, AHeight, ABitCount: Integer): Boolean;
function DynSetSize(AWidth, AHeight, ABitCount: Integer): Boolean;
public
constructor Create(ADXDraw: TCustomDXDraw);
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
function IndexOf(Width, Height, BitCount: Integer): Integer;
property Count: Integer read GetCount;
property Mode: TDXDrawDisplayMode read GetMode;
property Modes[Index: Integer]: TDXDrawDisplayMode read GetMode2; default;
published
property BitCount: Integer read FBitCount write SetBitCount default 8;
property FixedBitCount: Boolean read FFixedBitCount write FFixedBitCount;
property FixedRatio: Boolean read FFixedRatio write FFixedRatio;
property FixedSize: Boolean read FFixedSize write FFixedSize;
property Height: Integer read FHeight write SetHeight default 480;
property Width: Integer read FWidth write SetWidth default 640;
end;
TDirectDrawDisplay = TDXDrawDisplay;
TDirectDrawDisplayMode = TDXDrawDisplayMode;
{ EDXDrawError }
EDXDrawError = class(Exception);
{ TCustomDXDraw }
TDXDrawOption = (doFullScreen, doNoWindowChange, doAllowReboot, doWaitVBlank,
doAllowPalette256, doSystemMemory, doStretch, doCenter, doFlip,
do3D, doDirectX7Mode, doRetainedMode, doHardware, doSelectDriver, doZBuffer);
TDXDrawOptions = set of TDXDrawOption;
TDXDrawNotifyType = (dxntDestroying, dxntInitializing, dxntInitialize, dxntInitializeSurface,
dxntFinalize, dxntFinalizeSurface, dxntRestore, dxntSetSurfaceSize);
TDXDrawNotifyEvent = procedure(Sender: TCustomDXDraw; NotifyType: TDXDrawNotifyType) of object;
TCustomDXDraw = class(TCustomControl)
private
FAutoInitialize: Boolean;
FAutoSize: Boolean;
FCalledDoInitialize: Boolean;
FCalledDoInitializeSurface: Boolean;
FForm: TCustomForm;
FNotifyEventList: TList;
FInitialized: Boolean;
FInitialized2: Boolean;
FInternalInitialized: Boolean;
FUpdating: Boolean;
FSubClass: TControlSubClass;
FNowOptions: TDXDrawOptions;
FOptions: TDXDrawOptions;
FOnFinalize: TNotifyEvent;
FOnFinalizeSurface: TNotifyEvent;
FOnInitialize: TNotifyEvent;
FOnInitializeSurface: TNotifyEvent;
FOnInitializing: TNotifyEvent;
FOnRestoreSurface: TNotifyEvent;
FOffNotifyRestore: Integer;
{ DirectDraw }
FDXDrawDriver: TObject;
FDriver: PGUID;
FDriverGUID: TGUID;
FDDraw: TDirectDraw;
FDisplay: TDXDrawDisplay;
FClipper: TDirectDrawClipper;
FPalette: TDirectDrawPalette;
FPrimary: TDirectDrawSurface;
FSurface: TDirectDrawSurface;
FSurfaceWidth: Integer;
FSurfaceHeight: Integer;
{ Direct3D }
FD3D: IDirect3D;
FD3D2: IDirect3D2;
FD3D3: IDirect3D3;
FD3D7: IDirect3D7;
FD3DDevice: IDirect3DDevice;
FD3DDevice2: IDirect3DDevice2;
FD3DDevice3: IDirect3DDevice3;
FD3DDevice7: IDirect3DDevice7;
FD3DRM: IDirect3DRM;
FD3DRM2: IDirect3DRM2;
FD3DRM3: IDirect3DRM3;
FD3DRMDevice: IDirect3DRMDevice;
FD3DRMDevice2: IDirect3DRMDevice2;
FD3DRMDevice3: IDirect3DRMDevice3;
FCamera: IDirect3DRMFrame;
FScene: IDirect3DRMFrame;
FViewport: IDirect3DRMViewport;
FZBuffer: TDirectDrawSurface;
procedure FormWndProc(var Message: TMessage; DefWindowProc: TWndMethod);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -