unit Unit6;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, SdfData, FileUtil, IpHtml, Ipfilebroker, LResources, Forms,
  Controls, Graphics, Dialogs, ComCtrls, ValEdit, Grids, MaskEdit, LCLType,
  LCLProc, StdCtrls, ExtCtrls, ColorBox, Spin, Buttons, Types, ShlepsUtils, Dispatcher_iface;

type

  { TSettingsForm }

  TSettingsForm = class(TForm)
    AxisColorButton: TColorButton;
    BufferCheckBox: TCheckBox;
    InterpreterCheckGroup: TCheckGroup;
    ClipCheckBox: TCheckBox;
    ClipMaxCheckBox: TCheckBox;
    ClipSizeSpinEdit: TSpinEdit;
    GroupBox1: TGroupBox;
    InterpreterCommentMemo: TMemo;
    ListBox1: TListBox;
    SceneBGColorButton: TColorButton;
    ONameFontColorButton: TColorButton;
    SelHandleZoneSpinEdit: TSpinEdit;
    SamePlaceZoneSpinEdit: TSpinEdit;
    PortHandleZoneSpinEdit: TSpinEdit;
    ZoomStepSpinEdit: TFloatSpinEdit;
    ZoomModeComboBox: TComboBox;
    MouseSelectionStyleComboBox: TComboBox;
    ConnNameDisplayStyleComboBox: TComboBox;
    CurrentModeEdit: TEdit;
    Moving_Label: TLabel;
    Drawing_Label: TLabel;
    JustDrawing_Label: TLabel;
    ClickNotDrag_Label: TLabel;
    AllowMove_Label: TLabel;
    Resizing_Label: TLabel;
    Renaming_Label: TLabel;
    SelColorButton: TColorButton;
    DisplayStatsCheckBox: TCheckBox;
    SelFontDialog: TFontDialog;
    MaxDepthSpinEdit: TSpinEdit;
    ONameBGColorButton: TColorButton;
    OnameFontDialog: TFontDialog;
    ONameFontSpeedButton: TSpeedButton;
    ShortCutEdit: TEdit;
    PageControl1: TPageControl;
    KeyTabSheet: TTabSheet;
    ShortcutStringGrid: TStringGrid;
    MouseTabSheet: TTabSheet;
    ShowNameCheckBox: TCheckBox;
    ShowPortNamesCheckBox: TCheckBox;
    ShowShellsCheckBox: TCheckBox;
    SelFontSpeedButton: TSpeedButton;
    DebugTabSheet: TTabSheet;
    CommandTabSheet: TTabSheet;
    VisualOptionsStringGrid: TStringGrid;
    MouseOptionsStringGrid: TStringGrid;
    VisualTabSheet: TTabSheet;
    ValueListEditor1: TValueListEditor;
    procedure AxisColorButtonColorChanged(Sender: TObject);
    procedure BufferCheckBoxChange(Sender: TObject);
    procedure InterpreterCheckGroupItemClick(Sender: TObject; Index: integer);
    procedure ClipCheckBoxChange(Sender: TObject);
    procedure DisplayStatsCheckBoxChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormShow(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
    procedure MaxDepthSpinEditChange(Sender: TObject);
    procedure MouseOptionsStringGridChangeBounds(Sender: TObject);
    procedure MouseOptionsStringGridHeaderSized(Sender: TObject;
      IsColumn: Boolean; Index: Integer);
    procedure MouseSelectionStyleComboBoxChange(Sender: TObject);
    procedure ONameBGColorButtonColorChanged(Sender: TObject);
    procedure ONameFontSpeedButtonClick(Sender: TObject);
    procedure PortHandleZoneSpinEditChange(Sender: TObject);
    procedure SamePlaceZoneSpinEditChange(Sender: TObject);
    procedure SceneBGColorButtonColorChanged(Sender: TObject);
    Procedure SelColorButtonColorChanged(Sender: TObject);
    Procedure SelFontSpeedButtonClick(Sender: TObject);
    procedure SelHandleZoneSpinEditChange(Sender: TObject);
    procedure ShortCutEditKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure ShortCutEditMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure ShortcutStringGridSelection(Sender: TObject; aCol, aRow: Integer);
    procedure ShowNameCheckBoxChange(Sender: TObject);
    procedure ShowPortNamesCheckBoxChange(Sender: TObject);
    procedure ShowShellsCheckBoxChange(Sender: TObject);
    procedure VisualOptionsStringGridHeaderSizing(sender: TObject;
      const IsColumn: boolean; const aIndex, aSize: Integer);
    procedure VisualOptionsStringGridResize(Sender: TObject);
    procedure VisualOptionsStringGridSelection(Sender: TObject; aCol,
      aRow: Integer);
    procedure ZoomModeComboBoxChange(Sender: TObject);
    procedure ZoomStepSpinEditChange(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  SettingsForm: TSettingsForm;

implementation
Uses Dispatcher, Config, Unit1,tpg;
{ TSettingsForm }

procedure TSettingsForm.ShortcutStringGridSelection(Sender: TObject; aCol,
  aRow: Integer);
begin
  ShortcutEdit.Parent:=ShortcutStringGrid;
  ShortcutEdit.BoundsRect:=ShortcutStringGrid.CellRect(ACol,ARow);
  ShortcutEdit.Text:=ShortcutStringGrid.Cells[ShortcutStringGrid.Col,ShortcutStringGrid.Row];
  ShortcutEdit.Show;
  ShortcutEdit.SetFocus;
end;

procedure TSettingsForm.ShowNameCheckBoxChange(Sender: TObject);
begin
  If ShowNameCheckBox.Checked Then ConfigFile.Values['ShowNames']:='yes'
    Else ConfigFile.Values['ShowNames']:='no';
  Unit1.Scene.ShowObjectNames:=ShowNameCheckBox.Checked;
  Unit1.RepaintView;
end;

procedure TSettingsForm.ShowPortNamesCheckBoxChange(Sender: TObject);
begin
  If ShowNameCheckBox.Checked Then ConfigFile.Values['ShowPortNames']:='yes'
    Else ConfigFile.Values['ShowPortNames']:='no';
  Unit1.Scene.ShowPortNames:=ShowPortNamesCheckBox.Checked;
  Unit1.RepaintView;
end;

procedure TSettingsForm.ShowShellsCheckBoxChange(Sender: TObject);
begin
  Unit1.Scene.ShowShells:=ShowShellsCheckBox.Checked;
  Unit1.RepaintView;
  If ShowShellsCheckBox.Checked Then ConfigFile.Values['ShowShells']:='yes'
  Else ConfigFile.Values['ShowShells']:='no';
end;

procedure TSettingsForm.VisualOptionsStringGridHeaderSizing(sender: TObject;
  const IsColumn: boolean; const aIndex, aSize: Integer);
begin
    SettingsForm.FormShow(Nil);
end;

procedure TSettingsForm.VisualOptionsStringGridSelection(Sender: TObject; aCol,
  aRow: Integer);
begin
  SettingsForm.FormShow(Nil);
end;

procedure TSettingsForm.ZoomModeComboBoxChange(Sender: TObject);
begin
  If ZoomModeComboBox.ItemIndex=0 Then
    Config.ConfigFile.Values['ZoomMode']:='CAD'
  Else
    Config.ConfigFile.Values['ZoomMode']:='Maps';
end;

procedure TSettingsForm.ZoomStepSpinEditChange(Sender: TObject);
begin
  Config.ConfigFile.Values['ZoomStep']:=FloatToStr(ZoomStepSpinEdit.Value);
end;

procedure TSettingsForm.VisualOptionsStringGridResize(Sender: TObject);
begin
  If DisplayStatsCheckBox.Parent=VisualOptionsStringGrid Then
  VisualOptionsStringGridSelection(Sender,1,1);
end;

Procedure TSettingsForm.SelFontSpeedButtonClick(Sender: TObject);
Begin
  If Not SelFontDialog.Execute Then Exit;
  Unit1.Form1.HintLabel.Font.Assign(SelFontDialog.Font);
  SelFontSpeedButton.Font:=SelFontDialog.Font;
  SelColorButton.ButtonColor:=SelFontDialog.Font.Color;
end;

procedure TSettingsForm.SelHandleZoneSpinEditChange(Sender: TObject);
begin
  Config.ConfigFile.Values['SelHandleZone']:=IntToStr(SelHandleZoneSpinEdit.Value);
  SelHandleZone:=StrToInt(Config.ConfigFile.Values['SelHandleZone']);
  Scene.SelHandleSize:=SelHandleZone;
end;

procedure TSettingsForm.ShortCutEditKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  ShortCutEdit.Text:=KeyAndShiftStateToKeyString(Key,Shift);
  Key:=0;
  ShortcutStringGrid.Cells[ShortcutStringGrid.Col,ShortcutStringGrid.Row]:=ShortCutEdit.Text;
  SettingsForm.ShortCutStringGrid.SaveToCSVFile(OSPath(ExtractFilePath(ParamStr(0))+'/pencilshortcuts.cfg'));
end;

procedure TSettingsForm.ShortCutEditMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  ShortCutEdit.Text:=KeyAndShiftStateToKeyString(0,Shift);
 // Key:=0;
  ShortcutStringGrid.Cells[ShortcutStringGrid.Col,ShortcutStringGrid.Row]:=ShortCutEdit.Text;
  SettingsForm.ShortCutStringGrid.SaveToCSVFile(OSPath(ExtractFilePath(ParamStr(0))+'/pencilshortcuts.cfg'));
end;


procedure TSettingsForm.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  If KeyAndShiftStateToKeyString(Key,Shift)=ShortcutEdit.Text Then beep;
end;

procedure TSettingsForm.FormCreate(Sender: TObject);
begin
   SettingsForm.ShortCutStringGrid.LoadFromCSVFile(OSPath(ExtractFilePath(ParamStr(0))+'/pencilshortcuts.cfg'));
   ONameFontDialog.Font.Size:=10;
   SettingsForm.FormShow(Nil);
end;


procedure TSettingsForm.ClipCheckBoxChange(Sender: TObject);
begin
  Unit1.Scene.Clip:=ClipCheckBox.Checked;
  If ClipCheckBox.Checked Then ConfigFile.Values['Clip']:='yes'
  else ConfigFile.Values['Clip']:='no';
  Unit1.Scene.ClipMax:=ClipMaxCheckBox.Checked;
  If ClipMaxCheckBox.Checked Then ConfigFile.Values['ClipMax']:='yes'
  else ConfigFile.Values['ClipMax']:='no';
  Unit1.Scene.ClipSize:=ClipSizeSpinEdit.Value;
  ConfigFile.Values['ClipSize']:=IntToStr(ClipSizeSpinEdit.Value);
  Unit1.Scene.UpdateVisibility;
  Unit1.RepaintView;
end;

procedure TSettingsForm.BufferCheckBoxChange(Sender: TObject);
begin
  Unit1.BufferDrawing:=BufferCheckBox.Checked;
end;

procedure TSettingsForm.InterpreterCheckGroupItemClick(Sender: TObject; Index: integer);
begin
  Case Index Of
  0: If InterpreterCheckGroup.Checked[0] Then DispatcherForm.Show Else DispatcherForm.Hide;
  1: If InterpreterCheckGroup.Checked[1] Then
          ConfigFile.Values['InterpreterCreatesSaveable']:='yes'
     Else ConfigFile.Values['InterpreterCreatesSaveable']:='no';
  End;
end;

procedure TSettingsForm.AxisColorButtonColorChanged(Sender: TObject);
begin
  Config.ConfigFile.Values['AxisColor']:=ColorToString(AxisColorButton.ButtonColor);
  Dispatcher.ExecCommand('self::CAD_UpdateCoordBase');
end;

procedure TSettingsForm.DisplayStatsCheckBoxChange(Sender: TObject);
begin
  Form1.RefreshSpeedLabel.Left:=Form1.Splitter2.Left+20;
  Form1.RefreshSpeedLabel.Visible:=DisplayStatsCheckBox.Checked;
  If DisplayStatsCheckBox.Checked Then ConfigFile.Values['DisplayStats']:='yes'
  Else ConfigFile.Values['DisplayStats']:='no';
end;



procedure TSettingsForm.FormShow(Sender: TObject);
begin
  ShortCutStringGrid.RowCount:=23;
  ShortCutStringGrid.Cells[0,0]:='Action';ShortCutStringGrid.Cells[1,0]:='Shortcut';
  ShortCutStringGrid.Cells[2,0]:='Alternate';ShortCutStringGrid.Cells[3,0]:='Alternate 2';
  ShortCutStringGrid.Cells[0,1]:='Redraw';
  ShortCutStringGrid.Cells[0,2]:='Zoom in';
  ShortCutStringGrid.Cells[0,3]:='Zoom out';
  ShortCutStringGrid.Cells[0,4]:='Pan left';
  ShortCutStringGrid.Cells[0,5]:='Pan right';
  ShortCutStringGrid.Cells[0,6]:='Pan up';
  ShortCutStringGrid.Cells[0,7]:='Pan down';
  ShortCutStringGrid.Cells[0,8]:='Pan screen left';
  ShortCutStringGrid.Cells[0,9]:='Pan screen right';
  ShortCutStringGrid.Cells[0,10]:='Pan screen up';
  ShortCutStringGrid.Cells[0,11]:='Pan screen down';
  ShortCutStringGrid.Cells[0,12]:='Navigation mode';
  ShortCutStringGrid.Cells[0,13]:='Selection/Edit mode';
  ShortCutStringGrid.Cells[0,14]:='Pen';
  ShortCutStringGrid.Cells[0,15]:='Object';
  ShortCutStringGrid.Cells[0,16]:='Link';
  ShortCutStringGrid.Cells[0,17]:='Callout';
  ShortCutStringGrid.Cells[0,18]:='Copy';
  ShortCutStringGrid.Cells[0,19]:='Paste';
  ShortCutStringGrid.Cells[0,20]:='Delete';
  ShortCutStringGrid.Cells[0,21]:='Update All';
  ShortCutStringGrid.Cells[0,22]:='Create related callout';
  ShortCutStringGrid.Cells[0,23]:='Anchor';
  ShortCutStringGrid.Cells[0,24]:='Back';
  ShortCutStringGrid.Cells[0,25]:='Forward';

  VisualOptionsStringGrid.RowCount:=18;
  VisualOptionsStringGrid.Cells[0,00]:='Option';VisualOptionsStringGrid.Cells[1,0]:='Value';
  VisualOptionsStringGrid.Cells[0,01]:='Scene backgroup color';
  VisualOptionsStringGrid.Cells[0,02]:='Axis/grid color';
  VisualOptionsStringGrid.Cells[0,03]:='Display drawing statistics';
  VisualOptionsStringGrid.Cells[0,04]:='Enable buffering';
  VisualOptionsStringGrid.Cells[0,05]:='Level of detail';
  VisualOptionsStringGrid.Cells[0,06]:='Clip invisible';
  VisualOptionsStringGrid.Cells[0,07]:='Clip size';
  VisualOptionsStringGrid.Cells[0,08]:='Clip max';
  VisualOptionsStringGrid.Cells[0,09]:='Show shells';
  VisualOptionsStringGrid.Cells[0,10]:='Show object names';
  VisualOptionsStringGrid.Cells[0,11]:='     object names font';
  VisualOptionsStringGrid.Cells[0,12]:='     object names font color';
  VisualOptionsStringGrid.Cells[0,13]:='     object name bgcolor (Black is transparent)';
  VisualOptionsStringGrid.Cells[0,14]:='Show port names';
  VisualOptionsStringGrid.Cells[0,15]:='Selection label font';
  VisualOptionsStringGrid.Cells[0,16]:='Selection label font color';
  VisualOptionsStringGrid.Cells[0,17]:='Display style of connection name';

  SceneBGColorButton.Parent:=VisualOptionsStringGrid;
  SceneBGColorButton.BoundsRect:=VisualOptionsStringGrid.CellRect(1,1);
  SceneBGColorButton.ButtonColor:=StringToColor(Config.ConfigFile.Values['SceneBGColor']);

  AxisColorButton.Parent:=VisualOptionsStringGrid;
  AxisColorButton.BoundsRect:=VisualOptionsStringGrid.CellRect(1,2);
  AxisColorButton.ButtonColor:=StringToColor(Config.ConfigFile.Values['AxisColor']);

  DisplayStatsCheckBox.Parent:=VisualOptionsStringGrid;
  DisplayStatsCheckBox.BoundsRect:=VisualOptionsStringGrid.CellRect(1,3);
  DisplayStatsCheckBox.Checked:=(LowerCase(ConfigFile.Values['DisplayStats'])='yes')Or
                        (LowerCase(ConfigFile.Values['DisplayStats'])='on') Or
                        (LowerCase(ConfigFile.Values['DisplayStats'])='y') Or
                        (LowerCase(ConfigFile.Values['DisplayStats'])='1');

  BufferCheckBox.Parent:=VisualOptionsStringGrid;
  BufferCheckBox.BoundsRect:=VisualOptionsStringGrid.CellRect(1,4);
  BufferCheckBox.Checked:=(LowerCase(ConfigFile.Values['BufferedDraw'])='yes')Or
                 (LowerCase(ConfigFile.Values['BufferedDraw'])='on') Or
                 (LowerCase(ConfigFile.Values['BufferedDraw'])='y') Or
                 (LowerCase(ConfigFile.Values['BufferedDraw'])='1');

  MaxDepthSpinEdit.Parent:=VisualOptionsStringGrid;
  MaxDepthSpinEdit.BoundsRect:=VisualOptionsStringGrid.CellRect(1,5);
  MaxDepthSpinEdit.Value:=StrToInt(ConfigFile.Values['LoD']);

  ClipCheckBox.Parent:=VisualOptionsStringGrid;
  ClipCheckBox.BoundsRect:=VisualOptionsStringGrid.CellRect(1,6);
  ClipCheckBox.Checked:=(LowerCase(ConfigFile.Values['Clip'])='yes')Or
                        (LowerCase(ConfigFile.Values['Clip'])='on') Or
                        (LowerCase(ConfigFile.Values['Clip'])='y') Or
                        (LowerCase(ConfigFile.Values['Clip'])='1');

  ClipSizeSpinEdit.Parent:=VisualOptionsStringGrid;
  ClipSizeSpinEdit.BoundsRect:=VisualOptionsStringGrid.CellRect(1,7);
  ClipSizeSpinEdit.Value:=StrToInt(ConfigFile.Values['ClipSize']);

  ClipMaxCheckBox.Parent:=VisualOptionsStringGrid;
  ClipMaxCheckBox.BoundsRect:=VisualOptionsStringGrid.CellRect(1,8);
  ClipMaxCheckBox.Checked:=(LowerCase(ConfigFile.Values['Clip'])='yes')Or
                          (LowerCase(ConfigFile.Values['Clip'])='on') Or
                          (LowerCase(ConfigFile.Values['Clip'])='y') Or
                          (LowerCase(ConfigFile.Values['Clip'])='1');

  ShowShellsCheckBox.Parent:=VisualOptionsStringGrid;
  ShowShellsCheckBox.BoundsRect:=VisualOptionsStringGrid.CellRect(1,9);
  ShowShellsCheckBox.Checked:=(LowerCase(ConfigFile.Values['ShowShells'])='yes')Or
                            (LowerCase(ConfigFile.Values['ShowShells'])='on') Or
                            (LowerCase(ConfigFile.Values['ShowShells'])='y') Or
                            (LowerCase(ConfigFile.Values['ShowShells'])='1');

  ShowNameCheckBox.Parent:=VisualOptionsStringGrid;
  ShowNameCheckBox.BoundsRect:=VisualOptionsStringGrid.CellRect(1,10);
  ShowNameCheckBox.Checked:=(LowerCase(ConfigFile.Values['ShowNames'])='yes')Or
                              (LowerCase(ConfigFile.Values['ShowNames'])='on') Or
                              (LowerCase(ConfigFile.Values['ShowNames'])='y') Or
                              (LowerCase(ConfigFile.Values['ShowNames'])='1');

  ONameFontSpeedButton.Parent:=VisualOptionsStringGrid;
  ONameFontSpeedButton.BoundsRect:=VisualOptionsStringGrid.CellRect(1,11);
  ONameFontSpeedButton.Font.Color:=StringToColor(Config.ConfigFile.Values['ObjectNameColor']);

  ONameFontColorButton.Parent:=VisualOptionsStringGrid;
  ONameFontColorButton.BoundsRect:=VisualOptionsStringGrid.CellRect(1,12);
  ONameFontSpeedButton.Font.Color:=StringToColor(Config.ConfigFile.Values['ObjectNameColor']);

  ONameBGColorButton.Parent:=VisualOptionsStringGrid;
  ONameBGColorButton.BoundsRect:=VisualOptionsStringGrid.CellRect(1,13);
  ONameBGColorButton.ButtonColor:=StringToColor(Config.ConfigFile.Values['ObjectNameBGColor']);

  ShowPortNamesCheckBox.Parent:=VisualOptionsStringGrid;
  ShowPortNamesCheckBox.BoundsRect:=VisualOptionsStringGrid.CellRect(1,14);
  ShowPortNamesCheckBox.Checked:=(LowerCase(ConfigFile.Values['ShowPortNames'])='yes')Or
                              (LowerCase(ConfigFile.Values['ShowPortNames'])='on') Or
                              (LowerCase(ConfigFile.Values['ShowPortNames'])='y') Or
                              (LowerCase(ConfigFile.Values['ShowPortNames'])='1');

  SelFontSpeedButton.Parent:=VisualOptionsStringGrid;
  SelFontSpeedButton.BoundsRect:=VisualOptionsStringGrid.CellRect(1,15);
  SelFontSpeedButton.Font.Color:=StringToColor(Config.ConfigFile.Values['SelectionColor']);

  SelColorButton.Parent:=VisualOptionsStringGrid;
  SelColorButton.BoundsRect:=VisualOptionsStringGrid.CellRect(1,16);
  //SelColorButton.ButtonColor:=Unit1.Form1.HintLabel.Font.Color;
  SelColorButton.ButtonColor:=StringToColor(Config.ConfigFile.Values['SelectionColor']);

  ConnNameDisplayStyleComboBox.Parent:=VisualOptionsStringGrid;
  ConnNameDisplayStyleComboBox.BoundsRect:=VisualOptionsStringGrid.CellRect(1,17);


  MouseOptionsStringGrid.RowCount:=7;
  MouseOptionsStringGrid.Cells[0,0]:='Option';MouseOptionsStringGrid.Cells[1,0]:='Value';
  MouseOptionsStringGrid.Cells[0,1]:='Zoom mode';
  MouseOptionsStringGrid.Cells[0,2]:='Zoom step';
  MouseOptionsStringGrid.Cells[0,3]:='Selection mode';
  MouseOptionsStringGrid.Cells[0,4]:='Same Place zone size, pix';
  MouseOptionsStringGrid.Cells[0,5]:='Selection Handle zone size, pix';
  MouseOptionsStringGrid.Cells[0,6]:='Port Handle zone size, pix';

  ZoomModeComboBox.Parent:=MouseOptionsStringGrid;
  ZoomModeComboBox.BoundsRect:=MouseOptionsStringGrid.CellRect(1,1);
  If (LowerCase(ConfigFile.Values['ZoomMode'])='cad') Then ZoomModeComboBox.ItemIndex:=0
  Else ZoomModeComboBox.ItemIndex:=1;

  ZoomStepSpinEdit.Parent:=MouseOptionsStringGrid;
  ZoomStepSpinEdit.BoundsRect:=MouseOptionsStringGrid.CellRect(1,2);
  ZoomStepSpinEdit.Value:=StrToFloat(ConfigFile.Values['ZoomStep']);

  MouseSelectionStyleComboBox.Parent:=MouseOptionsStringGrid;
  MouseSelectionStyleComboBox.BoundsRect:=MouseOptionsStringGrid.CellRect(1,3);
  If LowerCase(ConfigFile.Values['SelectionMode'])='pen' Then MouseSelectionStyleComboBox.ItemIndex:=0
  Else MouseSelectionStyleComboBox.ItemIndex:=1;

  SamePlaceZoneSpinEdit.Parent:=MouseOptionsStringGrid;
  SamePlaceZoneSpinEdit.BoundsRect:=MouseOptionsStringGrid.CellRect(1,4);
  SamePlaceZoneSpinEdit.Value:=StrToInt(Config.ConfigFile.Values['SamePlaceZone']);

  SelHandleZoneSpinEdit.Parent:=MouseOptionsStringGrid;
  SelHandleZoneSpinEdit.BoundsRect:=MouseOptionsStringGrid.CellRect(1,5);
  SelHandleZoneSpinEdit.Value:=StrToInt(Config.ConfigFile.Values['SelHandleZone']);

  PortHandleZoneSpinEdit.Parent:=MouseOptionsStringGrid;
  PortHandleZoneSpinEdit.BoundsRect:=MouseOptionsStringGrid.CellRect(1,6);
  PortHandleZoneSpinEdit.Value:=StrToInt(Config.ConfigFile.Values['PortHandleZone']);

  InterpreterCheckGroup.Checked[1]:=(LowerCase(ConfigFile.Values['InterpreterCreatesSaveable'])='yes')Or
                              (LowerCase(ConfigFile.Values['InterpreterCreatesSaveable'])='on') Or
                              (LowerCase(ConfigFile.Values['InterpreterCreatesSaveable'])='y') Or
                              (LowerCase(ConfigFile.Values['InterpreterCreatesSaveable'])='1');


end;

procedure TSettingsForm.ListBox1Click(Sender: TObject);
begin
  ListBox1.Items.Assign(GraphCache);
end;

procedure TSettingsForm.MaxDepthSpinEditChange(Sender: TObject);
begin
  ConfigFile.Values['LoD']:=IntToStr(MaxDepthSpinEdit.Value);
  Unit1.Scene.MaxDisplayedDepth:=MaxDepthSpinEdit.Value;
  Unit1.RepaintView;
end;

procedure TSettingsForm.MouseOptionsStringGridChangeBounds(Sender: TObject);
begin
  SettingsForm.FormShow(Nil);
end;

procedure TSettingsForm.MouseOptionsStringGridHeaderSized(Sender: TObject;
  IsColumn: Boolean; Index: Integer);
begin
  SettingsForm.FormShow(Nil);
end;

procedure TSettingsForm.MouseSelectionStyleComboBoxChange(Sender: TObject);
begin
  Case MouseSelectionStyleComboBox.ItemIndex Of
  0: Config.ConfigFile.Values['SelectionMode']:='Pen';
  1: Config.ConfigFile.Values['SelectionMode']:='Mouse';
  end;
end;

procedure TSettingsForm.ONameBGColorButtonColorChanged(Sender: TObject);
begin
  If ONameBGColorButton.ButtonColor=clBlack Then
    ONameFontSpeedButton.Color:=SceneBGColorButton.ButtonColor
  Else ONameFontSpeedButton.Color:=ONameBGColorButton.ButtonColor;
  Config.ConfigFile.Values['ObjectNameBGColor']:=ColorToString(ONameBGColorButton.ButtonColor);

end;


procedure TSettingsForm.ONameFontSpeedButtonClick(Sender: TObject);
begin
  If Not ONameFontDialog.Execute Then exit;
  ONameFontSpeedButton.Font:=ONameFontDialog.Font;
  ONameFontColorButton.ButtonColor:=ONameFontDialog.Font.Color;
  Unit1.RepaintView;
end;

procedure TSettingsForm.PortHandleZoneSpinEditChange(Sender: TObject);
begin
  Config.ConfigFile.Values['PortHandleZone']:=IntToStr(PortHandleZoneSpinEdit.Value);
  PortHandleZone:=StrToInt(Config.ConfigFile.Values['PortHandleZone']);
  Scene.PortSize:=PortHandleZone;
end;

procedure TSettingsForm.SamePlaceZoneSpinEditChange(Sender: TObject);
begin
  Config.ConfigFile.Values['SamePlaceZone']:=IntToStr(SamePlaceZoneSpinEdit.Value);
  SamePlaceZone:=StrToInt(Config.ConfigFile.Values['SamePlaceZone']);
end;

procedure TSettingsForm.SceneBGColorButtonColorChanged(Sender: TObject);
begin
  Config.ConfigFile.Values['SceneBGColor']:=ColorToString(SceneBGColorButton.ButtonColor);
  SelFontSpeedButton.Color:=SceneBGColorButton.ButtonColor;
  ONameFontSpeedButton.Color:=SceneBGColorButton.ButtonColor;
  Form1.RefreshSpeedLabel.Font.Color:=Not(StringToColor(Config.ConfigFile.Values['SceneBGColor']));
  Dispatcher.ExecCommand('self::CAD_UpdateCoordBase');
end;

Procedure TSettingsForm.SelColorButtonColorChanged(Sender: TObject);
Begin
  Unit1.Form1.HintLabel.Font.Color:=SelColorButton.ButtonColor;
  Config.ConfigFile.Values['SelectionColor']:=ColorToString(SelColorButton.ButtonColor);
  SelFontSpeedButton.Font.Color:=SelColorButton.ButtonColor;
  ONameFontSpeedButton.Font.Color:=ONameFontColorButton.ButtonColor;
  ONameFontDialog.Font.Color:=ONameFontColorButton.ButtonColor;
  Config.ConfigFile.Values['ObjectNameColor']:=ColorToString(ONameFontColorButton.ButtonColor);
end;

initialization
  {$I unit6.lrs}

end.

