You've already forked lazarus-ccr
mbColorLib: Refactor OnChange events. (NOTE: OfficeColorDialog may hang when switching pickers).
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5578 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -22,7 +22,7 @@ type
|
||||
function ArrowPosFromYellow(y: integer): integer;
|
||||
function YellowFromArrowPos(p: integer): integer;
|
||||
function GetSelectedColor: TColor;
|
||||
procedure SetSelectedColor(c: TColor);
|
||||
procedure SetSelectedColor(clr: TColor);
|
||||
procedure SetYellow(y: integer);
|
||||
procedure SetMagenta(m: integer);
|
||||
procedure SetCyan(c: integer);
|
||||
@@ -55,74 +55,12 @@ begin
|
||||
inherited;
|
||||
FGradientWidth := 255;
|
||||
FGradientHeight := 1;
|
||||
FYellow := 255;
|
||||
FMagenta := 0;
|
||||
FCyan := 0;
|
||||
FBlack := 0;
|
||||
FArrowPos := ArrowPosFromYellow(255);
|
||||
FChange := false;
|
||||
Layout := lyVertical;
|
||||
SetYellow(255);
|
||||
Layout := lyVertical;
|
||||
HintFormat := 'Yellow: %value (selected)';
|
||||
FManual := false;
|
||||
FChange := true;
|
||||
end;
|
||||
|
||||
function TYColorPicker.GetGradientColor(AValue: Integer): TColor;
|
||||
begin
|
||||
Result := CMYKtoColor(FCyan, FMagenta, AValue, FBlack);
|
||||
end;
|
||||
|
||||
procedure TYColorPicker.SetYellow(y: integer);
|
||||
begin
|
||||
Clamp(y, 0, 255);
|
||||
if FYellow <> y then
|
||||
begin
|
||||
FYellow := y;
|
||||
FArrowPos := ArrowPosFromYellow(y);
|
||||
FManual := false;
|
||||
Invalidate;
|
||||
if FChange and Assigned(OnChange) then OnChange(Self);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TYColorPicker.SetMagenta(m: integer);
|
||||
begin
|
||||
Clamp(m, 0, 255);
|
||||
if FMagenta <> m then
|
||||
begin
|
||||
FMagenta := m;
|
||||
FManual := false;
|
||||
CreateGradient;
|
||||
Invalidate;
|
||||
if FChange and Assigned(OnChange) then OnChange(Self);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TYColorPicker.SetCyan(c: integer);
|
||||
begin
|
||||
Clamp(c, 0, 255);
|
||||
if FCyan <> c then
|
||||
begin
|
||||
FCyan := c;
|
||||
FManual := false;
|
||||
CreateGradient;
|
||||
Invalidate;
|
||||
if FChange and Assigned(OnChange) then OnChange(Self);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TYColorPicker.SetBlack(k: integer);
|
||||
begin
|
||||
Clamp(k, 0, 255);
|
||||
if FBlack <> k then
|
||||
begin
|
||||
FBlack := k;
|
||||
FManual := false;
|
||||
CreateGradient;
|
||||
Invalidate;
|
||||
if FChange and Assigned(OnChange) then OnChange(Self);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TYColorPicker.ArrowPosFromYellow(y: integer): integer;
|
||||
@@ -144,62 +82,17 @@ begin
|
||||
Result := a;
|
||||
end;
|
||||
|
||||
function TYColorPicker.YellowFromArrowPos(p: integer): integer;
|
||||
var
|
||||
r: integer;
|
||||
begin
|
||||
if Layout = lyHorizontal then
|
||||
r := Round(p/((Width - 12)/255))
|
||||
else
|
||||
r := Round(255 - p/((Height - 12)/255));
|
||||
Clamp(r, 0, 255);
|
||||
Result := r;
|
||||
end;
|
||||
|
||||
function TYColorPicker.GetSelectedColor: TColor;
|
||||
begin
|
||||
Result := CMYKtoColor(FCyan, FMagenta, FYellow, FBlack);
|
||||
if WebSafe then
|
||||
Result := GetWebSafe(Result);
|
||||
end;
|
||||
|
||||
function TYColorPicker.GetSelectedValue: integer;
|
||||
begin
|
||||
Result := FYellow;
|
||||
end;
|
||||
|
||||
procedure TYColorPicker.SetSelectedColor(c: TColor);
|
||||
var
|
||||
cy, m, y, k: integer;
|
||||
begin
|
||||
if WebSafe then c := GetWebSafe(c);
|
||||
ColorToCMYK(c, cy, m, y, k);
|
||||
FChange := false;
|
||||
SetMagenta(m);
|
||||
SetCyan(cy);
|
||||
SetBlack(k);
|
||||
SetYellow(y);
|
||||
FManual := false;
|
||||
FChange := true;
|
||||
if Assigned(OnChange) then OnChange(Self);
|
||||
end;
|
||||
|
||||
function TYColorPicker.GetArrowPos: integer;
|
||||
begin
|
||||
Result := ArrowPosFromYellow(FYellow);
|
||||
end;
|
||||
|
||||
procedure TYColorPicker.Execute(tbaAction: integer);
|
||||
begin
|
||||
case tbaAction of
|
||||
TBA_Resize:
|
||||
SetYellow(FYellow);
|
||||
TBA_MouseMove:
|
||||
FYellow := YellowFromArrowPos(FArrowPos);
|
||||
SetYellow(YellowFromArrowPos(FArrowPos));
|
||||
TBA_MouseDown:
|
||||
FYellow := YellowFromArrowPos(FArrowPos);
|
||||
SetYellow(YellowFromArrowPos(FArrowPos));
|
||||
TBA_MouseUp:
|
||||
FYellow := YellowFromArrowPos(FArrowPos);
|
||||
SetYellow(YellowFromArrowPos(FArrowPos));
|
||||
TBA_WheelUp:
|
||||
SetYellow(FYellow + Increment);
|
||||
TBA_WheelDown:
|
||||
@@ -225,4 +118,108 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TYColorPicker.GetArrowPos: integer;
|
||||
begin
|
||||
Result := ArrowPosFromYellow(FYellow);
|
||||
end;
|
||||
|
||||
function TYColorPicker.GetGradientColor(AValue: Integer): TColor;
|
||||
begin
|
||||
Result := CMYKtoColor(FCyan, FMagenta, AValue, FBlack);
|
||||
end;
|
||||
|
||||
function TYColorPicker.GetSelectedColor: TColor;
|
||||
begin
|
||||
Result := CMYKtoColor(FCyan, FMagenta, FYellow, FBlack);
|
||||
if WebSafe then
|
||||
Result := GetWebSafe(Result);
|
||||
end;
|
||||
|
||||
function TYColorPicker.GetSelectedValue: integer;
|
||||
begin
|
||||
Result := FYellow;
|
||||
end;
|
||||
|
||||
procedure TYColorPicker.SetBlack(k: integer);
|
||||
begin
|
||||
Clamp(k, 0, 255);
|
||||
if FBlack <> k then
|
||||
begin
|
||||
FBlack := k;
|
||||
CreateGradient;
|
||||
Invalidate;
|
||||
DoChange;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TYColorPicker.SetCyan(c: integer);
|
||||
begin
|
||||
Clamp(c, 0, 255);
|
||||
if FCyan <> c then
|
||||
begin
|
||||
FCyan := c;
|
||||
CreateGradient;
|
||||
Invalidate;
|
||||
DoChange;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TYColorPicker.SetMagenta(m: integer);
|
||||
begin
|
||||
Clamp(m, 0, 255);
|
||||
if FMagenta <> m then
|
||||
begin
|
||||
FMagenta := m;
|
||||
CreateGradient;
|
||||
Invalidate;
|
||||
DoChange;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TYColorPicker.YellowFromArrowPos(p: integer): integer;
|
||||
var
|
||||
r: integer;
|
||||
begin
|
||||
if Layout = lyHorizontal then
|
||||
r := Round(p/((Width - 12)/255))
|
||||
else
|
||||
r := Round(255 - p/((Height - 12)/255));
|
||||
Clamp(r, 0, 255);
|
||||
Result := r;
|
||||
end;
|
||||
|
||||
procedure TYColorPicker.SetSelectedColor(clr: TColor);
|
||||
var
|
||||
c, m, y, k: integer;
|
||||
newGradient: Boolean;
|
||||
begin
|
||||
if WebSafe then
|
||||
clr := GetWebSafe(clr);
|
||||
if clr = GetSelectedColor then
|
||||
exit;
|
||||
|
||||
ColorToCMYK(clr, c, m, y, k);
|
||||
newGradient := (c <> FCyan) or (m <> FMagenta) or (k <> FBlack);
|
||||
FCyan := c;
|
||||
FMagenta := m;
|
||||
FYellow := y;
|
||||
FBlack := k;
|
||||
if newGradient then
|
||||
CreateGradient;
|
||||
Invalidate;
|
||||
DoChange;
|
||||
end;
|
||||
|
||||
procedure TYColorPicker.SetYellow(y: integer);
|
||||
begin
|
||||
Clamp(y, 0, 255);
|
||||
if FYellow <> y then
|
||||
begin
|
||||
FYellow := y;
|
||||
FArrowPos := ArrowPosFromYellow(y);
|
||||
Invalidate;
|
||||
DoChange;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user