{

  Copyright (c) 1997-2003 by CoolDev.Com. Part of CoolControls package.

}

{$I versions.inc}
unit ColorListUnit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  CoolLists, ExtCtrls, StdCtrls, Buttons, CoolCtrls, CoolPolygons;

type
  TColorListForm = class(TForm)
    ColorBox: TCoolListBox;
    BtnOk: TBitBtn;
    BtnCancel: TBitBtn;
    BtnDelete: TBitBtn;
    ScrollBox: TScrollBox;
    Image: TImage;
    Label1: TLabel;
    Label2: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure BtnOkClick(Sender: TObject);
    procedure ImageMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BtnDeleteClick(Sender: TObject);
  private
    FColorList: TColorList;
    procedure SetColorList(Value: TColorList);
  public
    property ColorList: TColorList read FColorList write SetColorList;
  end;

var
  ColorListForm: TColorListForm;

implementation

{$R *.DFM}

procedure TColorListForm.SetColorList(Value: TColorList);
begin
  FColorList.Assign(Value);
end;

procedure TColorListForm.FormCreate(Sender: TObject);
begin
  FColorList := TColorList.Create;
end;

procedure TColorListForm.FormActivate(Sender: TObject);
var
  I: Integer;
begin
  ScrollBox.Height := ColorBox.Height;
  Image.Height := ScrollBox.Height - 2;

  ColorBox.Items.BeginUpdate;

  ColorBox.Items.Clear;
  for I := 0 to Pred(FColorList.Count) do
    ColorBox.Items.Add(ColorToString(FColorList[I]));

  ColorBox.Items.EndUpdate;
end;

procedure TColorListForm.FormDestroy(Sender: TObject);
begin
  FColorList.Free;
end;

procedure TColorListForm.BtnOkClick(Sender: TObject);
var
  I: Integer;
begin
  FColorList.Clear;
  for I := 0 to Pred(ColorBox.Items.Count) do
    FColorList.Add(StringToColor(ColorBox.Items[I]));
end;

procedure TColorListForm.ImageMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  ColorBox.Items.Add(ColorToString(Image.Picture.Bitmap.Canvas.Pixels[X, Y]));
end;

procedure TColorListForm.BtnDeleteClick(Sender: TObject);
var
  I: Integer;
begin
  ColorBox.Items.BeginUpdate;
  for I := Pred(ColorBox.Items.Count) downto 0 do
    if ColorBox.Selected[I] then
      ColorBox.Items.Delete(I);
  ColorBox.Items.EndUpdate;
end;

end.
