📄 iangulargauge.pas
字号:
procedure TiAngularGauge.SetShowLabel2 (const Value:Boolean);begin SetBooleanProperty(Value,FShowLabel2, irtBackGround);end;
procedure TiAngularGauge.SetLabel1Text (const Value:String );begin SetStringProperty (Value,FLabel1Text, irtBackGround);end;
procedure TiAngularGauge.SetLabel1OffsetX (const Value:Integer);begin SetIntegerProperty(Value,FLabel1OffsetX, irtBackGround);end;
procedure TiAngularGauge.SetLabel1OffsetY (const Value:Integer);begin SetIntegerProperty(Value,FLabel1OffsetY, irtBackGround);end;
procedure TiAngularGauge.SetLabel2Text (const Value:String );begin SetStringProperty (Value,FLabel2Text, irtBackGround);end;
procedure TiAngularGauge.SetLabel2OffsetX (const Value:Integer);begin SetIntegerProperty(Value,FLabel2OffsetX, irtBackGround);end;
procedure TiAngularGauge.SetLabel2OffsetY (const Value:Integer);begin SetIntegerProperty(Value,FLabel2OffsetY, irtBackGround);end;
procedure TiAngularGauge.SetReverseScale (const Value:Boolean);begin SetBooleanProperty(Value,FReverseScale, irtBackGround);end;
procedure TiAngularGauge.SetAutoCenter (const Value:Boolean);begin SetBooleanProperty(Value,FAutoCenter, irtBackGround);end;
procedure TiAngularGauge.iSetAutoSize (const Value:Boolean);begin SetBooleanProperty(Value,FAutoSize, irtBackGround);end;
procedure TiAngularGauge.SetOuterMargin (const Value:Integer);begin SetIntegerProperty(Value,FOuterMargin, irtBackGround);end;
procedure TiAngularGauge.SetPanelFaceInnerColor(const Value:TColor );begin SetColorProperty (Value,FPanelFaceInnerColor,irtBackGround);end;
procedure TiAngularGauge.SetPanelFaceOuterColor(const Value:TColor );begin SetColorProperty (Value,FPanelFaceOuterColor,irtBackGround);end;
procedure TiAngularGauge.SetPanelFaceSize (const Value:Integer);begin SetIntegerProperty(Value,FPanelFaceSize, irtBackGround);end;
//****************************************************************************************************************************************************
procedure TiAngularGauge.SetLabel1Font(const Value: TFont);begin FLabel1Font.Assign(Value);end;
procedure TiAngularGauge.SetLabel2Font(const Value: TFont);begin FLabel2Font.Assign(Value);end;
//****************************************************************************************************************************************************
procedure TiAngularGauge.SetPanelFaceStyle(const Value: TiPanelFaceStyle);
begin
if FPanelFaceStyle <> Value then
begin
FPanelFaceStyle := Value;
BackGroundChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiAngularGauge.SetMinMaxPointerStyle(const Value: TiAngularGaugePointerStyle);
begin
if FMinMaxPointerStyle <> Value then
begin
FMinMaxPointerStyle := Value;
BackGroundChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiAngularGauge.SetLabel1AlignHorizontal(const Value: TiAlignmentHorizontal);
begin
if FLabel1AlignHorizontal <> Value then
begin
FLabel1AlignHorizontal := Value;
BackGroundChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiAngularGauge.SetLabel1AlignVertical(const Value: TiAlignmentVertical);
begin
if FLabel1AlignVertical <> Value then
begin
FLabel1AlignVertical := Value;
BackGroundChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiAngularGauge.SetLabel2AlignHorizontal(const Value: TiAlignmentHorizontal);
begin
if FLabel2AlignHorizontal <> Value then
begin
FLabel2AlignHorizontal := Value;
BackGroundChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiAngularGauge.SetLabel2AlignVertical(const Value: TiAlignmentVertical);
begin
if FLabel2AlignVertical <> Value then
begin
FLabel2AlignVertical := Value;
BackGroundChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiAngularGauge.SetTickLabelAlignment(const Value: TiLabelAlignment);
begin
if FTickLabelAlignment <> Value then
begin
FTickLabelAlignment := Value;
BackGroundChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiAngularGauge.SetArcRangeDegrees(const Value: Integer);
begin
if FArcRangeDegrees <> Value then
begin
FArcRangeDegrees := Value;
if FArcRangeDegrees > 360 then FArcRangeDegrees := 360;
BackGroundChange;
end;
end;
//****************************************************************************************************************************************************
function TiAngularGauge.GetLabelValue(Index: Integer): Double;
var
ActualMin : Double;
ActualMax : Double;
begin
if AutoScaleEnabled and (AutoScaleStyle = iassFixedMinMax) then
begin
ActualMin := FAutoScaleMinTick;
ActualMax := FAutoScaleMaxTick;
end
else
begin
ActualMin := PositionMin;
ActualMax := PositionMax;
end;
Result := (ActualMax - ActualMin)/(TickMajorCount-1)*Index + ActualMin;
end;
//****************************************************************************************************************************************************
function TiAngularGauge.GetLabelText(Index: Integer): String;
begin
Result := Trim(SysUtils.Format('%.' + IntToStr(GetDecimalPoints) + 'f', [GetLabelValue(Index)]));
if Assigned(OnCustomizeTickLabel) then TOnCustomizeTickLabel(OnCustomizeTickLabel)(Self, Index, Result);
end;
//****************************************************************************************************************************************************
function TiAngularGauge.GetLabelRect(Canvas: TCanvas; Index: Integer; Origin: TPoint): TRect;
var
LabelRadius : Integer;
TextPoint : TPoint;
AText : String;
Degrees : Double;
begin
AText := GetLabelText(Index);
Degrees := PositionToDegrees(GetLabelValue(Index));
with Canvas do
begin
Font.Assign(TickLabelFont);
LabelRadius := FArcRadius + TickMargin + TickMajorLength + TickLabelMargin + 4;
TextPoint := GetXYRadPoint(Degrees, LabelRadius, Origin);
case FTickLabelAlignment of
ilaCenter : Result := Rect(TextPoint.X - TextWidth (AText) div 2, TextPoint.Y - TextHeight(AText) div 2,
TextPoint.X + TextWidth (AText) div 2, TextPoint.Y + TextHeight(AText) div 2);
ilaJustified : if (Degrees = 0) then
Result := Rect(TextPoint.X, TextPoint.Y - TextHeight(AText) div 2,
TextPoint.X + TextWidth(AText),TextPoint.Y + TextHeight(AText) div 2)
else if (Degrees > 0) and (Degrees < 90) then
Result := Rect(TextPoint.X, TextPoint.Y - TextHeight(AText),
TextPoint.X + TextWidth(AText),TextPoint.Y)
else if (Degrees = 90) then
Result := Rect(TextPoint.X - TextWidth(AText) div 2, TextPoint.Y - TextHeight(AText),
TextPoint.X + TextWidth(AText) div 2, TextPoint.Y)
else if (Degrees > 90) and (Degrees < 180) then
Result := Rect(TextPoint.X - TextWidth(AText), TextPoint.Y - TextHeight(AText),
TextPoint.X, TextPoint.Y)
else if (Degrees = 180) then
Result := Rect(TextPoint.X - TextWidth(AText), TextPoint.Y - TextHeight(AText) div 2,
TextPoint.X, TextPoint.Y + TextHeight(AText) div 2)
else if (Degrees > 180) and (Degrees < 270) then
Result := Rect(TextPoint.X - TextWidth(AText), TextPoint.Y,
TextPoint.X, TextPoint.Y + TextHeight(AText))
else if (Degrees = 270) then
Result := Rect(TextPoint.X - TextWidth(AText) div 2, TextPoint.Y,
TextPoint.X + TextWidth(AText) div 2, TextPoint.Y + TextHeight(AText) div 2)
else if (Degrees > 270) and (Degrees < 360) then
Result := Rect(TextPoint.X, TextPoint.Y,
TextPoint.X + TextWidth(AText), TextPoint.Y + TextHeight(AText));
end;
end;
end;
//****************************************************************************************************************************************************
function TiAngularGauge.GetCenterPoint(Canvas: TCanvas) : TPoint;
var
x : Integer;
ARect : TRect;
MaxLeft : Integer;
MaxRight : Integer;
MaxTop : Integer;
MaxBottom : Integer;
SpaceLeft : Integer;
SpaceRight : Integer;
SpaceTop : Integer;
SpaceBottom : Integer;
CurrentPosition : Double;
ARadius : Integer;
APoint : TPoint;
begin
Result := inherited GetCenterPoint(Canvas);
if FAutoCenter or FAutoSize then
with Canvas do
begin
Font.Assign(TickLabelFont);
MaxLeft := Result.x;
MaxRight := Result.x;
MaxTop := Result.y;
MaxBottom := Result.y;
ARect := Rect(Result.x - FHubSize div 2, Result.y - FHubSize div 2,
Result.x + FHubSize div 2, Result.y + FHubSize div 2);
if ARect.Left < MaxLeft then MaxLeft := ARect.Left;
if ARect.Right > MaxRight then MaxRight := ARect.Right;
if ARect.Top < MaxTop then MaxTop := ARect.Top;
if ARect.Bottom > MaxBottom then MaxBottom := ARect.Bottom;
CurrentPosition := PositionMin;
while CurrentPosition < PositionMax do
begin
ARadius := FArcRadius + TickMargin + TickMinorLength;
APoint := GetXYRadPoint(PositionToDegrees(CurrentPosition), ARadius, Result);
if APoint.X < MaxLeft then MaxLeft := APoint.X;
if APoint.X > MaxRight then MaxRight := APoint.X;
if APoint.Y < MaxTop then MaxTop := APoint.Y;
if APoint.Y > MaxBottom then MaxBottom := APoint.Y;
CurrentPosition := CurrentPosition + (PositionMax - PositionMin)/ 10;
end;
for x := 0 to TickMajorCount - 1 do
begin
ARect := GetLabelRect(Canvas, x, Result);
if ARect.Left < MaxLeft then MaxLeft := ARect.Left;
if ARect.Right > MaxRight then MaxRight := ARect.Right;
if ARect.Top < MaxTop then MaxTop := ARect.Top;
if ARect.Bottom > MaxBottom then MaxBottom := ARect.Bottom;
end;
FMaxWidth := MaxRight - MaxLeft;
FMaxHeight := MaxBottom - MaxTop;
SpaceLeft := MaxLeft;
SpaceTop := MaxTop;
SpaceRight := Width - MaxRight;
SpaceBottom := Height - MaxBottom;
Result.x := Result.x - (SpaceLeft - SpaceRight ) div 2;
Result.y := Result.y - (SpaceTop - SpaceBottom) div 2;
Result.x := Result.x + OffsetX;
Result.y := Result.y - OffsetY;
end;
FCenterPoint := Result;
end;
//****************************************************************************************************************************************************
function TiAngularGauge.PositionToDegrees(Value: Double): Double;
begin
if FReverseScale then Result := FArcStartDegrees - FArcRangeDegrees + FArcRangeDegrees * ValuePercent(Value)
else Result := FArcStartDegrees - FArcRangeDegrees * ValuePercent(Value);
end;
//****************************************************************************************************************************************************
procedure TiAngularGauge.AdjustArcRadius(Canvas:TCanvas);
var
x : Integer;
ARect : TRect;
MaxLeft : Integer;
MaxRight : Integer;
MaxTop : Integer;
MaxBottom : Integer;
SpaceHorz : Integer;
SpaceVert : Integer;
SpaceMin : Integer;
SpaceLeft : Integer;
SpaceRight : Integer;
SpaceTop : Integer;
SpaceBottom : Integer;
begin
FArcRadius := 0;
with Canvas do
begin
Font.Assign(TickLabelFont);
MaxLeft := 0;
MaxRight := 0;
MaxTop := 0;
MaxBottom := 0;
for x := 0 to TickMajorCount - 1 do
begin
ARect := GetLabelRect(Canvas, x, Point(0, 0));
if ARect.Left < MaxLeft then MaxLeft := ARect.Left;
if ARect.Right > MaxRight then MaxRight := ARect.Right;
if ARect.Top < MaxTop then MaxTop := ARect.Top;
if ARect.Bottom > MaxBottom then MaxBottom := ARect.Bottom;
end;
SpaceLeft := MaxLeft;
SpaceTop := MaxTop;
SpaceRight := Width - MaxRight;
SpaceBottom := Height - MaxBottom;
SpaceHorz := SpaceLeft + SpaceRight;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -