📄 bscolorctrls.pas
字号:
1:
begin
R := Round(q);
G := Round(L);
B := Round(p);
end;
2:
begin
R := Round(p);
G := Round(L);
B := Round(t);
end;
3:
begin
R := Round(p);
G := Round(q);
B := Round(L);
end;
4:
begin
R := Round(t);
G := Round(p);
B := Round(L);
end;
else
R := Round(L);
G := Round(p);
B := Round(q);
end;
end;
end;
procedure TbsEmptyControl.WMEraseBkgnd;
begin
Msg.Result := 1;
end;
procedure TbsEmptyControl.Paint;
begin
end;
constructor TbsSkinColorGrid.Create(AOwner: TComponent);
begin
inherited;
ControlStyle := ControlStyle - [csAcceptsControls];
FForceBackground := False;
CaptionMode := True;
Caption := BS_COLORGRID_CAP;
BorderStyle := bvFrame;
Width := 280;
Height := 115;
FColorValue := 0;
FColCount := 12;
FRowCount := 4;
end;
procedure TbsSkinColorGrid.WMEraseBkgnd;
begin
if not FromWMPaint
then
begin
PaintWindow(Msg.DC);
end;
end;
procedure TbsSkinColorGrid.PaintTransparent;
begin
PaintGrid(C);
end;
destructor TbsSkinColorGrid.Destroy;
begin
inherited;
end;
procedure TbsSkinColorGrid.SetColCount(Value: Integer);
begin
if Value < 1 then Exit;
FColCount := Value;
RePaint;
end;
procedure TbsSkinColorGrid.SetRowCount(Value: Integer);
begin
FRowCount := Value;
RePaint;
end;
procedure TbsSkinColorGrid.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 TbsSkinColorGrid.PaintGrid(Cnvs: TCanvas);
var
RX, RY, X, Y, CW, CH, i, j, k: Integer;
R, R1, 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;
//
R1 := Rect(0, 0, (CW + 2) * ColCount, (CH + 2) * RowCount);
RX := R.Left + RectWidth(R) div 2 - RectWidth(R1) div 2;
RY := R.Top + RectHeight(R) div 2 - RectHeight(R1) div 2;
R := Rect(RX, RY, RX + RectWidth(R1), RectHeight(R1));
//
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 := ColorValues[k];
Rct := Rect(X, Y, X + CW, Y + CH);
InflateRect(Rct, -1, -1);
FillRect(Rct);
InflateRect(Rct, 1, 1);
if FColorValue = ColorValues[k]
then
begin
if ColorValues[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 TbsSkinColorGrid.CreateControlDefaultImage;
begin
inherited;
PaintGrid(B.Canvas);
end;
procedure TbsSkinColorGrid.CreateControlSkinImage;
begin
inherited;
PaintGrid(B.Canvas);
end;
function TbsSkinColorGrid.CheckColor(Value: TColor): boolean;
var
I: Integer;
begin
Result := False;
for I := 1 to 48 do
if ColorValues[I] = Value
then
begin
Result := True;
Break;
end;
end;
procedure TbsSkinColorGrid.SetColorValue(Value: TColor);
begin
FColorValue := Value;
if CheckColor(FColorValue)
then
begin
if Assigned(FOnChange) then FOnChange(Self);
RePaint;
end;
end;
procedure TbsSkinColorGrid.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
var
RX, RY, X1, Y1, CW, CH, i, j, k: Integer;
R, R1, 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;
R1 := Rect(0, 0, (CW + 2) * ColCount, (CH + 2) * RowCount);
RX := R.Left + RectWidth(R) div 2 - RectWidth(R1) div 2;
RY := R.Top + RectHeight(R) div 2 - RectHeight(R1) div 2;
R := Rect(RX, RY, RX + RectWidth(R1), RectHeight(R1));
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
ColorValue := ColorValues[k];
Break;
end;
Inc(X1, CW + 2);
end;
Inc(Y1, CH + 2);
end;
end;
constructor TbsColorViewer.Create(AOwner: TComponent);
begin
inherited;
ControlStyle := ControlStyle + [csOpaque];
FColorValue := 0;
end;
procedure TbsColorViewer.Paint;
var
B: TBitMap;
begin
B := TBitMap.Create;
B.Width := Width;
B.Height := Height;
with B.Canvas do
begin
Pen.Color := clBlack;
Brush.Color := FColorValue;
Rectangle(0, 0, Width, Height);
end;
Canvas.Draw(0, 0, B);
B.Free;
end;
procedure TbsColorViewer.SetColorValue;
begin
if FColorValue = Value then Exit;
FColorValue := Value;
RePaint;
end;
function TPSPColor.RGBToHSL(Value: TRGB): THSL;
var
R,
G,
B,
D,
Cmax,
Cmin: double;
begin
R := Value.R / 255;
G := Value.G / 255;
B := Value.B / 255;
Cmax := Max (R, Max (G, B));
Cmin := Min (R, Min (G, B));
// calculate luminosity
Result.L := (Cmax + Cmin) / 2;
if Cmax = Cmin then
begin
Result.H := 0;
Result.S := 0
end else begin
D := Cmax - Cmin;
// calculate Saturation
if Result.L < 0.5 then
Result.S := D / (Cmax + Cmin)
else
Result.S := D / (2 - Cmax - Cmin);
// calculate Hue
if R = Cmax then
Result.H := (G - B) / D
else
if G = Cmax then
Result.H := 2 + (B - R) /D
else
Result.H := 4 + (R - G) / D;
Result.H := Result.H / 6;
if Result.H < 0 then
Result.H := Result.H + 1
end
end;
function TPSPColor.HSLToRGB(Value: THSL): TRGB;
var
M1,
M2: double;
function HueToColourValue (Hue: double) : byte;
var
V : double;
begin
if Hue < 0 then
Hue := Hue + 1
else
if Hue > 1 then
Hue := Hue - 1;
if 6 * Hue < 1 then
V := M1 + (M2 - M1) * Hue * 6
else
if 2 * Hue < 1 then
V := M2
else
if 3 * Hue < 2 then
V := M1 + (M2 - M1) * (2/3 - Hue) * 6
else
V := M1;
Result := round (255 * V)
end;
begin
if Value.S = 0 then
begin
Result.R := round (255 * Value.L);
Result.G := Result.R;
Result.B := Result.R
end else begin
if Value.L <= 0.5 then
M2 := Value.L * (1 + Value.S)
else
M2 := Value.L + Value.S - Value.L * Value.S;
M1 := 2 * Value.L - M2;
Result.R := HueToColourValue (Value.H + 1/3);
Result.G := HueToColourValue (Value.H);
Result.B := HueToColourValue (Value.H - 1/3)
end;
end;
function TPSPColor.HSLToHSLPSP: THSLPSP;
begin
Result.H := round(FHSL.H*255);
Result.S := round(FHSL.S*255);
Result.L := round(FHSL.L*255);
end;
function TPSPColor.HSLPSPToHSL: THSL;
begin
Result.H := FHSLPSP.H/255;
Result.S := FHSLPSP.S/255;
Result.L := FHSLPSP.L/255;
end;
constructor TPSPColor.Create;
begin
inherited;
end;
destructor TPSPColor.Destroy;
begin
inherited;
end;
procedure TPSPColor.SetRGB(const Value: TRGB);
begin
FRGB := Value;
FHSL := RGBToHSL(FRGB);
FHSLPSP := HSLToHSLPSP();
end;
procedure TPSPColor.SeTHSL(const Value: THSL);
begin
FHSL := Value;
FRGB := HSLToRGB(FHSL);
FHSLPSP := HSLToHSLPSP;
end;
procedure TPSPColor.SeTHSLPSP(const Value: THSLPSP);
begin
FHSLPSP := Value;
FHSL := HSLPSPToHSL;
FRGB := HSLToRGB(FHSL);
end;
procedure TPSPColor.Assign(const Value: TPSPColor);
begin
FRGB := Value.FRGB;
FHSL := Value.FHSL;
FHSLPSP := Value.FHSLPSP;
end;
constructor TbsSkinColorDialog.Create;
var
I: Integer;
begin
inherited Create(AOwner);
FGroupBoxTransparentMode := False;
RGBStopCheck := False;
HSLStopCheck := False;
FromPSP := False;
FColor := 0;
PSPColor := TPSPColor.Create;
FAlphaBlend := False;
FAlphaBlendAnimation := False;
FAlphaBlendValue := 200;
FCaption := 'Set color';
FButtonSkinDataName := 'button';
FLabelSkinDataName := 'stdlabel';
FEditSkinDataName := 'edit';
FDefaultLabelFont := TFont.Create;
FDefaultButtonFont := TFont.Create;
FDefaultEditFont := TFont.Create;
FUseSkinFont := True;
with FDefaultLabelFont do
begin
Name := 'Arial';
Style := [];
Height := 14;
end;
with FDefaultButtonFont do
begin
Name := 'Arial';
Style := [];
Height := 14;
end;
with FDefaultEditFont do
begin
Name := 'Arial';
Style := [];
Height := 14;
end;
for I := 1 to 12 do CustomColorValues[I] := clWhite;
CustomColorValuesCount := 0;
end;
destructor TbsSkinColorDialog.Destroy;
begin
PSPColor.Free;
FDefaultLabelFont.Free;
FDefaultButtonFont.Free;
FDefaultEditFont.Free;
inherited;
end;
procedure TbsSkinColorDialog.ChangeEdits;
var
R, G, B: Byte;
begin
FromPSP := True;
R := PSPColor.FRGB.R;
G := PSPColor.FRGB.G;
B := PSPColor.FRGB.B;
REdit.Value := R;
GEdit.Value := G;
BEdit.Value := B;
FromPSP := False;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -