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

📄 islidingcompass.pas

📁 iocopm3.04源码,一套很好的工控开发工具
💻 PAS
📖 第 1 页 / 共 4 页
字号:
{*******************************************************}
{                                                       }
{       TiSlidingCompass Component                      }
{                                                       }
{       Copyright (c) 1997,2003 Iocomp Software         }
{                                                       }
{*******************************************************}
{$I iInclude.inc}

{$ifdef iVCL}unit  iSlidingCompass;{$endif}
{$ifdef iCLX}unit QiSlidingCompass;{$endif}

interface

uses                                                 
  {$I iIncludeUses.inc}
  {$IFDEF iVCL} iTypes,  iGPFunctions,  iMath,  iCustomComponent;{$ENDIF}
  {$IFDEF iCLX}QiTypes, QiGPFunctions, QiMath, QiCustomComponent;{$ENDIF}

type
  TiSlidingCompass = class(TiCustomComponent)
  private
    FCenterPoint                : TPoint;
    FScaleRect                  : TRect;
    FScaleStartPosition         : Double;
    FScaleStopPosition          : Double;
    FRangePixels                : Integer;
    FTickMajorStepValue         : Double;
    FTickMajorLabelMarginPixels : Integer;
    FTickMinorStepValue         : Double;
    FTickMidLabelMarginPixels   : Integer;
    FMidTicksEnabled            : Boolean;
    FMidTickNumber              : Integer;
    FHalfMajorLength            : Integer;
    FHalfMidLength              : Integer;
    FHalfMinorLength            : Integer;

    FTickMajorLength            : Integer;
    FPointer1Position           : Double;
    FTickMidLength              : Integer;
    FPointer1Size               : Integer;
    FTickMajorLabelMargin       : Double;
    FScaleSpan                  : Double;
    FTickMidLabelMargin         : Double;
    FTickMidWidth               : Integer;
    FTickMajorWidth             : Integer;
    FTickMajorCount             : Integer;
    FPointer1LineWidth          : Integer;
    FTickMinorCount             : Integer;
    FTickMajorLabelPrecision    : Integer;
    FTickMinorWidth             : Integer;
    FTickMajorColor             : TColor;
    FPointer1Color              : TColor;
    FScaleBackgroundColor       : TColor;
    FTickMinorColor             : TColor;
    FTickMidColor               : TColor;
    FPointer1LineColor          : TColor;
    FTickMajorLabelFont         : TFont;
    FTickMidLabelFont           : TFont;
    FPointer1Style              : TiSlidingScalePointerStyle;
    FScaleAlignStyle            : TiScaleAlignStyle;
    FTickMinorLength            : Integer;
    FTickMidLabelPrecision      : Integer;
    FShowMidTickLabels          : Boolean;
    FShowMidTicks               : Boolean;
    FReverseScale               : Boolean;
    FOrientation                : TiOrientation;
    FScaleOrientation           : TiOrientationSide;
    FScaleAntiAliasEnabled      : Boolean;
    FScaleShadowEnabled         : Boolean;
    FScaleShadowColor           : TColor;
    FPointerOrientation         : TiOrientationSide;
    FOuterMarginTop             : Integer;
    FOuterMarginLeft            : Integer;
    FOuterMarginRight           : Integer;
    FOuterMarginBottom          : Integer;
    FTitleText                  : String;
    FTitleFont                  : TFont;
    FTitleAlignment             : TiAlignmentSideVertical;
    FTitleMargin                : Double;
    FPointer2Position           : Double;
    FPointer2Size               : Integer;
    FPointer2LineWidth          : Integer;
    FPointer2LineColor          : TColor;
    FPointer2Color              : TColor;
    FPointer2Style              : TiSlidingScalePointerStyle;
    FOnAutoSize                 : TNotifyEvent;

    procedure SetPointer1Color          (const Value: TColor);
    procedure SetPointer1LineColor      (const Value: TColor);
    procedure SetPointer1LineWidth      (const Value: Integer);
    procedure SetPointer1Size           (const Value: Integer);
    procedure SetPointer1Style          (const Value: TiSlidingScalePointerStyle);
    procedure SetPointer1Position       (const Value: Double);
    procedure SetScaleBackgroundColor   (const Value: TColor);
    procedure SetScaleSpan              (const Value: Double);
    procedure SetScaleAlignStyle        (const Value: TiScaleAlignStyle);
    procedure SetTickMajorColor         (const Value: TColor);
    procedure SetTickMajorCount         (const Value: Integer);
    procedure SetTickMajorLabelFont     (const Value: TFont);
    procedure SetTickMajorLabelMargin   (const Value: Double);
    procedure SetTickMajorLabelPrecision(const Value: Integer);
    procedure SetTickMajorLength        (const Value: Integer);
    procedure SetTickMajorWidth         (const Value: Integer);
    procedure SetTickMidColor           (const Value: TColor);
    procedure SetTickMidLabelFont       (const Value: TFont);
    procedure SetTickMidLabelMargin     (const Value: Double);
    procedure SetTickMidLength          (const Value: Integer);
    procedure SetTickMidWidth           (const Value: Integer);
    procedure SetTickMinorColor         (const Value: TColor);
    procedure SetTickMinorCount         (const Value: Integer);
    procedure SetTickMinorWidth         (const Value: Integer);
    procedure SetTickMinorLength        (const Value: Integer);
    procedure SetTickMidLabelPrecision  (const Value: Integer);
    procedure SetShowMidTickLabels      (const Value: Boolean);
    procedure SetShowMidTicks           (const Value: Boolean);
    procedure SetReverseScale           (const Value: Boolean);
    procedure SetOrientation            (const Value: TiOrientation);
    procedure SetScaleOrientation       (const Value: TiOrientationSide);
    procedure SetScaleAntiAliasEnabled  (const Value: Boolean);
    procedure SetScaleShadowEnabled     (const Value: Boolean);
    procedure SetScaleShadowColor       (const Value: TColor);
    procedure SetPointerOrientation     (const Value: TiOrientationSide);
    procedure SetOuterMarginBottom      (const Value: Integer);
    procedure SetOuterMarginLeft        (const Value: Integer);
    procedure SetOuterMarginRight       (const Value: Integer);
    procedure SetOuterMarginTop         (const Value: Integer);
    procedure SetTitleText              (const Value: String);
    procedure SetTitleAlignment         (const Value: TiAlignmentSideVertical);
    procedure SetTitleFont              (const Value: TFont);
    procedure SetTitleMargin            (const Value: Double);
    procedure SetPointer2Color(const Value: TColor);
    procedure SetPointer2LineColor(const Value: TColor);
    procedure SetPointer2LineWidth(const Value: Integer);
    procedure SetPointer2Position(const Value: Double);
    procedure SetPointer2Size(const Value: Integer);
    procedure SetPointer2Style(const Value: TiSlidingScalePointerStyle);
  protected
    procedure CalcPoints(Canvas: TCanvas);
    procedure iPaintTo(Canvas: TCanvas);                          override;
    function  GetPositionToPixels(Value : Double) : Integer;

    procedure DrawScaleBackGround (Canvas: TCanvas);
    procedure DrawTitle           (Canvas: TCanvas);
    procedure DrawPointer         (Canvas: TCanvas);
    procedure DrawPointerLine     (Canvas: TCanvas; APosition : Double; AColor : TColor; AWidth : Integer);
    procedure DrawPointerDualArrow(Canvas: TCanvas; APosition : Double; AColor : TColor; ASize : Integer);
    procedure DrawPointerArrow    (Canvas: TCanvas; APosition : Double; AColor : TColor; ASize : Integer);
    procedure DrawPointerPointer  (Canvas: TCanvas; APosition : Double; AColor : TColor; ASize : Integer);
    procedure DrawScale           (Canvas: TCanvas);

    property OnAutoSize              : TNotifyEvent               read FOnAutoSize             write FOnAutoSize;
  public
    constructor Create(AOwner: TComponent);override;
    destructor  Destroy;                   override;
  published
    property Orientation             : TiOrientation              read FOrientation             write SetOrientation             default ioHorizontal;
    property ReverseScale            : Boolean                    read FReverseScale            write SetReverseScale            default False;

    property ScaleSpan               : Double                     read FScaleSpan               write SetScaleSpan;
    property ScaleBackgroundColor    : TColor                     read FScaleBackgroundColor    write SetScaleBackgroundColor    default clWhite;
    property ScaleAlignStyle         : TiScaleAlignStyle          read FScaleAlignStyle         write SetScaleAlignStyle         default itasSide;
    property ScaleAntiAliasEnabled   : Boolean                    read FScaleAntiAliasEnabled   write SetScaleAntiAliasEnabled   default True;
    property ScaleShadowEnabled      : Boolean                    read FScaleShadowEnabled      write SetScaleShadowEnabled      default True;
    property ScaleShadowColor        : TColor                     read FScaleShadowColor        write SetScaleShadowColor        default clBlack;
    property ScaleOrientation        : TiOrientationSide          read FScaleOrientation        write SetScaleOrientation        default iosTopLeft;

    property TickMajorCount          : Integer                    read FTickMajorCount          write SetTickMajorCount          default 5;
    property TickMajorWidth          : Integer                    read FTickMajorWidth          write SetTickMajorWidth          default 2;
    property TickMajorLength         : Integer                    read FTickMajorLength         write SetTickMajorLength         default 9;
    property TickMajorColor          : TColor                     read FTickMajorColor          write SetTickMajorColor          default clBlack;
    property TickMajorLabelFont      : TFont                      read FTickMajorLabelFont      write SetTickMajorLabelFont;
    property TickMajorLabelPrecision : Integer                    read FTickMajorLabelPrecision write SetTickMajorLabelPrecision default 0;
    property TickMajorLabelMargin    : Double                     read FTickMajorLabelMargin    write SetTickMajorLabelMargin;

    property TickMidWidth            : Integer                    read FTickMidWidth            write SetTickMidWidth            default 2;
    property TickMidLength           : Integer                    read FTickMidLength           write SetTickMidLength           default 7;
    property TickMidColor            : TColor                     read FTickMidColor            write SetTickMidColor            default clBlack;
    property TickMidLabelFont        : TFont                      read FTickMidLabelFont        write SetTickMidLabelFont;
    property TickMidLabelPrecision   : Integer                    read FTickMidLabelPrecision   write SetTickMidLabelPrecision   default 1;
    property TickMidLabelMargin      : Double                     read FTickMidLabelMargin      write SetTickMidLabelMargin;

    property TickMinorCount          : Integer                    read FTickMinorCount          write SetTickMinorCount          default 4;
    property TickMinorWidth          : Integer                    read FTickMinorWidth          write SetTickMinorWidth          default 1;
    property TickMinorLength         : Integer                    read FTickMinorLength         write SetTickMinorLength         default 5;
    property TickMinorColor          : TColor                     read FTickMinorColor          write SetTickMinorColor          default clBlack;

    property Pointer1Position        : Double                     read FPointer1Position        write SetPointer1Position;
    property Pointer1Style           : TiSlidingScalePointerStyle read FPointer1Style           write SetPointer1Style           default isspsPointer;
    property Pointer1Color           : TColor                     read FPointer1Color           write SetPointer1Color           default clYellow;
    property Pointer1Size            : Integer                    read FPointer1Size            write SetPointer1Size            default 10;
    property Pointer1LineColor       : TColor                     read FPointer1LineColor       write SetPointer1LineColor       default clBlue;
    property Pointer1LineWidth       : Integer                    read FPointer1LineWidth       write SetPointer1LineWidth       default 2;

    property Pointer2Position        : Double                     read FPointer2Position        write SetPointer2Position;
    property Pointer2Style           : TiSlidingScalePointerStyle read FPointer2Style           write SetPointer2Style           default isspsArrow;
    property Pointer2Color           : TColor                     read FPointer2Color           write SetPointer2Color           default clRed;
    property Pointer2Size            : Integer                    read FPointer2Size            write SetPointer2Size            default 10;
    property Pointer2LineColor       : TColor                     read FPointer2LineColor       write SetPointer2LineColor       default clRed;
    property Pointer2LineWidth       : Integer                    read FPointer2LineWidth       write SetPointer2LineWidth       default 2;

    property PointerOrientation      : TiOrientationSide          read FPointerOrientation      write SetPointerOrientation      default iosTopLeft;

    property ShowMidTicks            : Boolean                    read FShowMidTicks            write SetShowMidTicks            default False;
    property ShowMidTickLabels       : Boolean                    read FShowMidTickLabels       write SetShowMidTickLabels       default False;

    property TitleText               : String                     read FTitleText               write SetTitleText;
    property TitleMargin             : Double                     read FTitleMargin             write SetTitleMargin;
    property TitleFont               : TFont                      read FTitleFont               write SetTitleFont;
    property TitleAlignment          : TiAlignmentSideVertical    read FTitleAlignment          write SetTitleAlignment          default iasvTop;

    property OuterMarginLeft         : Integer                    read FOuterMarginLeft         write SetOuterMarginLeft         default 0;
    property OuterMarginTop          : Integer                    read FOuterMarginTop          write SetOuterMarginTop          default 0;
    property OuterMarginRight        : Integer                    read FOuterMarginRight        write SetOuterMarginRight        default 0;
    property OuterMarginBottom       : Integer                    read FOuterMarginBottom       write SetOuterMarginBottom       default 0;

    property BackGroundColor;
    property BorderStyle;
    property Transparent;
    property CachedDrawing;
    property Width            default 250;
    property Height           default 60;
  end;

implementation
//****************************************************************************************************************************************************
constructor TiSlidingCompass.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  Width  := 250;
  Height := 60;

  FOrientation             := ioHorizontal;
  FScaleAntiAliasEnabled   := True;

  FScaleSpan               := 100;
  FScaleAlignStyle         := itasSide;
  FScaleBackgroundColor    := clWhite;
  FScaleOrientation        := iosTopLeft;
  FScaleShadowEnabled      := True;

  FTickMajorCount          := 5;
  FTickMajorLength         := 9;
  FTickMajorWidth          := 2;
  FTickMajorColor          := clBlack;
  FTickMajorLabelMargin    := 0.25;
  FTickMajorLabelPrecision := 0;

  FTickMidLength           := 7;
  FTickMidWidth            := 2;
  FTickMidColor            := clBlack;
  FTickMidLabelMargin      := 0.25;
  FTickMidLabelPrecision   := 1;

  FTickMinorCount          := 4;
  FTickMinorLength         := 5;
  FTickMinorWidth          := 1;
  FTickMinorColor          := clBlack;

  FPointerOrientation      := iosTopLeft;

  FPointer1Style           := isspsPointer;
  FPointer1Size            := 10;
  FPointer1Color           := clYellow;
  FPointer1LineWidth       := 2;
  FPointer1LineColor       := clBlue;

⌨️ 快捷键说明

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