Industrial: Make TA3nalogGauge and TLEDNumber high-dpi aware.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6857 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2019-04-22 16:12:52 +00:00
parent 950e85af8f
commit 19acc480ad
5 changed files with 116 additions and 56 deletions

View File

@@ -94,22 +94,16 @@ object Form1: TForm1
Width = 120 Width = 120
Caption = 'Voltage' Caption = 'Voltage'
Value = 50 Value = 50
Color = clPurple
ParentColor = False ParentColor = False
ColorFore = clRed
ColorBack = clInactiveCaption
SignalUnit = 'mV' SignalUnit = 'mV'
ValueMin = 0 ValueMin = 0
ValueMax = 100 ValueMax = 100
Digits = 0 Digits = 0
Increment = 10 Increment = 10
ShowIncrements = True
Transparent = True
GapTop = 10 GapTop = 10
GapBottom = 5 GapBottom = 5
BarThickness = 6 BarThickness = 6
MarkerColor = clBlue MarkerColor = clBlue
ShowMarker = True
end end
object Arrow1: TArrow object Arrow1: TArrow
Left = 48 Left = 48
@@ -150,12 +144,14 @@ object Form1: TForm1
Height = 35 Height = 35
Top = 180 Top = 180
Width = 504 Width = 504
ColorBetween = 16481536 ColorAbove = clRed
ColorThumb = 10768896 ColorBelow = clYellow
ColorBetween = clGreen
ColorThumb = clBlack
MaxPosition = 75 MaxPosition = 75
MinPosition = 25 MinPosition = 25
SliderMode = smMinValueMax SliderMode = smMinValueMax
ThumbStyle = tsTriangle ThumbStyle = tsTriangleOtherSide
OnPositionChange = MultiSlider1PositionChange OnPositionChange = MultiSlider1PositionChange
end end
object ComboBox1: TComboBox object ComboBox1: TComboBox

View File

@@ -32,6 +32,11 @@ const
foShowMainTicks, foShowSubTicks, foShowIndicatorMax, foShowMainTicks, foShowSubTicks, foShowIndicatorMax,
foShowValues, foShowCenter, foShowFrame, foShow3D, foShowCaption foShowValues, foShowCenter, foShowFrame, foShow3D, foShowCaption
]; ];
DEFAULT_CENTER_RADIUS = 8;
DEFAULT_CIRCLE_RADIUS = 3;
DEFAULT_LENGTH_MAINTICKS = 15;
DEFAULT_LENGTH_SUBTICKS = 8;
DEFAULT_MARGIN = 10;
type type
TA3nalogGauge = class(TCustomControl) TA3nalogGauge = class(TCustomControl)
@@ -85,6 +90,11 @@ type
FOnFrames: TNotifyEvent; FOnFrames: TNotifyEvent;
{$ENDIF} {$ENDIF}
// set properties // set properties
function IsCenterRadiusStored: Boolean;
function IsCircleRadiusStored: Boolean;
function IsLengthMainTicksStored: Boolean;
function IsLengthSubTicksStored: Boolean;
function IsMarginStored: Boolean;
procedure SetFrameColor(C: TColor); procedure SetFrameColor(C: TColor);
procedure SetMinColor(C: TColor); procedure SetMinColor(C: TColor);
procedure SetMidColor(C: TColor); procedure SetMidColor(C: TColor);
@@ -118,8 +128,10 @@ type
protected protected
procedure CaptionFontChanged(Sender: TObject); procedure CaptionFontChanged(Sender: TObject);
procedure DrawScale(Bitmap: TBitmap; K: Integer); procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
const AXProportion, AYProportion: Double); override;
procedure DrawArrow(Bitmap: TBitmap; K: Integer); procedure DrawArrow(Bitmap: TBitmap; K: Integer);
procedure DrawScale(Bitmap: TBitmap; K: Integer);
procedure FastAntiAliasPicture; procedure FastAntiAliasPicture;
procedure Loaded; override; procedure Loaded; override;
procedure RedrawArrow; procedure RedrawArrow;
@@ -134,6 +146,7 @@ type
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
procedure ScaleFontsPPI(const AToPPI: Integer; const AProportion: Double); override;
published published
property Angle: Integer property Angle: Integer
@@ -153,11 +166,11 @@ type
property CenterColor: TColor property CenterColor: TColor
read FCenterColor write SetCenterColor default clDkGray; read FCenterColor write SetCenterColor default clDkGray;
property CenterRadius: Integer property CenterRadius: Integer
read FCenterRadius write SetCenterRadius default 8; read FCenterRadius write SetCenterRadius stored IsCenterRadiusStored;
property CircleColor: TColor property CircleColor: TColor
read FCircleColor write SetCircleColor default clBlue; read FCircleColor write SetCircleColor default clBlue;
property CircleRadius: Integer property CircleRadius: Integer
read FCircleRadius write SetCircleRadius default 3; read FCircleRadius write SetCircleRadius stored IsCircleRadiusStored;
property FaceColor: TColor property FaceColor: TColor
read FFaceColor write SetFaceColor default clBtnFace; read FFaceColor write SetFaceColor default clBtnFace;
property FaceOptions: TFaceOptions property FaceOptions: TFaceOptions
@@ -169,11 +182,11 @@ type
property IndMinimum: Integer property IndMinimum: Integer
read FMinimum write SetMinimum default 20; read FMinimum write SetMinimum default 20;
property LengthMainTicks: Integer property LengthMainTicks: Integer
read FLengthMainTicks write SetLengthMainTicks default 15; read FLengthMainTicks write SetLengthMainTicks stored IsLengthMainTicksStored;
property LengthSubTicks: Integer property LengthSubTicks: Integer
read FLengthSubTicks write SetLengthSubTicks default 8; read FLengthSubTicks write SetLengthSubTicks stored IsLengthSubTicksStored;
property Margin: Integer property Margin: Integer
read FMargin write SetMargin default 10; read FMargin write SetMargin stored IsMarginStored;
property MarginColor: TColor property MarginColor: TColor
read FMarginColor write SetMarginColor default clSilver; read FMarginColor write SetMarginColor default clSilver;
property MaxColor: TColor property MaxColor: TColor
@@ -246,7 +259,7 @@ begin
FValueColor := clBlack; FValueColor := clBlack;
FCaptionColor := clBlack; FCaptionColor := clBlack;
FArrowColor := clBlack; FArrowColor := clBlack;
FMarginColor := clSilver; //Black; FMarginColor := clSilver;
FCenterColor := clDkGray; FCenterColor := clDkGray;
FCircleColor := clBlue; FCircleColor := clBlue;
FMinColor := clGreen; FMinColor := clGreen;
@@ -254,17 +267,17 @@ begin
FMaxColor := clRed; FMaxColor := clRed;
FArrowWidth := 1; FArrowWidth := 1;
FPosition := 0; FPosition := 0;
FMargin := 10; FMargin := Scale96ToFont(DEFAULT_MARGIN);
FStyle := agsCenterStyle; FStyle := agsCenterStyle;
FScaleValue := 100; FScaleValue := 100;
FMaximum := 80; FMaximum := 80;
FMinimum := 20; FMinimum := 20;
FScaleAngle := 120; FScaleAngle := 120;
FCircleRadius := 3; FCircleRadius := Scale96ToFont(DEFAULT_CIRCLE_RADIUS);
FCenterRadius := 8; FCenterRadius := Scale96ToFont(DEFAULT_CENTER_RADIUS);
FNumMainTicks := 5; FNumMainTicks := 5;
FLengthMainTicks := 15; FLengthMainTicks := Scale96ToFont(DEFAULT_LENGTH_MAINTICKS);
FLengthSubTicks := 8; FLengthSubTicks := Scale96ToFont(DEFAULT_LENGTH_SUBTICKS);
FCaption := ''; FCaption := '';
FFaceOptions := DEFAULT_FACE_OPTIONS; FFaceOptions := DEFAULT_FACE_OPTIONS;
FAntiAliased := aaNone; FAntiAliased := aaNone;
@@ -300,6 +313,31 @@ begin
RedrawScale; RedrawScale;
end; end;
procedure TA3nalogGauge.DoAutoAdjustLayout(
const AMode: TLayoutAdjustmentPolicy;
const AXProportion, AYProportion: Double);
begin
inherited DoAutoAdjustLayout(AMode, AXProportion, AYProportion);
if AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then
begin
DisableAutosizing;
try
if IsCenterRadiusStored then
FCenterRadius := Round(FCenterRadius * AXProportion);
if IsCircleRadiusStored then
FCircleRadius := Round(FCircleRadius * AXProportion);
if IsLengthMainTicksStored then
FLengthMainTicks := Round(FLengthMainTicks * AXProportion);
if IsLengthSubTicksStored then
FLengthSubTicks := Round(FLengthSubTicks * AXProportion);
if IsMarginStored then
FMargin := Round(FMargin * AXProportion);
finally
EnableAutoSizing;
end;
end;
end;
procedure TA3nalogGauge.DrawScale(Bitmap: TBitmap; K: Integer); procedure TA3nalogGauge.DrawScale(Bitmap: TBitmap; K: Integer);
var var
I, J, X, Y, N, M, W, H, R: Integer; I, J, X, Y, N, M, W, H, R: Integer;
@@ -312,15 +350,16 @@ var
pt: TPoint; pt: TPoint;
txt: String; txt: String;
txtDist: Integer; txtDist: Integer;
apw: Integer; // pen width of arc
begin begin
W := Bitmap.Width; W := Bitmap.Width;
H := Bitmap.Height; H := Bitmap.Height;
Max := FMaximum; Max := FMaximum;
Min := FMinimum; Min := FMinimum;
N := FNumMainTicks*5; N := FNumMainTicks * 5;
M := FMargin * K; M := FMargin * K;
R := FCircleRadius * K; R := FCircleRadius * K;
txtDist := 10; txtDist := Scale96ToFont(10);
with Bitmap do begin with Bitmap do begin
Canvas.Brush.Color := FFaceColor; Canvas.Brush.Color := FFaceColor;
@@ -412,8 +451,9 @@ begin
end; end;
{ Draw min/max indicator arcs } { Draw min/max indicator arcs }
apw := Scale96ToFont(4 * K);
if (foShowIndicatorMax in FFaceOptions) then begin if (foShowIndicatorMax in FFaceOptions) then begin
SetPenStyles(Canvas.Pen, 4 * K, FMaxColor); SetPenStyles(Canvas.Pen, apw, FMaxColor);
SinCos(DegToRad(A + FScaleAngle), sinA, cosA); SinCos(DegToRad(A + FScaleAngle), sinA, cosA);
SinCos(DegToRad(A + Max*FScaleAngle/FScaleValue), sinB, cosB); SinCos(DegToRad(A + Max*FScaleAngle/FScaleValue), sinB, cosB);
Canvas.Arc(X - J, Y - J, X + J, Y + J, Canvas.Arc(X - J, Y - J, X + J, Y + J,
@@ -424,7 +464,7 @@ begin
); );
end; end;
if (foShowIndicatorMid in FFaceOptions) and (FMinimum < FMaximum) then begin if (foShowIndicatorMid in FFaceOptions) and (FMinimum < FMaximum) then begin
SetPenStyles(Canvas.Pen, 4 * K, FMidColor); SetPenStyles(Canvas.Pen, apw, FMidColor);
SinCos(DegToRad(A + Max*FScaleAngle/FScaleValue), sinA, cosA); SinCos(DegToRad(A + Max*FScaleAngle/FScaleValue), sinA, cosA);
SinCos(DegToRad(A + Min*FScaleAngle/FScaleValue), sinB, cosB); SinCos(DegToRad(A + Min*FScaleAngle/FScaleValue), sinB, cosB);
Canvas.Arc(X - J, Y - J, X + J, Y + J, Canvas.Arc(X - J, Y - J, X + J, Y + J,
@@ -435,9 +475,9 @@ begin
); );
end; end;
if (foShowIndicatorMin in FFaceOptions) then begin if (foShowIndicatorMin in FFaceOptions) then begin
SetPenStyles(Canvas.Pen, apw, FMinColor);
SinCos(DegToRad(A + Min*FScaleAngle/FScaleValue), sinA, cosA); SinCos(DegToRad(A + Min*FScaleAngle/FScaleValue), sinA, cosA);
SinCos(DegToRad(A), sinB, cosB); SinCos(DegToRad(A), sinB, cosB);
SetPenStyles(Canvas.Pen, 4 * K, FMinColor);
Canvas.Arc(X - J, Y - J, X + J, Y + J, Canvas.Arc(X - J, Y - J, X + J, Y + J,
Round(C - J * cosA), Round(C - J * cosA),
Round(Y - J * sinA), Round(Y - J * sinA),
@@ -757,6 +797,31 @@ begin
end; end;
} }
function TA3nalogGauge.IsCenterRadiusStored: Boolean;
begin
Result := FCenterRadius <> Scale96ToFont(DEFAULT_CENTER_RADIUS);
end;
function TA3nalogGauge.IsCircleRadiusStored: Boolean;
begin
Result := FCircleRadius <> Scale96ToFont(DEFAULT_CIRCLE_RADIUS);
end;
function TA3nalogGauge.IsLengthMainTicksStored: Boolean;
begin
Result := FLengthMainTicks <> Scale96ToFont(DEFAULT_LENGTH_MAINTICKS);
end;
function TA3nalogGauge.IsLengthSubTicksStored: Boolean;
begin
Result := FLengthSubTicks <> Scale96ToFont(DEFAULT_LENGTH_SUBTICKS);
end;
function TA3nalogGauge.IsMarginStored: Boolean;
begin
Result := FMargin <> Scale96ToFont(DEFAULT_MARGIN);
end;
procedure TA3nalogGauge.Loaded; procedure TA3nalogGauge.Loaded;
begin begin
inherited; inherited;
@@ -813,6 +878,13 @@ begin
inherited; inherited;
end; end;
procedure TA3nalogGauge.ScaleFontsPPI(const AToPPI: Integer;
const AProportion: Double);
begin
inherited;
DoScaleFontPPI(FCaptionFont, AToPPI, AProportion);
end;
procedure TA3nalogGauge.SetCaptionFont(AValue: TFont); procedure TA3nalogGauge.SetCaptionFont(AValue: TFont);
begin begin
FCaptionFont.Assign(AValue); FCaptionFont.Assign(AValue);

View File

@@ -106,15 +106,15 @@ type
property Color; property Color;
property Font; property Font;
property ParentColor; property ParentColor;
property ColorFore: Tcolor read fColorFore write SetColorFore; property ColorFore: Tcolor read fColorFore write SetColorFore default clRed;
property ColorBack: Tcolor read fColorBack write SetColorBack; property ColorBack: Tcolor read fColorBack write SetColorBack default clBtnFace;
property SignalUnit: ShortString read fSignalUnit write SetSignalUnit; property SignalUnit: ShortString read fSignalUnit write SetSignalUnit;
property ValueMin: Double read fValueMin write SetValueMin; property ValueMin: Double read fValueMin write SetValueMin;
property ValueMax: Double read fValueMax write SetValueMax; property ValueMax: Double read fValueMax write SetValueMax;
property Digits: Byte read fDigits write SetDigits; property Digits: Byte read fDigits write SetDigits;
property Increment: Double read fIncrement write SetIncrement; property Increment: Double read fIncrement write SetIncrement;
property ShowIncrements: Boolean read fShowIncrements write SetShowIncrements; property ShowIncrements: Boolean read fShowIncrements write SetShowIncrements default true;
property Transparent: Boolean read GetTransparent write SetTransparent; property Transparent: Boolean read GetTransparent write SetTransparent default true;
property GapTop: Word property GapTop: Word
read fGapTop write SetGapTop stored IsGapTopStored; read fGapTop write SetGapTop stored IsGapTopStored;
property GapBottom: Word property GapBottom: Word
@@ -126,7 +126,7 @@ type
read fMarkerDist write SetMarkerDist stored IsMarkerDistStored; read fMarkerDist write SetMarkerDist stored IsMarkerDistStored;
property MarkerSize: Integer property MarkerSize: Integer
read fMarkerSize write SetMarkerSize stored IsMarkerSizeStored; read fMarkerSize write SetMarkerSize stored IsMarkerSizeStored;
property ShowMarker: Boolean read fShowMarker write SetShowMarker; property ShowMarker: Boolean read fShowMarker write SetShowMarker default true;
end; end;
@@ -462,9 +462,9 @@ begin
with Canvas do with Canvas do
begin begin
TheRect := ClientRect; TheRect := ClientRect;
TheRect.Left := LeftMeter + BarThickness + 10; TheRect.Left := LeftMeter + BarThickness + Scale96ToFont(10);
TheRect.Top := TopTextHeight; TheRect.Top := TopTextHeight;
TheRect.Bottom := Height - fGapBottom + 6; TheRect.Bottom := Height - fGapBottom + Scale96ToFont(6);
Brush.Style := bsClear; Brush.Style := bsClear;
DrawStyle := DT_SINGLELINE + DT_NOPREFIX + DT_LEFT + DT_BOTTOM; DrawStyle := DT_SINGLELINE + DT_NOPREFIX + DT_LEFT + DT_BOTTOM;
DisplayValue := FloatToStrF(ValueMin, ffFixed, 8, fDigits) + ' ' + fSignalUnit; DisplayValue := FloatToStrF(ValueMin, ffFixed, 8, fDigits) + ' ' + fSignalUnit;
@@ -478,8 +478,8 @@ begin
with Canvas do with Canvas do
begin begin
TheRect := ClientRect; TheRect := ClientRect;
TheRect.Left := LeftMeter + BarThickness + 10; TheRect.Left := LeftMeter + BarThickness + Scale96ToFont(10);
TheRect.Top := TopTextHeight - 6; TheRect.Top := TopTextHeight - Scale96ToFont(6);
Brush.Style := bsClear; Brush.Style := bsClear;
DrawStyle := DT_SINGLELINE + DT_NOPREFIX + DT_LEFT + DT_TOP; DrawStyle := DT_SINGLELINE + DT_NOPREFIX + DT_LEFT + DT_TOP;
DisplayValue := FloatToStrF(ValueMax, ffFixed, 8, fDigits) + ' ' + fSignalUnit; DisplayValue := FloatToStrF(ValueMax, ffFixed, 8, fDigits) + ' ' + fSignalUnit;
@@ -523,7 +523,6 @@ begin
MoveTo(LeftMeter + 1, ValueToPixels(fValue) - 1); MoveTo(LeftMeter + 1, ValueToPixels(fValue) - 1);
LineTo(LeftMeter + fBarThickness, ValueToPixels(fValue) - 1); LineTo(LeftMeter + fBarThickness, ValueToPixels(fValue) - 1);
end; end;
end; end;
end; end;
@@ -541,7 +540,7 @@ end;
procedure TindGnouMeter.Paint; procedure TindGnouMeter.Paint;
begin begin
LeftMeter := (Width div 2) - 10 - fBarThickness; LeftMeter := (Width div 2) - Scale96ToFont(10) - fBarThickness;
with Canvas do with Canvas do
begin begin
if not Transparent then if not Transparent then

