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

📄 iknob.pas

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

{$ifdef iVCL}unit  iKnob;{$endif}
{$ifdef iCLX}unit QiKnob;{$endif}

interface

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

type
  TiKnobStyle          = (iksRaisedEdge, iksRaised, iksSunken, iksSunkenEdge);
  TiKnobIndicatorStyle = (ikisDotLowered, ikisDotRaised, ikisDot, ikisLineCenter, ikisLineCustom, ikisTriangle);

  TiKnob = class(TiScaleComponent)
  private
    FMouseDownDegrees         : Double;
    FMouseDown                : Boolean;
    FKeyDown                  : Boolean;
    FLastWheelTime            : TDateTime;

    FIndicatorActiveColor     : TColor;
    FIndicatorInactiveColor   : TColor;
    FIndicatorMargin          : Integer;
    FIndicatorSize            : Integer;
    FIndicatorStyle           : TiKnobIndicatorStyle;
    FKeyPageStepSize          : Double;
    FKeyArrowStepSize         : Double;
    FMouseWheelStepSize       : Double;
    FKnobEdgeWidth            : Integer;
    FKnobRadius               : Integer;
    FKnobStyle                : TiKnobStyle;
    FPositionDisplayFont      : TFont;
    FPositionDisplayPrecision : Integer;
    FPositionDisplayUnits     : String;
    FRotationMaxDegrees       : Integer;
    FRotationStartDegrees     : Integer;
    FShowFocusRect            : Boolean;
    FShowPostionDisplay       : Boolean;
    FAutoSize                 : Boolean;
    FOuterMargin              : Integer;
    FUseKeyboard              : Boolean;
    FCenterPoint              : TPoint;

    function  GetPositionDegrees : Double;
    procedure SetRotationStartDegrees    (const Value: Integer);
    procedure SetRotationMaxDegrees      (const Value: Integer);
    procedure SetKnobRadius              (const Value: Integer);
    procedure SetIndicatorMargin         (const Value: Integer);
    procedure SetIndicatorSize           (const Value: Integer);
    procedure SetShowPostionDisplay      (const Value: Boolean);
    procedure SetPositionDisplayFont     (const Value: TFont);
    procedure SetPositionDisplayPrecision(const Value: Integer);
    procedure SetIndicatorActiveColor    (const Value: TColor);
    procedure SetIndicatorInactiveColor  (const Value: TColor);
    procedure SetPositionDisplayUnits    (const Value: String);
    procedure SetPositionDegrees         (const Value: Double);
    procedure SetIndicatorStyle          (const Value: TiKnobIndicatorStyle);
    procedure SetKnobEdgeWidth           (const Value: Integer);
    procedure SetKnobStyle               (const Value: TiKnobStyle);
    procedure SetKeyArrowStepSize        (const Value: Double);
    procedure SetKeyPageStepSize         (const Value: Double);
    procedure SetMouseWheelStepSize      (const Value: Double);
    procedure SetShowFocusRect           (const Value: Boolean);
    procedure iSetAutoSize               (const Value: Boolean);
    procedure SetOuterMargin             (const Value: Integer);
    procedure SetUseKeyboard             (const Value: Boolean);
    function PositionToDegrees           (Value: Double): Double;
  protected
    procedure iPaintTo(Canvas: TCanvas);                                           override;
    procedure iMouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure iMouseUp  (Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure iMouseMove(                      Shift: TShiftState; X, Y: Integer); override;
    property  PositionDegrees : Double read GetPositionDegrees  write SetPositionDegrees;
    procedure DrawKnob        (Canvas: TCanvas; const CenterPoint: TPoint);
    procedure DrawTicks       (Canvas: TCanvas; const CenterPoint: TPoint);
    procedure DrawPosition    (Canvas: TCanvas; const CenterPoint: TPoint);
    procedure DrawIndicator   (Canvas: TCanvas; const CenterPoint: TPoint);
    procedure AdjustKnobRadius(Canvas: TCanvas; const CenterPoint: TPoint);
    function GetXYRadPoint2(AngleDegrees, Radius: Double; OffsetX, OffsetY : Double) : TPoint;

    procedure iWantSpecialKey(var CharCode: Word; var Result: Longint);             override;
    procedure iKeyUp         (var CharCode: Word; Shift: TShiftState);              override;
    procedure iKeyDown       (var CharCode: Word; Shift: TShiftState);              override;

    procedure iDoKillFocus; override;

    {$ifdef iVCL}function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint      ): Boolean; override;{$endif}
    {$ifdef iCLX}function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; const MousePos: TPoint): Boolean; override;{$endif}

    procedure DoOPCPositionChangeFinished; override;

    procedure DefineProperties(Filer : TFiler); override;
    procedure WriteKeyArrowStepSize(Writer : TWriter);
    procedure ReadKeyArrowStepSize (Reader : TReader);
    procedure WriteKeyPageStepSize (Writer : TWriter);
    procedure ReadKeyPageStepSize  (Reader : TReader);
  public
    constructor Create(AOwner: TComponent);                                        override;
    destructor  Destroy;                                                           override;
  published
    property PositionDisplayFont      : TFont                read FPositionDisplayFont      write SetPositionDisplayFont;
    property PositionDisplayPrecision : Integer              read FPositionDisplayPrecision write SetPositionDisplayPrecision default 1;
    property PositionDisplayUnits     : String               read FPositionDisplayUnits     write SetPositionDisplayUnits;
    property IndicatorActiveColor     : TColor               read FIndicatorActiveColor     write SetIndicatorActiveColor     default clAqua;
    property IndicatorInactiveColor   : TColor               read FIndicatorInactiveColor   write SetIndicatorInactiveColor   default clRed;
    property IndicatorMargin          : Integer              read FIndicatorMargin          write SetIndicatorMargin          default 5;
    property IndicatorSize            : Integer              read FIndicatorSize            write SetIndicatorSize            default 4;
    property IndicatorStyle           : TiKnobIndicatorStyle read FIndicatorStyle           write SetIndicatorStyle           default ikisDotLowered;
    property KeyArrowStepSize         : Double               read FKeyArrowStepSize         write SetKeyArrowStepSize;
    property KeyPageStepSize          : Double               read FKeyPageStepSize          write SetKeyPageStepSize;
    property MouseWheelStepSize       : Double               read FMouseWheelStepSize       write SetMouseWheelStepSize;
    property KnobEdgeWidth            : Integer              read FKnobEdgeWidth            write SetKnobEdgeWidth            default 3;
    property KnobRadius               : Integer              read FKnobRadius               write SetKnobRadius               default 35;
    property KnobStyle                : TiKnobStyle          read FKnobStyle                write SetKnobStyle                default iksRaised;
    property RotationMaxDegrees       : Integer              read FRotationMaxDegrees       write SetRotationMaxDegrees       default 270;
    property RotationStartDegrees     : Integer              read FRotationStartDegrees     write SetRotationStartDegrees     default 225;
    property ShowFocusRect            : Boolean              read FShowFocusRect            write SetShowFocusRect            default True;
    property ShowPostionDisplay       : Boolean              read FShowPostiondisplay       write SetShowPostionDisplay       default False;
    property AutoSize                 : Boolean              read FAutoSize                 write iSetAutoSize                default True;
    property OuterMargin              : Integer              read FOuterMargin              write SetOuterMargin              default 2;
    property UseKeyboard              : Boolean              read FUseKeyboard              write SetUseKeyboard              default True;

    property BackGroundColor;
    property BackGroundPicture;
    property OffsetX;
    property OffsetY;
    property TabOrder;
    property TabStop              default True;
    property Transparent;

    property ShowTicksMajor;
    property ShowTicksMinor;
    property ShowTickLabels;
    property TickMajorCount;
    property TickMajorColor;
    property TickMajorLength;
    property TickMinorAlignment;
    property TickMinorCount;
    property TickMinorColor       default clGray;
    property TickMinorLength;
    property TickMargin;
    property TickLabelMargin      default 15;
    property TickLabelFont;
    property TickLabelPrecision;
    property PrecisionStyle;

    property AutoScaleEnabled;
    property AutoScaleDesiredTicks;
    property AutoScaleMaxTicks;
    property AutoScaleStyle;

    property OnPositionChangeFinished;
    property OnCustomizeTickLabel;
    property OnPositionChangeUser;
    property CachedDrawing;

    property Width   default 150;
    property Height  default 150;
  end;

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

  Width            := 150;
  Height           := 150;
  TabStop          := True;
  TickMinorColor   := clGray;
  TickLabelMargin  := 15;

  FKnobRadius               := 35;
  FKnobStyle                := iksRaised;
  FAutoSize                 := True;
  FKnobEdgeWidth            := 3;

  FUseKeyboard              := True;
  FKeyArrowStepSize         := 0.1;
  FKeyPageStepSize          := 1;
  FMouseWheelStepSize       := 1;

  FIndicatorSize            := 4;
  FIndicatorMargin          := 5;
  FIndicatorActiveColor     := clAqua;
  FIndicatorInactiveColor   := clRed;

  FShowFocusRect            := True;

  FOuterMargin              := 2;

  FRotationStartDegrees     := 225;
  FRotationMaxDegrees       := 270;

  FPositionDisplayPrecision := 1;

  FPositionDisplayFont := TFont.Create; FPositionDisplayFont.OnChange := InvalidateChangeEvent;

  CreateBackGroundPicture;
end;
//****************************************************************************************************************************************************
destructor TiKnob.Destroy;
begin
  FPositionDisplayFont.Free;
  inherited
end;
//****************************************************************************************************************************************************
procedure TiKnob.SetKnobRadius            (const Value:Integer);begin SetIntegerProperty(Value,FKnobRadius,            irtBackGround);end;
procedure TiKnob.SetRotationStartDegrees  (const Value:Integer);begin SetIntegerProperty(Value,FRotationStartDegrees,  irtBackGround);end;
procedure TiKnob.SetRotationMaxDegrees    (const Value:Integer);begin SetIntegerProperty(Value,FRotationMaxDegrees,    irtBackGround);end;
procedure TiKnob.SetIndicatorMargin       (const Value:Integer);begin SetIntegerProperty(Value,FIndicatorMargin,       irtBackGround);end;
procedure TiKnob.SetIndicatorActiveColor  (const Value:TColor );begin SetColorProperty  (Value,FIndicatorActiveColor,  irtBackGround);end;
procedure TiKnob.SetIndicatorInactiveColor(const Value:TColor );begin SetColorProperty  (Value,FIndicatorInactiveColor,irtBackGround);end;
procedure TiKnob.SetShowPostionDisplay    (const Value:Boolean);begin SetBooleanProperty(Value,FShowPostionDisplay,    irtBackGround);end;
procedure TiKnob.SetKnobEdgeWidth         (const Value:Integer);begin SetIntegerProperty(Value,FKnobEdgeWidth,         irtBackGround);end;
procedure TiKnob.SetKeyArrowStepSize      (const Value:Double );begin SetDoubleProperty (Value,FKeyArrowStepSize,      irtInvalidate);end;
procedure TiKnob.SetKeyPageStepSize       (const Value:Double );begin SetDoubleProperty (Value,FKeyPageStepSize,       irtInvalidate);end;
procedure TiKnob.SetMouseWheelStepSize    (const Value:Double );begin SetDoubleProperty (Value,FMouseWheelStepSize,    irtInvalidate);end;
procedure TiKnob.SetShowFocusRect         (const Value:Boolean);begin SetBooleanProperty(Value,FShowFocusRect,         irtInvalidate);end;
procedure TiKnob.iSetAutoSize             (const Value:Boolean);begin SetBooleanProperty(Value,FAutoSize,              irtBackGround);end;
procedure TiKnob.SetOuterMargin           (const Value:Integer);begin SetIntegerProperty(Value,FOuterMargin,           irtBackGround);end;
procedure TiKnob.SetUseKeyboard           (const Value:Boolean);begin SetBooleanProperty(Value,FUseKeyboard,           irtBackGround);end;
//****************************************************************************************************************************************************
procedure TiKnob.SetPositionDisplayFont(const Value:TFont);begin FPositionDisplayFont.Assign(Value);end;
//****************************************************************************************************************************************************
procedure TiKnob.SetKnobStyle(const Value: TiKnobStyle);
begin
  if FKnobStyle <> Value then
    begin
      FKnobStyle := Value;
      BackGroundChange;
    end;
end;
//****************************************************************************************************************************************************
procedure TiKnob.SetIndicatorStyle(const Value: TiKnobIndicatorStyle);
begin
  if FIndicatorStyle <> Value then
    begin
      FIndicatorStyle := Value;
      BackGroundChange;
    end;
end;
//****************************************************************************************************************************************************
procedure TiKnob.SetPositionDegrees(const Value: Double);
begin
  Position := Value * (PositionMax - PositionMin)/FRotationMaxDegrees + PositionMin;
end;
//****************************************************************************************************************************************************
procedure TiKnob.SetPositionDisplayPrecision(const Value: Integer);
begin
  if FPositionDisplayPrecision <> Value then
    begin
      FPositionDisplayPrecision := Value;
      if FPositionDisplayPrecision < 0 then FPositionDisplayPrecision := 0;
      InvalidateChange;
    end;
end;
//****************************************************************************************************************************************************
procedure TiKnob.SetIndicatorSize(const Value: Integer);
begin
  if FIndicatorSize <> Value then
    begin

⌨️ 快捷键说明

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