{**************************
Dashboard Clock OnSetting script Ver1.0 by snowfox
**************************}
var
  ts1:TTabSheet;
  //Tab1
  lblbgType:TLabel;
  cbbbgType:TComboBox;

  lblbgColor:TLabel;
  shpbgColor:TShape;
  edtbgColor:TEdit;

  
//Init Skin form setting
procedure InitSetting;
var
	s:string;
	inifn:TIniFile;
	bColor,bTrans:Boolean;
begin
  inifn:=TIniFile.create(SkinFileName);
  with inifn do
  try
    //Tab1
    bColor:=ReadBool('Item0','Enable',true);
    bTrans:=ReadBool('Item1','Enable',true);
    if bColor and bTrans then cbbbgType.ItemIndex:=1
    else if bTrans then cbbbgType.ItemIndex:=0
    else cbbbgType.ItemIndex:=2;
    cbbbgTypeChange(cbbbgType);

    s:=ReadString('Item0','Colorize','#000000');
    shpbgColor.brush.color:=StrToColor(s);
		edtbgColor.text:=ColorToHtmlStr(shpbgColor.brush.color);
  finally
    inifn.free;
  end;
end;

//save Skin form setting
function SaveSetting:boolean;
var
	s:string;
	inifn:TIniFile;
	i:integer;
	bColor,bTrans:Boolean;
begin
  result:=true;
  inifn:=TIniFile.create(SkinFileName);
  with inifn do
  try
    //
    case cbbbgType.ItemIndex of
      0: begin bColor:=false; bTrans:=true;  end;
      1: begin bColor:=true;  bTrans:=true; end;
      2: begin bColor:=false; bTrans:=false; end;
    end;
    //Color
    WriteBool('Item0','Enable',bColor);
    WriteBool('Item1','Enable',bTrans);
    if bColor then
    begin
      s:=ColorToStr(shpbgColor.brush.color);
      WriteString('Item0','Colorize',s);
    end;
    InitSkin; 
  finally
    inifn.free;
  end;
end;

//---界面设置---
procedure CreateTab1;
begin
  ts1:=TTabSheet.Create(pgc);
  ts1.PageControl:=pgc;
  ts1.Caption:='界面设置';
  
  lblbgColor:=TLabel.create(self);
  with lblbgColor do
  begin
    parent:=ts1;
    left:=16; top:=16; width:=84;
    caption:='背景显示类型：';
  end;
  cbbbgType:=TComboBox.create(self);
  with cbbbgType do
  begin
    parent:=ts1;
    left:=16; top:=38; width:=137;
    DropDownCount:=15;
    Items.Add('透明');
    Items.Add('颜色');
    Items.Add('无');
    OnChange:=@cbbbgTypeChange;
    Style:=csDropDownList;
  end;
  //Color
	lblbgColor:=TLabel.create(self);
	with lblbgColor do
	begin
	  parent:=ts1;
	  left:=16; top:=74; width:=60;
	  caption:='背景颜色：';
	end;
	shpbgColor:=TShape.create(self);
	with shpbgColor do
	begin
	  parent:=ts1;
	  left:=80; top:=72; width:=33; height:=17;
	  cursor:=crHandPoint;
	  OnMouseDown:=@shpMouseDown;
	end;
	edtbgColor:=TEdit.create(self);
	with edtbgColor do
	begin
	  parent:=ts1;
	  left:=120; top:=71; width:=65;
	  OnKeyUp:=@edtbgColorKeyUp;
	  //Options:=[cdFullOpen,cdPreventFullOpen];
	  //OnChange:=@edtbgColorChange;
	end;
end;

procedure edtbgColorKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  //if Key=vk_Return then
	shpbgColor.brush.color:=StrToColor(edtbgColor.text);
end;

procedure edtbgColorChange(Sender: TObject);
begin
  shpbgColor.brush.color:=StrToColor(edtbgColor.text);
end;

procedure cbbbgTypeChange(Sender: TObject);
var
	isShow:boolean;
begin
  if (cbbbgType.ItemIndex=1) then isShow:=true
    else isShow:=false;
  lblbgColor.Enabled:=isShow;
  shpbgColor.Enabled:=isShow;
end;

procedure shpMouseDown(Sender: TObject; Button: TMouseButton; 
	Shift: TShiftState; X, Y: Integer);
var
  dlgColor:TColorDialog;
begin
  dlgColor:=TColorDialog.create(self);
  dlgColor.color:=TShape(Sender).Brush.color;
  if dlgColor.Execute then
  try
    TShape(Sender).Brush.color:=dlgColor.color;
    edtbgColor.text:=ColorToHtmlStr(dlgColor.color);
  finally
    dlgColor.free;  
  end;
end;

begin
  CreateTab1;
  InitSetting;
  
end.