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

📄 ithermometer.pas

📁 iocopm3.04源码,一套很好的工控开发工具
💻 PAS
📖 第 1 页 / 共 3 页
字号:
    case Forientation of
      ioHorizontal : Result := Right  - Left - (2 * FEndsMargin);
      ioVertical   : Result := Bottom - Top  - (2 * FEndsMargin);
      else           Result := 0;
    end;

  case
    FIndicatorStyle of
      itisBulb : Result := Result - 2*FIndicatorBulbSize;
      itisBar  : Result := Result;
      else       Result := Result - 2;
  end;

end;
//****************************************************************************************************************************************************
function TiThermometer.GetCenterPoint(Canvas: TCanvas): TPoint;
var
  OldPoint            : TPoint;
  MaxTextWidth        : Integer;
  TotalWidth          : Integer;
  ATextWidth          : Integer;
  MaxPointerWidth     : Integer;
  CurrentPointerWidth : Integer;
  x                   : Integer;
begin
  Result := inherited GetCenterPoint(Canvas);
  if not FAutoCenter then exit;
  OldPoint := Result;

  if ShowTickLabels then
    begin
      with Canvas do
        begin
          Canvas.Font  := TickLabelFont;
          case Orientation of
            ioVertical   : begin
                             MaxTextWidth := TextWidth(Trim(Format('%.' + IntToStr(GetDecimalPoints) + 'f', [PositionMin])));
                             ATextWidth   := TextWidth(Trim(Format('%.' + IntToStr(GetDecimalPoints) + 'f', [PositionMax])));
                           end;
            else           begin
                             MaxTextWidth := TextHeight(Trim(Format('%.' + IntToStr(GetDecimalPoints) + 'f', [PositionMin])));
                             ATextWidth   := TextHeight(Trim(Format('%.' + IntToStr(GetDecimalPoints) + 'f', [PositionMax])));
                           end;
          end;
          if ATextWidth > MaxTextWidth then MaxTextWidth := ATextWidth;
          MaxTextWidth := MaxTextWidth + TickLabelMargin;
        end;
    end
  else MaxTextWidth := 0;

  TotalWidth := MaxTextWidth - FIndicatorWidth;

  MaxPointerWidth := 0;

  if ShowMaxPointer or ShowMinPointer then
    begin
      CurrentPointerWidth := MinMaxPointerMargin + MinMaxPointerSize;
      if CurrentPointerWidth > MaxPointerWidth then MaxPointerWidth := CurrentPointerWidth;
    end;

  for x := 0 to LimitCount - 1 do
    begin
      if LimitShowUpperPointer[x] or LimitShowLowerPointer[x] then
        begin
          CurrentPointerWidth := LimitPointerMargin[x] + LimitPointerSize[x];
          if CurrentPointerWidth > MaxPointerWidth then MaxPointerWidth := CurrentPointerWidth;
        end;
    end;

  TotalWidth := TotalWidth - MaxPointerWidth;

  if ShowTicksMajor then TotalWidth := TotalWidth + TickMajorLength + TickMargin;

  case Orientation of
    ioVertical   : case OrientationTickMarks of
                     iosBottomRight : Result := Point(OldPoint.x - (TotalWidth div 2), OldPoint.y);
                     iosTopLeft     : Result := Point(OldPoint.x + (TotalWidth div 2), OldPoint.y);
                   end;
    ioHorizontal : case OrientationTickMarks of
                     iosBottomRight : Result := Point(OldPoint.x, OldPoint.y - (TotalWidth div 2));
                     iosTopLeft     : Result := Point(OldPoint.x, OldPoint.y + (TotalWidth div 2));
                   end;
  end;
end;
//****************************************************************************************************************************************************
procedure TiThermometer.CalcPoints;
var
  ClientRect  : TRect;
begin
  ClientRect   := Rect(0, 0, Width, Height);
  FCenterPoint := GetCenterPoint(Canvas);
  with ClientRect do
      case FOrientation of
        ioVertical   : begin
                         FBarRect := Rect(FCenterPoint.X - FIndicatorWidth, Top    + FEndsMargin + OffsetY,
                                          FCenterPoint.X + FIndicatorWidth, Bottom - FEndsMargin + OffsetY);
                         with FBarRect do
                           case
                             FIndicatorStyle of
                               itisBulb : FBarRect := Rect(Left, Top,     Right, Bottom - 2*FIndicatorBulbSize);
                               itisBar  : FBarRect := FBarRect;
                               else       FBarRect := Rect(Left, Top + 2, Right, Bottom - 2);
                           end;
                       end;
        ioHorizontal : begin
                         FBarRect := Rect(Left  + FEndsMargin + OffsetX, FCenterPoint.Y - FIndicatorWidth,
                                          Right - FEndsMargin + OffsetX, FCenterPoint.Y + FIndicatorWidth);
                         with FBarRect do
                           case FIndicatorStyle of
                             itisBulb : FBarRect := Rect(Left  + 2*FIndicatorBulbSize, Top, Right,   Bottom);
                             itisBar  : FBarRect := FBarRect;
                             else       FBarRect := Rect(Left  + 2,                    Top, Right-2, Bottom);
                           end;
                       end;
      end;
end;
//****************************************************************************************************************************************************
procedure TiThermometer.iPaintTo(Canvas: TCanvas);
begin
  CalcPoints;
  if CachedDrawing then
    begin
      if BackGroundChanged then
        begin
          CreateBackGroundBitmap;
          DrawBackGround(BackGroundBitmap.Canvas, BackGroundColor);
          DrawTicks     (BackGroundBitmap.Canvas);
          ResetBackGroundChange;
        end;

      TransferBackGround(Canvas);

      case FIndicatorStyle of
        itisBulb : DrawIndicatorBulb(Canvas);
        else       DrawIndicatorBox (Canvas);
      end;

      if ShowMaxPointer then DrawPointer(Canvas, CurrentMax, MinMaxPointerMargin, MinMaxPointerSize, False, MaxPointerColor, FCurrentMaxRect);
      if ShowMinPointer then DrawPointer(Canvas, CurrentMin, MinMaxPointerMargin, MinMaxPointerSize, False, MinPointerColor, FCurrentMinRect);

      DrawLimits(Canvas);
    end
  else
    begin
      DrawBackGround(Canvas, BackGroundColor);
      DrawTicks     (Canvas);

      case FIndicatorStyle of
        itisBulb : DrawIndicatorBulb(Canvas);
        else       DrawIndicatorBox (Canvas);
      end;

      if ShowMaxPointer then DrawPointer(Canvas, CurrentMax, MinMaxPointerMargin, MinMaxPointerSize, False, MaxPointerColor, FCurrentMaxRect);
      if ShowMinPointer then DrawPointer(Canvas, CurrentMin, MinMaxPointerMargin, MinMaxPointerSize, False, MinPointerColor, FCurrentMinRect);

      DrawLimits(Canvas);
    end;
end;
//****************************************************************************************************************************************************
procedure TiThermometer.DrawIndicatorBulb(Canvas: TCanvas);
var
  IndicatorRect   : TRect;
  BulbCenterPoint : TPoint;
  BulbRect        : TRect;
  BulbRefRect     : TRect;
  PositionLength  : Integer;
  BarRect         : TRect;
begin
  BarRect := FBarRect;
  with Canvas do
    begin
      Brush.Color := FIndicatorColor;
      Brush.Style := bsSolid;
      Pen.Color := FIndicatorColor;
      case FOrientation of
        ioVertical   : begin
                         with BarRect do
                           begin
                             BulbCenterPoint := Point(FCenterPoint.X, Bottom + FIndicatorBulbSize);
                             with BulbCenterPoint do
                               begin
                                 BulbRect    := Rect(X-IndicatorBulbSize,         Y-IndicatorBulbSize,         X+IndicatorBulbSize,         Y+IndicatorBulbSize);
                                 BulbRefRect := Rect(X-(IndicatorBulbSize*2)div 5,Y-(IndicatorBulbSize*2)div 5,X+(IndicatorBulbSize*2)div 5,Y+(IndicatorBulbSize*2)div 5);
                                 OffsetRect(BulbRect,    0, -1);
                                 OffsetRect(BulbRefRect, 0, -1);
                               end;
                             IndicatorRect := Rect(Left, Top, Right, Bottom+1);
                           end;

                         with BulbRect do
                           begin
                             Ellipse(Left, Top, Right, Bottom);
                             Pen.Color := clBtnFace;  Arc(Left, Top, Right, Bottom, (Right + Left) div 2, Top, Left, Bottom);
                             Pen.Color := clBtnShadow;Arc(Left, Top, Right, Bottom, Left, Bottom, (Right + Left) div 2, Top);
                             BulbRect  := Rect(Left - 1, Top - 1, Right + 1, Bottom + 1);
                             Pen.Color := clBtnHighlight; Arc(Left, Top, Right, Bottom, (Right + Left) div 2, Top, Left, Bottom);
                             Pen.Color := clBtnShadow; Arc(Left, Top, Right, Bottom, Left, Bottom, (Right + Left) div 2, Top);

                             with BulbRefRect do
                               begin
                                 Pen.Color   := clWhite;
                                 Arc(Left, Top, Right, Bottom, (Right + Left) div 2, Top, Left, (Top + Bottom) div 2);
                                 BulbRefRect := Rect(Left - 1, Top - 1, Right + 1, Bottom + 1);
                                 Arc(Left, Top, Right, Bottom, (Right + Left) div 2, Top, Left, (Top + Bottom) div 2);
                               end;
                           end;


                         with IndicatorRect do
                           begin
                             Pen.Color   := FIndicatorBackGroundColor;
                             Brush.Color := FIndicatorBackGroundColor;
                             Ellipse(Left, Top, Right, Top + 2*FIndicatorWidth);     //Indicator BackGround Rounded Top
                             Rectangle(Left, Top + FIndicatorWidth, Right, Bottom);  //Indicator BackGround Rectangle

                             PositionLength := Round((Bottom - Top)*ValuePercent(Position));
                             IndicatorRect  := Rect(Left , Bottom - PositionLength, Right, Bottom);
                             Pen.Color   := FIndicatorColor;
                             Brush.Color := FIndicatorColor;
                             Ellipse(Left, Top, Right, Top + 2*FIndicatorWidth);    //Indicator BackGround Rounded Top
                             Rectangle(Left, Top + FIndicatorWidth, Right, Bottom); //Indicator BackGround Rectangle
                           end;
                       end;
        ioHorizontal : begin
                         with BarRect do
                           begin
                             BulbCenterPoint := Point(Left - FIndicatorBulbSize, FCenterPoint.Y);
                             with BulbCenterPoint do
                               begin
                                 BulbRect         := Rect(X - IndicatorBulbSize, Y  - IndicatorBulbSize, X + IndicatorBulbSize, Y + IndicatorBulbSize);
                                 BulbRefRect      := Rect(X - (IndicatorBulbSize*2)div 5, Y  - (IndicatorBulbSize*2)div 5, X + (IndicatorBulbSize*2)div 5, Y + (IndicatorBulbSize*2)div 5);
                                 OffsetRect(BulbRect,    0, +1);
                                 OffsetRect(BulbRefRect, 0, +1);
                               end;
                             IndicatorRect := Rect(Left, Top, Right + 1, Bottom);
                           end;

                         with BulbRect do
                           begin
                             Ellipse(Left, Top, Right, Bottom);
                             Pen.Color := clBtnFace;     Arc(Left, Top, Right, Bottom, (Right + Left) div 2, Top, Left, Bottom);
                             Pen.Color := clBtnShadow;   Arc(Left, Top, Right, Bottom, Left, Bottom, (Right + Left) div 2, Top);
                             BulbRect  := Rect(Left - 1, Top - 1, Right + 1, Bottom + 1);
                             Pen.Color := clBtnHighlight;Arc(Left, Top, Right, Bottom, (Right + Left) div 2, Top, Left, Bottom);

⌨️ 快捷键说明

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