{*************************************************************************}
{                                                                         }
{ EditBlendUnit.pas - object render effects window                        }
{                                                                         }
{ This file is a part of the project:                                     }
{   Dizzy Quest Editor - the quest editor for Dizzy-like games            }
{                                                                         }
{ © Parfenov Alexey Andreevich, 2007                                      }
{                                                                         }
{ e-mail: AlkatrazStudio@yandex.ru                                        }
{                                                                         }
{ This program is free software; you can redistribute it and/or modify    }
{ it under the terms of the GNU General Public License as published by    }
{ the Free Software Foundation; either version 2 of the License, or       }
{ (at your option) any later version.                                     }
{                                                                         }
{ This program is distributed in the hope that it will be useful,         }
{ but WITHOUT ANY WARRANTY; without even the implied warranty of          }
{ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            }
{ GNU General Public License for more details.                            }
{                                                                         }
{ You may read GNU General Public License at:                             }
{   http://www.gnu.org/copyleft/gpl.html                                  }
{                                                                         }
{*************************************************************************}
unit EditBlendUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,dqe2_types,asphyredef, Buttons, Spin, ExtCtrls,
  alkatraz;

type
  TForm_EditBlend = class(TForm)
    GroupBox1: TGroupBox;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    RadioButton4: TRadioButton;
    RadioButton5: TRadioButton;
    RadioButton6: TRadioButton;
    RadioButton7: TRadioButton;
    RadioButton8: TRadioButton;
    RadioButton9: TRadioButton;
    RadioButton10: TRadioButton;
    RadioButton11: TRadioButton;
    GroupBox2: TGroupBox;
    RadioButton12: TRadioButton;
    RadioButton13: TRadioButton;
    RadioButton14: TRadioButton;
    RadioButton15: TRadioButton;
    RadioButton16: TRadioButton;
    RadioButton17: TRadioButton;
    RadioButton18: TRadioButton;
    RadioButton19: TRadioButton;
    RadioButton20: TRadioButton;
    RadioButton21: TRadioButton;
    RadioButton22: TRadioButton;
    GroupBox3: TGroupBox;
    RadioButton23: TRadioButton;
    RadioButton24: TRadioButton;
    RadioButton25: TRadioButton;
    RadioButton26: TRadioButton;
    RadioButton27: TRadioButton;
    GroupBox4: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    ColorBox1: TColorBox;
    SpinEdit1: TSpinEdit;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure RadioButton1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure UpdateObject;
    procedure Localize;
  private
    { Private declarations }
    ok:boolean;
    tmpFX:Cardinal;
    tmpColor:TColor;
    tmpAlpha:byte;
    tObj:DQE2_Graphical;
  public
    { Public declarations }
  end;

var
  Form_EditBlend: TForm_EditBlend;

implementation

uses GameUnit, ObjectUnit, MainUnit;

{$R *.dfm}

var lng:array of string;

procedure TForm_EditBlend.BitBtn1Click(Sender: TObject);
begin
  ok:=true;close;
end;

procedure TForm_EditBlend.BitBtn2Click(Sender: TObject);
begin
  close;
end;

procedure TForm_EditBlend.FormClose(Sender: TObject; var Action: TCloseAction);
var
  a:integer;
  obj:DQE2_Graphical;
begin
  if not ok then
  begin
    tObj.DrawFX:=tmpFX;
    tObj.Color:=tmpColor;
    tObj.Alpha:=tmpAlpha;
  end
  else
  begin
    for a:=0 to PickList.Count-1 do
    begin
      obj:=DQE2_Graphical(PickList[a]);
      obj.DrawFX:=tObj.DrawFX;
      obj.Color:=tObj.Color;
      obj.Alpha:=tObj.Alpha;
    end;
    Form_Objects.GenerateProperties;
  end;
end;

procedure TForm_EditBlend.FormCreate(Sender: TObject);
begin  
  SetLength(lng,8);
end;

procedure TForm_EditBlend.FormShow(Sender: TObject);
var
  x1,x2:TBlendCoef;
  x3:TBlendOp;
begin
  ok:=false;
  tObj:=DQE2_Graphical(PickList[0]);
  tmpFX:=tObj.DrawFX;
  tmpColor:=tObj.Color;
  tmpAlpha:=tObj.Alpha;
  Fx2Blend(tmpFX,x1,x2,x3);
  case x1 of
    bcZero:RadioButton1.Checked:=true;
    bcOne:RadioButton2.Checked:=true;
    bcSrcColor:RadioButton3.Checked:=true;
    bcInvSrcColor:RadioButton4.Checked:=true;
    bcSrcAlpha:RadioButton5.Checked:=true;
    bcInvSrcAlpha:RadioButton6.Checked:=true;
    bcDestAlpha:RadioButton7.Checked:=true;
    bcInvDestAlpha:RadioButton8.Checked:=true;
    bcDestColor:RadioButton9.Checked:=true;
    bcInvDestColor:RadioButton10.Checked:=true;
    bcSrcAlphaSat:RadioButton11.Checked:=true;
  end;
  case x2 of
    bcZero:RadioButton12.Checked:=true;
    bcOne:RadioButton13.Checked:=true;
    bcSrcColor:RadioButton14.Checked:=true;
    bcInvSrcColor:RadioButton15.Checked:=true;
    bcSrcAlpha:RadioButton16.Checked:=true;
    bcInvSrcAlpha:RadioButton17.Checked:=true;
    bcDestAlpha:RadioButton18.Checked:=true;
    bcInvDestAlpha:RadioButton19.Checked:=true;
    bcDestColor:RadioButton20.Checked:=true;
    bcInvDestColor:RadioButton21.Checked:=true;
    bcSrcAlphaSat:RadioButton22.Checked:=true;
  end;
  case x3 of
    boAdd:RadioButton23.Checked:=true;
    boSub:RadioButton24.Checked:=true;
    boRevSub:RadioButton25.Checked:=true;
    boMin:RadioButton26.Checked:=true;
    boMax:RadioButton27.Checked:=true;
  end;
  ColorBox1.Selected:=tmpColor;
  SpinEdit1.Value:=tmpAlpha;
end;

procedure TForm_EditBlend.Localize;
begin
  LoadStringsFromIni(MainUnit.lang_ini,Name,lng);
  Caption:=lng[0];
  GroupBox1.Caption:=lng[1];
  GroupBox2.Caption:=lng[2];
  GroupBox3.Caption:=lng[3];
  GroupBox4.Caption:=lng[4];
  Label1.Caption:=lng[5];
  Label2.Caption:=lng[6];
  BitBtn2.Caption:=lng[7];
end;

procedure TForm_EditBlend.RadioButton1Click(Sender: TObject);
begin
  UpdateObject;
end;

procedure TForm_EditBlend.UpdateObject;
var
  x1,x2:TBlendCoef;
  x3:TBlendOp;
begin
  if RadioButton1.Checked then x1:=bcZero else
  if RadioButton2.Checked then x1:=bcOne else
  if RadioButton3.Checked then x1:=bcSrcColor else
  if RadioButton4.Checked then x1:=bcInvSrcColor else
  if RadioButton5.Checked then x1:=bcSrcAlpha else
  if RadioButton6.Checked then x1:=bcInvSrcAlpha else
  if RadioButton7.Checked then x1:=bcDestAlpha else
  if RadioButton8.Checked then x1:=bcInvDestAlpha else
  if RadioButton9.Checked then x1:=bcDestColor else
  if RadioButton10.Checked then x1:=bcInvDestColor else
    x1:=bcSrcAlphaSat;
  if RadioButton12.Checked then x2:=bcZero else
  if RadioButton13.Checked then x2:=bcOne else
  if RadioButton14.Checked then x2:=bcSrcColor else
  if RadioButton15.Checked then x2:=bcInvSrcColor else
  if RadioButton16.Checked then x2:=bcSrcAlpha else
  if RadioButton17.Checked then x2:=bcInvSrcAlpha else
  if RadioButton18.Checked then x2:=bcDestAlpha else
  if RadioButton19.Checked then x2:=bcInvDestAlpha else
  if RadioButton20.Checked then x2:=bcDestColor else
  if RadioButton21.Checked then x2:=bcInvDestColor else
    x2:=bcSrcAlphaSat;
  if RadioButton23.Checked then x3:=boAdd else
  if RadioButton24.Checked then x3:=boSub else
  if RadioButton25.Checked then x3:=boRevSub else
  if RadioButton26.Checked then x3:=boMin else
    x3:=boMax;
  tObj.DrawFX:=Blend2Fx(x1,x2,x3);
  tObj.Color:=ColorBox1.Selected;
  try
    tObj.Alpha:=SpinEdit1.Value;
  except
    tObj.Alpha:=255;
  end;
end;

end.
