home *** CD-ROM | disk | FTP | other *** search
- {------------------------------------------------------------------------------}
- { }
- { TCustomPicShow v2.62 }
- { by Kambiz R. Khojasteh }
- { }
- { kambiz@delphiarea.com }
- { http://www.delphiarea.com }
- { }
- { Special thanks to: }
- { :: <k3nx@hotmail.com> for help on D5 support. }
- { :: Douglass Titjan <support@delphipages.com> for help on D5 support. }
- { :: Jerry McLain <jkmclain@srcaccess.net> for manual control idea. }
- { :: M. R. Zamani <M_R_Zamani@yahoo.com> for adding 8 effects (110..117). }
- { :: Elliott Shevin <ShevinE@aol.com> for adding 4 effects (123..126). }
- { :: Ken Otto <ken.otto@enviros.com> for adding native JPG support to }
- { TDBPicShow and fixing a memory leak bug. }
- { :: Gary Bond <gary.bond@tesco.net> for name of the transitions. }
- { }
- {------------------------------------------------------------------------------}
-
- {$I DELPHIAREA.INC}
-
- // If you want to use TCustomPicShow as a non-windowed control, remove the
- // following compiler directive:
- {$DEFINE WINCONTROL_PICSHOW}
-
- unit PicShow;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
- Dialogs, Menus, DB, DBCtrls;
-
- const
- RegionStyles = [0, 58..117, 123..127];
-
- type
-
- {$IFNDEF DELPHI4_UP}
- HRgn = THandle;
- {$ENDIF}
-
- TShowStyle = 0..127;
- TPercent = 0..100;
- TBackgroundMode = (bmNone, bmTiled, bmStretched, bmCentered);
-
- TCustomDrawEvent = procedure(Sender: TObject; Picture, Screen: TBitmap) of object;
-
- TAbout = class(TObject);
-
- { TCustomPicShow }
-
- {$IFDEF WINCONTROL_PICSHOW}
- TCustomPicShow = class(TCustomControl)
- {$ELSE}
- TCustomPicShow = class(TGraphicControl)
- {$ENDIF}
- private
- fAbout: TAbout;
- fPicture: TPicture;
- fBgPicture: TPicture;
- fBgMode: TBackgroundMode;
- fAutoSize: Boolean;
- fCenter: Boolean;
- fStretch: Boolean;
- fStretchFine: Boolean;
- fThreaded: Boolean;
- fThreadPriority: TThreadPriority;
- fManual: Boolean;
- fStyle: TShowStyle;
- fStep: Word;
- fDelay: Word;
- fProgress: TPercent;
- fReverse: Boolean;
- fBusy: Boolean;
- fOnChange: TNotifyEvent;
- fOnProgress: TNotifyEvent;
- fOnComplete: TNotifyEvent;
- fOnCustomDraw: TCustomDrawEvent;
- fOnMouseEnter: TNotifyEvent;
- fOnMouseLeave: TNotifyEvent;
- fOnBeforeNewFrame: TCustomDrawEvent;
- fOnAfterNewFrame: TCustomDrawEvent;
- Media: TBitmap;
- PicRect: TRect;
- Thread: TThread;
- Drawing: Boolean;
- OffScreen: TBitmap;
- Stopping: Boolean;
- OldPic: TBitmap;
- Pic: TBitmap;
- procedure SetAutoSize_(Value: Boolean);
- procedure SetPicture(Value: TPicture);
- procedure SetBgPicture(Value: TPicture);
- procedure SetBgMode(Value: TBackgroundMode);
- procedure SetCenter(Value: Boolean);
- procedure SetStretch(Value: Boolean);
- procedure SetStretchFine(Value: Boolean);
- procedure SetStep(Value: Word);
- procedure SetProgress(Value: TPercent);
- procedure SetManual(Value: Boolean);
- procedure SetStyleName(const Value: String);
- function GetStyleName: String;
- function GetEmpty: Boolean;
- procedure AnimationComplete(Sender: TObject);
- procedure BgPictureChange(Sender: TObject);
- procedure WMEraseBkgnd(var Msg: TWMEraseBkgnd); message WM_ERASEBKGND;
- procedure WMPaint(var Msg: TWMPaint); message WM_PAINT;
- procedure WMSize(var Msg: TWMSize); message WM_SIZE;
- procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
- procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
- procedure AdjustClientSize;
- procedure CalculatePicRect;
- procedure InvalidateArea(Area: TRect);
- procedure Prepare;
- procedure Animate;
- procedure UpdateDisplay;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- procedure Execute;
- procedure Stop;
- procedure Clear;
- property Busy: Boolean read fBusy;
- property Empty: Boolean read GetEmpty;
- property Progress: TPercent read fProgress write SetProgress;
- protected
- procedure Paint; override;
- procedure PictureChange(Sender: TObject); dynamic;
- property AutoSize: Boolean read fAutoSize write SetAutoSize_ default True;
- property BgMode: TBackgroundMode read fBgMode write SetBgMode default bmTiled;
- property BgPicture: TPicture read fBgPicture write SetBgPicture;
- property Center: Boolean read fCenter write SetCenter default False;
- property Delay: Word read fDelay write fDelay default 40;
- property Manual: Boolean read fManual write SetManual default False;
- property Picture: TPicture read fPicture write SetPicture;
- property Reverse: Boolean read fReverse write fReverse default False;
- property Stretch: Boolean read fStretch write SetStretch default False;
- property StretchFine: Boolean read fStretchFine write SetStretchFine default False;
- property Step: Word read fStep write SetStep default 4;
- property Style: TShowStyle read fStyle write fStyle default 51;
- property StyleName: String read GetStyleName write SetStyleName stored False;
- property Threaded: Boolean read fThreaded write fThreaded default True;
- property ThreadPriority: TThreadPriority read fThreadPriority write fThreadPriority default tpNormal;
- property OnAfterNewFrame: TCustomDrawEvent read fOnAfterNewFrame write fOnAfterNewFrame;
- property OnBeforeNewFrame: TCustomDrawEvent read fOnBeforeNewFrame write fOnBeforeNewFrame;
- property OnCustomDraw: TCustomDrawEvent read fOnCustomDraw write fOnCustomDraw;
- property OnChange: TNotifyEvent read fOnChange write fOnChange;
- property OnComplete: TNotifyEvent read fOnComplete write fOnComplete;
- property OnMouseEnter: TNotifyEvent read fOnMouseEnter write fOnMouseEnter;
- property OnMouseLeave: TNotifyEvent read fOnMouseLeave write fOnMouseLeave;
- property OnProgress: TNotifyEvent read fOnProgress write fOnProgress;
- published
- property About: TAbout read fAbout write fAbout stored False;
- end;
-
- { TPicShow }
-
- TPicShow = class(TCustomPicShow)
- published
- property Align;
- {$IFDEF DELPHI4_UP}
- property Anchors;
- {$ENDIF}
- property AutoSize;
- property BgMode;
- property BgPicture;
- property Center;
- property Color;
- property Delay;
- property DragCursor;
- property DragMode;
- property Enabled;
- property Height;
- property Manual;
- property ParentColor;
- property ParentShowHint;
- property Picture;
- property PopupMenu;
- property ShowHint;
- property Reverse;
- property Stretch;
- property StretchFine;
- property Step;
- property Style;
- property StyleName;
- {$IFDEF WINCONTROL_PICSHOW}
- property TabOrder;
- property TabStop;
- {$ENDIF}
- property Threaded;
- property ThreadPriority;
- property Visible;
- property Width;
- property OnAfterNewFrame;
- property OnBeforeNewFrame;
- property OnClick;
- property OnChange;
- property OnComplete;
- property OnCustomDraw;
- property OnDblClick;
- property OnDragDrop;
- property OnDragOver;
- property OnEndDrag;
- {$IFDEF WINCONTROL_PICSHOW}
- property OnEnter;
- property OnExit;
- {$ENDIF}
- property OnMouseDown;
- property OnMouseEnter;
- property OnMouseLeave;
- property OnMouseMove;
- property OnMouseUp;
- {$IFDEF WINCONTROL_PICSHOW}
- property OnKeyDown;
- property OnKeyPress;
- property OnKeyUp;
- {$ENDIF}
- property OnProgress;
- property OnStartDrag;
- end;
-
- { TDBPicShow }
-
- TDBPicShow = class(TCustomPicShow)
- private
- fOnAfterLoadPicture: TNotifyEvent;
- fOnBeforeLoadPicture: TNotifyEvent;
- fDataLink: TFieldDataLink;
- fAutoDisplay: Boolean;
- fPictureLoaded: Boolean;
- procedure DataChange(Sender: TObject);
- function GetDataField: string;
- function GetDataSource: TDataSource;
- function GetField: TField;
- function GetReadOnly: Boolean;
- procedure SetAutoDisplay(Value: Boolean);
- procedure SetDataField(const Value: string);
- procedure SetDataSource(Value: TDataSource);
- procedure SetReadOnly(Value: Boolean);
- procedure UpdateData(Sender: TObject);
- procedure CMGetDataLink(var Message: TMessage); message CM_GETDATALINK;
- protected
- procedure Notification(AComponent: TComponent;
- Operation: TOperation); override;
- procedure PictureChange(Sender: TObject); override;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- procedure LoadPicture;
- property Field: TField read GetField;
- property Picture;
- published
- property OnAfterLoadPicture: TNotifyEvent read fOnAfterLoadPicture write fOnAfterLoadPicture;
- property OnBeforeLoadPicture: TNotifyEvent read fOnBeforeLoadPicture write fOnBeforeLoadPicture;
- property AutoDisplay: Boolean read FAutoDisplay write SetAutoDisplay default True;
- property DataField: string read GetDataField write SetDataField;
- property DataSource: TDataSource read GetDataSource write SetDataSource;
- property ReadOnly: Boolean read GetReadOnly write SetReadOnly default False;
- property Align;
- {$IFDEF DELPHI4_UP}
- property Anchors;
- {$ENDIF}
- property AutoSize;
- property BgMode;
- property BgPicture;
- property Center;
- property Color;
- property Delay;
- property DragCursor;
- property DragMode;
- property Enabled;
- property Height;
- property Manual;
- property ParentColor;
- property ParentShowHint;
- property PopupMenu;
- property ShowHint;
- property Reverse;
- property Stretch;
- property StretchFine;
- property Step;
- property Style;
- property StyleName;
- {$IFDEF WINCONTROL_PICSHOW}
- property TabOrder;
- property TabStop;
- {$ENDIF}
- property Threaded;
- property ThreadPriority;
- property Visible;
- property Width;
- property OnAfterNewFrame;
- property OnBeforeNewFrame;
- property OnClick;
- property OnCustomDraw;
- property OnDblClick;
- property OnDragDrop;
- property OnDragOver;
- property OnEndDrag;
- {$IFDEF WINCONTROL_PICSHOW}
- property OnEnter;
- property OnExit;
- {$ENDIF}
- property OnComplete;
- property OnMouseDown;
- property OnMouseEnter;
- property OnMouseLeave;
- property OnMouseMove;
- property OnMouseUp;
- {$IFDEF WINCONTROL_PICSHOW}
- property OnKeyDown;
- property OnKeyPress;
- property OnKeyUp;
- {$ENDIF}
- property OnProgress;
- property OnStartDrag;
- end;
-
- const
- PSTransitionNames: array[TShowStyle] of String = (
- 'Swap',
- 'Expand from right',
- 'Expand from left',
- 'Slide in from right',
- 'Slide in from left',
- 'Reveal from left',
- 'Reveal from right',
- 'Expand in from right',
- 'Expand in from left',
- 'Expand in to middle',
- 'Expand out from middle',
- 'Reveal out from middle',
- 'Reveal in from sides',
- 'Expand in from sides',
- 'Unroll from left',
- 'Unroll from right',
- 'Build up from right',
- 'Build up from left',
- 'Expand from bottom',
- 'Expand from top',
- 'Slide in from bottom',
- 'Slide in from top',
- 'Reveal from top',
- 'Reveal from bottom',
- 'Expand in from bottom',
- 'Expand in from top',
- 'Expand in to middle (horiz)',
- 'Expand out from middle (horiz)',
- 'Reveal from middle (horiz)',
- 'Slide in from top / bottom',
- 'Expand in from top / bottom',
- 'Unroll from top',
- 'Unroll from bottom',
- 'Expand from bottom',
- 'Expand in from top',
- 'Expand from bottom right',
- 'Expand from top right',
- 'Expand from top left',
- 'Expand from bottom left',
- 'Slide in from bottom right',
- 'Slide in from top right',
- 'Slide in from top left',
- 'Slide in from bottom left',
- 'Reveal from top left',
- 'Reveal from bottom left',
- 'Reveal from bottom right',
- 'Reveal from top right',
- 'Appear and Contract to top left',
- 'Appear and Contract to bottom left',
- 'Appear and Contract to bottom right',
- 'Appear and Contract to top right',
- 'Appear and Contract to middle',
- 'Expand out from centre',
- 'Reveal out from centre',
- 'Reveal in to centre',
- 'Quarters Reveal in to middle',
- 'Quarters Expand to middle',
- 'Quarters Slide in to middle',
- 'Curved Reveal from left',
- 'Curved Reveal from right',
- 'Bars in from right',
- 'Bars in from left',
- 'Bars left then right',
- 'Bars right then left',
- 'Bars from both sides',
- 'Uneven shred from right',
- 'Uneven shred from left',
- 'Uneven shred out from middle (horiz)',
- 'Uneven shred in to middle (horiz)',
- 'Curved Reveal from top',
- 'Curved Reveal from bottom',
- 'Bars from bottom',
- 'Bars from top',
- 'Bars top then bottom',
- 'Bars bottom then top',
- 'Bars from top and bottom',
- 'Unven shred from bottom',
- 'Uneven shred from top',
- 'Uneven shred from horizon',
- 'Uneven shred in to horizon',
- 'Curved reveal from top left',
- 'Curved reveal from top right',
- 'Curved reveal from bottom left',
- 'Curved reveal from bottom right',
- 'Circular reveal from centre',
- 'Circular reveal to centre',
- 'Criss Cross reveal from bottom right',
- 'Criss Cross reveal from top right',
- 'Criss Cross reveal from bottom left',
- 'Criss Cross reveal from top left',
- 'Criss Cross reveal bounce from top left',
- 'Criss Cross reveal bounce from bottom left',
- 'Criss Cross reveal bounce from top right',
- 'Criss Cross reveal bounce from bottom right',
- 'Criss Cross reveal from right top and bottom',
- 'Criss Cross reveal from left top and bottom',
- 'Criss Cross reveal from left right and bottom',
- 'Criss Cross reveal from left right and top',
- 'Criss Cross reveal from top left right and bottom',
- 'Criss Cross reveal from bottom left top right',
- 'Uneven shred from bottom and right',
- 'Uneven shred from top and right',
- 'Uneven shred from bottom and left',
- 'Uneven shred from top and left',
- 'Uneven shred from horiz and right',
- 'Uneven shred from horiz and left',
- 'Uneven shred from bottom and vert middle',
- 'Uneven shred from top and vert middle',
- 'Uneven shred from centre',
- 'Uneven shred to centre',
- 'Reveal diagonal from top left',
- 'Reveal diagonal from top right',
- 'Reveal diagonal from bottom left',
- 'Reveal diagonal from bottom right',
- 'Diagonal sweep from top left bottom right anticlockwise',
- 'Diagonal sweep from top left bottom right clockwise',
- 'Starburst clockwise from center',
- 'Triangular shred to right',
- 'Fade',
- 'Pivot from top left',
- 'Pivot from bottom left',
- 'Pivot from top right',
- 'Pivot from bottom right',
- 'Speckle appear from right',
- 'Speckle appear from left',
- 'Speckle appear from bottom',
- 'Speckle appear from top',
- 'Random squares appear');
-
- implementation
-
- uses
- Math, JPEG;
-
- const
- MaxPixelCount = 32768;
-
- type
-
- PRGBTripleArray = ^TRGBTripleArray;
- TRGBTripleArray = array[0..MaxPixelCount] of TRGBTriple;
-
- TAnimateThread = class(TThread)
- private
- PicShow: TCustomPicShow;
- procedure Update;
- public
- constructor Create(APicShow: TCustomPicShow);
- procedure Execute; override;
- end;
-
- { Miscellaneous routines }
-
- function CreateBarRgn(X, Y, W, H, S: Integer; XMode, YMode: Byte): HRgn;
- var
- X1, Y1: Integer;
- Rgn, tRgn: HRgn;
- begin
- Result := NULLREGION;
- Rgn := NULLREGION;
- if X <= W then Y1 := 0 else Y1 := 5;
- while Y1 < H + 5 do
- begin
- if X > W then
- begin
- tRgn := CreateRectRgn(0, Y1 - 5, W, Y1);
- if XMode in [1, 4] then
- Rgn := CreateRectRgn(2 * W - X, Y1, W, Y1 + 5)
- else if XMode in [2, 5] then
- Rgn := CreateRectRgn(0, Y1, X - W, Y1 + 5);
- CombineRgn(Rgn, Rgn, tRgn, RGN_OR);
- DeleteObject(tRgn);
- end
- else
- begin
- if (X + S) > W then X := W;
- if XMode in [1, 5] then
- Rgn := CreateRectRgn(W - X, Y1, W, Y1 + 5)
- else if XMode in [2, 4] then
- Rgn := CreateRectRgn(0, Y1, X, Y1 + 5)
- else if XMode = 3 then
- begin
- tRgn := CreateRectRgn(W - X, Y1, W, Y1 + 5);
- Rgn := CreateRectRgn(0, Y1 + 5, X, Y1 + 10);
- CombineRgn(Rgn, Rgn, tRgn, RGN_OR);
- DeleteObject(tRgn);
- end;
- end;
- if Result <> NULLREGION then
- begin
- CombineRgn(Result, Result, Rgn, RGN_OR);
- DeleteObject(Rgn);
- end
- else
- Result := Rgn;
- Inc(Y1, 10)
- end;
- if Y <= H then X1 := 0 else X1 := 5;
- while X1 < W + 5 do
- begin
- if Y > H then
- begin
- tRgn := CreateRectRgn(X1 - 5, 0, X1, H);
- if YMode in [1, 4] then
- Rgn := CreateRectRgn(X1, 2 * H - Y, X1 + 5, H)
- else if YMode in [2, 5] then
- Rgn := CreateRectRgn(X1, 0, X1 + 5, Y - H);
- CombineRgn(Rgn, Rgn, tRgn, RGN_OR);
- DeleteObject(tRgn);
- end
- else
- begin
- if (Y + S) > H then Y := H;
- if YMode in [1, 5] then
- Rgn := CreateRectRgn(X1, H - Y, X1 + 5, H)
- else if YMode in [2, 4] then
- Rgn := CreateRectRgn(X1, 0, X1 + 5, Y)
- else if YMode = 3 then
- begin
- tRgn := CreateRectRgn(X1, H - Y, X1 + 5, H);
- Rgn := CreateRectRgn(X1 + 5, 0, X1 + 10, Y);
- CombineRgn(Rgn, Rgn, tRgn, RGN_OR);
- DeleteObject(tRgn);
- end;
- end;
- if Result <> NULLREGION then
- begin
- CombineRgn(Result, Result, Rgn, RGN_OR);
- DeleteObject(Rgn);
- end
- else
- Result := Rgn;
- Inc(X1, 10)
- end;
- end;
-
- function CreateSplashRgn(X, Y, W, H, XMode, YMode: Integer): HRgn;
- var
- X1, Y1, N: Integer;
- Rgn, tRgn: HRgn;
- begin
- Result := NULLREGION;
- if XMode <> 0 then
- begin
- if X < W then
- N := W div 7
- else
- N := 0;
- Y1 := 0;
- while Y1 < H do
- begin
- if XMode = 1 then
- Rgn := CreateRectRgn(W - X + Random(N) - Random(N), Y1, W, Y1 + 5 + H mod 5)
- else if XMode = 2 then
- Rgn := CreateRectRgn(0, Y1, X + Random(N) - Random(N), Y1 + 5 + H mod 5)
- else if XMode = 3 then
- begin
- Rgn := CreateRectRgn((W - X + Random(N) - Random(N)) div 2, Y1, W div 2, Y1 + 5 + H mod 5);
- tRgn := CreateRectRgn(W div 2, Y1, (W + X + Random(N) - Random(N)) div 2, Y1 + 5 + H mod 5);
- CombineRgn(Rgn, Rgn, tRgn, RGN_OR);
- DeleteObject(tRgn);
- end
- else
- begin
- Rgn := CreateRectRgn(W - (X + Random(N) - Random(N)) div 2, Y1, W, Y1 + 5 + H mod 5);
- tRgn := CreateRectRgn(0, Y1, (X + Random(N) - Random(N)) div 2, Y1 + 5 + H mod 5);
- CombineRgn(Rgn, Rgn, tRgn, RGN_OR);
- DeleteObject(tRgn);
- end;
- if Result <> NULLREGION then
- begin
- CombineRgn(Result, Result, Rgn, RGN_OR);
- DeleteObject(Rgn);
- end
- else
- Result := Rgn;
- Inc(Y1, 5);
- end;
- end;
- if YMode <> 0 then
- begin
- if Y < H then
- N := H div 7
- else
- N := 0;
- X1 := 0;
- while X1 < W do
- begin
- if YMode = 1 then
- Rgn := CreateRectRgn(X1, H - Y + Random(N) - Random(N), X1 + 5 + W mod 5, H)
- else if YMode = 2 then
- Rgn := CreateRectRgn(X1, 0, X1 + 5 + W mod 5, Y + Random(N) - Random(N))
- else if YMode = 3 then
- begin
- Rgn := CreateRectRgn(X1, (H - Y + Random(N) - Random(N)) div 2, X1 + 5 + W mod 5, H div 2);
- tRgn := CreateRectRgn(X1, H div 2, X1 + 5 + W mod 5, (H + Y + Random(N) - Random(N)) div 2);
- CombineRgn(Rgn, Rgn, tRgn, RGN_OR);
- DeleteObject(tRgn);
- end
- else
- begin
- Rgn := CreateRectRgn(X1, H - (Y + Random(N) - Random(N)) div 2, X1 + 5 + W mod 5, H);
- tRgn := CreateRectRgn(X1, 0, X1 + 5 + W mod 5, (Y + Random(N) - Random(N)) div 2);
- CombineRgn(Rgn, Rgn, tRgn, RGN_OR);
- DeleteObject(tRgn);
- end;
- if Result <> NULLREGION then
- begin
- CombineRgn(Result, Result, Rgn, RGN_OR);
- DeleteObject(Rgn);
- end
- else
- Result := Rgn;
- Inc(X1, 5);
- end;
- end;
- end;
-
- function CreateSwarmRgn(X, Y, W, H, XMode, YMode: Integer): HRgn;
- var
- X1, Y1, N, M, I, J: Integer;
- Rgn, tRgn: HRgn;
- begin
- Result := NULLREGION;
- if XMode <> 0 then
- begin
- if X < W then
- N := W div 10
- else
- N := 0;
- M := N div 20;
- if M < 2 then M := 2;
- Y1 := 0;
- while Y1 < H do
- begin
- if XMode = 1 then
- begin
- Rgn := CreateRectRgn(W - X, Y1, W, Y1 + M);
- for I := N div M downto 1 do
- begin
- if I > 3 * N div M div 4 then J := 0 else J := 1;
- if Random(I) <= J then
- begin
- X1 := (W - X) - (I * M);
- tRgn := CreateRectRgn(X1, Y1, X1 + M, Y1 + M);
- CombineRgn(Rgn, Rgn, tRgn, RGN_OR);
- DeleteObject(tRgn);
- end;
- end;
- end
- else
- begin
- Rgn := CreateRectRgn(0, Y1, X, Y1 + M);
- for I := N div M downto 1 do
- begin
- if I > 3 * N div M div 4 then J := 0 else J := 1;
- if Random(I) <= J then
- begin
- X1 := X + (I * M);
- tRgn := CreateRectRgn(X1 - M, Y1, X1, Y1 + M);
- CombineRgn(Rgn, Rgn, tRgn, RGN_OR);
- DeleteObject(tRgn);
- end;
- end;
- end;
- if Result <> NULLREGION then
- begin
- CombineRgn(Result, Result, Rgn, RGN_OR);
- DeleteObject(Rgn);
- end
- else
- Result := Rgn;
- Inc(Y1, M div 2);
- end;
- end;
- if YMode <> 0 then
- begin
- if Y < H then
- N := H div 10
- else
- N := 0;
- M := N div 20;
- if M < 2 then M := 2;
- X1 := 0;
- while X1 < W do
- begin
- if YMode = 1 then
- begin
- Rgn := CreateRectRgn(X1, H - Y, X1 + M, H);
- for I := N div M downto 1 do
- begin
- if I > 3 * N div M div 4 then J := 0 else J := 1;
- if Random(I) <= J then
- begin
- Y1 := (H - Y) - (I * M);
- tRgn := CreateRectRgn(X1, Y1, X1 + M, Y1 + M);
- CombineRgn(Rgn, Rgn, tRgn, RGN_OR);
- DeleteObject(tRgn);
- end;
- end;
- end
- else
- begin
- Rgn := CreateRectRgn(X1, 0, X1 + M, Y);
- for I := N div M downto 1 do
- begin
- if I > 3 * N div M div 4 then J := 0 else J := 1;
- if Random(I) <= J then
- begin
- Y1 := Y + (I * M);
- tRgn := CreateRectRgn(X1, Y1 - M, X1 + M, Y1);
- CombineRgn(Rgn, Rgn, tRgn, RGN_OR);
- DeleteObject(tRgn);
- end;
- end;
- end;
- if Result <> NULLREGION then
- begin
- CombineRgn(Result, Result, Rgn, RGN_OR);
- DeleteObject(Rgn);
- end
- else
- Result := Rgn;
- Inc(X1, M div 2);
- end;
- end;
- end;
-
- function CreateBoxesRgn(W, H: Integer; Percent: TPercent): HRgn;
- var
- X, Y: Integer;
- S: Integer;
- Rgn: HRgn;
- begin
- Result := NULLREGION;
- if W < H then
- S := W div 50 + Percent div 10
- else
- S := H div 50 + Percent div 10;
- if S < 1 then S := 1;
- X := 0;
- while X < W do
- begin
- Y := 0;
- while Y < H do
- begin
- if Random(100) < Percent then
- begin
- Rgn := CreateRectRgn(X - S, Y - S, X + S, Y + S);
- if Result <> NULLREGION then
- begin
- CombineRgn(Result, Result, Rgn, RGN_OR);
- DeleteObject(Rgn);
- end
- else
- Result := Rgn;
- end;
- Inc(Y, S);
- end;
- Inc(X, S);
- end;
- end;
-
- function CreateTriangleRgn(x1, y1, x2, y2, x3, y3: Integer): HRgn;
- var
- ptArray : array[1..4] of TPoint;
- begin
- ptArray[1].x := x1;
- ptArray[1].y := y1;
- ptArray[2].x := x2;
- ptArray[2].y := y2;
- ptArray[3].x := x3;
- ptArray[3].y := y3;
- ptArray[4].x := x1;
- ptArray[4].y := y1;
- Result := CreatePolygonRgn(ptArray, 4, WINDING);
- end;
-
- function ScaleImageToRect(IR, R: TRect): TRect;
- var
- iW, iH: Integer;
- rW, rH: Integer;
- begin
- iW := IR.Right - IR.Left;
- iH := IR.Bottom - IR.Top;
- rW := R.Right - R.Left;
- rH := R.Bottom - R.Top;
- if (rW / iW) < (rH / iH) then
- begin
- iH := MulDiv(iH, rW, iW);
- iW := MulDiv(iW, rW, iW);
- end
- else
- begin
- iW := MulDiv(iW, rH, iH);
- iH := MulDiv(iH, rH, iH);
- end;
- SetRect(Result, 0, 0, iW, iH);
- OffsetRect(Result, R.Left + (rW - iW) div 2, R.Top + (rH - iH) div 2);
- end;
-
- procedure DrawTiledImage(Canvas: TCanvas; Rect: TRect; G: TGraphic);
- var
- R, Rows, C, Cols: Integer;
- begin
- if (G <> nil) and (not G.Empty) then
- begin
- Rows := ((Rect.Bottom - Rect.Top) div G.Height) + 1;
- Cols := ((Rect.Right - Rect.Left) div G.Width) + 1;
- for R := 1 to Rows do
- for C := 1 to Cols do
- Canvas.Draw(Rect.Left + (C-1) * G.Width, Rect.Top + (R-1) * G.Height, G)
- end;
- end;
-
- procedure MirrorCopyRect(Canvas: TCanvas; dstRect: TRect;
- Bitmap: TBitmap; srcRect: TRect; Horz, Vert: Boolean);
- var
- T: Integer;
- begin
- IntersectRect(srcRect, srcRect, Rect(0, 0, Bitmap.Width, Bitmap.Height));
- if Horz then
- begin
- T := dstRect.Left;
- dstRect.Left := dstRect.Right+1;
- dstRect.Right := T-1;
- end;
- if Vert then
- begin
- T := dstRect.Top;
- dstRect.Top := dstRect.Bottom+1;
- dstRect.Bottom := T-1;
- end;
- StretchBlt(Canvas.Handle, dstRect.Left, dstRect.Top,
- dstRect.Right - dstRect.Left, dstRect.Bottom - dstRect.Top,
- Bitmap.Canvas.Handle, srcRect.Left, srcRect.Top,
- srcRect.Right - srcRect.Left, srcRect.Bottom - srcRect.Top, SRCCOPY);
- end;
-
- // Both bitmaps must be equal size and 24 bit format.
- procedure MergeTransparent(dstBitmap, srcBitmap: TBitmap; Transparency: TPercent);
- var
- dstRow, srcRow: PRGBTripleArray;
- x, y: Integer;
- begin
- for y := 0 to srcBitmap.Height-1 do
- begin
- srcRow := srcBitmap.ScanLine[y];
- dstRow := dstBitmap.ScanLine[y];
- for x := 0 to srcBitmap.Width-1 do
- begin
- dstRow[x].rgbtRed := ((100-Transparency) * dstRow[X].rgbtRed) div 100 +
- (Transparency * srcRow[X].rgbtRed) div 100;
- dstRow[x].rgbtGreen := ((100-Transparency) * dstRow[X].rgbtGreen) div 100 +
- (Transparency * srcRow[X].rgbtGreen) div 100;
- dstRow[x].rgbtBlue := ((100-Transparency) * dstRow[X].rgbtBlue) div 100 +
- (Transparency * srcRow[X].rgbtBlue) div 100;
- end;
- end;
- end;
-
- // Both bitmaps must be equal size and 24 bit format.
- procedure MergeRotate(dstBitmap, srcBitmap: TBitmap; xOrg, yOrg: Integer;
- Angle: Double);
- var
- cosTheta: Extended;
- sinTheta: Extended;
- xSrc, ySrc: Integer;
- xDst, yDst: Integer;
- xPrime, yPrime: Integer;
- srcRow, dstRow: PRGBTripleArray;
- begin
- SinCos(Angle, sinTheta, cosTheta);
- for ySrc := 0 to srcBitmap.Height-1 do
- begin
- dstRow := dstBitmap.ScanLine[ySrc];
- yPrime := ySrc - yOrg;
- for xSrc := 0 to srcBitmap.Width-1 do
- begin
- xPrime := xSrc - xOrg;
- xDst := xOrg + Round(xPrime * CosTheta - yPrime * sinTheta);
- yDst := yOrg + Round(xPrime * sinTheta + yPrime * cosTheta);
- if (xDst >= 0) and (xDst < dstBitmap.Width) and
- (yDst >= 0) and (yDst < dstBitmap.Height)
- then
- begin
- srcRow := srcBitmap.Scanline[yDst];
- dstRow[xSrc] := srcRow[xDst]
- end;
- end;
- end;
- end;
-
- { TAnimateThread }
-
- constructor TAnimateThread.Create(APicShow: TCustomPicShow);
- begin
- PicShow := APicShow;
- OnTerminate := PicShow.AnimationComplete;
- FreeOnTerminate := True;
- inherited Create(False);
- Priority := PicShow.ThreadPriority;
- end;
-
- procedure TAnimateThread.Execute;
- var
- Elapsed: DWord;
- begin
- while not (Terminated or PicShow.Manual or PicShow.Stopping) do
- begin
- Elapsed := GetTickCount;
- Synchronize(Update);
- Elapsed := GetTickCount - Elapsed;
- if (PicShow.Reverse and (PicShow.Progress = Low(TPercent))) or
- (not PicShow.Reverse and (PicShow.Progress = High(TPercent))) then
- Terminate
- else if PicShow.Delay > Elapsed then
- Sleep(PicShow.Delay - Elapsed);
- end;
- end;
-
- procedure TAnimateThread.Update;
- begin
- if PicShow.Reverse then
- if PicShow.Progress - PicShow.Step >= Low(TPercent) then
- PicShow.Progress := PicShow.Progress - PicShow.Step
- else
- PicShow.Progress := Low(TPercent)
- else
- if PicShow.Progress + PicShow.Step <= High(TPercent) then
- PicShow.Progress := PicShow.Progress + PicShow.Step
- else
- PicShow.Progress := High(TPercent);
- end;
-
- { TCustomPicShow }
-
- constructor TCustomPicShow.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- ControlStyle := ControlStyle + [csOpaque];
- Media := TBitmap.Create;
- Media.PixelFormat := pf24bit;
- fStep := 4;
- fDelay := 40;
- fStyle := 51;
- fReverse := False;
- fCenter := False;
- fStretch := False;
- fStretchFine := False;
- fAutoSize := True;
- fThreaded := True;
- fThreadPriority := tpNormal;
- fManual := False;
- fProgress := Low(TPercent);
- fBusy := False;
- fPicture := TPicture.Create;
- fPicture.OnChange := PictureChange;
- fBgPicture := TPicture.Create;
- fBgPicture.OnChange := BgPictureChange;
- fBgMode := bmTiled;
- OffScreen := TBitmap.Create;
- Width := 100;
- Height := 100;
- Thread := nil;
- Stopping := False;
- Drawing := False;
- end;
-
- destructor TCustomPicShow.Destroy;
- begin
- if Assigned(Thread) then
- begin
- Thread.Terminate;
- repeat
- Application.ProcessMessages;
- until Assigned(Thread);
- end;
- Media.Free;
- fPicture.Free;
- fBgPicture.Free;
- OffScreen.Free;
- inherited Destroy;
- end;
-
- procedure TCustomPicShow.SetPicture(Value: TPicture);
- begin
- if Assigned(Value) then
- fPicture.Assign(Value)
- else
- fPicture.Graphic := nil;
- end;
-
- procedure TCustomPicShow.SetBgPicture(Value: TPicture);
- begin
- if Assigned(Value) then
- fBgPicture.Assign(Value)
- else
- fBgPicture.Graphic := nil;
- end;
-
- procedure TCustomPicShow.SetBgMode(Value: TBackgroundMode);
- begin
- if fBgMode <> Value then
- begin
- fBgMode := Value;
- if Assigned(fBgPicture.Graphic) and not Drawing then Invalidate;
- end;
- end;
-
- procedure TCustomPicShow.SetCenter(Value: Boolean);
- begin
- if fCenter <> Value then
- begin
- fCenter := Value;
- if Assigned(fPicture.Graphic) then
- begin
- CalculatePicRect;
- if not (Media.Empty or Drawing) then Invalidate;
- end;
- end;
- end;
-
- procedure TCustomPicShow.SetStretch(Value: Boolean);
- begin
- if fStretch <> Value then
- begin
- fStretch := Value;
- if not (Media.Empty or Drawing) then Invalidate;
- end;
- end;
-
- procedure TCustomPicShow.SetStretchFine(Value: Boolean);
- begin
- if fStretchFine <> Value then
- begin
- fStretchFine := Value;
- if not (Media.Empty or Drawing) then Invalidate;
- end;
- end;
-
- procedure TCustomPicShow.SetStep(Value: Word);
- begin
- if Value = 0 then Value := 1;
- if Value > High(TPercent) then Value := High(TPercent);
- fStep := Value;
- end;
-
- procedure TCustomPicShow.SetStyleName(const Value: String);
- var
- TheStyle: TShowStyle;
- begin
- for TheStyle := Low(TShowStyle) to High(TShowStyle) do
- if AnsiCompareText(PSTransitionNames[TheStyle], Value) = 0 then
- begin
- Style := TheStyle;
- Break;
- end;
- end;
-
- function TCustomPicShow.GetStyleName: String;
- begin
- Result := PSTransitionNames[Style];
- end;
-
- function TCustomPicShow.GetEmpty: Boolean;
- begin
- Result := not Assigned(fPicture.Graphic) or fPicture.Graphic.Empty;
- end;
-
- procedure TCustomPicShow.PictureChange(Sender: TObject);
- begin
- if not (csDestroying in ComponentState) then
- begin
- if Assigned(fPicture.Graphic) and fAutoSize then
- AdjustClientSize;
- if Assigned(fOnChange) then
- fOnChange(Self);
- end;
- end;
-
- procedure TCustomPicShow.BgPictureChange(Sender: TObject);
- begin
- if (fBgMode <> bmNone) and not Drawing then Invalidate;
- end;
-
- procedure TCustomPicShow.SetProgress(Value: TPercent);
- begin
- if Value < Low(TPercent) then Value := Low(TPercent);
- if Value > High(TPercent) then Value := High(TPercent);
- if fBusy and (fProgress <> Value) then
- begin
- if (fProgress > Value) and not Drawing then
- InvalidateArea(Rect(0, 0, Media.Width, Media.Height));
- fProgress := Value;
- UpdateDisplay;
- if Assigned(fOnProgress) and not (csDestroying in ComponentState) then
- fOnProgress(Self);
- end;
- end;
-
- procedure TCustomPicShow.SetManual(Value: Boolean);
- begin
- if fManual <> Value then
- begin
- fManual := Value;
- if not fBusy then
- if fReverse then
- fProgress := High(TPercent)
- else
- fProgress := Low(TPercent)
- else if not fManual then
- Animate;
- end;
- end;
-
- procedure TCustomPicShow.AnimationComplete(Sender: TObject);
- begin
- Thread := nil;
- if Stopping or not fManual then
- begin
- fBusy := False;
- if Assigned(Pic) then Pic.Free;
- if Assigned(OldPic) then OldPic.Free;
- Pic := nil;
- OldPic := nil;
- if Assigned(FOnComplete) and not (csDestroying in ComponentState) and
- not Stopping then fOnComplete(Self);
- end;
- end;
-
- procedure TCustomPicShow.WMEraseBkgnd(var Msg: TWMEraseBkgnd);
- begin
- Msg.Result := 1;
- end;
-
- procedure TCustomPicShow.WMPaint(var Msg: TWMPaint);
- begin
- if not Drawing and (GetCurrentThreadID = MainThreadID) then
- begin
- Drawing := True;
- try
- inherited;
- finally
- Drawing := False;
- end;
- end;
- end;
-
- procedure TCustomPicShow.CMMouseEnter(var Msg: TMessage);
- begin
- inherited;
- if Assigned(fOnMouseEnter) then fOnMouseEnter(Self);
- end;
-
- procedure TCustomPicShow.CMMouseLeave(var Msg: TMessage);
- begin
- inherited;
- if Assigned (fOnMouseLeave) then fOnMouseLeave(Self);
- end;
-
- procedure TCustomPicShow.SetAutoSize_(Value: Boolean);
- begin
- if fAutoSize <> Value then
- begin
- fAutoSize := Value;
- if fAutoSize then AdjustClientSize;
- end;
- end;
-
- procedure TCustomPicShow.AdjustClientSize;
- begin
- if Assigned(fPicture.Graphic) and (Align = alNone) then
- begin
- ClientWidth := fPicture.Width;
- ClientHeight := fPicture.Height;
- end;
- end;
-
- procedure TCustomPicShow.WMSize(var Msg: TWMSize);
- begin
- inherited;
- if Assigned(fPicture.Graphic) then
- begin
- CalculatePicRect;
- if not (Media.Empty or Drawing) then Invalidate;
- end;
- end;
-
- procedure TCustomPicShow.Paint;
- var
- R: TRect;
- C: TCanvas;
- begin
- OffScreen.Width := ClientWidth;
- OffScreen.Height := ClientHeight;
- C := OffScreen.Canvas;
- C.Lock;
- try
- R := ClientRect;
- C.Brush.Color := Color;
- C.FillRect(R);
- if Assigned(fBgPicture.Graphic) then
- case fBgMode of
- bmTiled: DrawTiledImage(C, R, fBgPicture.Graphic);
- bmStretched: C.StretchDraw(R, fBgPicture.Graphic);
- bmCentered: C.Draw((R.Right - R.Left - fBgPicture.Width) div 2,
- (R.Bottom - R.Top - fBgPicture.Height) div 2,
- fBgPicture.Graphic);
- end;
- if not Media.Empty then
- begin
- if fStretch then
- if fStretchFine then
- C.StretchDraw(ScaleImageToRect(PicRect, R), Media)
- else
- C.StretchDraw(R, Media)
- else
- C.Draw(PicRect.Left, PicRect.Top, Media);
- end;
- if csDesigning in ComponentState then
- begin
- C.Pen.Style := psDash;
- C.Brush.Style := bsClear;
- C.Rectangle(0, 0, Width, Height);
- end;
- finally
- C.Unlock;
- end;
- Canvas.Lock;
- try
- Canvas.Draw(0, 0, OffScreen);
- finally
- Canvas.Unlock;
- end;
- end;
-
- procedure TCustomPicShow.CalculatePicRect;
- begin
- if not Media.Empty then
- begin
- SetRect(PicRect, 0, 0, Media.Width, Media.Height);
- if fCenter then
- OffsetRect(PicRect, (ClientWidth - Media.Width) div 2,
- (ClientHeight - Media.Height) div 2);
- end;
- end;
-
- procedure TCustomPicShow.InvalidateArea(Area: TRect);
- var
- R: TRect;
- begin
- if fStretch then
- begin
- if fStretchFine then
- R := ScaleImageToRect(PicRect, ClientRect)
- else
- R := ClientRect;
- Area.Left := R.Left + MulDiv(Area.Left, R.Right - R.Left, PicRect.Right - PicRect.Left);
- Area.Right := R.Left + MulDiv(Area.Right, R.Right - R.Left, PicRect.Right - PicRect.Left);
- Area.Top := R.Top + MulDiv(Area.Top, R.Bottom - R.Top, PicRect.Bottom - PicRect.Top);
- Area.Bottom := R.Top + MulDiv(Area.Bottom, R.Bottom - R.Top, PicRect.Bottom - PicRect.Top);
- end
- else
- begin
- if fCenter then OffsetRect(Area, PicRect.Left, PicRect.Top);
- if Area.Left < PicRect.Left then Area.Left := PicRect.Left;
- if Area.Right > PicRect.Right then Area.Right := PicRect.Right;
- if Area.Top < PicRect.Top then Area.Top := PicRect.Top;
- if Area.Bottom > PicRect.Bottom then Area.Bottom := PicRect.Bottom;
- end;
- if not (csDestroying in ComponentState) then
- begin
- {$IFDEF WINCONTROL_PICSHOW}
- InvalidateRect(Handle, @Area, False);
- {$ELSE}
- OffsetRect(Area, Left, Top);
- InvalidateRect(Parent.Handle, @Area, False);
- {$ENDIF}
- end;
- end;
-
- Procedure TCustomPicShow.Clear;
- begin
- if not (fBusy or Media.Empty) then
- begin
- if Media.Canvas.TryLock then
- begin
- Media.Canvas.Unlock;
- Media.Free;
- Media := TBitmap.Create;
- Media.PixelFormat := pf24bit;
- Invalidate;
- end;
- end;
- end;
-
- procedure TCustomPicShow.Stop;
- begin
- if fBusy and not Stopping then
- begin
- Stopping := True;
- try
- if Assigned(Thread) then
- begin
- Thread.Terminate;
- repeat
- Application.ProcessMessages;
- until Assigned(Thread);
- end
- else
- AnimationComplete(nil);
- finally
- Stopping := False;
- end;
- end;
- end;
-
- procedure TCustomPicShow.Execute;
- begin
- if not fBusy and Assigned(Picture.Graphic) then
- begin
- fBusy := True;
- try
- Prepare;
- if not fManual then Animate;
- except
- if Assigned(Pic) then Pic.Free;
- if Assigned(OldPic) then OldPic.Free;
- fBusy := False;
- raise;
- end;
- end;
- end;
-
- procedure TCustomPicShow.Animate;
- var
- StartTime: DWord;
- Done: Boolean;
- begin
- if fThreaded then
- Thread := TAnimateThread.Create(Self)
- else
- begin
- repeat
- StartTime := GetTickCount;
- if Reverse then
- if Progress - Step >= Low(TPercent) then
- Progress := Progress - Step
- else
- Progress := Low(TPercent)
- else
- if Progress + Step <= High(TPercent) then
- Progress := Progress + Step
- else
- Progress := High(TPercent);
- Done := (Reverse and (Progress = Low(TPercent))) or
- (not Reverse and (Progress = High(TPercent)));
- if not Done then
- repeat
- Application.ProcessMessages;
- until ((GetTickCount - StartTime) > Delay) or not fBusy or fManual or Stopping;
- until Done or not fBusy or fManual or Stopping;
- if Done then AnimationComplete(nil);
- end;
- end;
-
- procedure TCustomPicShow.Prepare;
- var
- R: TRect;
- begin
- Media.Canvas.Brush.Color := Color;
- Media.Width := fPicture.Width;
- Media.Height := fPicture.Height;
- CalculatePicRect;
- OldPic := TBitmap.Create;
- OldPic.Width := Media.Width;
- OldPic.Height := Media.Height;
- OldPic.PixelFormat := pf24bit;
- if fStretch then
- if fStretchFine then
- R := ScaleImageToRect(PicRect, ClientRect)
- else
- R := ClientRect
- else
- R := PicRect;
- OldPic.Canvas.CopyRect(Rect(0, 0, OldPic.Width, OldPic.Height), OffScreen.Canvas, R);
- Pic := TBitmap.Create;
- Pic.Width := Media.Width;
- Pic.Height := Media.Height;
- Pic.PixelFormat := pf24bit;
- Pic.Canvas.Draw(0, 0, fPicture.Graphic);
- if Reverse then
- Progress := High(TPercent)
- else
- Progress := Low(TPercent);
- end;
-
- procedure TCustomPicShow.UpdateDisplay;
- var
- X, Y, W, H: Integer;
- R, Rgn: HRgn;
- R1, R2: TRect;
- I, J, S: Integer;
- begin
- Media.Canvas.Draw(0, 0, OldPic);
- if Assigned(fOnBeforeNewFrame) then
- fOnBeforeNewFrame(Self, Pic, Media);
- W := Pic.Width;
- H := Pic.Height;
- SetRect(R1, 0, 0, W, H);
- SetRect(R2, 0, 0, W, H);
- Rgn := NULLREGION;
- if W >= H then
- begin
- X := MulDiv(W, fProgress, 100);
- Y := MulDiv(X, H, W);
- S := MulDiv(W, fStep, 90);
- end
- else
- begin
- Y := MulDiv(H, fProgress, 100);
- X := MulDiv(Y, W, H);
- S := MulDiv(H, fStep, 90);
- end;
- case fStyle of
- 0: begin
- if Assigned(fOnCustomDraw) then
- fOnCustomDraw(Self, Pic, Media)
- else
- begin
- Media.Canvas.Draw(0, 0, Pic);
- Rgn := CreateRectRgn(0, 0, W, H);
- fProgress := High(TPercent);
- end;
- end;
- 1: begin
- R1.Left := W - X;
- end;
- 2: begin
- R1.Right := X;
- end;
- 3: begin
- R1.Left := W - X;
- R1.Right := (2 * W) - X;
- end;
- 4: begin
- R1.Left := X - W;
- R1.Right := X;
- end;
- 5: begin
- R1.Right := X;
- R2.Right := X;
- end;
- 6: begin
- R1.Left := W - X;
- R2.Left := W - X;
- end;
- 7: begin
- R1.Right := (2 * W) - X;
- R2.Right := X;
- end;
- 8: begin
- R1.Left := X - W;
- R2.Left := W - X;
- end;
- 9: begin
- R1.Left := X - W;
- R1.Right := (2 * W) - X;
- R2.Left := (W - X) div 2;
- R2.Right := (W + X) div 2;
- end;
- 10: begin
- R1.Left := (W - X) div 2;
- R1.Right := (W + X) div 2;
- end;
- 11: begin
- R1.Left := (W - X) div 2;
- R1.Right := (W + X) div 2;
- R2.Left := (W - X) div 2;
- R2.Right := (W + X) div 2;
- end;
- 12: begin
- R1.Left := 0;
- R1.Right := (X div 2) + 1;
- R2.Left := 0;
- R2.Right := (X div 2) + 1;
- Media.Canvas.CopyRect(R1, Pic.Canvas, R2);
- InvalidateArea(R1);
- R1.Left := W - (X div 2) - 1;
- R1.Right := W;
- R2.Left := W - (X div 2) - 1;
- R2.Right := W;
- end;
- 13: begin
- R1.Left := 0;
- R1.Right := (X div 2) + 1;
- R2.Left := 0;
- R2.Right := (W div 2) + 1;
- Media.Canvas.CopyRect(R1, Pic.Canvas, R2);
- InvalidateArea(R1);
- R1.Left := W - (X div 2) - 1;
- R1.Right := W;
- R2.Left := W div 2;
- R2.Right := W;
- end;
- 14: begin
- R1.Left := X;
- if R1.Left < W div 5 then
- R1.Right := R1.Left + X div 2
- else if (R1.Left + W div 5) > W then
- R1.Right := R1.Left + (W - X) div 2
- else
- R1.Right := R1.Left + W div 10;
- R2.Left := R1.Right;
- R2.Right := R2.Left + R1.Right - R1.Left;
- MirrorCopyRect(Media.Canvas, R1, Pic, R2, True, False);
- InvalidateArea(R1);
- R1.Left := 0;
- R1.Right := X;
- R2.Left := 0;
- R2.Right := X;
- end;
- 15: begin
- R1.Right := W - X;
- if (R1.Right + W div 5) > W then
- R1.Left := R1.Right - X div 2
- else if R1.Right < W div 5 then
- R1.Left := R1.Right - (W - X) div 2
- else
- R1.Left := R1.Right - W div 10;
- R2.Right := R1.Left;
- R2.Left := R2.Right - R1.Right + R1.Left;
- MirrorCopyRect(Media.Canvas, R1, Pic, R2, True, False);
- InvalidateArea(R1);
- R1.Left := W - X;
- R1.Right := W;
- R2.Left := W - X;
- R2.Right := W;
- end;
- 16: begin
- R1.Left := 0;
- R1.Right := X;
- R2.Left := 0;
- R2.Right := X;
- Media.Canvas.CopyRect(R1, Pic.Canvas, R2);
- InvalidateArea(R1);
- R1.Left := X;
- R1.Right := W;
- R2.Left := X;
- R2.Right := X + W div 20;
- end;
- 17: begin
- R1.Left := W - X;
- R1.Right := W;
- R2.Left := W - X;
- R2.Right := W;
- Media.Canvas.CopyRect(R1, Pic.Canvas, R2);
- InvalidateArea(R1);
- R1.Left := 0;
- R1.Right := W - X;
- R2.Left := (W - X) - W div 20;
- R2.Right := W - X;
- end;
- 18: begin
- R1.Top := H - Y;
- end;
- 19: begin
- R1.Bottom := Y;
- end;
- 20: begin
- R1.Top := H - Y;
- R1.Bottom := (2 * H) - Y;
- end;
- 21: begin
- R1.Top := Y - H;
- R1.Bottom := Y;
- end;
- 22: begin
- R1.Bottom := Y;
- R2.Bottom := Y;
- end;
- 23: begin
- R1.Top := H - Y;
- R2.Top := H - Y;
- end;
- 24: begin
- R1.Bottom := (2 * H) - Y;
- R2.Bottom := Y;
- end;
- 25: begin
- R1.Top := Y - H;
- R2.Top := H - Y;
- end;
- 26: begin
- R1.Top := Y - H;
- R1.Bottom := (2 * H) - Y;
- R2.Top := (H - Y) div 2;
- R2.Bottom := (H + Y) div 2;
- end;
- 27: begin
- R1.Top := (H - Y) div 2;
- R1.Bottom := (H + Y) div 2;
- end;
- 28: begin
- R1.Top := (H - Y) div 2;
- R1.Bottom := (H + Y) div 2;
- R2.Top := (H - Y) div 2;
- R2.Bottom := (H + Y) div 2;
- end;
- 29: begin
- R1.Top := 0;
- R1.Bottom := (Y div 2) + 1;
- R2.Top := 0;
- R2.Bottom := (Y div 2) + 1;
- Media.Canvas.CopyRect(R1, Pic.Canvas, R2);
- InvalidateArea(R1);
- R1.Top := H - (Y div 2) - 1;
- R1.Bottom := H;
- R2.Top := H - (Y div 2) - 1;
- R2.Bottom := H;
- end;
- 30: begin
- R1.Top := 0;
- R1.Bottom := (Y div 2) + 1;
- R2.Top := 0;
- R2.Bottom := (H div 2) + 1;
- Media.Canvas.CopyRect(R1, Pic.Canvas, R2);
- InvalidateArea(R1);
- R1.Top := H - (Y div 2) - 1;
- R1.Bottom := H;
- R2.Top := H div 2;
- R2.Bottom := H;
- end;
- 31: begin
- R1.Top := Y;
- if R1.Top < H div 5 then
- R1.Bottom := R1.Top + Y div 2
- else if (R1.Top + H div 5) > H then
- R1.Bottom := R1.Top + (H - Y) div 2
- else
- R1.Bottom := R1.Top + H div 10;
- R2.Top := R1.Bottom;
- R2.Bottom := R2.Top + R1.Bottom - R1.Top;
- MirrorCopyRect(Media.Canvas, R1, Pic, R2, False, True);
- InvalidateArea(R1);
- R1.Top := 0;
- R1.Bottom := Y;
- R2.Top := 0;
- R2.Bottom := Y;
- end;
- 32: begin
- R1.Bottom := H - Y;
- if (R1.Bottom + H div 5) > H then
- R1.Top := R1.Bottom - Y div 2
- else if R1.Bottom < H div 5 then
- R1.Top := R1.Bottom - (H - Y) div 2
- else
- R1.Top := R1.Bottom - H div 10;
- R2.Bottom := R1.Top;
- R2.Top := R2.Bottom - R1.Bottom + R1.Top;
- MirrorCopyRect(Media.Canvas, R1, Pic, R2, False, True);
- InvalidateArea(R1);
- R1.Top := H - Y;
- R1.Bottom := H;
- R2.Top := H - Y;
- R2.Bottom := H;
- end;
- 33: begin
- R1.Top := 0;
- R1.Bottom := Y;
- R2.Top := 0;
- R2.Bottom := Y;
- Media.Canvas.CopyRect(R1, Pic.Canvas, R2);
- InvalidateArea(R1);
- R1.Top := Y;
- R1.Bottom := H;
- R2.Top := Y;
- R2.Bottom := Y + H div 20;
- end;
- 34: begin
- R1.Top := H - Y;
- R1.Bottom := H;
- R2.Top := H - Y;
- R2.Bottom := H;
- Media.Canvas.CopyRect(R1, Pic.Canvas, R2);
- InvalidateArea(R1);
- R1.Top := 0;
- R1.Bottom := H - Y;
- R2.Top := (H - Y) - H div 20;
- R2.Bottom := H - Y;
- end;
- 35: begin
- R1.Left := W - X;
- R1.Top := H - Y;
- end;
- 36: begin
- R1.Left := W - X;
- R1.Bottom := Y;
- end;
- 37: begin
- R1.Right := X;
- R1.Bottom := Y;
- end;
- 38: begin
- R1.Right := X;
- R1.Top := H - Y;
- end;
- 39: begin
- R1.Left := W - X;
- R1.Top := H - Y;
- R1.Right := (2 * W) - X;
- R1.Bottom := (2 * H) - Y;
- end;
- 40: begin
- R1.Left := W - X;
- R1.Top := Y - H;
- R1.Right := (2 * W) - X;
- R1.Bottom := Y;
- end;
- 41: begin
- R1.Left := X - W;
- R1.Top := Y - H;
- R1.Right := X;
- R1.Bottom := Y;
- end;
- 42: begin
- R1.Left := X - W;
- R1.Top := H - Y;
- R1.Right := X;
- R1.Bottom := (2 * H) - Y;
- end;
- 43: begin
- R1.Right := X;
- R1.Bottom := Y;
- R2.Right := X;
- R2.Bottom := Y;
- end;
- 44: begin
- R1.Right := X;
- R1.Top := H - Y;
- R2.Right := X;
- R2.Top := H - Y;
- end;
- 45: begin
- R1.Left := W - X;
- R1.Top := H - Y;
- R2.Left := W - X;
- R2.Top := H - Y;
- end;
- 46: begin
- R1.Left := W - X;
- R1.Bottom := Y;
- R2.Left := W - X;
- R2.Bottom := Y;
- end;
- 47: begin
- R1.Right := (2 * W) - X;
- R1.Bottom := (2 * H) - Y;
- R2.Right := X;
- R2.Bottom := Y;
- end;
- 48: begin
- R1.Right := (2 * W) - X;
- R1.Top := Y - H;
- R2.Right := X;
- R2.Top := H - Y;
- end;
- 49: begin
- R1.Left := X - W;
- R1.Top := Y - H;
- R2.Left := W - X;
- R2.Top := H - Y;
- end;
- 50: begin
- R1.Left := X - W;
- R1.Bottom := (2 * H) - Y;
- R2.Left := W - X;
- R2.Bottom := Y;
- end;
- 51: begin
- R1.Left := X - W;
- R1.Top := Y - H;
- R1.Right := (2 * W) - X;
- R1.Bottom := (2 * H) - Y;
- R2.Left := (W - X) div 2;
- R2.Top := (H - Y) div 2;
- R2.Right := (W + X) div 2;
- R2.Bottom := (H + Y) div 2;
- end;
- 52: begin
- R1.Left := (W - X) div 2;
- R1.Top := (H - Y) div 2;
- R1.Right := (W + X) div 2;
- R1.Bottom := (H + Y) div 2;
- end;
- 53: begin
- R1.Left := (W - X) div 2;
- R1.Top := (H - Y) div 2;
- R1.Right := (W + X) div 2;
- R1.Bottom := (H + Y) div 2;
- R2.Left := (W - X) div 2;
- R2.Top := (H - Y) div 2;
- R2.Right := (W + X) div 2;
- R2.Bottom := (H + Y) div 2;
- end;
- 54: begin
- R1.Left := 0;
- R1.Right := W;
- R1.Top := 0;
- R1.Bottom := Y div 2;
- R2.Left := 0;
- R2.Right := W;
- R2.Top := 0;
- R2.Bottom := Y div 2;
- Media.Canvas.CopyRect(R1, Pic.Canvas, R2);
- InvalidateArea(R1);
- R1.Left := 0;
- R1.Right := W;
- R1.Top := H - (Y div 2);
- R1.Bottom := H;
- R2.Left := 0;
- R2.Right := W;
- R2.Top := H - (Y div 2);
- R2.Bottom := H;
- Media.Canvas.CopyRect(R1, Pic.Canvas, R2);
- InvalidateArea(R1);
- R1.Left := 0;
- R1.Right := X div 2;
- R1.Top := 0;
- R1.Bottom := H;
- R2.Left := 0;
- R2.Right := X div 2;
- R2.Top := 0;
- R2.Bottom := H;
- Media.Canvas.CopyRect(R1, Pic.Canvas, R2);
- InvalidateArea(R1);
- R1.Left := W - (X div 2);
- R1.Right := W;
- R1.Top := 0;
- R1.Bottom := H;
- R2.Left := W - (X div 2);
- R2.Right := W;
- R2.Top := 0;
- R2.Bottom := H;
- end;
- 55: begin
- R1.Left := 0;
- R1.Top := 0;
- R1.Right := (X div 2) + 1;
- R1.Bottom := (Y div 2) + 1;
- R2.Left := 0;
- R2.Top := 0;
- R2.Right := (X div 2) + 1;
- R2.Bottom := (Y div 2) + 1;
- Media.Canvas.CopyRect(R1, Pic.Canvas, R2);
- InvalidateArea(R1);
- R1.Left := 0;
- R1.Top := H - (Y div 2) - 1;
- R1.Right := (X div 2) + 1;
- R1.Bottom := H;
- R2.Left := 0;
- R2.Top := H - (Y div 2) - 1;
- R2.Right := (X div 2) + 1;
- R2.Bottom := H;
- Media.Canvas.CopyRect(R1, Pic.Canvas, R2);
- InvalidateArea(R1);
- R1.Left := W - (X div 2) - 1;
- R1.Top := H - (Y div 2) - 1;
- R1.Right := W;
- R1.Bottom := H;
- R2.Left := W - (X div 2) - 1;
- R2.Top := H - (Y div 2) - 1;
- R2.Right := W;
- R2.Bottom := H;
- Media.Canvas.CopyRect(R1, Pic.Canvas, R2);
- InvalidateArea(R1);
- R1.Left := W - (X div 2) - 1;
- R1.Top := 0;
- R1.Right := W;
- R1.Bottom := (Y div 2) + 1;
- R2.Left := W - (X div 2) - 1;
- R2.Top := 0;
- R2.Right := W;
- R2.Bottom := (Y div 2) + 1;
- end;
- 56: begin
- R1.Left := 0;
- R1.Top := 0;
- R1.Right := (X div 2) + 1;
- R1.Bottom := (Y div 2) + 1;
- R2.Left := 0;
- R2.Top := 0;
- R2.Right := (W div 2) + 1;
- R2.Bottom := (H div 2) + 1;
- Media.Canvas.CopyRect(R1, Pic.Canvas, R2);
- InvalidateArea(R1);
- R1.Left := 0;
- R1.Top := H - (Y div 2);
- R1.Right := (X div 2) + 1;
- R1.Bottom := H;
- R2.Left := 0;
- R2.Top := (H div 2) + 1;
- R2.Right := (W div 2) + 1;
- R2.Bottom := H;
- Media.Canvas.CopyRect(R1, Pic.Canvas, R2);
- InvalidateArea(R1);
- R1.Left := W - (X div 2);
- R1.Top := H - (Y div 2);
- R1.Right := W;
- R1.Bottom := H;
- R2.Left := (W div 2) + 1;
- R2.Top := (H div 2) + 1;
- R2.Right := W;
- R2.Bottom := H;
- Media.Canvas.CopyRect(R1, Pic.Canvas, R2);
- InvalidateArea(R1);
- R1.Left := W - (X div 2);
- R1.Top := 0;
- R1.Right := W;
- R1.Bottom := (Y div 2) + 1;
- R2.Left := (W div 2) + 1;
- R2.Top := 0;
- R2.Right := W;
- R2.Bottom := (H div 2) + 1;
- end;
- 57: begin
- R1.Left := (X - W) div 2;
- R1.Right := (X div 2) + 1;
- R1.Top := 0;
- R1.Bottom := (H div 2) + 1;
- R2.Left := 0;
- R2.Right := (W div 2) + 1;
- R2.Top := 0;
- R2.Bottom := (H div 2) + 1;
- Media.Canvas.CopyRect(R1, Pic.Canvas, R2);
- InvalidateArea(R1);
- R1.Left := (W div 2) - 1;
- R1.Right := W;
- R1.Top := (Y - H) div 2;
- R1.Bottom := (Y div 2) + 1;
- R2.Left := (W div 2) - 1;
- R2.Right := W;
- R2.Top := 0;
- R2.Bottom := (H div 2) + 1;
- Media.Canvas.CopyRect(R1, Pic.Canvas, R2);
- InvalidateArea(R1);
- R1.Left := W - X div 2;
- R1.Right := W + (W - X) div 2;
- R1.Top := (H div 2) - 1;
- R1.Bottom := H;
- R2.Left := (W div 2) + 1;
- R2.Right := W;
- R2.Top := (H div 2) - 1;
- R2.Bottom := H;
- Media.Canvas.CopyRect(R1, Pic.Canvas, R2);
- InvalidateArea(R1);
- R1.Left := 0;
- R1.Right := (W div 2) + 1;
- R1.Top := H - Y div 2;
- R1.Bottom := H + (H - Y) div 2;
- R2.Left := 0;
- R2.Right := (W div 2) + 1;
- R2.Top := (H div 2) + 1;
- R2.Bottom := H;
- end;
- 58: Rgn := CreateRoundRectRgn(-(2 * W), -5, 2 * X, H + 5, 2 * W, 2 * W);
- 59: Rgn := CreateRoundRectRgn(W - 2 * X, -5, W + (2 * W), H + 5, 2 * W, 2 * W);
- 60: Rgn := CreateBarRgn(2 * X, 0, W, H, S, 1, 0);
- 61: Rgn := CreateBarRgn(2 * X, 0, W, H, S, 2, 0);
- 62: Rgn := CreateBarRgn(2 * X, 0, W, H, S, 4, 0);
- 63: Rgn := CreateBarRgn(2 * X, 0, W, H, S, 5, 0);
- 64: Rgn := CreateBarRgn(X, 0, W, H, 0, 3, 0);
- 65: Rgn := CreateSplashRgn(X, 0, W, H, 1, 0);
- 66: Rgn := CreateSplashRgn(X, 0, W, H, 2, 0);
- 67: Rgn := CreateSplashRgn(X, 0, W, H, 3, 0);
- 68: Rgn := CreateSplashRgn(X, 0, W, H, 4, 0);
- 69: Rgn := CreateRoundRectRgn(-5, -(2 * H), W + 5, 2 * Y, 2 * H, 2 * H);
- 70: Rgn := CreateRoundRectRgn(-5, H - 2 * Y, W + 5, H + (2 * H), 2 * H, 2 * H);
- 71: Rgn := CreateBarRgn(0, 2 * Y, W, H, S, 0, 1);
- 72: Rgn := CreateBarRgn(0, 2 * Y, W, H, S, 0, 2);
- 73: Rgn := CreateBarRgn(0, 2 * Y, W, H, S, 0, 4);
- 74: Rgn := CreateBarRgn(0, 2 * Y, W, H, S, 0, 5);
- 75: Rgn := CreateBarRgn(0, Y, W, H, 0, 0, 3);
- 76: Rgn := CreateSplashRgn(0, Y, W, H, 0, 1);
- 77: Rgn := CreateSplashRgn(0, Y, W, H, 0, 2);
- 78: Rgn := CreateSplashRgn(0, Y, W, H, 0, 3);
- 79: Rgn := CreateSplashRgn(0, Y, W, H, 0, 4);
- 80: Rgn := CreateRoundRectRgn(-(2 * W), -(2 * H), 2 * X, 2 * Y, 2 * W, 2 * H);
- 81: Rgn := CreateRoundRectRgn(W - 2 * X, -(2 * H), W + (2 * W), 2 * Y, 2 * W, 2 * H);
- 82: Rgn := CreateRoundRectRgn(-(2 * W), H - 2 * Y, 2 * X, H + (2 * H), 2 * W, 2 * H);
- 83: Rgn := CreateRoundRectRgn(W - 2 * X, H - 2 * Y, W + (2 * W), H + (2 * H), 2 * H, 2 * H);
- 84: Rgn := CreateRoundRectRgn(W div 2 - X, H div 2 - Y, W div 2 + X, H div 2 + Y, 9 * X div 5, 9 * Y div 5);
- 85: begin
- R := CreateRectRgn(0, 0, W, H);
- Rgn := CreateRoundRectRgn(X - W div 2, Y - H div 2, 3 * W div 2 - X,
- 3 * H div 2 - Y, 9 * (W - X) div 5, 9 * (H - Y) div 5);
- CombineRgn(Rgn, Rgn, R, RGN_XOR);
- DeleteObject(R);
- end;
- 86: Rgn := CreateBarRgn(2 * X, 2 * Y, W, H, S, 1, 1);
- 87: Rgn := CreateBarRgn(2 * X, 2 * Y, W, H, S, 1, 2);
- 88: Rgn := CreateBarRgn(2 * X, 2 * Y, W, H, S, 2, 1);
- 89: Rgn := CreateBarRgn(2 * X, 2 * Y, W, H, S, 2, 2);
- 90: Rgn := CreateBarRgn(2 * X, 2 * Y, W, H, S, 4, 4);
- 91: Rgn := CreateBarRgn(2 * X, 2 * Y, W, H, S, 4, 5);
- 92: Rgn := CreateBarRgn(2 * X, 2 * Y, W, H, S, 5, 4);
- 93: Rgn := CreateBarRgn(2 * X, 2 * Y, W, H, S, 5, 5);
- 94: Rgn := CreateBarRgn(X, Y, W, H, S, 1, 3);
- 95: Rgn := CreateBarRgn(X, Y, W, H, S, 2, 3);
- 96: Rgn := CreateBarRgn(X, Y, W, H, S, 3, 1);
- 97: Rgn := CreateBarRgn(X, Y, W, H, S, 3, 2);
- 98: Rgn := CreateBarRgn(X, Y, W, H, 0, 3, 3);
- 99: begin
- R := CreateBarRgn(2 * X, 2 * Y, W, H, S, 1, 1);
- Rgn := CreateBarRgn(2 * X, 2 * Y, W, H, S, 2, 2);
- CombineRgn(Rgn, Rgn, R, RGN_AND);
- DeleteObject(R);
- end;
- 100: Rgn := CreateSplashRgn(X, Y, W, H, 1, 1);
- 101: Rgn := CreateSplashRgn(X, Y, W, H, 1, 2);
- 102: Rgn := CreateSplashRgn(X, Y, W, H, 2, 1);
- 103: Rgn := CreateSplashRgn(X, Y, W, H, 2, 2);
- 104: Rgn := CreateSplashRgn(X, Y, W, H, 1, 3);
- 105: Rgn := CreateSplashRgn(X, Y, W, H, 2, 3);
- 106: Rgn := CreateSplashRgn(X, Y, W, H, 3, 1);
- 107: Rgn := CreateSplashRgn(X, Y, W, H, 3, 2);
- 108: Rgn := CreateSplashRgn(X, Y, W, H, 3, 3);
- 109: Rgn := CreateSplashRgn(X, Y, W, H, 4, 4);
- // Thanks to M. R. Zamani for followinf 8 effects (110..117)
- 110: Rgn := CreateTriangleRgn(0, 0, 2 * X, 0, 0, 2 * Y);
- 111: Rgn := CreateTriangleRgn(W, 0, W - 2 * X, 0, W, 2 * Y);
- 112: Rgn := CreateTriangleRgn(0, H, 2 * X, H, 0, H - 2 * Y);
- 113: Rgn := CreateTriangleRgn(W, H, W - 2 * X, H, W, H - 2 * Y);
- 114: begin
- R := CreateTriangleRgn(0, H, 0, 0, X, H);
- Rgn := CreateTriangleRgn(W, H, W, 0, W - X, 0);
- CombineRgn(Rgn, Rgn, R, RGN_OR);
- DeleteObject(R);
- end;
- 115: begin
- R := CreateTriangleRgn(W, 0, 0, 0, W, Y);
- Rgn := CreateTriangleRgn(W, H, 0, H, 0, H - Y);
- CombineRgn(Rgn, Rgn, R, RGN_OR);
- DeleteObject(R);
- end;
- 116: begin
- Rgn := CreateTriangleRgn(W div 2, H div 2, 0, H, 0, H - Y);
- R := CreateTriangleRgn(0, 0, X, 0, W div 2, H div 2);
- CombineRgn(Rgn, Rgn, R, RGN_OR);
- DeleteObject(R);
- R := CreateTriangleRgn(W - X, H, W div 2, H div 2, W, H);
- CombineRgn(Rgn, Rgn, R, RGN_OR);
- DeleteObject(R);
- R := CreateTriangleRgn(W div 2, H div 2, W, 0, W, Y);
- CombineRgn(Rgn, Rgn, R, RGN_OR);
- DeleteObject(R);
- end;
- 117: begin
- X := X div 5;
- Y := MulDiv(X, H, W);
- for J := 0 to 9 do
- begin
- for I := 0 to 9 do
- begin
- R := CreateTriangleRgn(I * W div 10, J * H div 10,
- I * W div 10 + X, J * H div 10, I * W div 10, J * H div 10 + Y);
- if Rgn <> NULLREGION then
- begin
- CombineRgn(Rgn, Rgn, R, RGN_OR);
- DeleteObject(R);
- end
- else
- Rgn := R;
- end;
- end;
- end;
- 118: MergeTransparent(Media, Pic, Progress);
- 119: MergeRotate(Media, Pic, -1, -1, (100-Progress) * PI / 200);
- 120: MergeRotate(Media, Pic, -1, H, (100-Progress) * PI / 200);
- 121: MergeRotate(Media, Pic, W, -1, (100-Progress) * PI / 200);
- 122: MergeRotate(Media, Pic, W, H, (100-Progress) * PI / 200);
- // Thanks to Elliott Shevin for following 4 effects (123..126)
- 123: Rgn := CreateSwarmRgn(X, Y, W, H, 1, 0);
- 124: Rgn := CreateSwarmRgn(X, Y, W, H, 2, 0);
- 125: Rgn := CreateSwarmRgn(X, Y, W, H, 0, 1);
- 126: Rgn := CreateSwarmRgn(X, Y, W, H, 0, 2);
- 127: Rgn := CreateBoxesRgn(W, H, Progress);
- else
- Exit;
- end; // end of case
- if fProgress = High(TPercent) then begin
- Media.Canvas.Draw(0, 0, Pic);
- if Rgn <> NULLREGION then DeleteObject(Rgn);
- end
- else if fProgress <> Low(TPercent) then
- if fStyle in RegionStyles then
- begin
- ExtSelectClipRgn(Media.Canvas.Handle, Rgn, RGN_AND);
- Media.Canvas.Draw(0, 0, Pic);
- SelectClipRgn(Media.Canvas.Handle, 0);
- end
- else if fStyle in [1..57] then
- Media.Canvas.CopyRect(R1, Pic.Canvas, R2);
- if Rgn <> NULLREGION then DeleteObject(Rgn);
- InvalidateArea(R1);
- if Assigned(fOnAfterNewFrame) then
- fOnAfterNewFrame(Self, Pic, Media);
- if not Drawing then Update;
- end;
-
- { TDBPicShow }
-
- constructor TDBPicShow.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- fAutoDisplay := True;
- fDataLink := TFieldDataLink.Create;
- fDataLink.Control := Self;
- fDataLink.OnDataChange := DataChange;
- fDataLink.OnUpdateData := UpdateData;
- end;
-
- destructor TDBPicShow.Destroy;
- begin
- fDataLink.Free;
- fDataLink := nil;
- inherited Destroy;
- end;
-
- function TDBPicShow.GetDataSource: TDataSource;
- begin
- Result := fDataLink.DataSource;
- end;
-
- procedure TDBPicShow.SetDataSource(Value: TDataSource);
- begin
- if not (fDataLink.DataSourceFixed and (csLoading in ComponentState)) then
- fDataLink.DataSource := Value;
- if Value <> nil then Value.FreeNotification(Self);
- end;
-
- function TDBPicShow.GetDataField: string;
- begin
- Result := fDataLink.FieldName;
- end;
-
- procedure TDBPicShow.SetDataField(const Value: string);
- begin
- fDataLink.FieldName := Value;
- end;
-
- function TDBPicShow.GetReadOnly: Boolean;
- begin
- Result := fDataLink.ReadOnly;
- end;
-
- procedure TDBPicShow.SetReadOnly(Value: Boolean);
- begin
- fDataLink.ReadOnly := Value;
- end;
-
- function TDBPicShow.GetField: TField;
- begin
- Result := fDataLink.Field;
- end;
-
- procedure TDBPicShow.SetAutoDisplay(Value: Boolean);
- begin
- if fAutoDisplay <> Value then
- begin
- fAutoDisplay := Value;
- if fAutoDisplay then LoadPicture;
- end;
- end;
-
- procedure TDBPicShow.PictureChange(Sender: TObject);
- begin
- if fPictureLoaded then FDataLink.Modified;
- fPictureLoaded := True;
- inherited PictureChange(Self);
- end;
-
- procedure TDBPicShow.Notification(AComponent: TComponent;
- Operation: TOperation);
- begin
- inherited Notification(AComponent, Operation);
- if (Operation = opRemove) and (fDataLink <> nil) and
- (AComponent = DataSource) then DataSource := nil;
- end;
-
- procedure TDBPicShow.LoadPicture;
- var
- Stream: TMemoryStream;
- IsJPEGImage: Boolean;
- JPEG: TJPEGImage;
- begin
- if not fPictureLoaded and (not Assigned(fDataLink.Field) or
- fDataLink.Field.IsBlob) then
- begin
- if Assigned(fOnBeforeLoadPicture) then
- fOnBeforeLoadPicture(Self);
- IsJPEGImage := False;
- if TBlobField(fDataLink.Field).BlobSize >= 10 then
- begin
- Stream := TMemoryStream.Create;
- try
- TBlobField(fDataLink.Field).SaveToStream(Stream);
- if StrLIComp(@(PChar(Stream.Memory)[6]), 'JFIF', 4) = 0 then
- begin
- Stream.Position := 0;
- JPEG := TJPEGImage.Create;
- try
- JPEG.LoadFromStream(Stream);
- Picture.Assign(JPEG);
- IsJPEGImage := True;
- finally
- JPEG.Free;
- end;
- end;
- finally
- Stream.Free;
- end;
- end;
- if not IsJPEGImage then
- Picture.Assign(fDataLink.Field);
- if Assigned(fOnAfterLoadPicture) then
- fOnAfterLoadPicture(Self);
- // Calling abort in OnAfterLoadPicture event causes the following part
- // of code to be bypassed.
- if Busy then Stop;
- if (Picture.Graphic = nil) or Picture.Graphic.Empty then
- Clear
- else
- Execute;
- end;
- end;
-
- procedure TDBPicShow.DataChange(Sender: TObject);
- begin
- Picture.Graphic := nil;
- fPictureLoaded := False;
- if fAutoDisplay then LoadPicture;
- end;
-
- procedure TDBPicShow.UpdateData(Sender: TObject);
- var
- Stream: TMemoryStream;
- begin
- if Picture.Graphic is TBitmap then
- fDataLink.Field.Assign(Picture.Graphic)
- else if Picture.Graphic is TJPEGImage then
- begin
- Stream := TMemoryStream.Create;
- try
- Picture.Graphic.SaveToStream(Stream);
- TBlobField(fDataLink.Field).LoadFromStream(Stream);
- finally
- Stream.Free;
- end;
- end
- else
- fDataLink.Field.Clear;
- end;
-
- procedure TDBPicShow.CMGetDataLink(var Message: TMessage);
- begin
- Message.Result := Integer(fDataLink);
- end;
-
- end.
-
-