You've already forked lazarus-ccr
mbColorLib: Delphi support removed. Change version number to 2.1 (standard even/odd numbering scheme).
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5549 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -1,19 +1,12 @@
|
||||
unit RColorPicker;
|
||||
|
||||
{$IFDEF FPC}
|
||||
{$MODE DELPHI}
|
||||
{$ENDIF}
|
||||
{$MODE DELPHI}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
{$IFDEF FPC}
|
||||
LCLIntf, LCLType, LMessages,
|
||||
{$ELSE}
|
||||
Windows, Messages,
|
||||
{$ENDIF}
|
||||
SysUtils, Classes, Controls, Graphics, Forms,
|
||||
mbTrackBarPicker, HTMLColors, Scanlines;
|
||||
LCLIntf, LCLType, SysUtils, Classes, Controls, Graphics, Forms,
|
||||
HTMLColors, Scanlines, mbTrackBarPicker;
|
||||
|
||||
type
|
||||
|
||||
@@ -23,12 +16,12 @@ type
|
||||
private
|
||||
FRed, FGreen, FBlue: integer;
|
||||
function ArrowPosFromRed(r: integer): integer;
|
||||
function RedFromArrowPos(p: integer): integer;
|
||||
function GetSelectedColor: TColor;
|
||||
procedure SetSelectedColor(c: TColor);
|
||||
procedure SetRed(r: integer);
|
||||
procedure SetGreen(g: integer);
|
||||
function RedFromArrowPos(p: integer): integer;
|
||||
procedure SetBlue(b: integer);
|
||||
procedure SetGreen(g: integer);
|
||||
procedure SetRed(r: integer);
|
||||
procedure SetSelectedColor(c: TColor);
|
||||
protected
|
||||
procedure Execute(tbaAction: integer); override;
|
||||
function GetArrowPos: integer; override;
|
||||
@@ -50,7 +43,6 @@ implementation
|
||||
uses
|
||||
mbUtils;
|
||||
|
||||
|
||||
{TRColorPicker}
|
||||
|
||||
constructor TRColorPicker.Create(AOwner: TComponent);
|
||||
@@ -70,111 +62,25 @@ begin
|
||||
FChange := true;
|
||||
end;
|
||||
|
||||
function TRColorPicker.GetGradientColor(AValue: Integer): TColor;
|
||||
begin
|
||||
Result := RGB(AValue, FGreen, FBlue);
|
||||
end;
|
||||
|
||||
procedure TRColorPicker.SetRed(r: integer);
|
||||
begin
|
||||
Clamp(r, 0, 255);
|
||||
if FRed <> r then
|
||||
begin
|
||||
FRed := r;
|
||||
FArrowPos := ArrowPosFromRed(r);
|
||||
FManual := false;
|
||||
Invalidate;
|
||||
if FChange and Assigned(OnChange) then OnChange(Self);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TRColorPicker.SetGreen(g: integer);
|
||||
begin
|
||||
Clamp(g, 0, 255);
|
||||
if FGreen <> g then
|
||||
begin
|
||||
FGreen := g;
|
||||
FManual := false;
|
||||
CreateGradient;
|
||||
Invalidate;
|
||||
if FChange and Assigned(OnChange) then OnChange(Self);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TRColorPicker.SetBlue(b: integer);
|
||||
begin
|
||||
Clamp(b, 0, 255);
|
||||
if FBlue <> b then
|
||||
begin
|
||||
FBlue := b;
|
||||
FManual := false;
|
||||
CreateGradient;
|
||||
Invalidate;
|
||||
if FChange and Assigned(OnChange) then OnChange(Self);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TRColorPicker.ArrowPosFromRed(r: integer): integer;
|
||||
var
|
||||
a: integer;
|
||||
begin
|
||||
if Layout = lyHorizontal then
|
||||
begin
|
||||
a := Round(((Width - 12)/255)*r);
|
||||
a := Round((Width - 12) / 255 * r);
|
||||
if a > Width - FLimit then a := Width - FLimit;
|
||||
end
|
||||
else
|
||||
begin
|
||||
r := 255 - r;
|
||||
a := Round(((Height - 12)/255)*r);
|
||||
a := Round((Height - 12) / 255 * r);
|
||||
if a > Height - FLimit then a := Height - FLimit;
|
||||
end;
|
||||
if a < 0 then a := 0;
|
||||
Result := a;
|
||||
end;
|
||||
|
||||
function TRColorPicker.RedFromArrowPos(p: integer): integer;
|
||||
var
|
||||
r: integer;
|
||||
begin
|
||||
if Layout = lyHorizontal then
|
||||
r := Round(p/((Width - 12)/255))
|
||||
else
|
||||
r := Round(255 - p/((Height - 12)/255));
|
||||
Clamp(r, 0, 255);
|
||||
Result := r;
|
||||
end;
|
||||
|
||||
function TRColorPicker.GetSelectedColor: TColor;
|
||||
begin
|
||||
if not WebSafe then
|
||||
Result := RGB(FRed, FGreen, FBlue)
|
||||
else
|
||||
Result := GetWebSafe(RGB(FRed, FGreen, FBlue));
|
||||
end;
|
||||
|
||||
function TRColorPicker.GetSelectedValue: integer;
|
||||
begin
|
||||
Result := FRed;
|
||||
end;
|
||||
|
||||
procedure TRColorPicker.SetSelectedColor(c: TColor);
|
||||
begin
|
||||
if WebSafe then c := GetWebSafe(c);
|
||||
FChange := false;
|
||||
SetGreen(GetGValue(c));
|
||||
SetBlue(GetBValue(c));
|
||||
SetRed(GetRValue(c));
|
||||
FManual := false;
|
||||
FChange := true;
|
||||
if Assigned(OnChange) then OnChange(Self);
|
||||
end;
|
||||
|
||||
function TRColorPicker.GetArrowPos: integer;
|
||||
begin
|
||||
Result := ArrowPosFromRed(FRed);
|
||||
end;
|
||||
|
||||
procedure TRColorPicker.Execute(tbaAction: integer);
|
||||
begin
|
||||
case tbaAction of
|
||||
@@ -211,4 +117,90 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TRColorPicker.GetArrowPos: integer;
|
||||
begin
|
||||
Result := ArrowPosFromRed(FRed);
|
||||
end;
|
||||
|
||||
function TRColorPicker.GetGradientColor(AValue: Integer): TColor;
|
||||
begin
|
||||
Result := RGB(AValue, FGreen, FBlue);
|
||||
end;
|
||||
|
||||
function TRColorPicker.GetSelectedColor: TColor;
|
||||
begin
|
||||
if not WebSafe then
|
||||
Result := RGB(FRed, FGreen, FBlue)
|
||||
else
|
||||
Result := GetWebSafe(RGB(FRed, FGreen, FBlue));
|
||||
end;
|
||||
|
||||
function TRColorPicker.GetSelectedValue: integer;
|
||||
begin
|
||||
Result := FRed;
|
||||
end;
|
||||
|
||||
function TRColorPicker.RedFromArrowPos(p: integer): integer;
|
||||
var
|
||||
r: integer;
|
||||
begin
|
||||
if Layout = lyHorizontal then
|
||||
r := Round(p * 255 / (Width - 12))
|
||||
else
|
||||
r := Round(255 - p * 255 / (Height - 12));
|
||||
Clamp(r, 0, 255);
|
||||
Result := r;
|
||||
end;
|
||||
|
||||
procedure TRColorPicker.SetBlue(b: integer);
|
||||
begin
|
||||
Clamp(b, 0, 255);
|
||||
if FBlue <> b then
|
||||
begin
|
||||
FBlue := b;
|
||||
FManual := false;
|
||||
CreateGradient;
|
||||
Invalidate;
|
||||
if FChange and Assigned(OnChange) then OnChange(Self);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TRColorPicker.SetGreen(g: integer);
|
||||
begin
|
||||
Clamp(g, 0, 255);
|
||||
if FGreen <> g then
|
||||
begin
|
||||
FGreen := g;
|
||||
FManual := false;
|
||||
CreateGradient;
|
||||
Invalidate;
|
||||
if FChange and Assigned(OnChange) then OnChange(Self);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TRColorPicker.SetRed(r: integer);
|
||||
begin
|
||||
Clamp(r, 0, 255);
|
||||
if FRed <> r then
|
||||
begin
|
||||
FRed := r;
|
||||
FArrowPos := ArrowPosFromRed(r);
|
||||
FManual := false;
|
||||
Invalidate;
|
||||
if FChange and Assigned(OnChange) then OnChange(Self);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TRColorPicker.SetSelectedColor(c: TColor);
|
||||
begin
|
||||
if WebSafe then c := GetWebSafe(c);
|
||||
FChange := false;
|
||||
SetGreen(GetGValue(c));
|
||||
SetBlue(GetBValue(c));
|
||||
SetRed(GetRValue(c));
|
||||
FManual := false;
|
||||
FChange := true;
|
||||
if Assigned(OnChange) then OnChange(Self);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user