📄 bscolorctrls.pas
字号:
Temp : TRGB;
I: Integer;
PSPBGColor: TColor;
begin
Form := TForm.Create(Application);
Form.BorderStyle := bsDialog;
Form.Caption := FCaption;
Form.Position := poScreenCenter;
BSF := TbsBusinessSkinForm.Create(Form);
BSF.BorderIcons := [];
BSF.SkinData := SkinData;
BSF.MenusSkinData := CtrlSkinData;
BSF.AlphaBlend := AlphaBlend;
BSF.AlphaBlendAnimation := AlphaBlendAnimation;
BSF.AlphaBlendValue := AlphaBlendValue;
try
Form.ClientWidth := 378;
ColorGrid := TbsSkinColorGrid.Create(Form);
with ColorGrid do
begin
Parent := Form;
CaptionMode := True;
RowCount := 8;
ColCount := 6;
Left := 5;
Top := 5;
Width := 167;
Height := 195;
SkinDataName := 'groupbox';
SkinData := CtrlSkinData;
OnChange := ColorGridChange;
end;
CustomColorGrid := TbsSkinCustomColorGrid.Create(Form);
with CustomColorGrid do
begin
Parent := Form;
CaptionMode := True;
Left := 5;
Top := ColorGrid.Top + ColorGrid.Height + 10;
Width := 167;
Height := 68;
SkinDataName := 'groupbox';
SkinData := CtrlSkinData;
OnChange := CustomColorGridChange;
end;
for I := 1 to 12 do
CustomColorGrid.CustomColorValues[I] := Self.CustomColorValues[I];
CustomColorGrid.FColorsCount := CustomColorValuesCount;
//
PalettePSPPanel:= TbsEmptyControl.Create(Form);
with PalettePSPPanel do
begin
Parent := Form;
Top := 5;
Left := ColorGrid.Left + ColorGrid.Width + 5;
Width := 195;
Height := 195;
end;
PalettePSP := TImage.Create(Form);
with PalettePSP do
begin
Parent := PalettePSPPanel;
Top := 0;
Left := 0;
Width := 195;
Height := 195;
OnMouseMove := PalettePSPMouseMove;
OnMouseUp := PalettePSPMouseUp;
OnMouseDown := PalettePSPMouseDown;
Picture.Bitmap.PixelFormat := pf32bit;
Picture.Bitmap.width := PalettePSP.width;
Picture.Bitmap.height := PalettePSP.Height;
end;
ClickImg := czpspPnone;
Temp.R := 0;
Temp.G := 0;
Temp.B := 0;
PSPColor.RGB := Temp;
PosCircle := (PalettePSP.Width-PalettePSPCoord.Right)div 2;
PosCar := PosCircle;
InitPSPPalette;
//
RLabel := TbsSkinStdLabel.Create(Form);
with RLabel do
begin
Parent := Form;
Left := PalettePSPPanel.Left;
Top := ColorGrid.Top + ColorGrid.Height + 12;
DefaultFont := DefaultLabelFont;
UseSkinFont := Self.UseSkinFont;
SkinData := CtrlSkinData;
Caption := 'R:';
end;
REdit := TbsSkinTrackEdit.Create(Self);
with REdit do
begin
Parent := Form;
PopupKind := tbpLeft;
SetBounds(RLabel.Left + RLabel.Width + 5, ColorGrid.Top + ColorGrid.Height + 10, 50, 21);
TrackBarWidth := 200;
MinValue := 0;
MaxValue := 255;
Value := 0;
SkinData := CtrlSkinData;
JumpWhenClick := True;
OnChange := RGBEditChange;
end;
GLabel := TbsSkinStdLabel.Create(Form);
with GLabel do
begin
Parent := Form;
Left := PalettePSPPanel.Left;
Top := REdit.Top + REdit.Height + 12;
DefaultFont := DefaultLabelFont;
UseSkinFont := Self.UseSkinFont;
SkinData := CtrlSkinData;
Caption := 'G:';
end;
GEdit := TbsSkinTrackEdit.Create(Self);
with GEdit do
begin
Parent := Form;
PopupKind := tbpLeft;
SetBounds(REdit.Left, REdit.Top + REdit.Height + 10, 50, 21);
TrackBarWidth := 200;
MinValue := 0;
MaxValue := 255;
Value := 0;
SkinData := CtrlSkinData;
JumpWhenClick := True;
OnChange := RGBEditChange;
end;
BLabel := TbsSkinStdLabel.Create(Form);
with BLabel do
begin
Parent := Form;
Left := PalettePSPPanel.Left;
Top := GEdit.Top + GEdit.Height + 12;
DefaultFont := DefaultLabelFont;
UseSkinFont := Self.UseSkinFont;
SkinData := CtrlSkinData;
Caption := 'B:';
end;
BEdit := TbsSkinTrackEdit.Create(Self);
with BEdit do
begin
Parent := Form;
PopupKind := tbpLeft;
SetBounds(REdit.Left, GEdit.Top + GEdit.Height + 10, 50, 21);
TrackBarWidth := 200;
MinValue := 0;
MaxValue := 255;
Value := 0;
SkinData := CtrlSkinData;
JumpWhenClick := True;
OnChange := RGBEditChange;
end;
HLabel := TbsSkinStdLabel.Create(Form);
with HLabel do
begin
Parent := Form;
Left := REdit.Left + REdit.Width + 5;
Top := ColorGrid.Top + ColorGrid.Height + 12;
DefaultFont := DefaultLabelFont;
UseSkinFont := Self.UseSkinFont;
SkinData := CtrlSkinData;
Caption := 'H:';
end;
HEdit := TbsSkinTrackEdit.Create(Self);
with HEdit do
begin
Parent := Form;
PopupKind := tbpLeft;
SetBounds(HLabel.Left + HLabel.Width + 5, ColorGrid.Top + ColorGrid.Height + 10, 50, 21);
TrackBarWidth := 250;
MinValue := 0;
MaxValue := 359;
Value := 0;
SkinData := CtrlSkinData;
JumpWhenClick := True;
OnChange := HSLEditChange;
end;
SLabel := TbsSkinStdLabel.Create(Form);
with SLabel do
begin
Parent := Form;
Left := REdit.Left + REdit.Width + 5;
Top := HEdit.Top + HEdit.Height + 12;
DefaultFont := DefaultLabelFont;
UseSkinFont := Self.UseSkinFont;
SkinData := CtrlSkinData;
Caption := 'S:';
end;
SEdit := TbsSkinTrackEdit.Create(Self);
with SEdit do
begin
Parent := Form;
PopupKind := tbpLeft;
SetBounds(HEdit.Left, HEdit.Top + HEdit.Height + 10, 50, 21);
TrackBarWidth := 120;
MinValue := 0;
MaxValue := 100;
Value := 0;
SkinData := CtrlSkinData;
JumpWhenClick := True;
OnChange := HSLEditChange;
end;
LLabel := TbsSkinStdLabel.Create(Form);
with LLabel do
begin
Parent := Form;
Left := REdit.Left + REdit.Width + 5;
Top := SEdit.Top + SEdit.Height + 12;
DefaultFont := DefaultLabelFont;
UseSkinFont := Self.UseSkinFont;
SkinData := CtrlSkinData;
Caption := 'L:';
end;
LEdit := TbsSkinTrackEdit.Create(Self);
with LEdit do
begin
Parent := Form;
PopupKind := tbpLeft;
SetBounds(HEdit.Left, SEdit.Top + SEdit.Height + 10, 50, 21);
TrackBarWidth := 120;
MinValue := 0;
MaxValue := 100;
Value := 0;
SkinData := CtrlSkinData;
JumpWhenClick := True;
OnChange := HSLEditChange;
end;
ColorViewer := TbsColorViewer.Create(Form);
with ColorViewer do
begin
Parent := Form;
SetBounds(HEdit.Left + HEdit.Width + 5,
PalettePSPPanel.Top + PalettePSPPanel.Height + 10,
PalettePSPPanel.Left + PalettePSPPanel.Width - (HEdit.Left + HEdit.Width + 5),
PalettePSPPanel.Left + PalettePSPPanel.Width - (HEdit.Left + HEdit.Width + 5));
end;
ButtonTop := LEdit.Top + LEdit.Height + 15;
ButtonWidth := 70;
ButtonHeight := 25;
OkButton := TbsSkinButton.Create(Form);
with OkButton do
begin
Parent := Form;
DefaultFont := DefaultButtonFont;
UseSkinFont := Self.UseSkinFont;
Caption := BS_MSG_BTN_OK;
ModalResult := mrOk;
Default := True;
SetBounds(5, ButtonTop, ButtonWidth, ButtonHeight);
DefaultHeight := ButtonHeight;
SkinDataName := FButtonSkinDataName;
SkinData := CtrlSkinData;
end;
CancelButton := TbsSkinButton.Create(Form);
with CancelButton do
begin
Parent := Form;
DefaultFont := DefaultButtonFont;
UseSkinFont := Self.UseSkinFont;
Caption := BS_MSG_BTN_CANCEL;
ModalResult := mrCancel;
Cancel := True;
SetBounds(90, ButtonTop, ButtonWidth,
ButtonHeight);
DefaultHeight := ButtonHeight;
SkinDataName := FButtonSkinDataName;
SkinData := CtrlSkinData;
end;
AddCustomColorButton := TbsSkinButton.Create(Form);
with AddCustomColorButton do
begin
Parent := Form;
DefaultFont := DefaultButtonFont;
UseSkinFont := Self.UseSkinFont;
Caption := BS_ADDCUSTOMCOLORBUTTON_CAP;
SetBounds(PalettePSPPanel.Left, ButtonTop, PalettePSPPanel.Width, ButtonHeight);
DefaultHeight := ButtonHeight;
SkinDataName := FButtonSkinDataName;
SkinData := CtrlSkinData;
OnClick := AddCustomColorButtonClick;
end;
Form.ClientHeight := AddCustomColorButton.Top + AddCustomColorButton.Height + 10;
ColorViewer.ColorValue := Color;
ColorGrid.ColorValue := Color;
ColorToR_G_B(Color, R, G, B);
REdit.Value := R;
GEdit.Value := G;
BEdit.Value := B;
if Form.ShowModal = mrOk
then
begin
Color := ColorViewer.ColorValue;
for I := 1 to 12 do
Self.CustomColorValues[I] := CustomColorGrid.CustomColorValues[I];
CustomColorValuesCount := CustomColorGrid.FColorsCount;
Result := True;
end
else
Result := False;
finally
Form.Free;
end;
end;
procedure TbsSkinColorDialog.CalcAngle360(var Angle: Double);
begin
while (Angle < 0) do Angle := Angle + 360;
while (Angle >= 360) do Angle:=Angle - 360;
end;
function TbsSkinColorDialog.CalcAngle3Points(X1, Y1, Xc, Yc, X2, Y2: Double): Double;
var
Angle1, Angle2, Angle: Double;
begin
Angle1 := CalcAnglePoints(Xc, Yc, X1, Y1);
Angle2 := CalcAnglePoints(Xc, Yc, X2, Y2);
Angle := Angle2-Angle1;
CalcAngle360(Angle);
CalcAngle3Points := Angle;
end;
procedure TbsSkinColorDialog.CalcRotationPoint(Xc, Yc, Angle, X1, Y1: Double; var X2,Y2: Double);
var
Angle0: Double;
Distance: Double;
begin
Angle0 := CalcAnglePoints(Xc, Yc, X1, Y1);
Distance := CalcDistancePoints(Xc, Yc, X1, Y1);
CalcPointSurEllipse(Xc, Yc, Distance, Distance, Angle0 + Angle, X2, Y2);
end;
procedure TbsSkinColorDialog.CalcPointSurEllipse(Xc, Yc, RayonX, RayonY, Angle: Double;
var X, Y: Double);
var
Angle1, AngleA: Double;
A, B: Double;
begin
CalcAngle360(Angle);
Angle1 := 90 - Angle;
A := Cos(Angle1 * CalcRadian) * RayonX;
B := Sin(Angle1 * CalcRadian) * RayonY;
if (Abs(B) < CalcEpsilon)
then
if (Abs(Angle - 90) < 1E-7)
then
AngleA := 90
else
AngleA := 270
else
begin
AngleA := CalcArcTan(A/B);
if (Angle < 90)
then
else
if (Angle < 270)
then
AngleA := AngleA + 180
else
AngleA := AngleA + 0;
end;
Y := Yc + Sin(AngleA * CalcRadian) * RayonY;
X := Xc + Cos(AngleA * CalcRadian) * RayonX;
end;
function TbsSkinColorDialog.CalcArcTan(TanAngle: Double): Double;
begin
CalcArcTan := Arctan(TanAngle) / CalcRadian;
end;
function TbsSkinColorDialog.CalcAnglePoints(X1, Y1, X2, Y2: Double): Double;
var
Distance, CosAngle, Angle: Double;
begin
Distance := CalcDistancePoints(X1, Y1, X2, Y2);
if (Abs(Distance) < CalcEpsilon)
then
Angle := 0
else
begin
CosAngle := Abs(X1 - X2) / Distance;
Angle := CalcArcCosRadians(CosAngle);
if (Abs(Y1 - Y2) >= CalcEpsilon) and (Y2 < Y1) then Angle := -Angle;
if (Abs(X1-X2) >= CalcEpsilon) and (X2 < X1) then Angle := Pi-Angle;
if (Abs(Angle) < CalcEpsilon) then Angle:=0;
if (Angle < 0) then Angle := Angle + 2 * Pi;
Angle := Angle / CalcRadian;
end;
CalcAnglePoints := Angle;
end;
function TbsSkinColorDialog.CalcArcCosRadians(CosAngle: Double): Double;
var
Angle: Double;
begin
Angle := Pi/2 - CalcArcSinRadians(CosAngle);
CalcArcCosRadians := Angle;
end;
function TbsSkinColorDialog.CalcArcSinRadians(SinAngle: Double): Double;
var
Diviseur, Angle: Double;
begin
Diviseur := Sqrt(1 - Sqr(SinAngle));
if (Abs(Diviseur) < CalcEpsilon)
then
if (SinAngle > 0)
then
Angle := Pi/2
else
Angle := -Pi/2
else
Angle := ArcTan(SinAngle / Diviseur);
CalcArcSinRadians := Angle;
end;
function TbsSkinColorDialog.CalcDistancePoints(X1, Y1, X2, Y2: Double): Double;
begin
CalcDistancePoints := Sqrt(Sqr(Y2 - Y1) + Sqr(X2 - X1));
end;
procedure TbsSkinColorDialog.InitPSPPalette;
var
GCircle, PCircle, Disque: HRGN;
PLigneCircle: pointer;
I, J : Integer;
C_X, C_Y: Integer;
Col: TPSPColor;
Col2: THSL;
Val: THSL;
TabCol: array[0..359]of TRGB;
Angle: Integer;
PanelData: TbsDataSkinPanelControl;
PanelDataIndex: Integer;
NewClRect: TRect;
w, h, rw, rh, X, Y, XCnt, YCnt, XO, YO: Integer;
SB: TBitMap;
begin
Col := TPSPColor.Create;
GCircle := CreateEllipticRgn(PalettePSPCoord.Left, PalettePSPCoord.Top,
PalettePSPCoord.Right, PalettePSPCoord.Bottom);
PCircle := CreateEllipticRgn((PalettePSPCoord.Left + 20),
(PalettePSPCoord.Top + 20), (PalettePSPCoord.Right - 20), (PalettePSPCoord.Bottom - 20));
Disque := CreateRectRgn(0, 0, 2, 2);
CombineRgn(Disque, GCircle, PCircle, RGN_DIFF);
Val.S := 1;
Val.L := 0.47;
for I := 0 to 359 do
begin
Val.H := I/359;
Col.HSL := Val;
TabCol[I] := Col.RGB;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -