mbColorLib: Fix mouse color tracking of CIEL/A/B pickers in Linux.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5554 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-12-21 18:50:20 +00:00
parent b582b0b78e
commit 77f9d53a72
6 changed files with 91 additions and 114 deletions

View File

@ -33,6 +33,7 @@ type
procedure SetSelectedColor(c: TColor); override; procedure SetSelectedColor(c: TColor); override;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
function GetColorAtPoint(x, y: Integer): TColor; override;
published published
property SelectedColor default clFuchsia; property SelectedColor default clFuchsia;
property LValue: integer read FL write SetLValue default 100; property LValue: integer read FL write SetLValue default 100;
@ -98,6 +99,26 @@ begin
InternalDrawMarker(x, y, c); InternalDrawMarker(x, y, c);
end; end;
{
function TCIEAColorPicker.GetColorAtPoint(x, y: Integer): TColor;
var
l, a, b: Integer;
begin
l := round(100 * (1 - y / (Height-1)));
a := FA;
b := round(255 * (x / (Width - 1))) - 128;
Result := LabToRGB(l, a, b);
end;
}
function TCIEAColorPicker.GetColorAtPoint(x, y: Integer): TColor;
var
l, b: Integer; //Double;
begin
l := round((1 - y / (Height - 1)) * 100);
b := round((x / (Width - 1) - 0.5) * 255);
Result := LabToRGB(l, FA, b);
end;
// In the original code: for L ... for B ... LabToRGB(Round(100-L*100/255), FA, B-128); // In the original code: for L ... for B ... LabToRGB(Round(100-L*100/255), FA, B-128);
// --> x is B, y is L // --> x is B, y is L
function TCIEAColorPicker.GetGradientColor2D(x, y: Integer): TColor; function TCIEAColorPicker.GetGradientColor2D(x, y: Integer): TColor;
@ -169,10 +190,12 @@ end;
procedure TCIEAColorPicker.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure TCIEAColorPicker.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin begin
inherited; inherited;
mxx := x;
myy := y;
if Button = mbLeft then if Button = mbLeft then
begin begin
mxx := x;
myy := y;
CorrectCoords(mxx, myy);
FSelected := GetColorAtPoint(mxx, myy);
FSelected := GetColorAtPoint(x, y); FSelected := GetColorAtPoint(x, y);
FManual := true; FManual := true;
Invalidate; Invalidate;
@ -189,7 +212,8 @@ begin
begin begin
mxx := x; mxx := x;
myy := y; myy := y;
FSelected := GetColorAtPoint(x, y); CorrectCoords(mxx, myy);
FSelected := GetColorAtPoint(mxx, myy);
FManual := true; FManual := true;
Invalidate; Invalidate;
if Assigned(FOnChange) then if Assigned(FOnChange) then
@ -204,7 +228,8 @@ begin
begin begin
mxx := x; mxx := x;
myy := y; myy := y;
FSelected := GetColorAtPoint(x, y); CorrectCoords(mxx, myy);
FSelected := GetColorAtPoint(mxx, myy);
FManual := true; FManual := true;
Invalidate; Invalidate;
if Assigned(FOnChange) then if Assigned(FOnChange) then
@ -215,7 +240,6 @@ end;
procedure TCIEAColorPicker.Paint; procedure TCIEAColorPicker.Paint;
begin begin
Canvas.StretchDraw(ClientRect, FBufferBmp); Canvas.StretchDraw(ClientRect, FBufferBmp);
CorrectCoords(mxx, myy);
DrawMarker(mxx, myy); DrawMarker(mxx, myy);
end; end;

View File

