1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
{*****************************************}
{ }
{ FastReport v2.3 }
{ Color selector }
{ }
{ Copyright (c) 1998-99 by Tzyganenko A. }
{ }
{*****************************************}
unit LR_Color;
interface
{$I LR_Vers.inc}
uses
SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, Buttons, ExtCtrls,
LR_Const;
type
TColorSelector = class(TPanel)
private
FColor: TColor;
FOtherBtn: TSpeedButton;
FOnColorSelected: TNotifyEvent;
procedure ButtonClick(Sender: TObject);
procedure SetColor(Value: TColor); reintroduce;
public
constructor Create(AOwner: TComponent); override;
property Color: TColor read FColor write SetColor;
property OnColorSelected: TNotifyEvent read FOnColorSelected write
FOnColorSelected;
end;
implementation
uses LR_Class;
var
frColors: Array[0..15] of TColor =
(clWhite, clBlack, clMaroon, clGreen, clOlive, clNavy, clPurple, clTeal,
clGray, clSilver, clRed, clLime, clYellow, clBlue, clFuchsia, clAqua);
constructor TColorSelector.Create(AOwner: TComponent);
var
b : TSpeedButton;
i,j: Integer;
bmp: TBitmap;
begin
inherited Create(AOwner);
Parent := AOwner as TWinControl;
Width := 96;
Height := 132;
bmp := TBitmap.Create;
bmp.Width := 16;
bmp.Height := 17;
with bmp.Canvas do
begin
Brush.Color := clBtnFace;
FillRect(Rect(0, 0, 16, 17));
end;
for i := 0 to 3 do
begin
for j := 0 to 3 do
begin
b := TSpeedButton.Create(Self);
b.Parent := Self;
b.SetBounds(j * 22 + 4, i * 22 + 4, 22, 22);
with bmp.Canvas do
begin
Brush.Color := frColors[i * 4 + j];
Pen.Color := clBtnShadow;
Rectangle(0, 0, 16, 16);
end;
b.Glyph.Assign(bmp);
b.Tag := i * 4 + j;
b.OnClick := @ButtonClick;
b.GroupIndex := 1;
b.Flat := True;
end;
end;
b := TSpeedButton.Create(Self);
with b do
begin
Parent := Self;
SetBounds(4, 92, 88, 18);
Tag := 16;
Caption := sTransparent;
OnClick := @ButtonClick;
GroupIndex := 1;
Flat := True;
end;
FOtherBtn := TSpeedButton.Create(Self);
with FOtherBtn do
begin
Parent := Self;
SetBounds(4, 110, 88, 18);
Tag := 17;
Caption := sOther;
OnClick := @ButtonClick;
GroupIndex := 1;
Flat := True;
end;
bmp.Free;
end;
procedure TColorSelector.ButtonClick(Sender: TObject);
var
cd: TColorDialog;
i: Integer;
begin
try
i := (Sender as TSpeedButton).Tag;
case i of
0..15: FColor := frColors[i];
16 : FColor := clNone;
17 : begin
cd := TColorDialog.Create(Self);
//** cd.Options := [cdFullOpen];
if cd.Execute then
FColor := cd.Color
else
Exit;
end;
end;
finally
if Assigned(fOnColorSelected) then
FOnColorSelected(Self);
Hide;
end;
end;
procedure TColorSelector.SetColor(Value: TColor);
var
i,j: Integer;
c : TSpeedButton;
bmp: TBitmap;
begin
for i := 0 to 16 do
begin
if ((i=16) and (Value=clNone)) or (frColors[i]=Value) then
begin
for j := 0 to ControlCount-1 do
begin
c:=Controls[j] as TSpeedButton;
if c.Tag=i then
begin
c.Down:=True;
FOtherBtn.Glyph.FreeImage;
break;
end;
end;
Exit;
end;
end;
bmp := TBitmap.Create;
try
bmp.Width := 12;
bmp.Height := 13;
with bmp.Canvas do
begin
Brush.Color := clBtnFace;
FillRect(Rect(0, 0, 12, 13));
Brush.Color := Value;
Pen.Color := clBtnShadow;
Rectangle(0, 0, 12, 12);
end;
FOtherBtn.Glyph.Assign(bmp);
finally
bmp.Free;
end;
end;
end.
|