View File

@@ -311,8 +311,8 @@ var
I : Integer; I : Integer;
begin begin
for I := 0 to MAX_POINTS do begin for I := 0 to MAX_POINTS do begin
Points[i].X := DigitPoints[i].X * (FSize - 1); Points[i].X := Scale96ToFont(DigitPoints[i].X * (FSize - 1));
Points[i].Y := DigitPoints[i].Y * (FSize - 1); Points[i].Y := Scale96ToFont(DigitPoints[i].Y * (FSize - 1));
end; end;
end; end;
{=====} {=====}
@@ -320,9 +320,9 @@ end;
function TCustomLEDNumber.NewOffset(xOry: char; OldOffset: Integer): Integer; function TCustomLEDNumber.NewOffset(xOry: char; OldOffset: Integer): Integer;
begin begin
if (xOry = 'x')then if (xOry = 'x')then
newOffset := oldOffset + 17 * (FSize - 1) newOffset := oldOffset + Scale96ToFont(17 * (FSize - 1))
else else
newOffset := oldOffset + 30 * (FSize -1) newOffset := oldOffset + Scale96ToFont(30 * (FSize -1))
end; end;
{=====} {=====}

View File

@@ -137,14 +137,9 @@ begin
with FlblShowText do with FlblShowText do
begin begin
Alignment := taCenter; Alignment := taCenter;
AutoSize := False;
Font := Self.Font;
Height := 17;
Left := 5;
Top := 57;
Width := 160;
Parent := Self;
Align := alBottom; Align := alBottom;
Font := Self.Font;
Parent := Self;
end; end;
FShowLevel := True; FShowLevel := True;
@@ -325,8 +320,8 @@ var
begin begin
X := Scale96ToFont(20); X := Scale96ToFont(20);
Y := Scale96ToFont(23); Y := Scale96ToFont(23);
W := ClientWidth - 2*X; W := ClientWidth - 2*X; //130;
H := ClientHeight - 2*Y; H := ClientHeight - 2*Y; //33;
if (W < 1) or (H < 1) then Exit; if (W < 1) or (H < 1) then Exit;
with Canvas do with Canvas do
@@ -366,9 +361,8 @@ begin
end; end;
procedure TAnalogSensor.PaintAsHorizontal; procedure TAnalogSensor.PaintAsHorizontal;
var var MiddleX: Integer;
MiddleX: Integer; X, Y, W, H: Integer;
X, Y, W, H: Integer;
begin begin
X := Scale96ToFont(20); X := Scale96ToFont(20);
Y := Scale96ToFont(23); Y := Scale96ToFont(23);
@@ -408,9 +402,8 @@ begin
end; end;
procedure TAnalogSensor.PaintAsVertical; procedure TAnalogSensor.PaintAsVertical;
var var MiddleY: Integer;
MiddleY: Integer; X, Y, W, H: Integer;
X, Y, W, H: Integer;
begin begin
X := Scale96ToFont(20); X := Scale96ToFont(20);
Y := Scale96ToFont(23); Y := Scale96ToFont(23);