unit UxThemeForm;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, HSColorMap, ValueSelector, UxPanel,
  SVColorMap, HueSelector, UxForm, Vcl.ComCtrls, UITypes, Rux;

type
  TUxThemeFrm = class(TForm)
    HueSelector: THueSelector;
    SVColorMap: TSVColorMap;
    StatusBar: TStatusBar;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure HueSelectorChange(Sender: TObject);
    procedure SVColorMapChange(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    FNoUpdate: Boolean;
    procedure UpdateSB;
  public
    function CurColor: TColor;
  end;

var
  UxThemeFrm: TUxThemeFrm;

implementation

uses
  ASColors, RColors, MainForm, FormFader, WinMgrForm;

{$R *.dfm}

function TUxThemeFrm.CurColor: TColor;
begin
  Result := GetPascalColor(HSV(HueSelector.Hue, SVColorMap.Saturation, SVColorMap.Value));
end;

procedure TUxThemeFrm.FormActivate(Sender: TObject);
var
  hsv: THSV;
begin
  FNoUpdate := True;
  try
    hsv := RGBToHSV(PascalColorToRGB(TUx.ThemeData.ActiveCaptionColor));
    HueSelector.Hue := hsv.hsvHue;
    SVColorMap.Color := hsv;
    UpdateSB;
  finally
    FNoUpdate := False;
  end;
end;

procedure TUxThemeFrm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TUxThemeFrm.FormCreate(Sender: TObject);
begin
  TFormFader.Create(Self);
  TWindowWatcher.Create(Self);
end;

procedure TUxThemeFrm.HueSelectorChange(Sender: TObject);
begin
  if FNoUpdate then
    Exit;
  TUx.ThemeUpdate(TUxTheme.Create(CurColor));
  SVColorMap.Hue := HueSelector.Hue;
  AlgosimMainForm.DelaySaveSettings([csUxColor]);
  UpdateSB;
end;

procedure TUxThemeFrm.SVColorMapChange(Sender: TObject);
begin
  if FNoUpdate then
    Exit;
  TUx.ThemeUpdate(TUxTheme.Create(CurColor));
  AlgosimMainForm.DelaySaveSettings([csUxColor]);
  UpdateSB;
end;

procedure TUxThemeFrm.UpdateSB;
begin
  StatusBar.SimplePanel := True;
  StatusBar.SimpleText := Format('Hue: %d°  Sat: %.2f  Val: %.2f  Hex: %s',
    [Round(HueSelector.Hue), SVColorMap.Saturation, SVColorMap.Value,
     ASColors.ColorToHex(GetPascalColor(SVColorMap.Color))]);
end;

end.
