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

📄 spcolorctrls.pas

📁 一款支持Delphi和C++ Builder的VCL控件
💻 PAS
📖 第 1 页 / 共 5 页
字号:
      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 TspSkinColorDialog.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 TspSkinCustomColorGrid.Create(AOwner: TComponent);
var
  i: Integer;
begin
  inherited;
  ControlStyle := ControlStyle - [csAcceptsControls];
  FForceBackground := False;
  CaptionMode := True;
  Caption := SP_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 TspSkinCustomColorGrid.Destroy;
begin
  inherited;
end;

procedure TspSkinCustomColorGrid.PaintTransparent;
begin
  PaintGrid(C);
end;


procedure TspSkinCustomColorGrid.WMEraseBkgnd;
begin
  if not FromWMPaint
  then
    begin
      PaintWindow(Msg.DC);
    end;
end;

procedure TspSkinCustomColorGrid.AddColor(AColor: TColor);
begin
  if FColorsCount = 12 then FColorsCount := 0;
  Inc(FColorsCount);
  CustomColorValues[FColorsCount] := AColor;
  RePaint;
end;

procedure TspSkinCustomColorGrid.SetColCount(Value: Integer);
begin
  if Value < 1 then Exit;
  FColCount := Value;
  RePaint;
end;

procedure TspSkinCustomColorGrid.SetRowCount(Value: Integer);
begin
  FRowCount := Value;
  RePaint;
end;

procedure TspSkinCustomColorGrid.DrawCursor;
var
  Buffer: TBitMap;
  CIndex: Integer;
  ButtonData: TspDataSkinButtonControl;
  BtnSkinPicture: TBitMap;
  BtnLtPoint, BtnRTPoint, BtnLBPoint, BtnRBPoint: TPoint;
  BtnCLRect: TRect;
  XO, YO: Integer;
  SR: TRect;
begin
  if FIndex = -1
  then
    begin
      Buffer := TBitMap.Create;
      Buffer.Width := RectWidth(R);
      Buffer.Height := RectHeight(R);
      with Buffer.Canvas do
      begin
        Brush.Color :=  SP_XP_BTNDOWNCOLOR;
        Pen.Color := SP_XP_BTNFRAMECOLOR;
        Rectangle(0, 0, Buffer.Width, Buffer.Height);
      end;
      Cnvs.Draw(R.Left, R.Top, Buffer);
      Buffer.Free;
      Exit;
    end;
  CIndex := SkinData.GetControlIndex('resizebutton');
  if CIndex = -1
  then
    Exit
  else
    ButtonData := TspDataSkinButtonControl(SkinData.CtrlList[CIndex]);
    
  Buffer := TBitMap.Create;
  Buffer.Width := RectWidth(R);
  Buffer.Height := RectHeight(R);
  //
  with ButtonData do
  begin
    XO := RectWidth(R) - RectWidth(SkinRect);
    YO := RectHeight(R) - RectHeight(SkinRect);
    BtnLTPoint := LTPoint;
    BtnRTPoint := Point(RTPoint.X + XO, RTPoint.Y);
    BtnLBPoint := Point(LBPoint.X, LBPoint.Y + YO);
    BtnRBPoint := Point(RBPoint.X + XO, RBPoint.Y + YO);
    BtnClRect := Rect(CLRect.Left, ClRect.Top,
      CLRect.Right + XO, ClRect.Bottom + YO);
    BtnSkinPicture := TBitMap(SkinData.FActivePictures.Items[ButtonData.PictureIndex]);
    SR := DownSkinRect;
    if IsNullRect(SR) then SR := ActiveSkinRect;
    CreateSkinImage(LTPoint, RTPoint, LBPoint, RBPoint, CLRect,
        BtnLtPoint, BtnRTPoint, BtnLBPoint, BtnRBPoint, BtnCLRect,
        Buffer, BtnSkinPicture, SR, Buffer.Width, Buffer.Height, True,
        LeftStretch, TopStretch, RightStretch, BottomStretch,
        StretchEffect, StretchType);
  end;
  //
  Cnvs.Draw(R.Left, R.Top, Buffer);
  Buffer.Free;
end;


procedure TspSkinCustomColorGrid.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 := CustomColorValues[k];

        Rct := Rect(X - 1, Y -1 , X + CW + 1, Y + CH + 1);

        if k = FColorIndex
        then
          begin
            DrawCursor(Cnvs, Rct);
          end;

        if k = FColorIndex
        then
          Rct := Rect(X + 3, Y + 3 , X + CW - 3, Y + CH - 3)
        else
          Rct := Rect(X + 2, Y + 2 , X + CW - 2, Y + CH - 2);
          
        InflateRect(Rct, -1, -1);
        FillRect(Rct);
        InflateRect(Rct, 1, 1);
      end;
      Inc(X, CW + 2);
    end;
    Inc(Y, CH + 2);
  end;
end;

procedure TspSkinCustomColorGrid.CreateControlDefaultImage;
begin
  inherited;
  PaintGrid(B.Canvas);
