unit umain;

interface

uses
  ieNativeJPEG, ieNativePNG, ieNativeJ2K,  // Required for Native JPEG, PNG and JPEG2000 support (32bit only)
  
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus, StdCtrls, ieview, imageenview, ExtCtrls, ComCtrls, iexUtils, iexBitmaps, 
  iexDefs, iesettings, iexLayers, iexRulers, imageenproc, imageenio, iexColorButton;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    btnOpen: TButton;
    btnSave: TButton;
    Panel2: TPanel;
    Image1: TImage;
    ImageEnIO1: TImageEnIO;
    ImageEnProc1: TImageEnProc;
    btnUndo: TButton;
    btnProcEditing: TButton;
    btnProcEffects: TButton;
    btnProcColors: TButton;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    edtRotate: TEdit;
    UpDown1: TUpDown;
    IEColorButton1: TIEColorButton;
    Label4: TLabel;
    btnRotate: TButton;
    procedure btnOpenClick(Sender: TObject);
    procedure btnProcEditingClick(Sender: TObject);
    procedure btnRotateClick(Sender: TObject);
    procedure btnSaveClick(Sender: TObject);
    procedure btnUndoClick(Sender: TObject);
    procedure btnProcColorsClick(Sender: TObject);
    procedure btnProcEffectsClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
{$R ImageEnManifest.res}

uses
  iexHelperFunctions;


procedure TForm1.FormShow(Sender: TObject);
begin
  ImageEnIO1  .AttachedTImage := Image1;
  ImageEnProc1.AttachedTImage := Image1;
  ImageEnProc1.UndoLimit := 20;
end;


// File Open
procedure TForm1.btnOpenClick(Sender: TObject);
var
  fn: string;
begin
  fn := ImageEnIO1.ExecuteOpenDialog();
  if fn = '' then
    exit;

  ShowTempHourglass();
  ImageEnIO1.LoadFromFile( fn );

  btnSave       .Enabled := True;
  btnRotate     .Enabled := True;
  btnProcColors .Enabled := True;
  btnProcEditing.Enabled := True;
  btnProcEffects.Enabled := True;
end;

procedure TForm1.btnProcEditingClick(Sender: TObject);
begin
  ImageEnProc1.DoPreviews( ppeEditingFunctions );
  btnUndo.Enabled := ImageEnProc1.UndoCount > 0;
end;

procedure TForm1.btnProcColorsClick(Sender: TObject);
begin
  ImageEnProc1.DoPreviews( ppeColorAdjustments );
  btnUndo.Enabled := ImageEnProc1.UndoCount > 0;
end;

procedure TForm1.btnProcEffectsClick(Sender: TObject);
begin
  ImageEnProc1.DoPreviews( ppeSpecialEffects );
  btnUndo.Enabled := ImageEnProc1.UndoCount > 0;
end;


// Rotate
procedure TForm1.btnRotateClick(Sender: TObject);
begin
  ShowTempHourglass();
  ImageEnProc1.Rotate(  StrToFloat( edtRotate.text), ierBicubic, IEColorButton1.SelectedColor );
  btnUndo.Enabled := True;
end;

procedure TForm1.btnUndoClick(Sender: TObject);
begin
  ShowTempHourglass();
  ImageEnProc1.Undo( True );
  btnUndo.Enabled := ImageEnProc1.UndoCount > 0;
end;


// File Save
procedure TForm1.btnSaveClick(Sender: TObject);
var
  filename, ext: string;
begin
  // Note: no alpha channel support in TImage
  filename := ImageEnIO1.ExecuteSaveDialog('', '', false, 0, '');
  if filename <> '' then
      ImageEnIO1.SaveToFile(filename);
end;

end.