@ -36,6 +36,7 @@ type
procedure SetSelectedColor(c: TColor); override; procedure SetSelectedColor(c: TColor); override;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
function GetColorAtPoint(x, y: Integer): TColor; override;
published published
property AValue: integer read FA write SetAValue default -128; property AValue: integer read FA write SetAValue default -128;
property BValue: integer read FB write SetBValue default 127; property BValue: integer read FB write SetBValue default 127;
@ -101,6 +102,26 @@ begin
InternalDrawMarker(x, y, c); InternalDrawMarker(x, y, c);
end; end;
{
function TCIEBColorPicker.GetColorAtPoint(x, y: Integer): TColor;
var
l, a, b: Integer;
begin
l := round(100 * (1 - y / (Height-1)));
a := round(255 * (x / (Width - 1))) - 128;
b := FB;
Result := LabToRGB(l, a, b);
end;
}
function TCIEBColorPicker.GetColorAtPoint(x, y: Integer): TColor;
var
l, a: Double;
begin
l := (1 - y / (Height - 1)) * 100;
a := (x / (Width - 1) - 0.5) * 255;
Result := LabToRGB(l, a, FB);
end;
{ In the original code: for L ... for A ... LabToRGB(Round(100-L*100/244), A-128, FB) { In the original code: for L ... for A ... LabToRGB(Round(100-L*100/244), A-128, FB)
--> x is A, y is L} --> x is A, y is L}
function TCIEBColorPicker.GetGradientColor2D(x, y: Integer): TColor; function TCIEBColorPicker.GetGradientColor2D(x, y: Integer): TColor;
@ -170,20 +191,14 @@ begin
end; end;
procedure TCIEBColorPicker.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure TCIEBColorPicker.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
R: TRect;
begin begin
inherited; inherited;
mxx := x;
myy := y;
if Button = mbLeft then if Button = mbLeft then
begin begin
R := ClientRect; mxx := x;
R.TopLeft := ClientToScreen(R.TopLeft); myy := y;
R.BottomRight := ClientToScreen(R.BottomRight); CorrectCoords(mxx, myy);
{$IFDEF DELPHI} FSelected := GetColorAtPoint(mxx, myy);
ClipCursor(@R);
{$ENDIF}
FSelected := GetColorAtPoint(x, y); FSelected := GetColorAtPoint(x, y);
FManual := true; FManual := true;
Invalidate; Invalidate;
@ -196,12 +211,10 @@ begin
inherited; inherited;
if ssLeft in Shift then if ssLeft in Shift then
begin begin
{$IFDEF DELPHI}
ClipCursor(nil);
{$ENDIF}
mxx := x; mxx := x;
myy := y; myy := y;
FSelected := GetColorAtPoint(x, y); CorrectCoords(mxx, myy);
FSelected := GetColorAtPoint(mxx, myy);
FManual := true; FManual := true;
Invalidate; Invalidate;
if Assigned(FOnChange) then if Assigned(FOnChange) then
@ -216,7 +229,8 @@ begin
begin begin
mxx := x; mxx := x;
myy := y; myy := y;
FSelected := GetColorAtPoint(x, y); CorrectCoords(mxx, myy);
FSelected := GetColorAtPoint(mxx, myy);
FManual := true; FManual := true;
Invalidate; Invalidate;
if Assigned(FOnChange) then if Assigned(FOnChange) then
@ -227,7 +241,6 @@ end;
procedure TCIEBColorPicker.Paint; procedure TCIEBColorPicker.Paint;
begin begin
Canvas.StretchDraw(ClientRect, FBufferBmp); Canvas.StretchDraw(ClientRect, FBufferBmp);
CorrectCoords(mxx, myy);
DrawMarker(mxx, myy); DrawMarker(mxx, myy);
end; end;

View File

@ -33,6 +33,7 @@ type
procedure SetSelectedColor(c: TColor); override; procedure SetSelectedColor(c: TColor); override;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
function GetColorAtPoint(X, Y: Integer): TColor; override;
published published
property AValue: integer read FA write SetAValue default -128; property AValue: integer read FA write SetAValue default -128;
property BValue: integer read FB write SetBValue default 127; property BValue: integer read FB write SetBValue default 127;
@ -99,6 +100,24 @@ begin
InternalDrawMarker(x, y, c); InternalDrawMarker(x, y, c);
end; end;
function TCIELColorPicker.GetColorAtPoint(x, y: Integer): TColor;
var
a, b: Double;
begin
a := (y / (Height - 1) - 0.5) * 255;
b := (x / (Width - 1) - 0.5) * 255;
Result := LabToRGB(FL, a, b);
end;
{
var
a, b: Integer;
begin
a := round(255 * (y / (Height - 1))) - 128;
b := round(255 * (x / (Width - 1))) - 128;
Result := LabToRGB(FL, a, b);
end;
}
{ Original code: for A ... for B ---> LabToRGB(FL, A - 128, B - 128) } { Original code: for A ... for B ---> LabToRGB(FL, A - 128, B - 128) }
function TCIELColorPicker.GetGradientColor2D(x, y: Integer): TColor; function TCIELColorPicker.GetGradientColor2D(x, y: Integer): TColor;
begin begin
@ -168,11 +187,12 @@ end;
procedure TCIELColorPicker.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure TCIELColorPicker.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin begin
inherited; inherited;
mxx := x;
myy := y;
if Button = mbLeft then if Button = mbLeft then
begin begin
FSelected := GetColorAtPoint(x, y); mxx := x;
myy := y;
CorrectCoords(mxx, myy);
FSelected := GetColorAtPoint(mxx, myy);
FManual := true; FManual := true;
Invalidate; Invalidate;
end; end;
@ -186,7 +206,8 @@ begin
begin begin
mxx := x; mxx := x;
myy := y; myy := y;
FSelected := GetColorAtPoint(x, y); CorrectCoords(mxx, myy);
FSelected := GetColorAtPoint(mxx, myy);
FManual := true; FManual := true;
Invalidate; Invalidate;
if Assigned(FOnChange) then if Assigned(FOnChange) then
@ -201,7 +222,8 @@ begin
begin begin
mxx := x; mxx := x;
myy := y; myy := y;
FSelected := GetColorAtPoint(x, y); CorrectCoords(mxx, myy);
FSelected := GetColorAtPoint(mxx, myy);
FManual := true; FManual := true;
Invalidate; Invalidate;
if Assigned(FOnChange) then if Assigned(FOnChange) then

View File

@ -125,6 +125,8 @@ begin
end; end;
function XYZToRGB(space: xyz): TColor; function XYZToRGB(space: xyz): TColor;
// see:
// https://de.mathworks.com/matlabcentral/fileexchange/28790-colorspace-transformations/content/colorspace/colorspace.html?requestedDomain=www.mathworks.com
var var
r, g, b, x, y, z: double; r, g, b, x, y, z: double;
begin begin

View File

@ -43,9 +43,9 @@ object Form1: TForm1
Height = 384 Height = 384
Top = 6 Top = 6
Width = 403 Width = 403
ActivePage = TabSheet9 ActivePage = TabSheet7
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
TabIndex = 9 TabIndex = 7
TabOrder = 0 TabOrder = 0
OnChange = PageControl1Change OnChange = PageControl1Change
OnMouseMove = PageControl1MouseMove OnMouseMove = PageControl1MouseMove
@ -721,8 +721,8 @@ object Form1: TForm1
TabOrder = 2 TabOrder = 2
Hue = 0 Hue = 0
Saturation = 0 Saturation = 0
Luminance = 73 Luminance = 65
SelectedColor = 4802889 SelectedColor = 4276545
end end
object VColorPicker1: TVColorPicker object VColorPicker1: TVColorPicker
Left = 34 Left = 34
@ -1038,7 +1038,6 @@ object Form1: TForm1
Width = 100 Width = 100
HintFormat = 'G: %g B: %b'#13'Hex: #%hex' HintFormat = 'G: %g B: %b'#13'Hex: #%hex'
TabOrder = 0 TabOrder = 0
OnChange = RAxisColorPicker1Change
end end
object GAxisColorPicker1: TGAxisColorPicker object GAxisColorPicker1: TGAxisColorPicker
Left = 130 Left = 130
@ -1048,7 +1047,6 @@ object Form1: TForm1
HintFormat = 'R: %r B: %b'#13'Hex: #%hex' HintFormat = 'R: %r B: %b'#13'Hex: #%hex'
TabOrder = 1 TabOrder = 1
MarkerStyle = msCross MarkerStyle = msCross
OnChange = GAxisColorPicker1Change
end end
object BAxisColorPicker1: TBAxisColorPicker object BAxisColorPicker1: TBAxisColorPicker
Left = 250 Left = 250
@ -1058,7 +1056,6 @@ object Form1: TForm1
HintFormat = 'R: %r G: %g'#13'Hex: #%hex' HintFormat = 'R: %r G: %g'#13'Hex: #%hex'
TabOrder = 2 TabOrder = 2
MarkerStyle = msCrossCirc MarkerStyle = msCrossCirc
OnChange = BAxisColorPicker1Change
end end
object CIELColorPicker1: TCIELColorPicker object CIELColorPicker1: TCIELColorPicker
Left = 10 Left = 10
@ -1071,7 +1068,6 @@ object Form1: TForm1
AValue = -47 AValue = -47
BValue = -32 BValue = -32
LValue = 88 LValue = 88
OnChange = CIELColorPicker1Change
end end
object CIEAColorPicker1: TCIEAColorPicker object CIEAColorPicker1: TCIEAColorPicker
Left = 130 Left = 130
@ -1085,7 +1081,6 @@ object Form1: TForm1
AValue = 96 AValue = 96
BValue = -78 BValue = -78
MarkerStyle = msSquare MarkerStyle = msSquare
OnChange = CIEAColorPicker1Change
end end
object CIEBColorPicker1: TCIEBColorPicker object CIEBColorPicker1: TCIEBColorPicker
Left = 250 Left = 250
@ -1098,7 +1093,6 @@ object Form1: TForm1
AValue = -88 AValue = -88
BValue = 74 BValue = 74
LValue = 88 LValue = 88
OnChange = CIEBColorPicker1Change
end end
object Label10: TLabel object Label10: TLabel
Left = 130 Left = 130
@ -1148,42 +1142,6 @@ object Form1: TForm1
Caption = 'CIEBColorPicker' Caption = 'CIEBColorPicker'
ParentColor = False ParentColor = False
end end
object RAxisIndicator: TShape
Left = 88
Height = 21
Top = 132
Width = 22
end
object GAxisIndicator: TShape
Left = 208
Height = 21
Top = 132
Width = 22
end
object BAxisIndicator: TShape
Left = 328
Height = 21
Top = 132
Width = 22
end
object CIEBIndicator: TShape
Left = 328
Height = 21
Top = 296
Width = 22
end
object CIEAIndicator: TShape
Left = 208
Height = 21
Top = 296
Width = 22
end
object CIELIndicator: TShape
Left = 88
Height = 21
Top = 296
Width = 22
end
end end
end end
object sc: TmbColorPreview object sc: TmbColorPreview

View File

@ -20,10 +20,8 @@ type
{ TForm1 } { TForm1 }
TForm1 = class(TForm) TForm1 = class(TForm)
CIEBIndicator: TShape;
CbShowHints: TCheckBox; CbShowHints: TCheckBox;
CbEnabled: TCheckBox; CbEnabled: TCheckBox;
CIEAIndicator: TShape;
Label10: TLabel; Label10: TLabel;
Label11: TLabel; Label11: TLabel;
Label12: TLabel; Label12: TLabel;
@ -31,10 +29,6 @@ type
Label14: TLabel; Label14: TLabel;
Label15: TLabel; Label15: TLabel;
PageControl1: TPageControl; PageControl1: TPageControl;
RAxisIndicator: TShape;
GAxisIndicator: TShape;
BAxisIndicator: TShape;
CIELIndicator: TShape;
TabSheet1: TTabSheet; TabSheet1: TTabSheet;
TabSheet2: TTabSheet; TabSheet2: TTabSheet;
TabSheet3: TTabSheet; TabSheet3: TTabSheet;
@ -111,19 +105,13 @@ type
Memo1: TMemo; Memo1: TMemo;
Label9: TLabel; Label9: TLabel;
CbSwatchStyle: TCheckBox; CbSwatchStyle: TCheckBox;
procedure BAxisColorPicker1Change(Sender: TObject);
procedure CbEnabledChange(Sender: TObject); procedure CbEnabledChange(Sender: TObject);
procedure CbShowHintsChange(Sender: TObject); procedure CbShowHintsChange(Sender: TObject);
procedure CIEAColorPicker1Change(Sender: TObject);
procedure CIEBColorPicker1Change(Sender: TObject);
procedure CIELColorPicker1Change(Sender: TObject);
procedure GAxisColorPicker1Change(Sender: TObject);
procedure HColorPicker1GetHintStr(Sender: TObject; X, Y: Integer; procedure HColorPicker1GetHintStr(Sender: TObject; X, Y: Integer;
var AText: String); var AText: String);
procedure PageControl1Change(Sender: TObject); procedure PageControl1Change(Sender: TObject);
procedure PageControl1MouseMove(Sender: TObject; Shift: TShiftState; procedure PageControl1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer); X, Y: Integer);
procedure RAxisColorPicker1Change(Sender: TObject);
procedure tb1Change(Sender: TObject); procedure tb1Change(Sender: TObject);
procedure tb2Change(Sender: TObject); procedure tb2Change(Sender: TObject);
procedure HSLColorPicker1Change(Sender: TObject); procedure HSLColorPicker1Change(Sender: TObject);
@ -220,11 +208,6 @@ begin
uc.color := hexacolorpicker1.ColorUnderCursor; uc.color := hexacolorpicker1.ColorUnderCursor;
end; end;
procedure TForm1.BAxisColorPicker1Change(Sender: TObject);
begin
BAxisIndicator.Brush.Color := BAxisColorPicker1.SelectedColor;
end;
procedure TForm1.Button1Click(Sender: TObject); procedure TForm1.Button1Click(Sender: TObject);
begin begin
mbColorPalette1.GeneratePalette(clblue); mbColorPalette1.GeneratePalette(clblue);
@ -298,11 +281,6 @@ begin
uc.color := HSLColorpicker1.ColorUnderCursor; uc.color := HSLColorpicker1.ColorUnderCursor;
end; end;
procedure TForm1.RAxisColorPicker1Change(Sender: TObject);
begin
RAxisIndicator.Brush.Color := RAxisColorPicker1.SelectedColor;
end;
procedure TForm1.OfficeColorDialogButtonClick(Sender: TObject); procedure TForm1.OfficeColorDialogButtonClick(Sender: TObject);
begin begin
if mbOfficeColorDialog1.Execute then if mbOfficeColorDialog1.Execute then
@ -363,11 +341,6 @@ begin
end; end;
end; end;
procedure TForm1.GAxisColorPicker1Change(Sender: TObject);
begin
GAxisIndicator.Brush.Color := GAxisColorPicker1.SelectedColor;
end;
procedure TForm1.HColorPicker1GetHintStr(Sender: TObject; X, Y: Integer; procedure TForm1.HColorPicker1GetHintStr(Sender: TObject; X, Y: Integer;
var AText: String); var AText: String);
begin begin
@ -389,21 +362,6 @@ begin
hexacolorpicker1.NewArrowStyle := checkbox2.checked; hexacolorpicker1.NewArrowStyle := checkbox2.checked;
end; end;
procedure TForm1.CIEAColorPicker1Change(Sender: TObject);
begin
CIEAIndicator.Brush.Color := CIEAColorPicker1.SelectedColor;
end;
procedure TForm1.CIEBColorPicker1Change(Sender: TObject);
begin
CIEBIndicator.Brush.Color := CIEBColorPicker1.SelectedColor;
end;
procedure TForm1.CIELColorPicker1Change(Sender: TObject);
begin
CIELIndicator.Brush.Color := CIELColorPicker1.SelectedColor;
end;
procedure TForm1.Button4Click(Sender: TObject); procedure TForm1.Button4Click(Sender: TObject);
begin begin
if opendialog1.Execute then if opendialog1.Execute then