unit uHueForm;

interface

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

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

var
  HueForm: THueForm;

implementation

uses    uMulpatcher;

{$R *.dfm}

procedure THueForm.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 THueForm.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+1 ] );
        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;
        MainForm.lbHue.ItemIndex := Index;
        MainForm.eHueName.Text := Hues.GetName( Index );
        MainForm.lbHueClick( Sender );        
end;

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

procedure THueForm.btnCancelClick(Sender: TObject);
begin
        Hide;
end;

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

procedure THueForm.eColorKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var     Index, i : integer;
begin
        if Key <> VK_RETURN then exit;
        Index := strtoint( eColor.Text ) -1;
        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;
        MainForm.eHueName.Text := Hues.GetName( Index );        
        MainForm.lbHue.ItemIndex := Index;
        MainForm.lbHueClick( Sender );
end;

procedure THueForm.Activate;
begin
        if not Hues.loaded then exit;
        HueForm.Show;
        ZeichneFarben;
end;


end.
