⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spcolorctrls.pas

📁 一款支持Delphi和C++ Builder的VCL控件
💻 PAS
📖 第 1 页 / 共 5 页
字号:

  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 TspSkinColorDialog.Destroy;
begin
  PSPColor.Free;
  FDefaultLabelFont.Free;
  FDefaultButtonFont.Free;
  FDefaultEditFont.Free;
  inherited;
end;

procedure TspSkinColorDialog.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;

procedure TspSkinColorDialog.HSLEditChange(Sender: TObject);
var
  R, G, B: Byte;
  RGB: TRGB;
begin
  if HSLStopCheck then Exit;
  HSLTORGB(R, G, B, HEdit.Value, SEdit.Value, LEdit.Value);
  ColorViewer.ColorValue := R_G_BToColor(R, G, B);
  RGBStopCheck := True;
  //
  REdit.Value := R;
  GEdit.Value := G;
  BEdit.Value := B;
  //
  if not FromPSP
  then
    begin
      DrawCursor;
      RGB.R := R;
      RGB.G := G;
      RGB.B := B;
      PSPColor.SetRGB(RGB);
      DrawPSPPalette;
    end;  
  //
  RGBStopCheck := False;
end;

procedure TspSkinColorDialog.AddCustomColorButtonClick(Sender: TObject);
begin
  CustomColorGrid.AddColor(ColorViewer.ColorValue);
end;

procedure TspSkinColorDialog.RGBEditChange(Sender: TObject);
var
  R, G, B: Byte;
  H, S, L: Integer;
  RGB: TRGB;
begin
  if RGBStopCheck then Exit;
  ColorViewer.ColorValue := R_G_BToColor(REdit.Value, GEdit.Value, BEdit.Value);
  ColorToR_G_B(ColorViewer.ColorValue, R, G, B);
  HSLStopCheck := True;
  RGBToHSL(R, G, B, H, S, L);
  HEdit.Value := H;
  SEdit.Value := S;
  LEdit.Value := L;
  //
  if not FromPSP
  then
    begin
      DrawCursor;
      RGB.R := R;
      RGB.G := G;
      RGB.B := B;
      PSPColor.SetRGB(RGB);
      DrawPSPPalette;
    end;  
  //
  HSLStopCheck := False;
end;

procedure TspSkinColorDialog.CustomColorGridChange(Sender: TObject);
var
  R, G, B: Byte;
  H, S, L: Integer;
  RGB: TRGB;
begin
  ColorToR_G_B(CustomColorGrid.ColorValue, R, G, B);
  RGBStopCheck := True;
  REdit.Value := R;
  GEdit.Value := G;
  BEdit.Value := B;
  RGBStopCheck := False;
  ColorViewer.ColorValue := CustomColorGrid.ColorValue;
  RGBToHSL(R, G, B, H, S, L);
  HSLStopCheck := True;
  HEdit.Value := H;
  SEdit.Value := S;
  LEdit.Value := L;
  if not FromPSP
  then
    begin
      DrawCursor;
      RGB.R := R;
      RGB.G := G;
      RGB.B := B;
      PSPColor.SetRGB(RGB);
      DrawPSPPalette;
    end;  
  HSLStopCheck := False;
end;

procedure TspSkinColorDialog.ColorGridChange(Sender: TObject);
var
  R, G, B: Byte;
  H, S, L: Integer;
  RGB: TRGB;
begin
  ColorToR_G_B(ColorGrid.ColorValue, R, G, B);
  RGBStopCheck := True;
  REdit.Value := R;
  GEdit.Value := G;
  BEdit.Value := B;
  RGBStopCheck := False;
  ColorViewer.ColorValue := ColorGrid.ColorValue;
  RGBToHSL(R, G, B, H, S, L);
  HSLStopCheck := True;
  HEdit.Value := H;
  SEdit.Value := S;
  LEdit.Value := L;
  if not FromPSP
  then
    begin
      DrawCursor;
      RGB.R := R;
      RGB.G := G;
      RGB.B := B;
      PSPColor.SetRGB(RGB);
      DrawPSPPalette;
    end;  
  HSLStopCheck := False;
end;

procedure TspSkinColorDialog.SetDefaultLabelFont;
begin
  FDefaultLabelFont.Assign(Value);
end;

procedure TspSkinColorDialog.SetDefaultEditFont;
begin
  FDefaultEditFont.Assign(Value);
end;

procedure TspSkinColorDialog.SetDefaultButtonFont;
begin
  FDefaultButtonFont.Assign(Value);
end;

procedure TspSkinColorDialog.Notification;
begin
  inherited Notification(AComponent, Operation);
  if (Operation = opRemove) and (AComponent = FSD) then FSD := nil;
  if (Operation = opRemove) and (AComponent = FCtrlFSD) then FCtrlFSD := nil;
end;

function TspSkinColorDialog.Execute: Boolean;
var
  Form: TForm;
  DSF: TspDynamicSkinForm;
  ButtonTop, ButtonWidth, ButtonHeight: Integer;
  R, G, B: Byte;
  Temp : TRGB;
  I: Integer;
  PSPBGColor: TColor;
begin
  Form := TForm.Create(Application);
  Form.BorderStyle := bsDialog;
  Form.Caption := FCaption;
  Form.Position := poScreenCenter;

  DSF := TspDynamicSkinForm.Create(Form);
  DSF.SizeAble := False;
  DSF.BorderIcons := [];
  DSF.SkinData := SkinData;
  DSF.MenusSkinData := CtrlSkinData;
  DSF.AlphaBlend := AlphaBlend;
  DSF.AlphaBlendAnimation := AlphaBlendAnimation;
  DSF.AlphaBlendValue := AlphaBlendValue;

  try

  Form.ClientWidth := 378;

  ColorGrid := TspSkinColorGrid.Create(Form);
  with ColorGrid do
  begin
    BorderStyle := bvNone;
    Parent := Form;
    if FGroupBoxTransparentMode
    then
      TransparentMode := FGroupBoxTransparentMode;
    CaptionMode := True;
    RowCount := 8;
    ColCount := 6;
    Left := 5;
    Top := 5;
    Width := 167;
    Height := 195;
    SkinDataName := 'groupbox';
    SkinData := CtrlSkinData;
    if (SkinData <> nil) and (SkinData.ResourceStrData <> nil)
    then
      Caption := SkinData.ResourceStrData.GetResStr('COLORGRID_CAP')
    else
      Caption := SP_COLORGRID_CAP;
    OnChange := ColorGridChange;
  end;

  CustomColorGrid := TspSkinCustomColorGrid.Create(Form);
  with CustomColorGrid  do
  begin
    Parent := Form;
     if FGroupBoxTransparentMode
    then
      TransparentMode := FGroupBoxTransparentMode;
    CaptionMode := True;
    Left := 5;
    Top := ColorGrid.Top + ColorGrid.Height + 10;
    Width := 167;
    Height := 68;
    SkinDataName := 'groupbox';
    SkinData := CtrlSkinData;
    if (SkinData <> nil) and (SkinData.ResourceStrData <> nil)
    then
      Caption := SkinData.ResourceStrData.GetResStr('CUSTOMCOLORGRID_CAP')
    else
      Caption := SP_CUSTOMCOLORGRID_CAP;
    OnChange := CustomColorGridChange;
  end;

  for I := 1 to 12 do
    CustomColorGrid.CustomColorValues[I] := Self.CustomColorValues[I];
  CustomColorGrid.FColorsCount := CustomColorValuesCount;

  //
  PalettePSPPanel:= TspEmptyControl.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;

  //

  RLabel := TspSkinStdLabel.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 := TspSkinTrackEdit.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 := TspSkinStdLabel.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 := TspSkinTrackEdit.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 := TspSkinStdLabel.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 := TspSkinTrackEdit.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 := TspSkinStdLabel.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 := TspSkinTrackEdit.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 := TspSkinStdLabel.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 := TspSkinTrackEdit.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 := TspSkinStdLabel.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 := TspSkinTrackEdit.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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -