cxlookandfeelpainters.pas

来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,181 行 · 第 1/5 页

PAS
1,181
字号
end;

function cxExtendedStylePaintersSortProc(Item1: TcxExtendedStylePainterInfo;
  Item2: TcxExtendedStylePainterInfo): Integer;
begin
  Result := AnsiCompareStr(Item1.Name, Item2.Name);
end;

{ TSystemPaletteChangedNotifier }

procedure TSystemPaletteChangedNotifier.DoChanged;
begin
  if FRadioButtonImageList <> nil then
    FRadioButtonImageList.Reset;
end;

{ TcxCustomLookAndFeelPainter }

class procedure TcxCustomLookAndFeelPainter.DrawBackground(ACanvas: TcxCanvas;
  const ARect: TRect; ATransparent: Boolean; ABackgroundColor: TColor;
  const ABackgroundBitmap: TBitmap);
begin
  if not ATransparent then
  begin
    ACanvas.Brush.Color := ABackgroundColor;
    ACanvas.FillRect(ARect);
  end
  else
    if ABackgroundBitmap <> nil then
      ACanvas.FillRect(ARect, ABackgroundBitmap);
end;

class procedure TcxCustomLookAndFeelPainter.DrawButtonArrow(ACanvas: TcxCanvas;
  const R: TRect; AColor: TColor);
var
  P: array[0..2] of TPoint;

  procedure CalculatePoints;
  var
    ASize: TPoint;

    function _GetSize: TPoint;
    begin
      Result.X := (R.Right - R.Left) div 2;
      if not Odd(Result.X) then Inc(Result.X);
      Result.Y := Result.X div 2 + 1;
    end;

  begin
    with R do
    begin
      ASize := _GetSize;
      P[0] := Point((Left + Right - ASize.X) div 2, MulDiv(Top + Bottom - ASize.Y, 1, 2));
      P[1] := Point(P[0].X + ASize.X - 1, P[0].Y);
      P[2] := Point(P[0].X + ASize.X div 2, P[0].Y + ASize.Y - 1);
    end;
  end;

begin
  CalculatePoints;
  with ACanvas do
  begin
    Brush.Color := AColor;
    Pen.Color := AColor;
    Polygon(P);
  end;
end;

class procedure TcxCustomLookAndFeelPainter.DrawContent(ACanvas: TcxCanvas;
  const ABounds, ATextAreaBounds: TRect; AState: Integer; AAlignmentHorz: TAlignment;
  AAlignmentVert: TcxAlignmentVert; AMultiLine, AShowEndEllipsis: Boolean;
  const AText: string; AFont: TFont; ATextColor, ABkColor: TColor;
  AOnDrawBackground: TcxDrawBackgroundEvent = nil; AIsFooter: Boolean = False);
const
  MultiLines: array[Boolean] of Integer = (cxSingleLine, cxWordBreak);
  ShowEndEllipsises: array[Boolean] of Integer = (0, cxShowEndEllipsis);
begin
  with ACanvas do
  begin
    if not Assigned(AOnDrawBackground) or not AOnDrawBackground(ACanvas, ABounds) then
    begin
      SetBrushColor(ABkColor);
      FillRect(ABounds);
    end;
    if AText <> '' then
    begin
      Brush.Style := bsClear;
      Font := AFont;
      Font.Color := ATextColor;
      DrawText(AText, ATextAreaBounds, cxAlignmentsHorz[AAlignmentHorz] or
        cxAlignmentsVert[AAlignmentVert] or MultiLines[AMultiLine] or
        ShowEndEllipsises[AShowEndEllipsis]);
      Brush.Style := bsSolid;
    end;
  end;
end;

class procedure TcxCustomLookAndFeelPainter.DrawExpandButtonCross(ACanvas: TcxCanvas;
  const R: TRect; AExpanded: Boolean; AColor: TColor);
var
  ASize, X, Y: Integer;
begin
  with R do
  begin
    ASize := Right - Left - 2 * 2;
    X := GetRangeCenter(Left, Right);
    Y := GetRangeCenter(Top, Bottom);
  end;
  ACanvas.Brush.Color := AColor;
  ACanvas.FillRect(Rect(X - ASize div 2, Y, X + ASize div 2 + 1, Y + 1));
  if not AExpanded then
    ACanvas.FillRect(Rect(X, Y - ASize div 2, X + 1, Y + ASize div 2 + 1));
end;

class procedure TcxCustomLookAndFeelPainter.DrawGroupExpandButtonMark(ACanvas: TcxCanvas;
  const R: TRect; AExpanded: Boolean; AState: TcxButtonState);
var
  Size, X, MainY, I: Integer;

  procedure DrawOneMark(Y: Integer);
  var
    ASign, ADelta: Integer;
  begin
    if AExpanded then Inc(Y, Size);
    ASign := 2 * Ord(AExpanded) - 1;
    ADelta := Ord(Odd(I - MainY));
    if not AExpanded then
      ADelta := Ord(not Boolean(ADelta));
    ACanvas.MoveTo(X + ADelta, Y - ASign * ADelta);
    ACanvas.LineTo(X + Size, Y - ASign * Size);
    ACanvas.LineTo(X + 2 * Size + 1 - ADelta, Y + ASign * (1 - ADelta));
  end;

begin
  Size := 3;
  ACanvas.Pen.Color := ButtonSymbolColor(AState);
  with R do
  begin
    X := (Left + Right - (2 * Size + 1)) div 2;
    MainY := (Top + Bottom - 2 * (Size + 1)) div 2;
    for I := MainY to MainY + 4 - 1 do
      DrawOneMark(I + Ord(I >= MainY + 2) * (Size - 1));
  end;
end;

class procedure TcxCustomLookAndFeelPainter.DrawIndicatorCustomizationMark(
  ACanvas: TcxCanvas; const R: TRect; AColor: TColor);
const
  LineOffset = 3;
  LineCount = 5;
var
  X, Y, AWidth, I: Integer;

  procedure DrawLine(X, Y: Integer; AChecked: Boolean);
  begin
    with ACanvas do
    begin
      if AChecked then
        Pixels[X, Y] := Pen.Color;
      MoveTo(X + 2, Y);
      LineTo(X + AWidth, Y);
    end;
  end;

begin
  X := R.Left + LineOffset;
  AWidth := R.Right - R.Left - 2 * LineOffset;
  Y := (R.Top + R.Bottom - (2 * LineCount - 1)) div 2;
  ACanvas.Pen.Color := AColor;
  for I := 0 to LineCount - 1 do
  begin
    DrawLine(X, Y, not Odd(I));
    Inc(Y, 2);
  end;
end;

class procedure TcxCustomLookAndFeelPainter.DrawIndicatorImage(ACanvas: TcxCanvas;
  const R: TRect; AKind: TcxIndicatorKind);
var
  X, Y: Integer;
begin
  if AKind = ikNone then Exit;
  with cxIndicatorImages, R do
  begin
    X := (Left + Right - Width) div 2;
    Y := (Top + Bottom - Height) div 2;
  end;
  cxIndicatorImages.Draw(ACanvas.Canvas, X, Y, Ord(AKind) - 1);
end;

class procedure TcxCustomLookAndFeelPainter.DrawMonthHeaderArrows(
  ACanvas: TcxCanvas; const ABounds: TRect; AArrows: TcxHeaderArrows;
  ASideWidth: Integer; AColor: TColor);
var
  R: TRect;

  procedure InternalDrawArrow(LeftArrow: Boolean);
  var
    X, Sign, ArrowHeight: Integer;
    P: array[1..3] of TPoint;
  begin
    with R do
    begin
      ArrowHeight := (Bottom - Top) div 2;
      if not Odd(ArrowHeight) then Inc(ArrowHeight);
      if LeftArrow then X := Left
      else X := Right;
      Sign := 2 * Byte(LeftArrow) - 1;
      P[1] := Point(X + Sign * (ASideWidth - 1), (Top + Bottom - ArrowHeight) div 2 - 1);
      P[2] := Point(P[1].X, P[1].Y + ArrowHeight + 1);
      P[3] := Point(P[1].X - Sign * (ArrowHeight div 2 + 1), P[1].Y + ArrowHeight div 2 + 1);
      ACanvas.SetBrushColor(AColor);
      ACanvas.Pen.Color := AColor;
      ACanvas.Polygon(P);
    end;
  end;

begin
  R := ABounds;
  Inc(R.Top, BorderSize);
  InflateRect(R, 0, -1);
  if AArrows in [haLeft, haBoth] then
    InternalDrawArrow(True);
  if AArrows in [haRight, haBoth] then
    InternalDrawArrow(False);
end;

class procedure TcxCustomLookAndFeelPainter.DrawSortingArrow(ACanvas: TcxCanvas;
  const R: TRect; AColor1, AColor2: TColor; AAscendingSorting: Boolean);
var
  Sign, AWidth, AHeight, X, Y, ALeftSide, ARightSide: Integer;
begin
  Sign := 2 * Byte(AAscendingSort

⌨️ 快捷键说明

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