unit U_RasterImageSettings;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, siComp, ComCtrls, U_LNG, GDIPOBJ, Math;

type
  TF_RasterImageSettings = class(TForm)
    Button1: TButton;
    Button2: TButton;
    siLang1: TsiLang;
    TrackBar1: TTrackBar;
    CheckBox1: TCheckBox;
    MbLabel: TLabel;
    ImageSizeCapt: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    KBLabel: TLabel;
    procedure TrackBar1Change(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    PixelImageX, PixelImageY: Integer;
    aFName: String;

    CadPicWidth, CadPicHeight: integer;
    ScaleKoef: Double;
    FormImageScaleKoef: Double;
    CadIsBiggerThanImage: boolean;
    MaxAllowedTrackVal: Integer;
  end;

var
  F_RasterImageSettings: TF_RasterImageSettings;

implementation
uses U_BaseCommon, U_Common, U_Cad;
{$R *.dfm}

procedure TF_RasterImageSettings.Button1Click(Sender: TObject);
begin
  ModalResult := mrOK;
end;

procedure TF_RasterImageSettings.TrackBar1Change(Sender: TObject);
var isize: double;
    sPixelImageX, sPixelImageY: Double;
begin
  FormImageScaleKoef := TrackBar1.Position/100;

  if CadIsBiggerThanImage then
  begin
    sPixelImageX := CadPicWidth * (TrackBar1.Position/100);
    sPixelImageY := CadPicHeight * (TrackBar1.Position/100);
  end
  else
  begin
    sPixelImageX := PixelImageX * (TrackBar1.Position/100);
    sPixelImageY := PixelImageY * (TrackBar1.Position/100);
  end;
  isize := sPixelImageX*sPixelImageY;

  isize := isize * 3;
  //isize := isize * TrackBar1.Position;
  isize := isize / 1024;
  isize := isize / 10;

  if isize > 18000 then
    ImageSizeCapt.Font.Color := clRed
  else
  if isize > 5000 then
    ImageSizeCapt.Font.Color := clblue
  else
    if isize < 5000 then
    ImageSizeCapt.Font.Color := clGreen;

  if isize > 1024 then
  begin
    isize := isize/1024;
    MbLabel.Visible := True;
    KbLabel.Visible := False;
    ImageSizeCapt.Caption := FormatFloat('0.0', isize);
  end
  else
  begin
    MbLabel.Visible := False;
    KbLabel.Visible := True;
    ImageSizeCapt.Caption := IntToStr(Round(isize));
  end;

  Label2.Caption := inttostr(TrackBar1.Position) + ' %';
end;

procedure TF_RasterImageSettings.Button2Click(Sender: TObject);
begin
  close;
end;

procedure TF_RasterImageSettings.CheckBox1Click(Sender: TObject);
begin
  if Checkbox1.Checked then
    TrackBar1.ShowSelRange := True
  else
    TrackBar1.ShowSelRange := False;
end;

Procedure TF_RasterImageSettings.FormCreate(Sender: TObject);
begin
  //inherited;
  CheckBox1.Checked := true;
  ModalResult := mrCancel;
  CadIsBiggerThanImage := False;
end;

procedure TF_RasterImageSettings.FormShow(Sender: TObject);
var isize: double;
    sPixelImageX, sPixelImageY: Double;
begin
  ModalResult := mrCancel;
  {sPixelImageX := PixelImageX * (TrackBar1.Position/100);
  sPixelImageY := PixelImageY * (TrackBar1.Position/100);
  isize := sPixelImageX*sPixelImageY;
  isize := isize * 3;
  isize := isize / 10;
  //isize := isize * TrackBar1.Position;
  isize := isize / 1024;

  Label2.Caption := inttostr(TrackBar1.Position) + ' %';
  ImageSizeCapt.Caption := IntToStr(Round(isize));}
end;

end.
