📄 bscolorctrls.pas
字号:
end;
C_X := PalettePSPCoord.Left + 98;
C_Y := PalettePSPCoord.Left + 98;
Val.S := 0.93;
Val.L := 0.47;
// Draw background
if (FCtrlFSD <> nil) and not FCtrlFSD.Empty and
(FCtrlFSD.GetControlIndex('panel') <> -1)
then
begin
PanelDataIndex := FCtrlFSD.GetControlIndex('panel');
PanelData := TbsDataSkinPanelControl(FCtrlFSD.CtrlList.Items[PanelDataIndex]);
SB := TBitMap(FCtrlFSD.FActivePictures.Items[PanelData.PictureIndex]);
NewClRect := Rect(0, 0, PalettePSP.Width, PalettePSP.Height);
w := RectWidth(PanelData.ClRect);
h := RectHeight(PanelData.ClRect);
rw := RectWidth(NewClRect);
rh := RectHeight(NewClRect);
XCnt := rw div w;
YCnt := rh div h;
for X := 0 to XCnt do
for Y := 0 to YCnt do
begin
if X * w + w > rw then XO := X * W + W - rw else XO := 0;
if Y * h + h > rh then YO := Y * h + h - rh else YO := 0;
PalettePSP.Canvas.CopyRect(
Rect(NewClRect.Left + X * w, NewClRect.Top + Y * h,
NewClRect.Left + X * w + w - XO, NewClRect.Top + Y * h + h - YO),
SB.Canvas,
Rect(PanelData.SkinRect.Left + PanelData.ClRect.Left,
PanelData.SkinRect.Top + PanelData.ClRect.Top,
PanelData.SkinRect.Left + PanelData.ClRect.Right - XO,
PanelData.SkinRect.Top + PanelData.ClRect.Bottom - YO));
end;
end
else
begin
PalettePSP.Canvas.Pen.Color := ColorToRGB(clBtnFace);
PalettePSP.Canvas.Brush.Color := ColorToRGB(clBtnFace);
Rectangle(PalettePSP.Canvas.Handle, 0, 0, PalettePSP.Width, PalettePSP.Height);
end;
//
for J := 0 to PalettePSPCoord.Bottom - 1 do
begin
PLigneCircle := PalettePSP.Picture.Bitmap.ScanLine[PalettePSPCoord.Top+J];
for I := 0 to PalettePSPCoord.Bottom - 1 do
if PtInRegion(Disque,PalettePSPCoord.Left+I,PalettePSPCoord.Top+J) then
begin
Angle := Round(CalcAngle3Points(C_X, 0, C_X, C_Y, I, J));
if Angle = 360 then Angle := 0;
Angle := 359 - Angle;
TLineB(PLigneCircle)[(PosCircle+I)*4 + 0] := TabCol[Angle].B;
TLineB(PLigneCircle)[(PosCircle+I)*4 + 1] := TabCol[Angle].G;
TLineB(PLigneCircle)[(PosCircle+I)*4 + 2] := TabCol[Angle].R;
end;
end;
Col.Assign(PSPColor);
Col2 := Col.HSL;
for J :=RectPSP.Top to RectPSP.Bottom do
begin
PLigneCircle := PalettePSP.Picture.Bitmap.ScanLine[J];
Col2.L := (J-RectPSP.Top)/(RectPSP.Bottom-RectPSP.Top);
for I := RectPSP.Left to (RectPSP.Right) do
begin
Col2.S := (I-RectPSP.Left)/(RectPSP.Right-RectPSP.Left);
Col.HSL := Col2;
TLineB(PLigneCircle)[(I+PosCar)*4 ] := Col.RGB.B;
TLineB(PLigneCircle)[(I+PosCar)*4 + 1] := Col.RGB.G;
TLineB(PLigneCircle)[(I+PosCar)*4 + 2] := Col.RGB.R;
end;
end;
PalettePSP.Canvas.Pen.Color := $FFFFFF;
PalettePSP.Canvas.Pen.Mode := pmXor;
PalettePSP.Canvas.Brush.Style := bsClear;
DrawCursor;
PalettePSP.Picture.Bitmap.modified := true;
Col.Free;
end;
procedure TbsSkinColorDialog.DrawPSPPalette;
procedure DrawRect;
var
PLigneCircle : pointer;
I, J : Integer;
Col : TPSPColor;
Col2 : THSL;
begin
Col := TPSPColor.Create;
Col.Assign(PSPColor);
Col2 := Col.HSL;
for J :=RectPSP.Top to RectPSP.Bottom do
begin
PLigneCircle := PalettePSP.Picture.Bitmap.ScanLine[J];
Col2.L := (J-RectPSP.Top)/(RectPSP.Bottom-RectPSP.Top);
for I := RectPSP.Left to (RectPSP.Right) do
begin
Col2.S := (I-RectPSP.Left)/(RectPSP.Right-RectPSP.Left);
Col.HSL := Col2;
TLineB(PLigneCircle)[(I+PosCar)*4 ] := Col.RGB.B;
TLineB(PLigneCircle)[(I+PosCar)*4 + 1] := Col.RGB.G;
TLineB(PLigneCircle)[(I+PosCar)*4 + 2] := Col.RGB.R;
end;
end;
Col.free;
end;
begin
DrawRect;
DrawCursor;
PalettePSP.Picture.Bitmap.Modified := true;
end;
procedure TbsSkinColorDialog.DrawCursor;
procedure DrawCircle(X,Y,R:Integer);
begin
Ellipse(PalettePSP.Canvas.Handle,X - R, Y - R,X + R, Y + R);
end;
var
Angle: Integer;
X,Y: Double;
C_X,C_Y: Integer;
begin
X := round((PSPColor.HSL.S * (RectPSP.Right-RectPSP.Left)) + (PosCar + RectPSP.Left));
Y := round((PSPColor.HSL.L * (RectPSP.Bottom-RectPSP.Top)) + RectPSP.Top);
DrawCircle(Round(X), Round(Y),5);
C_X := PosCar + RectPSP.Left + (RectPSP.Right-RectPSP.Left)div 2;
C_Y := RectPSP.Top + (RectPSP.Bottom - RectPSP.Top)div 2;
Angle := Round(PSPColor.HSL.H * 360);
CalcRotationPoint(C_X, C_Y, -Angle, C_X, C_Y-((PalettePSPCoord.Bottom-20) div 2), X,Y);
DrawCircle(Round(X),Round(Y),5);
end;
procedure TbsSkinColorDialog.PalettePSPMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
GCircle, PCircle, Disque, Car: HRGN;
HSLPSP: THSLPSP;
C_X,C_Y: Integer;
Angle: Integer;
begin
GCircle := CreateEllipticRgn(PosCircle+PalettePSPCoord.Left,PalettePSPCoord.Top,PosCircle+PalettePSPCoord.Right,PalettePSPCoord.Bottom);
PCircle := CreateEllipticRgn(PosCircle+PalettePSPCoord.Left+20,PalettePSPCoord.Top+20,PosCircle+PalettePSPCoord.Right-21,PalettePSPCoord.Bottom-21);
Disque := CreateRectRgn(0,0,2,2);
CombineRgn(Disque,GCircle,PCircle,RGN_DIFF);
Car := CreateRectRgn(PosCar+RectPSP.Left,RectPSP.Top,PosCar+RectPSP.Right,RectPSP.Bottom);
if PtInRegion(Car,X,Y)
then
ClickImg := czpspPCar
else
if PtInRegion(Disque,X,Y)
then
ClickImg := czpspPCircle
else
ClickImg := czpspPnone;
if mbLeft = Button then
case ClickImg of
czpspPCircle :
begin
C_X := PosCar+RectPSP.Left+(RectPSP.Right-RectPSP.Left)div 2;
C_Y := RectPSP.Top+(RectPSP.Bottom-RectPSP.Top)div 2;;
Angle := Round(CalcAngle3Points(C_X, 0, C_X, C_Y, X, Y));
if Angle = 360 then Angle := 0;
Angle := 359 - Angle;
HSLPSP := PSPColor.HSLPSP;
HSLPSP.H := Round(255 * (Angle / 359));
if HSLPSP.H <> PSPColor.HSLPSP.H
then
begin
DrawCursor;
PSPColor.HSLPSP := HSLPSP;
ChangeEdits;
DrawPSPPalette;
end;
end;
czpspPCar :
begin
C_X := X;
C_Y := Y;
if C_X<PosCar+RectPSP.Left
then
C_X:= PosCar+RectPSP.Left
else
if C_X>PosCar+RectPSP.Right
then
C_X:= PosCar+RectPSP.Right;
if C_Y<RectPSP.Top
then
C_Y:= RectPSP.Top
else
if C_Y>RectPSP.Bottom
then
C_Y:= RectPSP.Bottom;
HSLPSP := PSPColor.HSLPSP;
HSLPSP.S := Round(255 * ((C_X - (PosCar+RectPSP.Left)) / (RectPSP.Right-RectPSP.Left)));
HSLPSP.L := Round(255 * ((C_Y - RectPSP.Top)/(RectPSP.Bottom - RectPSP.Top)));
DrawCursor;
PSPColor.HSLPSP := HSLPSP;
ChangeEdits;
DrawCursor;
PalettePSP.Repaint;
end;
end;
end;
procedure TbsSkinColorDialog.PalettePSPMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var
HSLPSP : THSLPSP;
C_X,C_Y : Integer;
Angle : Integer;
begin
if ssLeft in Shift then
case ClickImg of
czpspPCircle:
begin
C_X := PosCar + RectPSP.Left + (RectPSP.Right - RectPSP.Left)div 2;
C_Y := RectPSP.Top + (RectPSP.Bottom - RectPSP.Top) div 2;
Angle := Round(CalcAngle3Points(C_X, 0, C_X, C_Y, X, Y));
if Angle = 360 then Angle := 0;
Angle := 359 - Angle;
HSLPSP := PSPColor.HSLPSP;
HSLPSP.H := Round(255*(Angle/359));
if HSLPSP.H <> PSPColor.HSLPSP.H
then
begin
DrawCursor;
PSPColor.HSLPSP := HSLPSP;
ChangeEdits;
DrawPSPPalette;
end;
end;
czpspPCar :
begin
C_X := X;
C_Y := Y;
if C_X < PosCar+RectPSP.Left
then
C_X := PosCar+RectPSP.Left
else
if C_X > PosCar+RectPSP.Right
then
C_X := PosCar+RectPSP.Right;
if C_Y < RectPSP.Top
then
C_Y := RectPSP.Top
else
if C_Y > RectPSP.Bottom
then
C_Y := RectPSP.Bottom;
HSLPSP := PSPColor.HSLPSP;
HSLPSP.S := Round(255 * ((C_X-(PosCar+RectPSP.Left)) / (RectPSP.Right-RectPSP.Left)));
HSLPSP.L := Round(255 * ((C_Y-RectPSP.Top) / (RectPSP.Bottom-RectPSP.Top)));
DrawCursor;
PSPColor.HSLPSP := HSLPSP;
ChangeEdits;
DrawCursor;
PalettePSP.Repaint;
end;
end;
end;
procedure TbsSkinColorDialog.PalettePSPMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
HSLPSP : THSLPSP;
C_X,C_Y : Integer;
Angle : Integer;
begin
if mbLeft=Button then
case ClickImg of
czpspPCircle :
begin
C_X := PosCar+RectPSP.Left+(RectPSP.Right-RectPSP.Left)div 2;
C_Y := RectPSP.Top+(RectPSP.Bottom-RectPSP.Top)div 2;;
Angle := Round(CalcAngle3Points(C_X, 0, C_X, C_Y, X,Y));
if Angle = 360 then Angle := 0;
Angle := 359 - Angle;
HSLPSP := PSPColor.HSLPSP;
HSLPSP.H := Round(255 * (Angle / 359));
if HSLPSP.H <> PSPColor.HSLPSP.H
then
begin
DrawCursor;
PSPColor.HSLPSP := HSLPSP;
ChangeEdits;
DrawPSPPalette;
end;
end;
czpspPCar :
begin
C_X := X;
C_Y := Y;
if C_X<PosCar+RectPSP.Left
then
C_X:= PosCar+RectPSP.Left
else
if C_X>PosCar+RectPSP.Right
then
C_X:= PosCar+RectPSP.Right;
if C_Y<RectPSP.Top
then
C_Y:= RectPSP.Top
else
if C_Y>RectPSP.Bottom
then
C_Y:= RectPSP.Bottom;
HSLPSP := PSPColor.HSLPSP;
HSLPSP.S := Round(255 * ((C_X - (PosCar + RectPSP.Left)) / (RectPSP.Right - RectPSP.Left)));
HSLPSP.L := Round(255 * ((C_Y - RectPSP.Top) / (RectPSP.Bottom-RectPSP.Top)));
DrawCursor;
PSPColor.HSLPSP := HSLPSP;
ChangeEdits;
DrawCursor;
PalettePSP.Repaint;
end;
end;
ClickImg := czpspPnone;
end;
constructor TbsSkinCustomColorGrid.Create(AOwner: TComponent);
var
i: Integer;
begin
inherited;
ControlStyle := ControlStyle - [csAcceptsControls];
CaptionMode := True;
Caption := BS_CUSTOMCOLORGRID_CAP;
BorderStyle := bvFrame;
Width := 280;
Height := 115;
FColorValue := 0;
FColCount := 6;
FRowCount := 2;
for i := 1 to 12 do CustomColorValues[I] := clWhite;
FColorsCount := 0;
FColorIndex := 0;
end;
destructor TbsSkinCustomColorGrid.Destroy;
begin
inherited;
end;
procedure TbsSkinCustomColorGrid.AddColor(AColor: TColor);
begin
if FColorsCount = 12 then FColorsCount := 0;
Inc(FColorsCount);
CustomColorValues[FColorsCount] := AColor;
RePaint;
end;
procedure TbsSkinCustomColorGrid.SetColCount(Value: Integer);
begin
if Value < 1 then Exit;
FColCount := Value;
RePaint;
end;
procedure TbsSkinCustomColorGrid.SetRowCount(Value: Integer);
begin
FRowCount := Value;
RePaint;
end;
procedure TbsSkinCustomColorGrid.DrawCursor;
var
CX, CY, Rd: Integer;
begin
CX := R.Left + RectWidth(R) div 2;
CY := R.Top + RectHeight(R) div 2;
if RectWidth(R) > RectHeight(R)
then
Rd := RectHeight(R) div 2 - 2
else
Rd := RectWidth(R) div 2 - 2;
with Cnvs do
begin
if pmNotMode then Pen.Mode := pmNot else Pen.Color := 0;
MoveTo(CX - rd, CY); LineTo(CX - 2, CY);
MoveTo(CX + 3, CY); LineTo(CX + rd + 1, CY);
MoveTo(CX, CY - rd); LineTo(CX, CY - 2);
MoveTo(CX, CY + 3); LineTo(CX, CY + rd);
end;
end;
procedure TbsSkinCustomColorGrid.PaintGrid(Cnvs: TCanvas);
var
X, Y, CW, CH, i, j, k: Integer;
R, Rct: TRect;
begin
R := Rect(0, 0, Width, Height);
AdjustClientRect(R);
CW := (RectWidth(R) - ColCount * 2) div ColCount;
CH := (RectHeight(R) - RowCount * 2) div RowCount;
Y := R.Top + 1;
k := 0;
for i := 1 to RowCount do
begin
X := R.Left + 1;
for j := 1 to ColCount do
begin
Inc(k);
with Cnvs do
begin
Brush.Color := CustomColorValues[k];
Rct := Rect(X, Y, X + CW, Y + CH);
InflateRect(Rct, -1, -1);
FillRect(Rct);
InflateRect(Rct, 1, 1);
if k = FColorIndex
then
begin
if CustomColorValues[k] <> clGray
then
DrawCursor(Cnvs, Rct, True)
else
DrawCursor(Cnvs, Rct, False);
end
end;
Inc(X, CW + 2);
end;
Inc(Y, CH + 2);
end;
end;
procedure TbsSkinCustomColorGrid.CreateControlDefaultImage;
begin
inherited;
PaintGrid(B.Canvas);
end;
procedure TbsSkinCustomColorGrid.CreateControlSkinImage;
begin
inherited;
PaintGrid(B.Canvas);
end;
procedure TbsSkinCustomColorGrid.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
var
X1, Y1, CW, CH, i, j, k: Integer;
R, Rct: TRect;
begin
inherited;
R := Rect(0, 0, Width, Height);
AdjustClientRect(R);
CW := (RectWidth(R) - ColCount * 2) div ColCount;
CH := (RectHeight(R) - RowCount * 2) div RowCount;
Y1 := R.Top + 1;
k := 0;
for i := 1 to RowCount do
begin
X1 := R.Left + 1;
for j := 1 to ColCount do
begin
Inc(k);
Rct := Rect(X1, Y1, X1 + CW, Y1 + CH);
if PtInRect(Rct, Point(X, Y))
then
begin
FColorValue := CustomColorValues[k];
FColorIndex := k;
RePaint;
if Assigned(FOnChange) then FOnChange(Self);
Break;
end;
Inc(X1, CW + 2);
end;
Inc(Y1, CH + 2);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -