You've already forked lazarus-ccr
mbColorLib: Fix mismatch of picked vs displayed color in HSColorTracker (Linux issue)
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5553 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -32,19 +32,21 @@ type
|
|||||||
procedure SetMaxSat(S: Integer);
|
procedure SetMaxSat(S: Integer);
|
||||||
protected
|
protected
|
||||||
procedure CorrectCoords(var x, y: integer);
|
procedure CorrectCoords(var x, y: integer);
|
||||||
function GetGradientColor2D(X, Y: Integer): TColor; override;
|
procedure CreateWnd; override;
|
||||||
procedure SetSelectedColor(c: TColor); override;
|
function GetGradientColor2D(x, y: Integer): TColor; override;
|
||||||
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||||
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
|
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
|
||||||
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
|
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
|
||||||
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
|
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
|
||||||
procedure DrawMarker(x, y: integer);
|
procedure DrawMarker(x, y: integer);
|
||||||
procedure Paint; override;
|
procedure Paint; override;
|
||||||
procedure Resize; override;
|
|
||||||
procedure CreateWnd; override;
|
|
||||||
function PredictColor: TColor;
|
function PredictColor: TColor;
|
||||||
|
procedure Resize; override;
|
||||||
|
procedure SelectColor(x, y: Integer);
|
||||||
|
procedure SetSelectedColor(c: TColor); override;
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
|
function GetColorAtPoint(x, y: Integer): TColor; override;
|
||||||
property Hue: integer read GetHue write SetHue;
|
property Hue: integer read GetHue write SetHue;
|
||||||
property Saturation: integer read GetSat write SetSat;
|
property Saturation: integer read GetSat write SetSat;
|
||||||
published
|
published
|
||||||
@ -120,7 +122,24 @@ begin
|
|||||||
InternalDrawMarker(x, y, c);
|
InternalDrawMarker(x, y, c);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function THSColorPicker.GetGradientColor2D(X, Y: Integer): TColor;
|
function THSColorPicker.GetColorAtPoint(x, y: Integer): TColor;
|
||||||
|
var
|
||||||
|
h, s, l: Double;
|
||||||
|
begin
|
||||||
|
if InRange(x, 0, Width - 1) and InRange(y, 0, Height - 1) then
|
||||||
|
begin
|
||||||
|
h := x / (Width - 1);
|
||||||
|
s := 1 - y / (Height - 1);
|
||||||
|
{$IFDEF USE_COLOR_TO_RGB}
|
||||||
|
Result := HSLToColor(h, s, FLum);
|
||||||
|
{$ELSE}
|
||||||
|
Result := HSLToRGB(h, s, FLum);
|
||||||
|
{$ENDIF}
|
||||||
|
end else
|
||||||
|
Result := clNone;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function THSColorPicker.GetGradientColor2D(x, y: Integer): TColor;
|
||||||
begin
|
begin
|
||||||
{$IFDEF USE_COLOR_TO_RGB}
|
{$IFDEF USE_COLOR_TO_RGB}
|
||||||
Result := HSLToColor(x / FMaxHue, (FBufferBmp.Height - 1 - y) / FMaxSat, FLum);
|
Result := HSLToColor(x / FMaxHue, (FBufferBmp.Height - 1 - y) / FMaxSat, FLum);
|
||||||
@ -208,9 +227,8 @@ begin
|
|||||||
myy := y;
|
myy := y;
|
||||||
if Button = mbLeft then
|
if Button = mbLeft then
|
||||||
begin
|
begin
|
||||||
SetSelectedColor(GetColorAtPoint(x, y));
|
SelectColor(x, y);
|
||||||
FManual := true;
|
FManual := true;
|
||||||
Invalidate;
|
|
||||||
end;
|
end;
|
||||||
SetFocus;
|
SetFocus;
|
||||||
end;
|
end;
|
||||||
@ -220,11 +238,8 @@ begin
|
|||||||
inherited;
|
inherited;
|
||||||
if ssLeft in Shift then
|
if ssLeft in Shift then
|
||||||
begin
|
begin
|
||||||
mxx := x;
|
SelectColor(x, y);
|
||||||
myy := y;
|
|
||||||
SetSelectedColor(GetColorAtPoint(x, y));
|
|
||||||
FManual := true;
|
FManual := true;
|
||||||
Invalidate;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -233,18 +248,14 @@ begin
|
|||||||
inherited;
|
inherited;
|
||||||
if ssLeft in Shift then
|
if ssLeft in Shift then
|
||||||
begin
|
begin
|
||||||
mxx := x;
|
SelectColor(x, y);
|
||||||
myy := y;
|
|
||||||
SetSelectedColor(GetColorAtPoint(x, y));
|
|
||||||
FManual := true;
|
FManual := true;
|
||||||
Invalidate;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure THSColorPicker.Paint;
|
procedure THSColorPicker.Paint;
|
||||||
begin
|
begin
|
||||||
Canvas.StretchDraw(ClientRect, FBufferBmp);
|
Canvas.StretchDraw(ClientRect, FBufferBmp);
|
||||||
CorrectCoords(mxx, myy);
|
|
||||||
DrawMarker(mxx, myy);
|
DrawMarker(mxx, myy);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -266,6 +277,27 @@ begin
|
|||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure THSColorPicker.SelectColor(x, y: Integer);
|
||||||
|
var
|
||||||
|
c: TColor;
|
||||||
|
L: Double;
|
||||||
|
begin
|
||||||
|
mxx := x;
|
||||||
|
myy := y;
|
||||||
|
CorrectCoords(mxx, myy);
|
||||||
|
c := GetColorAtPoint(mxx, myy);
|
||||||
|
if WebSafe then c := GetWebSafe(c);
|
||||||
|
{$IFDEF USE_COLOR_TO_RGB}
|
||||||
|
ColorToHSL(c, FHue, FSat, L);
|
||||||
|
{$ELSE}
|
||||||
|
RGBtoHSL(c, FHue, FSat, L);
|
||||||
|
{$ENDIF}
|
||||||
|
FSelected := c;
|
||||||
|
FManual := false;
|
||||||
|
Invalidate;
|
||||||
|
if Assigned(OnChange) then OnChange(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure THSColorPicker.SetHue(H: integer);
|
procedure THSColorPicker.SetHue(H: integer);
|
||||||
begin
|
begin
|
||||||
Clamp(H, 0, FMaxHue);
|
Clamp(H, 0, FMaxHue);
|
||||||
@ -346,6 +378,7 @@ begin
|
|||||||
FManual := false;
|
FManual := false;
|
||||||
mxx := Round(FHue * Width);
|
mxx := Round(FHue * Width);
|
||||||
myy := Round((1.0 - FSat) * Height);
|
myy := Round((1.0 - FSat) * Height);
|
||||||
|
CorrectCoords(mxx, myy);
|
||||||
Invalidate;
|
Invalidate;
|
||||||
if Assigned(OnChange) then OnChange(Self);
|
if Assigned(OnChange) then OnChange(Self);
|
||||||
end;
|
end;
|
||||||
|
Reference in New Issue
Block a user