unit uHFSE;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, GR32_Image, GR32, GR32_Layers, uUtilities, uHues,
  ExtCtrls;

type
  THFSE = class(TForm)
    lFarbindex: TLabel;
    lFarbname: TLabel;
    tbFarbe: TTrackBar;
    Farbtabelle: TImage32;
    Farbe: TImage32;
    lNameWert: TLabel;
    btnOK: TButton;
    eColor: TEdit;
    procedure tbFarbeChange(Sender: TObject);
    procedure FarbtabelleMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer; Layer: TCustomLayer);
    procedure btnOKClick(Sender: TObject);
    procedure eColorKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
    procedure ZeichneFarben;
  public
    { Public declarations }
    ChosenColor : Word;
  end;

var
  HFSE: THFSE;

implementation

uses    uStaticToolForm;

{$R *.dfm}

procedure THFSE.ZeichneFarben;
var     hoehe, breite, index : integer;
begin
        Farbtabelle.Bitmap.Height := 320;
        Farbtabelle.Bitmap.Width := 423;
        for breite := 0 to 46 do begin
                for hoehe := 0 to 63 do begin
                        index := breite * 64 + hoehe;
                        //showmessage( inttostr( index ) + ':' + inttostr( Hue.ColorTable[ tbFarbe.Position ] ) + ':' + inttostr( Color15to32( Hue.ColorTable[ tbFarbe.Position ] ) ) );
                        if index < 3000 then begin
                                Farbtabelle.Bitmap.FillRect( breite*9, hoehe*5, breite*9+8, hoehe*5+4, Color15to32( Hues.GetColor( Index, tbFarbe.Position ) ) );
                        end;
                end;
        end;
end;

procedure THFSE.FarbtabelleMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer; Layer: TCustomLayer);
var     hoehe, breite, index : integer;
        i : integer;
begin
        breite := X div 9;
        hoehe := Y div 5;
        index := breite * 64 + hoehe;
        lNameWert.Caption := Hues.GetName( Index );
        eColor.Text := '0x' + Format( '%x', [ index ] );
        Farbe.Bitmap.Height := 17;
        Farbe.Bitmap.Width := 416;
        ChosenColor := Index;
        for i := 0 to 31 do begin
                Farbe.Bitmap.FillRect( i*13, 0, i*13+12, 16, Color15to32( Hues.GetColor( Index, i ) ) );
        end;
        StaticToolForm.iColor.Tag := Index+1;
        StaticToolForm.iColor.Bitmap.SetSize( 44, 20 );
        if Index > -1 then
                StaticToolForm.iColor.Bitmap.Clear( Color15to32( Hues.GetColor( Index, 28 ) ) )
        else
                StaticToolForm.iColor.Bitmap.Clear( Color32( StaticToolForm.iColor.Color ) );
        StaticToolForm.ColorHistoryAdd( Index );
end;

procedure THFSE.tbFarbeChange(Sender: TObject);
begin
        ZeichneFarben;
end;

procedure THFSE.btnOKClick(Sender: TObject);
begin
        Hide;
end;

procedure THFSE.eColorKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var     Index, i : integer;
begin
        if Key <> VK_RETURN then exit;
        Index := strtoint( eColor.Text );
        lNameWert.Caption := Hues.GetName( Index );
        Farbe.Bitmap.Height := 17;
        Farbe.Bitmap.Width := 416;
        ChosenColor := Index;
        for i := 0 to 31 do begin
                Farbe.Bitmap.FillRect( i*13, 0, i*13+12, 16, Color15to32( Hues.GetColor( Index, i ) ) );
        end;
        StaticToolForm.iColor.Tag := Index+1;
        StaticToolForm.iColor.Bitmap.SetSize( 44, 20 );
        if Index > -1 then
                StaticToolForm.iColor.Bitmap.Clear( Color15to32( Hues.GetColor( Index, 28 ) ) )
        else
                StaticToolForm.iColor.Bitmap.Clear( Color32( StaticToolForm.iColor.Color ) );
        StaticToolForm.ColorHistoryAdd( Index );        
end;

procedure THFSE.FormShow(Sender: TObject);
begin
        ZeichneFarben;
end;

end.
