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

📄 iangulargauge.pas

📁 iocopm3.04源码,一套很好的工控开发工具
💻 PAS
📖 第 1 页 / 共 4 页
字号:
      SpaceVert  := SpaceBottom + SpaceTop;

      if SpaceHorz > SpaceVert then SpaceMin := SpaceVert
        else                        SpaceMin := SpaceHorz;
  end;

  if FArcRangeDegrees <= 90 then
    FArcRadius := SpaceMin - FOuterMargin - FHubSize
  else if FArcRangeDegrees <= 180 then
    FArcRadius := Round(SpaceMin/(1 +(FArcRangeDegrees-90)/90)) - FOuterMargin
  else
    FArcRadius := Round(SpaceMin /2) - FOuterMargin
end;
//****************************************************************************************************************************************************
procedure TiAngularGauge.iPaintTo(Canvas: TCanvas);
var
  CenterPoint : TPoint;
  x           : Integer;
begin
  if FAutoSize then AdjustArcRadius(Canvas);
  CenterPoint := GetCenterPoint(Canvas);

  if CachedDrawing then
    begin
      if BackGroundChanged then
        begin
          CreateBackGroundBitmap;
          DrawBackGround(BackGroundBitmap.Canvas, BackGroundColor);
          DrawPanelFace (BackGroundBitmap.Canvas, CenterPoint);
          DrawSections  (BackGroundBitmap.Canvas, CenterPoint);
          DrawArcRadius (BackGroundBitmap.Canvas, CenterPoint);
          DrawTicks     (BackGroundBitmap.Canvas, CenterPoint);
          ResetBackGroundChange;
        end;

      TransferBackGround(Canvas);

      DrawLabels    (Canvas, CenterPoint);
      DrawMinMax    (Canvas, CenterPoint);
      DrawLimits    (Canvas, CenterPoint);

      for x := 0 to PointerManager.Count - 1 do
        begin
          if not PointerManager.Items[x].Visible then Continue;
          DrawIndicator (Canvas, CenterPoint, PointerManager.Items[x]);
        end;

      DrawHub(Canvas, CenterPoint);
    end
  else
    begin
      DrawBackGround(Canvas, BackGroundColor);
      DrawPanelFace (BackGroundBitmap.Canvas, CenterPoint);
      DrawSections  (Canvas, CenterPoint);
      DrawArcRadius (Canvas, CenterPoint);
      DrawTicks     (Canvas, CenterPoint);

      DrawLabels    (Canvas, CenterPoint);
      DrawMinMax    (Canvas, CenterPoint);
      DrawLimits    (Canvas, CenterPoint);

      for x := 0 to PointerManager.Count - 1 do
        begin
          if not PointerManager.Items[x].Visible then Continue;
          DrawIndicator (Canvas, CenterPoint, PointerManager.Items[x]);
        end;

      DrawHub(Canvas, CenterPoint);
    end;
end;
//****************************************************************************************************************************************************
procedure TiAngularGauge.DrawPanelFace(Canvas: TCanvas; const CenterPoint: TPoint);
begin
if FPanelFaceStyle = ipfsNone then Exit;
  with Canvas do
    begin
      Brush.Style := bsSolid;
      Pen.Style   := psSolid;
      Brush.Color := FPanelFaceOuterColor;
      Pen.Color   := clWhite;
      RoundRect(0, 0, Width, Height, Width div 8, Height div 8);

      Brush.Color := FPanelFaceInnerColor;
      Pen.Color   := FPanelFaceInnerColor;
      Ellipse(FPanelFaceSize, FPanelFaceSize, Width-FPanelFaceSize, Height-FPanelFaceSize);
    end;
end;
//****************************************************************************************************************************************************
procedure TiAngularGauge.DrawSections(Canvas: TCanvas; const OffsetPoint: TPoint);
var
  x              : Integer;
  LastStart      : Double;
  CurrentColor   : TColor;
  CurrentEnd     : Double;
  InnerRadius    : Integer;
  OuterRadius    : Integer;
begin
  LastStart   := PositionMin;
  InnerRadius := FArcRadius + TickMargin;
  OuterRadius := FArcRadius + TickMargin + TickMajorLength;

  if FShowInnerArcRadius then InnerRadius := InnerRadius+1;
  if FShowOuterArcRadius then OuterRadius := OuterRadius-1;

  for x := 1 to SectionCount do
    begin
      case x of
        1 :  begin CurrentColor := SectionColor1; CurrentEnd := SectionEnd1; end;
        2 :  begin CurrentColor := SectionColor2; CurrentEnd := SectionEnd2; end;
        3 :  begin CurrentColor := SectionColor3; CurrentEnd := SectionEnd3; end;
        4 :  begin CurrentColor := SectionColor4; CurrentEnd := SectionEnd4; end;
        else begin CurrentColor := SectionColor5; CurrentEnd := PositionMax; end;
      end;

      if CurrentEnd > PositionMax then CurrentEnd := PositionMax;
      if CurrentEnd < PositionMin then CurrentEnd := PositionMin;
      if CurrentEnd < LastStart   then CurrentEnd := PositionMax;
      if x = SectionCount         then CurrentEnd := PositionMax;


      ArcSegment(Canvas, PositionToDegrees(LastStart), PositionToDegrees(CurrentEnd), InnerRadius, OuterRadius, OffsetPoint, CurrentColor);

      LastStart := CurrentEnd;

      if CurrentEnd = PositionMax then exit;
    end;
end;
//****************************************************************************************************************************************************
procedure TiAngularGauge.DrawArcRadius(Canvas: TCanvas; const OffsetPoint: TPoint);
var
  InnerRadius    : Integer;
  OuterRadius    : Integer;
begin
  InnerRadius := FArcRadius + TickMargin;
  OuterRadius := FArcRadius + TickMargin + TickMajorLength;
  if FShowInnerArcRadius then ArcSegment(Canvas, PositionToDegrees(PositionMin), PositionToDegrees(PositionMax), InnerRadius, InnerRadius, OffsetPoint, TickMajorColor);
  if FShowOuterArcRadius then ArcSegment(Canvas, PositionToDegrees(PositionMin), PositionToDegrees(PositionMax), OuterRadius, OuterRadius, OffsetPoint, TickMajorColor);
end;
//****************************************************************************************************************************************************
procedure TiAngularGauge.DrawTicks(Canvas: TCanvas; const OffsetPoint: TPoint);
var
  OuterPoint      : TPoint;
  InnerPoint      : TPoint;
  MajorRadius1    : Double;
  MajorRadius2    : Double;
  MinorRadius1    : Double;
  MinorRadius2    : Double;
  TextString      : String;
  x, y            : Integer;
  ActualMin       : Double;
  ActualMax       : Double;
  CurrentPosition : Double;
  MajorStepSize   : Double;
  MinorStepSize   : Double;
  TextRect1       : TRect;
begin
  with Canvas do
    begin
      Brush.Style := bsClear;

      MajorRadius1 := FArcRadius + TickMargin;
      MajorRadius2 := FArcRadius + TickMargin + TickMajorLength;

      case TickMinorAlignment of
        itmnaInside  : begin
                         MinorRadius1 := MajorRadius1;
                         MinorRadius2 := MajorRadius1 + TickMinorLength;
                       end;
        itmnaCenter  : begin
                         MinorRadius1 := (MajorRadius1 + MajorRadius2)/2 - TickMinorLength/2;
                         MinorRadius2 := (MajorRadius1 + MajorRadius2)/2 + TickMinorLength/2;
                       end;
        else           begin
                         MinorRadius1 := MajorRadius2;
                         MinorRadius2 := MajorRadius2 - TickMinorLength;
                       end;
      end;

      if not ShowTicksMajor then MajorRadius1 := FArcRadius;

      if AutoScaleEnabled and (AutoScaleStyle = iassFixedMinMax) then
        begin
          ActualMin := FAutoScaleMinTick;
          ActualMax := FAutoScaleMaxTick;
        end
      else
        begin
          ActualMin := PositionMin;
          ActualMax := PositionMax;
        end;

      MajorStepSize := (ActualMax-ActualMin)/(TickMajorCount - 1);
      MinorStepSize := MajorStepSize /(TickMinorCount + 1);

      for x := 0 to TickMajorCount - 1 do
        begin
          CurrentPosition := ActualMin + MajorStepSize * x;
          //------------------------------------------------------------------------------------------------------------------------------------------
          if ShowTicksMajor then
            begin
              Pen.Color  := TickMajorColor;
              OuterPoint := GetXYRadPoint(PositionToDegrees(CurrentPosition), MajorRadius1, OffsetPoint);
              InnerPoint := GetXYRadPoint(PositionToDegrees(CurrentPosition), MajorRadius2, OffsetPoint);
              Polyline([InnerPoint, OuterPoint]);
            end;
          //------------------------------------------------------------------------------------------------------------------------------------------
          if ShowTickLabels then
            begin
              Font.Assign(TickLabelFont);
              TextString := GetLabelText(x);
              TextRect1  := GetLabelRect(Canvas, x, OffsetPoint);
              iDrawText(Canvas, TextString, TextRect1, [itfHCenter, itfVCenter, itfSingleLine, itfNoClip]);
            end;
          //------------------------------------------------------------------------------------------------------------------------------------------
          if ShowTicksMinor and (x < TickMajorCount - 1) then
            begin
              Pen.Color := TickMinorColor;
              for y := 1 to TickMinorCount do
                begin
                  CurrentPosition := ActualMin + MajorStepSize*x + MinorStepSize*y;
                  OuterPoint := GetXYRadPoint(PositionToDegrees(CurrentPosition), MinorRadius1, OffsetPoint);
                  InnerPoint := GetXYRadPoint(PositionToDegrees(CurrentPosition), MinorRadius2, OffsetPoint);
                  Polyline([InnerPoint, OuterPoint]);
                end;
            end;
        end;
          //------------------------------------------------------------------------------------------------------------------------------------------
      if (AutoScaleStyle = iassFixedMinMax) and ShowTicksMinor and (MinorStepSize <> 0) then
        begin
          CurrentPosition := FAutoScaleMaxTick + MinorStepSize;
          while CurrentPosition <= PositionMax do
            begin
              OuterPoint := GetXYRadPoint(PositionToDegrees(CurrentPosition), MinorRadius1, OffsetPoint);
              InnerPoint := GetXYRadPoint(PositionToDegrees(CurrentPosition), MinorRadius2, OffsetPoint);
              Polyline([InnerPoint, OuterPoint]);

              CurrentPosition := CurrentPosition + MinorStepSize;
            end;

          CurrentPosition := FAutoScaleMinTick - MinorStepSize;
          while CurrentPosition >= PositionMin do
            begin
              OuterPoint := GetXYRadPoint(PositionToDegrees(CurrentPosition), MinorRadius1, OffsetPoint);
              InnerPoint := GetXYRadPoint(PositionToDegrees(CurrentPosition), MinorRadius2, OffsetPoint);
              Polyline([InnerPoint, OuterPoint]);

              CurrentPosition := CurrentPosition - MinorStepSize;
            end;
        end;
    end;
end;
//****************************************************************************************************************************************************
procedure TiAngularGauge.DrawHub(Canvas: TCanvas; const OffsetPoint: TPoint);
begin
  with Canvas do
    begin
      if FShowHub then
        begin
          Pen.Color   := FHubColor;
          Brush.Color := FHubColor;
          Ellipse(OffsetPoint.x + FHubSize div 2, OffsetPoint.y + FHubSize div 2, OffsetPoint.x - FHubSize div 2, OffsetPoint.y - FHubSize div 2);
        end;
    end;
end;
//****************************************************************************************************************************************************
procedure TiAngularGauge.DrawMinMax(Canvas: TCanvas; const OffsetPoint: TPoint);
begin
  if ShowMaxPointer then
    begin
      FMaxPointer.Position      := CurrentMax;
      FMaxPointer.Style         := ord(MinMaxPointerStyle);
      FMaxPointer.Margin        := MinMaxPointerMargin;
      FMaxPointer.Size          := MinMaxPointerSize;
      FMaxPointer.DrawScaleSide := False;
      FMaxPointer.Color         := MaxPointerColor;

      DrawIndicator(Canvas, OffsetPoint, FMaxPointer);
    end;

  if ShowMinPointer then
    begin
      FMinPointer.Position      := CurrentMin;
      FMinPointer.Style         := ord(MinMaxPointerStyle);
      FMinPointer.Margin        := MinMaxPointerMargin;
      FMinPointer.Size          := MinMaxPointerSize;
      FMinPointer.DrawScaleSide := False;
      FMinPointer.Color         := MinPointerColor;

      DrawIndicator(Canvas, OffsetPoint, FMinPointer);
    end;
end;

⌨️ 快捷键说明

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