From e134fd7bbeff8cd1d530d11e1c71b410bf7a9fa0 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Tue, 20 Dec 2016 22:42:41 +0000 Subject: [PATCH] mbColorLib: Fix GetColorAtPoint in Linux for R/G/B AxisColorPickers. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5552 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/mbColorLib/BAxisColorPicker.pas | 14 +++++- components/mbColorLib/GAxisColorPicker.pas | 15 ++++++- components/mbColorLib/RAxisColorPicker.pas | 50 +++++++++++++--------- 3 files changed, 55 insertions(+), 24 deletions(-) diff --git a/components/mbColorLib/BAxisColorPicker.pas b/components/mbColorLib/BAxisColorPicker.pas index cde16d1b8..5967526c0 100644 --- a/components/mbColorLib/BAxisColorPicker.pas +++ b/components/mbColorLib/BAxisColorPicker.pas @@ -23,6 +23,7 @@ type procedure CorrectCoords(var x, y: integer); procedure CreateWnd; override; procedure DrawMarker(x, y: integer); + function GetColorAtPoint(x, y: Integer): TColor; override; function GetGradientColor2D(x, y: Integer): TColor; override; procedure KeyDown(var Key: Word; Shift: TShiftState); override; procedure MouseMove(Shift: TShiftState; X, Y: Integer); override; @@ -99,6 +100,15 @@ begin InternalDrawMarker(x, y, c); end; +function TBAxisColorPicker.GetColorAtPoint(x, y: Integer): TColor; +var + r, g: Integer; +begin + r := round(x / (Width - 1) * 255); + g := 255 - round(y / (Height - 1) * 255); + Result := RGBtoColor(r, g, FB); +end; + { x is RED, y is GREEN } function TBAxisColorPicker.GetGradientColor2D(x, y: Integer): TColor; begin @@ -249,8 +259,8 @@ begin FB := GetBValue(c); FSelected := c; FManual := false; - mxx := Round(FR*(Width/255)); - myy := Round((255-FG)*(Height/255)); + mxx := Round(FR * Width / 255); // RED is on x + myy := Round((255 - FG) * Height / 255); // GREEN is on y Invalidate; if Assigned(FOnChange) then FOnChange(self); end; diff --git a/components/mbColorLib/GAxisColorPicker.pas b/components/mbColorLib/GAxisColorPicker.pas index ae85db2da..a962286ad 100644 --- a/components/mbColorLib/GAxisColorPicker.pas +++ b/components/mbColorLib/GAxisColorPicker.pas @@ -22,6 +22,7 @@ type procedure CorrectCoords(var x, y: integer); procedure CreateWnd; override; procedure DrawMarker(x, y: integer); + function GetColorAtPoint(x, y: Integer): TColor; override; function GetGradientColor2D(x, y: Integer): TColor; override; procedure KeyDown(var Key: Word; Shift: TShiftState); override; procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; @@ -97,6 +98,16 @@ begin InternalDrawMarker(x, y, c); end; +function TGAxisColorPicker.GetColorAtPoint(x, y: Integer): TColor; +var + r, b: Integer; +begin + b := round(x / (Width - 1) * 255); + r := 255 - round(y / (Height - 1) * 255); + Result := RGBtoColor(r, FG, b); +end; + +// x is BLUE, y is RED function TGAxisColorPicker.GetGradientColor2D(x, y: Integer): TColor; begin Result := RGB(FBufferBmp.Height - 1 - y, FG, x); @@ -251,8 +262,8 @@ begin FB := GetBValue(c); FSelected := c; FManual := false; - myy := Round((255 - FR) * Height / 255); - mxx := Round(FB * Width / 255); + mxx := Round(FB * Width / 255); // BLUE is x + myy := Round((255 - FR) * Height / 255); // RED is y Invalidate; if Assigned(FOnChange) then FOnChange(Self); diff --git a/components/mbColorLib/RAxisColorPicker.pas b/components/mbColorLib/RAxisColorPicker.pas index d19283e85..806b3f0a7 100644 --- a/components/mbColorLib/RAxisColorPicker.pas +++ b/components/mbColorLib/RAxisColorPicker.pas @@ -20,6 +20,7 @@ type procedure CorrectCoords(var x, y: integer); procedure CreateWnd; override; procedure DrawMarker(x, y: integer); + function GetColorAtPoint(x, y: Integer): TColor; override; function GetGradientColor2D(x, y: Integer): TColor; override; procedure KeyDown(var Key: Word; Shift: TShiftState); override; procedure MouseMove(Shift: TShiftState; X, Y: Integer); override; @@ -95,27 +96,21 @@ begin InternalDrawMarker(x, y, c); end; +function TRAxisColorPicker.GetColorAtPoint(x, y: Integer): TColor; +var + g, b: Integer; +begin + b := round(x / (Width - 1) * 255); + g := 255 - round(y / (Height - 1) * 255); + Result := RGBtoColor(FR, g, b); +end; + { x is BLUE, y is GREEN } function TRAxisColorPicker.GetGradientColor2D(x, y: Integer): TColor; begin Result := RGB(FR, FBufferBmp.Height - 1 - y, x); end; -procedure TRAxisColorPicker.Paint; -begin - Canvas.StretchDraw(ClientRect, FBufferBmp); - CorrectCoords(mxx, myy); - DrawMarker(mxx, myy); -end; - -procedure TRAxisColorPicker.Resize; -begin - FManual := false; - myy := Round((255 - FG) * Height / 255); - mxx := Round(FB * Width / 255); - inherited; -end; - procedure TRAxisColorPicker.KeyDown(var Key: Word; Shift: TShiftState); var delta: Integer; @@ -229,25 +224,40 @@ begin end; end; +procedure TRAxisColorPicker.Paint; +begin + Canvas.StretchDraw(ClientRect, FBufferBmp); + CorrectCoords(mxx, myy); + DrawMarker(mxx, myy); +end; + +procedure TRAxisColorPicker.Resize; +begin + FManual := false; + myy := Round((255 - FG) * Height / 255); + mxx := Round(FB * Width / 255); + inherited; +end; + procedure TRAxisColorPicker.SetBValue(b: integer); begin Clamp(b, 0, 255); FB := b; - SetSelectedColor(RGB(FR, FG, FB)); + SetSelectedColor(RGBtoColor(FR, FG, FB)); end; procedure TRAxisColorPicker.SetGValue(g: integer); begin Clamp(g, 0, 255); FG := g; - SetSelectedColor(RGB(FR, FG, FB)); + SetSelectedColor(RGBtoColor(FR, FG, FB)); end; procedure TRAxisColorPicker.SetRValue(r: integer); begin Clamp(r, 0, 255); FR := r; - SetSelectedColor(RGB(FR, FG, FB)); + SetSelectedColor(RGBtoColor(FR, FG, FB)); end; procedure TRAxisColorPicker.SetSelectedColor(c: TColor); @@ -258,8 +268,8 @@ begin FB := GetBValue(c); FSelected := c; FManual := false; - myy := Round((255-FG)*(Height/255)); - mxx := Round(FB*(Width/255)); + myy := Round((255 - FG) * Height / 255); // GREEN on y + mxx := Round(FB * Width / 255); // BLUE on x Invalidate; if Assigned(FOnChange) then FOnChange(self); end;