(* PanZoom Example Application Developed 2014 by Nigel Cross, Xequte Software There is no limitation in the distribution, reuse or abuse of this application, other than those imposed by HiComponents. http://www.imageen.com *) unit uMain; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, iexTransitions, StdCtrls, imageenview, Spin, ieopensavedlg, hyieutils, ieview, iexBitmaps, hyiedefs, iesettings, iexLayers, iexRulers; type TfrmMain = class(TForm) ieDisplay: TImageEnView; btnViewEffect: TButton; Label1: TLabel; spnStartX1: TSpinEdit; spnStartY1: TSpinEdit; spnStartX2: TSpinEdit; spnStartY2: TSpinEdit; spnEndY2: TSpinEdit; spnEndX2: TSpinEdit; spnEndY1: TSpinEdit; spnEndX1: TSpinEdit; Label2: TLabel; Label3: TLabel; spnSeconds: TSpinEdit; Memo1: TMemo; btnBrowseFile: TButton; OpenImageEnDialog1: TOpenImageEnDialog; cmbPZEffect: TComboBox; cmbFilename: TComboBox; btnSelectStart: TButton; bnSelectEnd: TButton; btnViewStart: TButton; btnViewEnd: TButton; Label4: TLabel; cmbTiming: TComboBox; lblZoom: TLabel; spnZoom: TSpinEdit; lblSmooth: TLabel; spnSmooth: TSpinEdit; chkBlurredImageBackground: TCheckBox; Label5: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel; procedure btnViewEffectClick(Sender: TObject); procedure btnBrowseFileClick(Sender: TObject); procedure cmbPZEffectChange(Sender: TObject); procedure FormCreate(Sender: TObject); procedure cmbFilenameChange(Sender: TObject); procedure btnSelectStartClick(Sender: TObject); procedure bnSelectEndClick(Sender: TObject); procedure btnViewStartClick(Sender: TObject); procedure chkBlurredImageBackgroundClick(Sender: TObject); private { Private declarations } function PromptForDisplayRect(CurrentRect: TRect): TRect; procedure RunPanZoomTransition(AnImageEnView: TImageEnView; sFilename: string; StartRect: TRect; EndRect: TRect; iMilliseconds: Integer; Smoothing: Integer = 96; Timing: TIETransitionTiming = iettLinear); function GetEndRect: TRect; function GetStartRect: TRect; procedure SetEndRect(const Value: TRect); procedure SetStartRect(const Value: TRect); procedure LoadImage; function GetSelectedPanZoomEffect: TIEPanZoomType; procedure SetSelectedPanZoomEffect(const Value: TIEPanZoomType); public { Public declarations } // The area of the image that will be displayed at the start of the transition property StartRect: TRect read GetStartRect write SetStartRect; // The area of the image that will be displayed at the end of the transition property EndRect: TRect read GetEndRect write SetEndRect; // The pan zoom that has been selected property SelectedPanZoomEffect : TIEPanZoomType read GetSelectedPanZoomEffect write SetSelectedPanZoomEffect; end; var frmMain: TfrmMain; implementation uses uGetSelection; {$R *.DFM} const iepzCustom = TIEPanZoomType(MAX_PAN_ZOOM_EFFECT_COUNT); Maintain_Aspect_Ratio = True; // Perform a Pan Zoom transition effect procedure TfrmMain.RunPanZoomTransition(AnImageEnView: TImageEnView; sFilename: string; StartRect: TRect; EndRect: TRect; iMilliseconds: Integer; Smoothing: Integer = 96; Timing: TIETransitionTiming = iettLinear); begin AnImageEnView.PrepareTransition; AnImageEnView.io.LoadFromFile(sFilename); AnImageEnView.TransitionTiming := Timing; Memo1.Clear; Memo1.Lines.Add(Format('Adjusted Start Rect: (%d,%d,%d,%d) W: %d, H: %d', [StartRect.Left, StartRect.Top, StartRect.Right, StartRect.Bottom, StartRect.Right - StartRect.Left, StartRect.Bottom - StartRect.Top])); Memo1.lines.add(format('Adjusted End Rect: (%d,%d,%d,%d) W: %d, H: %d', [EndRect.Left, EndRect.Top, EndRect.Right, EndRect.Bottom, StartRect.Right - StartRect.Left, StartRect.Bottom - StartRect.Top])); if SelectedPanZoomEffect = iepzCustom then AnImageEnView.RunTransition(iettPanZoom, iMilliseconds, StartRect, EndRect, Maintain_Aspect_Ratio, Smoothing) else AnImageEnView.RunTransition(iettPanZoom, iMilliseconds, SelectedPanZoomEffect, spnZoom.Value, Smoothing); AnImageEnView.update; Memo1.Lines.Add(Format('End Position: (%d,%d) %d%%', [AnImageEnView.ViewX, AnImageEnView.ViewY, Round(AnImageEnView.Zoom)])); end; procedure TfrmMain.btnViewEffectClick(Sender: TObject); begin RunPanZoomTransition(ieDisplay, cmbFilename.text, StartRect, EndRect, spnSeconds.value * 1000, spnSmooth.value, TIETransitionTiming(cmbTiming.Itemindex)); end; procedure TfrmMain.btnBrowseFileClick(Sender: TObject); begin if not OpenImageEnDialog1.Execute then exit; cmbFilename.Items.Insert(0, OpenImageEnDialog1.Filename); cmbFilename.ItemIndex := 0; LoadImage; end; // Load the currently selected image procedure TfrmMain.LoadImage; begin ieDisplay.IO.LoadFromFile(cmbFilename.text); ieDisplay.Fit; // reset the Start/End rects cmbPZEffect.Enabled := true; cmbPZEffect.Itemindex := 0; cmbPZEffectChange(nil); end; procedure TfrmMain.cmbPZEffectChange(Sender: TObject); var rStartRect, rEndRect: TRect; bZoomEffect: Boolean; begin bZoomEffect := SelectedPanZoomEffect in [iepzZoomInToTopLeft, iepzZoomInToTopRight, iepzZoomInToCenter, iepzZoomInToBottomLeft, iepzZoomInToBottomRight, iepzZoomOutFromTopLeft, iepzZoomOutFromTopRight, iepzZoomOutFromCenter, iepzZoomOutFromBottomLeft, iepzZoomOutFromBottomRight, iepzFullZoomInToTopLeft, iepzFullZoomInToTop, iepzFullZoomInToTopRight, iepzFullZoomInToLeft, iepzFullZoomInToCenter, iepzFullZoomInToRight, iepzFullZoomInToBottomLeft, iepzFullZoomInToBottom, iepzFullZoomInToBottomRight, iepzFullZoomOutFromTopLeft, iepzFullZoomOutFromTop, iepzFullZoomOutFromTopRight, iepzFullZoomOutFromLeft, iepzFullZoomOutFromCenter, iepzFullZoomOutFromRight, iepzFullZoomOutFromBottomLeft, iepzFullZoomOutFromBottom, iepzFullZoomOutFromBottomRight]; spnZoom.Enabled := bZoomEffect; lblZoom.Enabled := bZoomEffect; if (cmbPZEffect.ItemIndex >= 0) and (SelectedPanZoomEffect <> iepzCustom) then begin GetPanZoomEffectStartEndRects(ieDisplay.ClientWidth, ieDisplay.ClientHeight, ieDisplay.IEBitmap.Width, ieDisplay.IEBitmap.Height, SelectedPanZoomEffect, spnZoom.Value, rStartRect, rEndRect); if Maintain_Aspect_Ratio then begin StartRect := IEAdjustRectToAspectRatio(rStartRect, ieDisplay.IEBitmap.Width, ieDisplay.IEBitmap.Height, ieDisplay.ClientWidth, ieDisplay.ClientHeight); EndRect := IEAdjustRectToAspectRatio(rEndRect, ieDisplay.IEBitmap.Width, ieDisplay.IEBitmap.Height, ieDisplay.ClientWidth, ieDisplay.ClientHeight); end else begin StartRect := rStartRect; EndRect := rEndRect; end; end; end; procedure TfrmMain.FormCreate(Sender: TObject); var I: Integer; sApplicationFolder: string; begin cmbPZEffect.Items.Clear; for I := ord(iepzPanTopLeftToBottomRight) to ord(iepzFullZoomOutFromBottomRight) do cmbPZEffect.Items.Add(IEPanZoomEffectNames[I]); cmbPZEffect.Items.Add('Custom'); cmbTiming.itemindex := 0; sApplicationFolder := IncludeTrailingBackslash(extractfilepath(Application.Exename)); if FileExists(sApplicationFolder + 'landscape.jpg') then cmbFilename.Items.Add(sApplicationFolder + 'landscape.jpg'); if FileExists(sApplicationFolder + 'portrait.jpg') then cmbFilename.Items.Add(sApplicationFolder + 'portrait.jpg'); if cmbFilename.Items.Count > 0 then begin cmbFilename.ItemIndex := 0; LoadImage; end; end; function TfrmMain.GetEndRect: TRect; begin result := rect(spnEndx1.Value, spnEndy1.Value, spnEndx2.Value, spnEndy2.Value); end ; function TfrmMain.GetSelectedPanZoomEffect: TIEPanZoomType; begin Result := TIEPanZoomType(cmbPZEffect.ItemIndex); end; function TfrmMain.GetStartRect: TRect; begin result := rect(spnstartx1.Value, spnstarty1.Value, spnstartx2.Value, spnstarty2.Value); end; procedure TfrmMain.SetEndRect(const Value: TRect); begin spnEndX1.Value := Value.left; spnEndY1.Value := Value.top; spnEndX2.Value := Value.right; spnEndY2.Value := Value.bottom; end; procedure TfrmMain.SetSelectedPanZoomEffect(const Value: TIEPanZoomType); begin cmbPZEffect.ItemIndex := Ord(Value); end; procedure TfrmMain.SetStartRect(const Value: TRect); begin spnStartX1.Value := Value.Left; spnStartY1.Value := Value.Top; spnStartX2.Value := Value.Right; spnStartY2.Value := Value.Bottom; end; procedure TfrmMain.cmbFilenameChange(Sender: TObject); begin LoadImage; end; // Return an area of the image for display function TfrmMain.PromptForDisplayRect(CurrentRect: TRect): TRect; var WholeImageRect: TRect; begin result := CurrentRect; WholeImageRect := Rect(0, 0, ieDisplay.IEBitmap.Width - 1, ieDisplay.IEBitmap.Height - 1); Application.CreateForm(TdlgGetSelection, dlgGetSelection); with dlgGetSelection do try ieSelect.Assign(ieDisplay); rdbWholeImage.Checked := (CurrentRect.Left = WholeImageRect.Left) and (CurrentRect.Top = WholeImageRect.Top) and (CurrentRect.Bottom = WholeImageRect.Bottom) and (CurrentRect.Right = WholeImageRect.Right); if rdbWholeImage.Checked = false then ieSelect.select(CurrentRect.Left, CurrentRect.Top, CurrentRect.Right, CurrentRect.Bottom, iespReplace); if dlgGetSelection.ShowModal <> mrOk then exit; if rdbWholeImage.checked then result := WholeImageRect else result := Rect(ieSelect.SelX1, ieSelect.SelY1, ieSelect.SelX2, ieSelect.SelY2); finally dlgGetSelection.free; end; end; procedure TfrmMain.btnSelectStartClick(Sender: TObject); begin StartRect := PromptForDisplayRect(StartRect); SelectedPanZoomEffect := iepzCustom; end; procedure TfrmMain.bnSelectEndClick(Sender: TObject); begin EndRect := PromptForDisplayRect(EndRect); SelectedPanZoomEffect := iepzCustom; end; procedure TfrmMain.btnViewStartClick(Sender: TObject); begin if Sender = btnViewStart then ieDisplay.VisibleBitmapRect := StartRect else ieDisplay.VisibleBitmapRect := EndRect; Memo1.clear; Memo1.Lines.Add(Format('Display: (%d,%d) %d%%', [ieDisplay.ViewX, ieDisplay.ViewY, Round(ieDisplay.Zoom)])); end; procedure TfrmMain.chkBlurredImageBackgroundClick(Sender: TObject); begin if chkBlurredImageBackground.checked then ieDisplay.BackgroundStyle := iebsBlurredImage else ieDisplay.BackgroundStyle := iebsGradient; end; end.