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;
public
constructor Create(AOwner: TComponent); override;
function GetColorAtPoint(x, y: Integer): TColor; override;
published
property SelectedColor default clFuchsia;
property LValue: integer read FL write SetLValue default 100;
@@ -98,6 +99,26 @@ begin
InternalDrawMarker(x, y, c);
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);
// --> x is B, y is L
function TCIEAColorPicker.GetGradientColor2D(x, y: Integer): TColor;
@@ -169,10 +190,12 @@ end;
procedure TCIEAColorPicker.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited;
mxx := x;
myy := y;
if Button = mbLeft then
begin
mxx := x;
myy := y;
CorrectCoords(mxx, myy);
FSelected := GetColorAtPoint(mxx, myy);
FSelected := GetColorAtPoint(x, y);
FManual := true;
Invalidate;
@@ -189,7 +212,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
@@ -204,7 +228,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
@@ -215,7 +240,6 @@ end;
procedure TCIEAColorPicker.Paint;
begin
Canvas.StretchDraw(ClientRect, FBufferBmp);
CorrectCoords(mxx, myy);
DrawMarker(mxx, myy);
end;