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

📄 iloggauge.pas

📁 iocopm3.04源码,一套很好的工控开发工具
💻 PAS
📖 第 1 页 / 共 4 页
字号:
  APointer : TiGaugePointer;
begin
  for x := 0 to LimitCount -1 do
    begin
      if LimitShowUpperPointer[x] then
        begin
          APointer := TiGaugePointer.Create(nil);
          try
            APointer.Position      := LimitUpperValue[x];
            APointer.Margin        := LimitPointerMargin[x];
            APointer.Size          := LimitPointerSize[x];
            APointer.DrawScaleSide := LimitDrawScaleSide[x];
            APointer.Color         := LimitUpperPointerColor[x];

            DrawPointer(Canvas, APointer);
          finally
            APointer.Free;
          end;
        end;

      if LimitShowLowerPointer[x] then
        begin
          APointer := TiGaugePointer.Create(nil);
          try
            APointer.Position      := LimitLowerValue[x];
            APointer.Margin        := LimitPointerMargin[x];
            APointer.Size          := LimitPointerSize[x];
            APointer.DrawScaleSide := LimitDrawScaleSide[x];
            APointer.Color         := LimitLowerPointerColor[x];

            DrawPointer(Canvas, APointer);
          finally
            APointer.Free;
          end;
        end;
    end;
end;
//****************************************************************************************************************************************************
procedure TiLogGauge.DrawTicks(Canvas: TCanvas);
var
  MajorCount          : Double;
  MajorLoopCount      : Integer;
  MajorPosition       : Double;
  MajorPositionPixels : Integer;
  MinorPosition       : Integer;
  CenterOffset        : Integer;
  TextString          : String;
  x, y                : Integer;
  ATextHeight         : Integer;
  ATextWidth          : Integer;
begin
  with Canvas, FBarRect do
    begin
      try
        MajorCount := Log10(PositionMax) - Log10(PositionMin);
      except
        MajorCount := 0;
      end;

      MajorLoopCount := Trunc(MajorCount);

      Brush.Style := bsClear;
      Font.Assign(TickLabelFont);

      for x := 0 to MajorLoopCount do
        begin
          Pen.Color           := TickMajorColor;
          MajorPosition       := PositionMin * Power(10, x);
          MajorPositionPixels := GetPositionPixels(MajorPosition);
          case Orientation of
            ioVertical   : begin
                             case OrientationTickMarks of
                               iosBottomRight : LineBevel(Canvas, Right - TickMajorLength + TickMargin, MajorPositionPixels, Right + TickMargin, MajorPositionPixels, TickMajorStyle);
                               iosTopLeft     : LineBevel(Canvas, Right - TickMajorLength - TickMargin, MajorPositionPixels, Right - TickMargin, MajorPositionPixels, TickMajorStyle);
                             end;

                           end;
            else           begin
                             case OrientationTickMarks of
                               iosBottomRight : LineBevel(Canvas, MajorPositionPixels, Top + TickMargin, MajorPositionPixels, Top + TickMajorLength + TickMargin, TickMajorStyle);
                               iosTopLeft     : LineBevel(Canvas, MajorPositionPixels, Top - TickMargin, MajorPositionPixels, Top + TickMajorLength - TickMargin, TickMajorStyle);
                             end;
                           end;
          end;

          for y := 2 to 9 do
            begin
              if (PositionMin * Power(10, x) * y) > PositionMax then Break;
              Pen.Color := TickMinorColor;
              CenterOffset := (TickMajorLength div 2 - TickMinorLength div 2);
              MinorPosition := GetPositionPixels(MajorPosition + MajorPosition*(y-1));
              case Orientation of
                ioVertical   : case OrientationTickMarks of
                                 iosBottomRight : case TickMinorAlignment of
                                                    itmnaInside  : LineBevel(Canvas, Right - TickMinorLength + TickMargin, MinorPosition, Right + TickMargin, MinorPosition, TickMinorStyle);
                                                    itmnaCenter  : LineBevel(Canvas, Left + CenterOffset + TickMargin, MinorPosition, Left + CenterOffset + TickMinorLength + TickMargin, MinorPosition, TickMinorStyle);
                                                    itmnaOutside : LineBevel(Canvas, Left + TickMargin, MinorPosition, Left  + TickMinorLength + TickMargin, MinorPosition, TickMinorStyle);
                                                  end;
                                 iosTopLeft     : case TickMinorAlignment of
                                                    itmnaInside  : LineBevel(Canvas, Left - TickMargin, MinorPosition, Left  + TickMinorLength - TickMargin, MinorPosition, TickMinorStyle);
                                                    itmnaCenter  : LineBevel(Canvas, Left + CenterOffset - TickMargin, MinorPosition, Left + CenterOffset + TickMinorLength - TickMargin, MinorPosition, TickMinorStyle);
                                                    itmnaOutside : LineBevel(Canvas, Right - TickMinorLength - TickMargin, MinorPosition, Right - TickMargin, MinorPosition, TickMinorStyle);
                                                  end;
                               end;
                ioHorizontal : case OrientationTickMarks of
                                 iosBottomRight : case TickMinorAlignment of
                                                    itmnaInside  : LineBevel(Canvas, MinorPosition, Bottom - TickMinorLength + TickMargin, MinorPosition, Bottom + TickMargin, TickMinorStyle);
                                                    itmnaCenter  : LineBevel(Canvas, MinorPosition, Top + CenterOffset + TickMargin, MinorPosition, Top + TickMinorLength + CenterOffset + TickMargin, TickMinorStyle);
                                                    itmnaOutside : LineBevel(Canvas, MinorPosition, Top + TickMargin, MinorPosition, Top + TickMinorLength + TickMargin, TickMinorStyle);
                                                  end;
                                 iosTopLeft     : case TickMinorAlignment of
                                                    itmnaInside  : LineBevel(Canvas, MinorPosition, Top - TickMargin, MinorPosition, Top + TickMinorLength - TickMargin, TickMinorStyle);
                                                    itmnaCenter  : LineBevel(Canvas, MinorPosition, Top + CenterOffset - TickMargin, MinorPosition, Top + TickMinorLength + CenterOffset - TickMargin, TickMinorStyle);
                                                    itmnaOutside : LineBevel(Canvas, MinorPosition, Bottom - TickMinorLength - TickMargin, MinorPosition, Bottom - TickMargin, TickMinorStyle);
                                                  end;
                               end;
              end;
            end;

          if ShowTickLabels then
            begin
              case FTickLabelStyle of
                illsValue      : TextString  := Trim(SysUtils.Format('%.' + IntToStr(TickLabelPrecision  ) + 'f', [MajorPosition]));
                illsScientific : TextString  := Trim(SysUtils.Format('%.' + IntToStr(TickLabelPrecision+1) + 'e', [MajorPosition]));
              end;

              if Assigned(OnCustomizeTickLabel) then TOnCustomizeTickLabel(OnCustomizeTickLabel)(Self, x, TextString);

              ATextHeight := TextHeight(TextString);
              ATextWidth  := TextWidth (TextString);

              case FOrientation of
                ioVertical   : case FOrientationTickMarks of
                                 iosBottomRight : TextOut(Right + TickLabelMargin               , MajorPositionPixels - ATextHeight div 2, TextString);
                                 iosTopLeft     : TextOut(Left - TickLabelMargin - ATextWidth   , MajorPositionPixels - ATextHeight div 2, TextString);
                               end;
                ioHorizontal : case FOrientationTickMarks of
                                 iosBottomRight : TextOut(MajorPositionPixels - ATextWidth div 2, Bottom + TickLabelMargin               , TextString);
                                 iosTopLeft     : TextOut(MajorPositionPixels - ATextWidth div 2, Top    - TickLabelMargin - ATextHeight , TextString);
                               end;
              end;
            end;
        end;
    end;
end;
//****************************************************************************************************************************************************
procedure TiLogGauge.iMouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  i : Integer;
begin
  if (Button = mbLeft) then
    begin
      if MinMaxUserCanMove then
        begin
          FMouseDownX := X;
          FMouseDownY := Y;
          if      ShowMinPointer {$IFDEF iVCL}and (FMinPointer.Region <> 0) and PtInRegion(FMinPointer.Region, X,Y){$ENDIF} then
            begin
              FMinPointer.MouseDown := True;
              FOldCurrentValue      := CurrentMin;
            end
          else if ShowMaxPointer {$IFDEF iVCL}and (FMaxPointer.Region <> 0) and PtInRegion(FMaxPointer.Region, X,Y){$ENDIF} then
            begin
              FMaxPointer.MouseDown := True;
              FOldCurrentValue := CurrentMax;
            end;
          InvalidateChange;
        end;

      for i := 0 to PointerCount-1 do
        begin
          PointerManager.Items[i].MouseDown := True;
          if not PointerManager.Items[i].Visible then Continue;
          {$IFDEF iVCL}PointerManager.Items[i].MouseDown := PtInRegion(PointerManager.Items[i].Region, X, Y);{$ENDIF}
        end;
    end;
end;
//****************************************************************************************************************************************************
procedure TiLogGauge.iMouseMove(Shift: TShiftState; X, Y: Integer);
var
  YValue : Integer;
begin
  if FMaxPointer.MouseDown then
    begin
      case Forientation of
        ioHorizontal : if FReverseScale then
                            CurrentMax := FOldCurrentValue + (FMouseDownX - X)/TravelRange*(PositionMax - PositionMin)
                       else CurrentMax := FOldCurrentValue - (FMouseDownX - X)/TravelRange*(PositionMax - PositionMin);
        ioVertical   : begin
                         if FReverseScale then YValue := Y - FEndsMargin else YValue := Height - FEndsMargin - Y;
                         CurrentMax := Power(10, (Log10(PositionMax)-Log10(PositionMin)) * YValue/TravelRange + Log10(PositionMin));
                       end;
      end;
      if CurrentMin > CurrentMax then CurrentMin := CurrentMax;
    end
  else if FMinPointer.MouseDown then
    begin
      case Forientation of
        ioHorizontal : if FReverseScale then
                            CurrentMin := FOldCurrentValue + (FMouseDownX - X)/TravelRange*(PositionMax - PositionMin)
                       else CurrentMin := FOldCurrentValue - (FMouseDownX - X)/TravelRange*(PositionMax - PositionMin);
        ioVertical   : begin
                         if FReverseScale then YValue := Y - FEndsMargin else YValue := Height - FEndsMargin - Y;
                         CurrentMin := Power(10, (Log10(PositionMax)-Log10(PositionMin)) * YValue/TravelRange + Log10(PositionMin));
                       end;
      end;
      if CurrentMax < CurrentMin then CurrentMax := CurrentMin;
    end;
end;
//****************************************************************************************************************************************************
procedure TiLogGauge.iMouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  i : Integer;
begin
  FMinPointer.MouseDown := False;
  FMaxPointer.MouseDown := False;

  for i := 0 to PointerCount-1 do
    begin
      if not PointerManager.Items[i].Visible then Continue;
      if PointerManager.Items[i].MouseDown then
        begin
          {$IFDEF iVCL}
          if PtInRegion(PointerManager.Items[i].Region, X, Y) then if Assigned(OnClickPointer) then OnClickPointer(i);
          {$ENDIF}
        end;
    end;
end;
//****************************************************************************************************************************************************
function TiLogGauge.GetPointerColor  : TColor;                   begin Result :=                           PointerManager.Items[0].Color; end;
function TiLogGauge.GetPointerOffSet : Integer;                  begin Result :=                           PointerManager.Items[0].Margin;end;
function TiLogGauge.GetPointerSize   : Integer;                  begin Result :=                           PointerManager.Items[0].Size;  end;
function TiLogGauge.GetPointerStyle  : TiLinearGaugePointerStyle;begin Result := TiLinearGaugePointerStyle(PointerManager.Items[0].Style);end;
//****************************************************************************************************************************************************
procedure TiLogGauge.SetPointerOffSet(const Value: Integer);                  begin PointerManager.Items[0].Margin := Value;     end;
procedure TiLogGauge.SetPointerColor (const Value: TColor);                   begin PointerManager.Items[0].Color  := Value;     end;
procedure TiLogGauge.SetPointerSize  (const Value: Integer);                  begin PointerManager.Items[0].Size   := Value;     end;
procedure TiLogGauge.SetPointerStyle (const Value: TiLinearGaugePointerStyle);begin PointerManager.Items[0].Style  := ord(Value);end;
//****************************************************************************************************************************************************
function TiLogGauge.GetPointersOffSet(Index:Integer):Integer;                  begin Result:=PointerManager.Items[Index].Margin;                          end;
function TiLogGauge.GetPointersStyle (Index:Integer):TiLinearGaugePointerStyle;begin Result:=TiLinearGaugePointerStyle(PointerManager.Items[Index].Style);end;
//****************************************************************************************************************************************************
procedure TiLogGauge.SetPointersOffSet(Index,          Value: Integer);                  begin PointerManager.Items[Index].Margin:=Value;     end;
procedure TiLogGauge.SetPointersStyle (Index: Integer; Value: TiLinearGaugePointerStyle);begin PointerManager.Items[Index].Style :=ord(Value);end;
//****************************************************************************************************************************************************
procedure TiLogGauge.InitializePointer(iGaugePointer: TiGaugePointer);
begin
  iGaugePointer.Position := 1;
  iGaugePointer.Size     := 10;
  iGaugePointer.Color    := clBlue;
  iGaugePointer.Style    := ord(ilgpsPointer);
end;
//****************************************************************************************************************************************************
end.

⌨️ 快捷键说明

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