[Pas2js] lazarus color unit
warleyalex
warleyalex at yahoo.com.br
Fri Jul 19 19:21:32 CEST 2019
I used to define this color unit at pas2js graphic projects.
*****
unit pas2js.Color;
{$mode objfpc}
interface
uses
Classes, SysUtils;
type
TColor = Integer;
Const
{ 18 standard colors }
clBlack = TColor($000000);
clMaroon = TColor($000080);
clGreen = TColor($008000);
clOlive = TColor($008080);
clNavy = TColor($800000);
clPurple = TColor($800080);
clTeal = TColor($808000);
clGray = TColor($808080);
clSilver = TColor($C0C0C0);
clRed = TColor($0000FF);
clLime = TColor($00FF00);
clYellow = TColor($00FFFF);
clBlue = TColor($FF0000);
clFuchsia = TColor($FF00FF);
clAqua = TColor($FFFF00);
clLtGray = TColor($C0C0C0); // clSilver alias
clDkGray = TColor($808080); // clGray alias
clWhite = TColor($FFFFFF);
{ 4 extended colors }
clMoneyGreen = TColor($C0DCC0);
clSkyBlue = TColor($F0CAA6);
clCream = TColor($F0FBFF);
clMedGray = TColor($A4A0A0);
{ 2 special colors }
clNone = TColor($1FFFFFFF);
clDefault = TColor($20000000);
{ system base color }
clBase = TColor($80000000);
{ 31 system colors }
clScrollBar = TColor(clBase+0);
clBackground = TColor(1);
clActiveCaption = TColor(2);
clInactiveCaption = TColor(3);
clMenu = TColor(4);
clWindow = TColor(5);
clWindowFrame = TColor(6);
clMenuText = TColor(7);
clWindowText = TColor(8);
clCaptionText = TColor(9);
clActiveBorder = TColor(10);
clInactiveBorder = TColor(11);
clAppWorkspace = TColor(12);
clHighlight = TColor(13);
clHighlightText = TColor(14);
clBtnFace = TColor(15);
clBtnShadow = TColor(16);
clGrayText = TColor(17);
clBtnText = TColor(18);
clInactiveCaptionText = TColor(19);
clBtnHighlight = TColor(20);
cl3DDkShadow = TColor(21);
cl3DLight = TColor(22);
clInfoText = TColor(23);
clInfoBk = TColor(24);
// PBD: 25 is unassigned = TColor(25);
clHotLight = TColor(26);
clGradientActiveCaption = TColor(27);
clGradientInactiveCaption = TColor(28);
clMenuHighlight = TColor(29);
clMenuBar = TColor(30);
clForm = TColor(31);
{ Web Colors }
clWebSnow = TColor($FAFAFF);
clWebFloralWhite = TColor($F0FAFF);
clWebLavenderBlush = TColor($F5F0FF);
clWebOldLace = TColor($E6F5FD);
clWebIvory = TColor($F0FFFF);
clWebCornSilk = TColor($DCF8FF);
clWebBeige = TColor($DCF5F5);
clWebAntiqueWhite = TColor($D7EBFA);
clWebWheat = TColor($B3DEF5);
clWebAliceBlue = TColor($FFF8F0);
clWebGhostWhite = TColor($FFF8F8);
clWebLavender = TColor($FAE6E6);
clWebSeashell = TColor($EEF5FF);
clWebLightYellow = TColor($E0FFFF);
clWebPapayaWhip = TColor($D5EFFF);
clWebNavajoWhite = TColor($ADDEFF);
clWebMoccasin = TColor($B5E4FF);
clWebBurlywood = TColor($87B8DE);
clWebAzure = TColor($FFFFF0);
clWebMintcream = TColor($FAFFF5);
clWebHoneydew = TColor($F0FFF0);
clWebLinen = TColor($E6F0FA);
clWebLemonChiffon = TColor($CDFAFF);
clWebBlanchedAlmond = TColor($CDEBFF);
clWebBisque = TColor($C4E4FF);
clWebPeachPuff = TColor($B9DAFF);
clWebTan = TColor($8CB4D2);
clWebYellow = TColor($00FFFF);
clWebDarkOrange = TColor($008CFF);
clWebRed = TColor($0000FF);
clWebDarkRed = TColor($00008B);
clWebMaroon = TColor($000080);
clWebIndianRed = TColor($5C5CCD);
clWebSalmon = TColor($7280FA);
clWebCoral = TColor($507FFF);
clWebGold = TColor($00D7FF);
clWebTomato = TColor($4763FF);
clWebCrimson = TColor($3C14DC);
clWebBrown = TColor($2A2AA5);
clWebChocolate = TColor($1E69D2);
clWebSandyBrown = TColor($60A4F4);
clWebLightSalmon = TColor($7AA0FF);
clWebLightCoral = TColor($8080F0);
clWebOrange = TColor($00A5FF);
clWebOrangeRed = TColor($0045FF);
clWebFirebrick = TColor($2222B2);
clWebSaddleBrown = TColor($13458B);
clWebSienna = TColor($2D52A0);
clWebPeru = TColor($3F85CD);
clWebDarkSalmon = TColor($7A96E9);
clWebRosyBrown = TColor($8F8FBC);
clWebPaleGoldenrod = TColor($AAE8EE);
clWebLightGoldenrodYellow = TColor($D2FAFA);
clWebOlive = TColor($008080);
clWebForestGreen = TColor($228B22);
clWebGreenYellow = TColor($2FFFAD);
clWebChartreuse = TColor($00FF7F);
clWebLightGreen = TColor($90EE90);
clWebAquamarine = TColor($D4FF7F);
clWebSeaGreen = TColor($578B2E);
clWebGoldenRod = TColor($20A5DA);
clWebKhaki = TColor($8CE6F0);
clWebOliveDrab = TColor($238E6B);
clWebGreen = TColor($008000);
clWebYellowGreen = TColor($32CD9A);
clWebLawnGreen = TColor($00FC7C);
clWebPaleGreen = TColor($98FB98);
clWebMediumAquamarine = TColor($AACD66);
clWebMediumSeaGreen = TColor($71B33C);
clWebDarkGoldenRod = TColor($0B86B8);
clWebDarkKhaki = TColor($6BB7BD);
clWebDarkOliveGreen = TColor($2F6B55);
clWebDarkgreen = TColor($006400);
clWebLimeGreen = TColor($32CD32);
clWebLime = TColor($00FF00);
clWebSpringGreen = TColor($7FFF00);
clWebMediumSpringGreen = TColor($9AFA00);
clWebDarkSeaGreen = TColor($8FBC8F);
clWebLightSeaGreen = TColor($AAB220);
clWebPaleTurquoise = TColor($EEEEAF);
clWebLightCyan = TColor($FFFFE0);
clWebLightBlue = TColor($E6D8AD);
clWebLightSkyBlue = TColor($FACE87);
clWebCornFlowerBlue = TColor($ED9564);
clWebDarkBlue = TColor($8B0000);
clWebIndigo = TColor($82004B);
clWebMediumTurquoise = TColor($CCD148);
clWebTurquoise = TColor($D0E040);
clWebCyan = TColor($FFFF00);
clWebAqua = TColor($FFFF00);
clWebPowderBlue = TColor($E6E0B0);
clWebSkyBlue = TColor($EBCE87);
clWebRoyalBlue = TColor($E16941);
clWebMediumBlue = TColor($CD0000);
clWebMidnightBlue = TColor($701919);
clWebDarkTurquoise = TColor($D1CE00);
clWebCadetBlue = TColor($A09E5F);
clWebDarkCyan = TColor($8B8B00);
clWebTeal = TColor($808000);
clWebDeepskyBlue = TColor($FFBF00);
clWebDodgerBlue = TColor($FF901E);
clWebBlue = TColor($FF0000);
clWebNavy = TColor($800000);
clWebDarkViolet = TColor($D30094);
clWebDarkOrchid = TColor($CC3299);
clWebMagenta = TColor($FF00FF);
clWebFuchsia = TColor($FF00FF);
clWebDarkMagenta = TColor($8B008B);
clWebMediumVioletRed = TColor($8515C7);
clWebPaleVioletRed = TColor($9370DB);
clWebBlueViolet = TColor($E22B8A);
clWebMediumOrchid = TColor($D355BA);
clWebMediumPurple = TColor($DB7093);
clWebPurple = TColor($800080);
clWebDeepPink = TColor($9314FF);
clWebLightPink = TColor($C1B6FF);
clWebViolet = TColor($EE82EE);
clWebOrchid = TColor($D670DA);
clWebPlum = TColor($DDA0DD);
clWebThistle = TColor($D8BFD8);
clWebHotPink = TColor($B469FF);
clWebPink = TColor($CBC0FF);
clWebLightSteelBlue = TColor($DEC4B0);
clWebMediumSlateBlue = TColor($EE687B);
clWebLightSlateGray = TColor($998877);
clWebWhite = TColor($FFFFFF);
clWebLightgrey = TColor($D3D3D3);
clWebGray = TColor($808080);
clWebSteelBlue = TColor($B48246);
clWebSlateBlue = TColor($CD5A6A);
clWebSlateGray = TColor($908070);
clWebWhiteSmoke = TColor($F5F5F5);
clWebSilver = TColor($C0C0C0);
clWebDimGray = TColor($696969);
clWebMistyRose = TColor($E1E4FF);
clWebDarkSlateBlue = TColor($8B3D48);
clWebDarkSlategray = TColor($4F4F2F);
clWebGainsboro = TColor($DCDCDC);
clWebDarkGray = TColor($A9A9A9);
clWebBlack = TColor($000000);
{ global methods }
function ColorToHexStr(Value: Integer): String;
function ColorToRGBStr(Value: Integer): String;
function ColorToRGBAStr(Value: Integer): String;
function JSColor(const AColor: TColor): string;
function ColorToHex(c: TColor): string;
function ColorToHTML(c: TColor): string;
implementation
function GetR(Color: Integer): Integer;
begin
Result:=((Color and $FF0000) shr 16);
end;
function GetG(Color: Integer): Integer;
begin
Result:=((Color and $FF00) shr 8);
end;
function GetB(Color: Integer): Integer;
begin
Result:=(Color and $FF);
end;
function GetA(Color: Integer): Integer;
begin
Result:=((Color and $FF000000) shr 24);
end;
function ColorToHexStr(Value: Integer): String;
begin
Result:='#'+
IntToHex(GetR(Value),2)+
IntToHex(GetG(Value),2)+
IntToHex(GetB(Value),2);
end;
function ColorToRGBStr(Value: Integer): String;
begin
Result:='rgb('+
IntToStr(GetR(Value))+','+
IntToStr(GetG(Value))+','+
IntToStr(GetB(Value))+
')';
end;
function ColorToRGBAStr(Value: Integer): String;
begin
Result:='rgba('+
IntToStr(GetR(Value))+','+
IntToStr(GetG(Value))+','+
IntToStr(GetB(Value))+','+
FloatToStr(GetA(Value)/255)+
')';
end;
function JSColor(const AColor: TColor): string;
var
R, G, B: byte;
begin
case AColor of
//// System colors
clScrollBar: Result := 'Scrollbar';
clBackground: Result := 'Background';
clActiveCaption: Result := 'ActiveCaption';
clInactiveCaption: Result := 'InactiveCaption';
clMenu: Result := 'Menu';
clWindow: Result := 'Window';
clWindowFrame: Result := 'WindowFrame';
clMenuText: Result := 'MenuText';
clWindowText: Result := 'WindowText';
clCaptionText: Result := 'CaptionText';
clActiveBorder: Result := 'ActiveBorder';
clInactiveBorder: Result := 'InactiveBorder';
clAppWorkspace: Result := 'AppWorkspace';
clHighlight: Result := 'Highlight';
clHighlightText: Result := 'HighlightText';
clBtnFace: Result := 'ButtonFace';
clBtnShadow: Result := 'ButtonShadow';
clGrayText: Result := 'GrayText';
clBtnText: Result := 'ButtonText';
clInactiveCaptionText: Result := 'InactiveCaptionText';
clBtnHighlight: Result := 'ButtonHighlight';
cl3DDkShadow: Result := 'ThreeDDarkShadow';
cl3DLight: Result := 'ThreeDHighlight';
clInfoText: Result := 'InfoText';
clInfoBk: Result := 'InfoBackground';
else
begin
R := (AColor) and $FF;
G := (AColor shr 8) and $FF;
B := (AColor shr 16) and $FF;
Result := '#' + IntToHex(R, 2) + IntToHex(G, 2) + IntToHex(B, 2);
end;
end;
end;
function ColorToHex(c: TColor): string;
var
s: string;
begin
asm
s = c.toString(16);
while (s.length < 6)
{
s = "0" + s;
}
end;
Result := Copy(s,5,2) + Copy(s,3,2) + Copy(s,1,2);
end;
function ColorToHTML(c: TColor): string;
begin
Result := '#' + ColorToHex(c);
end;
end.
--
Sent from: http://pas2js.38893.n8.nabble.com/
More information about the Pas2js
mailing list