end;

procedure TspSkinCustomColorGrid.CreateControlSkinImage;
begin
  inherited;
  PaintGrid(B.Canvas);
end;

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


constructor TspSkinColorButton.Create(AOwner: TComponent);
begin
  inherited;
  FDrawColorMarker := True;
  ColorDialog := nil;
  FColorMarkerValue := 0;
  FColorImages := TCustomImageList.Create(Self);
  FColorMenu := TspSkinImagesMenu.Create(Self);
  FColorMenu.Images := FColorImages;
  FColorMenu.OnItemClick := OnImagesMenuClick;
  FColorMenu.OnMenuPopup := OnImagesMenuPopup;
  FAutoColor := 0;
  FShowAutoColor := True;
  FShowMoreColor := True;
  InitColors;
end;

procedure TspSkinColorButton.SetShowAutoColor(Value: Boolean);
begin
  if FShowAutoColor <> Value
  then
    begin
      FShowAutoColor := Value;
      if not (csDesigning in ComponentState) and
         not (csLoading in ComponentState)
      then
        InitColors;
    end;
end;

procedure TspSkinColorButton.SetShowMoreColor(Value: Boolean);
begin
  if FShowMoreColor <> Value
  then
    begin
      FShowMoreColor := Value;
      if not (csDesigning in ComponentState) and
         not (csLoading in ComponentState)
      then
        InitColors;
    end;
end;

procedure TspSkinColorButton.SetColorValue;
begin
  FColorMarkerValue := Value;
  RePaint;
  if not (csDesigning in ComponentState) and
     not (csLoading in ComponentState)
  then
    if Assigned(FOnChangeColor) then FOnChangeColor(Self);
end;

procedure TspSkinColorButton.InitColors;
var
  B: TBitMap;
  Item: TspImagesMenuItem;
  I: Integer;
begin
  //
  FSkinImagesMenu := FColorMenu;
  FSkinPopupMenu := nil;
  //
  if FColorImages.Count <> 0 then FColorImages.Clear;
  if FColorMenu.ImagesItems.Count <> 0 then FColorMenu.ImagesItems.Clear;
  // init menu
  FColorMenu.ColumnsCount := 8;
  FColorMenu.SkinData := Self.SkinData;
  FColorMenu.ItemIndex := 0;
  // 1
  if FShowAutoColor
  then
    begin
      Item := TspImagesMenuItem(FColorMenu.ImagesItems.Add);
      with Item do
      begin
        ImageIndex := 0;
        FColor := FAutoColor;
        if (FColorMenu.SkinData <> nil) and
           (FColorMenu.SkinData.ResourceStrData <> nil)
        then
          Caption := FColorMenu.SkinData.ResourceStrData.GetResStr('AUTOCOLOR')
        else
          Caption := SP_AUTOCOLOR;
        Button := True;
      end;
    end;
  // 2
  Item := TspImagesMenuItem(FColorMenu.ImagesItems.Add);
  with Item do
  begin
    ImageIndex := 1;
    FColor := clBlack;
  end;
  // 3
  Item := TspImagesMenuItem(FColorMenu.ImagesItems.Add);
  with Item do
  begin
    ImageIndex := 2;
    FColor := $00003399;;
  end;
  // 4
  Item := TspImagesMenuItem(FColorMenu.ImagesItems.Add);
  with Item do
  begin
    ImageIndex := 3;
    FColor := $00003333;
  end;
  // 5
  Item := TspImagesMenuItem(FColorMenu.ImagesItems.Add);
  with Item do
  begin
    ImageIndex := 4;
    FColor := $00003300;
  end;
  // 6
  Item := TspImagesMenuItem(FColorMenu.ImagesItems.Add);
  with Item do
  begin
    ImageIndex := 5;
    FColor := $00663300;
  end;
  // 7
  Item := TspImagesMenuItem(FColorMenu.ImagesItems.Add);
  with Item do
  begin
    ImageIndex := 6;
    FColor := clNavy;
  end;
  // 8
  Item := TspImagesMenuItem(FColorMenu.ImagesItems.Add);
  with Item do
  begin
    ImageIndex := 7;
    FColor := $00353333;
  end;
  // 9
  Item := TspImagesMenuItem(FColorMenu.ImagesItems.Add);
  with Item do
  begin
    ImageIndex := 8;
    FColor := $00333333;
  end;
  // 10
  Item := TspImagesMenuItem(FColorMenu.ImagesItems.Add);
  with Item do
  begin
    ImageIndex := 9;
    FColor := RGB(128, 0, 0);
  end;
  // 11
  Item := TspImagesMenuItem(FColorMenu.ImagesItems.Add);
  with Item do
  begin
    ImageIndex := 10;
    FColor := RGB(255, 102, 0);
  end;
  // 12
  Item := TspImagesMenuItem(FColorMenu.ImagesItems.Add);
  with Item do
  begin
    I

⌨️ 快捷键说明

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