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

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