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
This commit is contained in:
wp_xxyyzz
2016-12-20 22:42:41 +00:00
parent db5064590a
commit e134fd7bbe
3 changed files with 55 additions and 24 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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;