📄 iangulargauge.pas
字号:
{*******************************************************}
{ }
{ TiAngularGauge Component }
{ }
{ Copyright (c) 1997,2003 Iocomp Software }
{ }
{*******************************************************}
{$I iInclude.inc}
{$ifdef iVCL}unit iAngularGauge;{$endif}
{$ifdef iCLX}unit QiAngularGauge;{$endif}
interface
uses
{$I iIncludeUses.inc}
{$IFDEF iVCL} iMath, iTypes, iGaugeComponent, iGPFunctions, iGaugePointer, iOPCItem;{$ENDIF}
{$IFDEF iCLX}QiMath, QiTypes, QiGaugeComponent, QiGPFunctions, QiGaugePointer; {$ENDIF}
type
TiPanelFaceStyle = (ipfsNone, ipfsStandard, ipfsPicture);
TiAngularGauge = class(TiGaugeComponent)
private
FArcRangeDegrees : Integer;
FArcRadius : Integer;
FArcStartDegrees : Integer;
FShowInnerArcRadius : Boolean;
FShowHub : Boolean;
FHubSize : Integer;
FHubColor : TColor;
FShowOuterArcRadius : Boolean;
FMinMaxPointerStyle : TiAngularGaugePointerStyle;
FShowLabel2 : Boolean;
FShowLabel1 : Boolean;
FLabel1OffsetX : Integer;
FLabel2OffsetY : Integer;
FLabel1OffsetY : Integer;
FLabel2OffsetX : Integer;
FLabel2Text : String;
FLabel1Text : String;
FLabel1Font : TFont;
FLabel2Font : TFont;
FLabel1AlignHorizontal : TiAlignmentHorizontal;
FLabel2AlignHorizontal : TiAlignmentHorizontal;
FLabel1AlignVertical : TiAlignmentVertical;
FLabel2AlignVertical : TiAlignmentVertical;
FReverseScale : Boolean;
FAutoCenter : Boolean;
FCenterPoint : TPoint;
FMaxWidth : Integer;
FMaxHeight : Integer;
FMouseDownX : Integer;
FMouseDownY : Integer;
FMouseDownDegrees : Double;
FOldCurrentValue : Double;
FTickLabelAlignment : TiLabelAlignment;
FAutoSize : Boolean;
FOuterMargin : Integer;
FPanelFaceStyle : TiPanelFaceStyle;
FPanelFaceSize : Integer;
FPanelFaceOuterColor : TColor;
FPanelFaceInnerColor : TColor;
FMinPointer : TiGaugePointer;
FMaxPointer : TiGaugePointer;
procedure SetArcRadius (const Value: Integer);
procedure SetArcRangeDegrees (const Value: Integer);
procedure SetArcStartDegrees (const Value: Integer);
procedure SetPointerMargin (const Value: Integer);
procedure SetPointerStyle (const Value: TiAngularGaugePointerStyle);
procedure SetMinMaxPointerStyle (const Value: TiAngularGaugePointerStyle);
procedure SetShowInnerArcRadius (const Value: Boolean);
procedure SetPointerColor (const Value: TColor);
procedure SetPointerSize (const Value: Integer);
procedure SetHubSize (const Value: Integer);
procedure SetShowHub (const Value: Boolean);
procedure SetShowOuterArcRadius (const Value: Boolean);
procedure SetLabel1Text (const Value: String);
procedure SetLabel1AlignHorizontal(const Value: TiAlignmentHorizontal);
procedure SetLabel1AlignVertical (const Value: TiAlignmentVertical);
procedure SetLabel1OffsetX (const Value: Integer);
procedure SetLabel1OffsetY (const Value: Integer);
procedure SetLabel1Font (const Value: TFont);
procedure SetLabel2Text (const Value: String);
procedure SetLabel2AlignHorizontal(const Value: TiAlignmentHorizontal);
procedure SetLabel2AlignVertical (const Value: TiAlignmentVertical);
procedure SetLabel2OffsetX (const Value: Integer);
procedure SetLabel2OffsetY (const Value: Integer);
procedure SetLabel2Font (const Value: TFont);
procedure SetShowLabel1 (const Value: Boolean);
procedure SetShowLabel2 (const Value: Boolean);
procedure SetReverseScale (const Value: Boolean);
procedure SetHubColor (const Value: TColor);
procedure SetAutoCenter (const Value: Boolean);
procedure SetTickLabelAlignment (const Value: TiLabelAlignment);
procedure iSetAutoSize (const Value: Boolean);
procedure SetOuterMargin (const Value: Integer);
procedure SetPanelFaceStyle (const Value: TiPanelFaceStyle);
function GetPointerColor : TColor;
function GetPointerMargin: Integer;
function GetPointerSize : Integer;
function GetPointerStyle : TiAngularGaugePointerStyle;
procedure AdjustArcRadius(Canvas:TCanvas);
procedure SetPanelFaceInnerColor(const Value: TColor);
procedure SetPanelFaceOuterColor(const Value: TColor);
procedure SetPanelFaceSize(const Value: Integer);
protected
function GetLabelValue(Index: Integer): Double;
function GetLabelText(Index: Integer): String;
function GetLabelRect(Canvas: TCanvas; Index: Integer; Origin: TPoint): TRect;
function GetCenterPoint(Canvas: TCanvas): TPoint; override;
procedure DrawTicks (Canvas: TCanvas; const OffsetPoint: TPoint);
procedure DrawSections (Canvas: TCanvas; const OffsetPoint: TPoint);
procedure DrawArcRadius(Canvas: TCanvas; const OffsetPoint: TPoint);
procedure DrawIndicator(Canvas: TCanvas; const OffsetPoint: TPoint; APointer: TiGaugePointer);
procedure DrawHub (Canvas: TCanvas; const OffsetPoint: TPoint);
procedure DrawMinMax (Canvas: TCanvas; const OffsetPoint: TPoint);
procedure DrawLimits (Canvas: TCanvas; const OffsetPoint: TPoint);
procedure DrawLabels (Canvas: TCanvas; const CenterPoint: TPoint);
procedure DrawPanelFace(Canvas: TCanvas; const CenterPoint: TPoint);
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;
function PositionToDegrees(Value : Double) : Double;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function GetPointersMargin(Index: Integer): Integer;
function GetPointersStyle (Index: Integer): TiAngularGaugePointerStyle;
procedure SetPointersMargin(Index: Integer; Value: Integer);
procedure SetPointersStyle(Index: Integer; Value: TiAngularGaugePointerStyle);
published
property ArcRadius : Integer read FArcRadius write SetArcRadius default 60;
property ArcRangeDegrees : Integer read FArcRangeDegrees write SetArcRangeDegrees default 90;
property ArcStartDegrees : Integer read FArcStartDegrees write SetArcStartDegrees default 180;
property Label1Text : String read FLabel1Text write SetLabel1Text;
property Label1Font : TFont read FLabel1Font write SetLabel1Font;
property Label1AlignVertical : TiAlignmentVertical read FLabel1AlignVertical write SetLabel1AlignVertical default iavCenter;
property Label1AlignHorizontal : TiAlignmentHorizontal read FLabel1AlignHorizontal write SetLabel1AlignHorizontal default iahCenter;
property Label1OffsetX : Integer read FLabel1OffsetX write SetLabel1OffsetX default -15;
property Label1OffsetY : Integer read FLabel1OffsetY write SetLabel1OffsetY default -35;
property Label2Text : String read FLabel2Text write SetLabel2Text;
property Label2Font : TFont read FLabel2Font write SetLabel2Font;
property Label2AlignVertical : TiAlignmentVertical read FLabel2AlignVertical write SetLabel2AlignVertical default iavCenter;
property Label2AlignHorizontal : TiAlignmentHorizontal read FLabel2AlignHorizontal write SetLabel2AlignHorizontal default iahCenter;
property Label2OffsetX : Integer read FLabel2OffsetX write SetLabel2OffsetX default -15;
property Label2OffsetY : Integer read FLabel2OffsetY write SetLabel2OffsetY default -25;
property HubSize : Integer read FHubSize write SetHubSize default 14;
property HubColor : TColor read FHubColor write SetHubColor default clBlack;
property MinMaxPointerStyle : TiAngularGaugePointerStyle read FMinMaxPointerStyle write SetMinMaxPointerStyle default iagpsArrowLine;
property PointerMargin : Integer read GetPointerMargin write SetPointerMargin default 0;
property PointerColor : TColor read GetPointerColor write SetPointerColor default clBlack;
property PointerSize : Integer read GetPointerSize write SetPointerSize default 10;
property PointerStyle : TiAngularGaugePointerStyle read GetPointerStyle write SetPointerStyle default iagpsTriangle;
property ShowInnerArcRadius : Boolean read FShowInnerArcRadius write SetShowInnerArcRadius default False;
property ShowOuterArcRadius : Boolean read FShowOuterArcRadius write SetShowOuterArcRadius default False;
property ShowHub : Boolean read FShowHub write SetShowHub default True;
property ShowLabel1 : Boolean read FShowLabel1 write SetShowLabel1 default False;
property ShowLabel2 : Boolean read FShowLabel2 write SetShowLabel2 default False;
property AutoCenter : Boolean read FAutoCenter write SetAutoCenter default True;
property TickLabelAlignment : TiLabelAlignment read FTickLabelAlignment write SetTickLabelAlignment default ilaCenter;
property ReverseScale : Boolean read FReverseScale write SetReverseScale default False;
property AutoSize : Boolean read FAutoSize write iSetAutoSize default False;
property OuterMargin : Integer read FOuterMargin write SetOuterMargin default 5;
property PanelFaceStyle : TiPanelFaceStyle read FPanelFaceStyle write SetPanelFaceStyle;
property PanelFaceOuterColor : TColor read FPanelFaceOuterColor write SetPanelFaceOuterColor;
property PanelFaceInnerColor : TColor read FPanelFaceInnerColor write SetPanelFaceInnerColor;
property PanelFaceSize : Integer read FPanelFaceSize write SetPanelFaceSize;
property OffsetX;
property OffsetY;
property BackGroundPicture;
property BackGroundColor;
property BorderStyle;
property CachedDrawing;
property Transparent;
property ShowTicksMajor;
property ShowTicksMinor;
property ShowTickLabels;
property TickMajorCount;
property TickMajorColor;
property TickMajorLength;
property TickMinorAlignment;
property TickMinorCount;
property TickMinorColor;
property TickMinorLength;
property TickMargin;
property TickLabelMargin default 15;
property TickLabelFont;
property TickLabelPrecision;
property PrecisionStyle;
property OnCustomizeTickLabel;
property SectionColor1;
property SectionColor2;
property SectionColor3;
property SectionColor4;
property SectionColor5;
property SectionCount;
property SectionEnd1;
property SectionEnd2;
property SectionEnd3;
property SectionEnd4;
property ShowMaxPointer;
property ShowMinPointer;
property MinMaxPointerSize;
property MinMaxPointerMargin;
property MaxPointerColor;
property MinPointerColor;
property MinMaxUserCanMove;
property AutoScaleEnabled;
property AutoScaleDesiredTicks;
property AutoScaleMaxTicks;
property AutoScaleStyle;
property Width default 150;
property Height default 150;
end;
implementation
//****************************************************************************************************************************************************
constructor TiAngularGauge.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width := 150;
Height := 150;
TickLabelMargin := 15;
FArcRadius := 60;
FArcRangeDegrees := 90;
FArcStartDegrees := 180;
FShowHub := True;
FHubSize := 14;
FLabel1OffsetX := -15;
FLabel1OffsetY := -35;
FLabel2OffsetX := -15;
FLabel2OffsetY := -20;
FOuterMargin := 5;
FPanelFaceSize := 15;
FPanelFaceInnerColor := clWhite;
FLabel1Font := TFont.Create; FLabel1Font.OnChange := BackGroundChangeEvent;
FLabel2Font := TFont.Create; FLabel2Font.OnChange := BackGroundChangeEvent;
FAutoCenter := True;
FMinPointer := TiGaugePointer.Create(nil);
FMaxPointer := TiGaugePointer.Create(nil);
CreateBackGroundPicture;
end;
//****************************************************************************************************************************************************
destructor TiAngularGauge.Destroy;
begin
FMinPointer.Free;
FMaxPointer.Free;
FLabel1Font.Free;
FLabel2Font.Free;
inherited;
end;
//****************************************************************************************************************************************************
procedure TiAngularGauge.SetArcRadius (const Value:Integer);begin SetIntegerProperty(Value,FArcRadius, irtBackGround);end;
procedure TiAngularGauge.SetArcStartDegrees (const Value:Integer);begin SetIntegerProperty(Value,FArcStartDegrees, irtBackGround);end;
procedure TiAngularGauge.SetShowInnerArcRadius (const Value:Boolean);begin SetBooleanProperty(Value,FShowInnerArcRadius, irtBackGround);end;
procedure TiAngularGauge.SetShowOuterArcRadius (const Value:Boolean);begin SetBooleanProperty(Value,FShowOuterArcRadius, irtBackGround);end;
procedure TiAngularGauge.SetHubSize (const Value:Integer);begin SetIntegerProperty(Value,FHubSize, irtBackGround);end;
procedure TiAngularGauge.SetHubColor (const Value:TColor );begin SetColorProperty (Value,FHubColor, irtBackGround);end;
procedure TiAngularGauge.SetShowHub (const Value:Boolean);begin SetBooleanProperty(Value,FShowHub, irtBackGround);end;
procedure TiAngularGauge.SetShowLabel1 (const Value:Boolean);begin SetBooleanProperty(Value,FShowLabel1, irtBackGround);end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -