SPEKT

Top  Previous  Next

unit Spekt;

 

interface

 

uses

SysUtils, WinTypes, WinProcs, Messages, Classes,

Graphics, Controls, Forms, Dialogs;

 

type

TSpectrum = class(TCustomControl)

private

  FActualColor: TColor;

  FOnChange     : TNotifyEvent;

protected

  procedure Paint; override;

  procedure MouseDown(Button: TMouseButton; Shift: TShiftState;

    X, Y: Integer); override;

  procedure Change; dynamic;

public

  constructor Create(AOwner:TComponent);override;

  destructor Destroy;override;

published

  property ActualColor: TColor read FActualColor write FActualColor;

  property OnChange: TNotifyEvent read FOnChange write FOnChange;

  property Width default 450;

  property Height default 20;

  Property OnDblClick;

  property OnClick;

  property OnDragDrop;

  property OnDragOver;

  property OnEndDrag;

  property OnEnter;

  property OnExit;

  property OnKeyDown;

  property OnKeyPress;

  property OnKeyUp;

  Property OnMouseDown;

  Property OnMouseMove;

  Property OnMouseUp;

end;

 

procedure Register;

 

 

implementation

 

procedure Register;

begin

   RegisterComponents('AL',[TSpectrum]);

end;

 

constructor TSpectrum.Create(AOwner:TComponent);

begin

   inherited Create(AOwner);

   FActualColor:=clBlack;

   Width := 450;

   height := 20;

end;

 

destructor TSpectrum.Destroy;

begin

   inherited Destroy;

end;

 

procedure TSpectrum.Paint;

var i: byte;

begin

wITH Canvas do begin

For i:=0 to $ff do begin

  Pen.Color := RGB(255,I,0);

  MoveTo(i div 2,0); LineTo(I div 2,Height);

  Pen.Color := RGB(255-I,255,0);

  MoveTo((i+256) div 2,0); LineTo((I+256) div 2,Height);

  Pen.Color := RGB(0,255,I);

  MoveTo((i+512) div 2,0); LineTo((I+512) div 2,Height);

  Pen.Color := RGB(0,255-I,255);

  MoveTo((i+768) div 2,0); LineTo((I+768) div 2,Height);

  Pen.Color := RGB(I,0,255);

  MoveTo((i+768+256) div 2,0); LineTo((I+768+256) div 2,Height);

end;

end;

inherited Paint;

end;

 

procedure TSpectrum.MouseDown(Button: TMouseButton; Shift: TShiftState;

    X, Y: Integer);

begin

ActualColor:=Canvas.Pixels[x,y];

Change;

inherited MouseDown(Button, Shift, X, Y);

end;

 

procedure TSpectrum.Change;

begin

if Assigned(FOnChange) then FOnChange(Self);

end;

 

end.