{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
osCommerce Product Manager for Windows (oscpmwin).
Copyright ©2003-2006 by Mario A. Valdez-Ramirez.

You can contact Mario A. Valdez-Ramirez
by email at mario@mariovaldez.org or paper mail at
Olmos 809, San Nicolas, NL. 66495, Mexico.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
unit colorsel;

interface

uses
  SysUtils, Classes, Graphics, Controls, Forms,
  StdCtrls, Buttons, ExtCtrls, Spin;

type
  Topm_Form_ColorSel = class(TForm)
    opm_BitBtn_ColorSelOk: TBitBtn;
    opm_BitBtn_ColorSelCancel: TBitBtn;
    opm_Image_ColorSelTable: TImage;
    opm_Panel_ColorSelSample: TPanel;
    opm_Edit_ColorSelInput: TEdit;
    procedure opm_Image_ColorSelTableMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure opm_Image_ColorSelTableMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure opm_Image_ColorSelTableMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure opm_BitBtn_ColorSelOkClick(Sender: TObject);
    procedure opm_Edit_ColorSelInputExit(Sender: TObject);
  private
    opmG_ChoosingColor : BOOLEAN;
  public
    opmG_ColorChoosed : TColor;
    opmG_ColorChoosedDec : LONGINT;
    opmG_ColorChoosedRGB : STRING;
  end;

var
  opm_Form_ColorSel: Topm_Form_ColorSel;


implementation

Uses gnugettext, dataman;


{$R *.dfm}


{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
procedure Topm_Form_ColorSel.opm_Image_ColorSelTableMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  opmG_ColorChoosed := opm_Image_ColorSelTable.Canvas.Pixels[X,Y];
  opmG_ColorChoosedRGB := FNopm_ColorToRGB (opmG_ColorChoosed);
  opmG_ColorChoosedDec := FNopm_ColorToDecColor (opmG_ColorChoosed);
  opmG_ColorChoosed := FNopm_DecColorToColor (opmG_ColorChoosedDec);
  opm_Panel_ColorSelSample.Color := opmG_ColorChoosed;
  opm_Panel_ColorSelSample.Caption := opmG_ColorChoosedRGB;
  opm_Panel_ColorSelSample.Font.Color := FNopm_ComplementaryColor (opmG_ColorChoosed);
  opm_Edit_ColorSelInput.Text := opmG_ColorChoosedRGB;
  opmG_ChoosingColor := TRUE;
end;


{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
procedure Topm_Form_ColorSel.opm_Image_ColorSelTableMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  IF (opmG_ChoosingColor = TRUE) THEN
    BEGIN
      opmG_ColorChoosed := opm_Image_ColorSelTable.Canvas.Pixels[X,Y];
      opmG_ColorChoosedRGB := FNopm_ColorToRGB (opmG_ColorChoosed);
      opmG_ColorChoosedDec := FNopm_ColorToDecColor (opmG_ColorChoosed);
      opmG_ColorChoosed := FNopm_DecColorToColor (opmG_ColorChoosedDec);
      opm_Panel_ColorSelSample.Color := opmG_ColorChoosed;
      opm_Panel_ColorSelSample.Caption := opmG_ColorChoosedRGB;
      opm_Panel_ColorSelSample.Font.Color := FNopm_ComplementaryColor (opmG_ColorChoosed);
      opm_Edit_ColorSelInput.Text := opmG_ColorChoosedRGB;
    END;
end;


{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
procedure Topm_Form_ColorSel.opm_Image_ColorSelTableMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  opmG_ChoosingColor := FALSE;
END;


{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
procedure Topm_Form_ColorSel.FormShow(Sender: TObject);
begin
  opm_Form_ColorSel.Caption := _('Choose a color...');
  opmG_ChoosingColor := FALSE;
  opm_Panel_ColorSelSample.Color := opmG_ColorChoosed;
  opmG_ColorChoosedRGB := FNopm_ColorToRGB (opmG_ColorChoosed);
  opm_Panel_ColorSelSample.Caption := opmG_ColorChoosedRGB;
  opm_Panel_ColorSelSample.Font.Color := FNopm_ComplementaryColor (opmG_ColorChoosed);
  opmG_ColorChoosedDec := FNopm_ColorToDecColor (opmG_ColorChoosed);
  opm_Edit_ColorSelInput.Text := opmG_ColorChoosedRGB;
end;


{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
procedure Topm_Form_ColorSel.FormCreate(Sender: TObject);
begin
  TranslateComponent (self);
  opm_Panel_ColorSelSample.DoubleBuffered := TRUE;
  opmG_ColorChoosed := clWhite;
  opmG_ColorChoosedRGB := 'FFFFFF';
end;



{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
procedure Topm_Form_ColorSel.opm_BitBtn_ColorSelOkClick(Sender: TObject);
begin
  opm_Edit_ColorSelInput.Text := FNopm_CleanHexNumber (opm_Edit_ColorSelInput.Text, 6);
  opmG_ColorChoosed := STRTOINT ('$00' + COPY (opm_Edit_ColorSelInput.Text, 5, 2) + COPY (opm_Edit_ColorSelInput.Text, 3, 2) + COPY (opm_Edit_ColorSelInput.Text, 1, 2));
  opmG_ColorChoosedRGB := FNopm_ColorToRGB (opmG_ColorChoosed);
  opmG_ColorChoosedDec := FNopm_ColorToDecColor (opmG_ColorChoosed);
  opmG_ColorChoosed := FNopm_DecColorToColor (opmG_ColorChoosedDec);
end;


{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
procedure Topm_Form_ColorSel.opm_Edit_ColorSelInputExit(Sender: TObject);
begin
  opm_Edit_ColorSelInput.Text := FNopm_CleanHexNumber (opm_Edit_ColorSelInput.Text, 6);
  opmG_ColorChoosed := STRTOINT ('$00' + COPY (opm_Edit_ColorSelInput.Text, 5, 2) + COPY (opm_Edit_ColorSelInput.Text, 3, 2) + COPY (opm_Edit_ColorSelInput.Text, 1, 2));
  opmG_ColorChoosedRGB := FNopm_ColorToRGB (opmG_ColorChoosed);
  opmG_ColorChoosedDec := FNopm_ColorToDecColor (opmG_ColorChoosed);
  opmG_ColorChoosed := FNopm_DecColorToColor (opmG_ColorChoosedDec);
  opm_Panel_ColorSelSample.Color := opmG_ColorChoosed;
  opm_Panel_ColorSelSample.Caption := opmG_ColorChoosedRGB;
  opm_Panel_ColorSelSample.Font.Color := FNopm_ComplementaryColor (opmG_ColorChoosed);
end;

end.
