📄 ilineargauge.pas
字号:
FMaxPointer.Position := CurrentMax;
FMaxPointer.Margin := MinMaxPointerMargin;
FMaxPointer.Size := MinMaxPointerSize;
FMaxPointer.DrawScaleSide := False;
FMaxPointer.Color := MaxPointerColor;
DrawPointer(Canvas, FMaxPointer);
end;
if ShowMinPointer then
begin
FMinPointer.Position := CurrentMin;
FMinPointer.Margin := MinMaxPointerMargin;
FMinPointer.Size := MinMaxPointerSize;
FMinPointer.DrawScaleSide := False;
FMinPointer.Color := MinPointerColor;
DrawPointer(Canvas, FMinPointer);
end;
end;
//****************************************************************************************************************************************************
procedure TiLinearGauge.DrawLimits(Canvas: TCanvas);
var
x : Integer;
APointer : TiGaugePointer;
begin
for x := 0 to LimitCount -1 do
begin
if LimitShowUpperPointer[x] then
begin
APointer := TiGaugePointer.Create(nil);
try
APointer.Position := LimitUpperValue[x];
APointer.Margin := LimitPointerMargin[x];
APointer.Size := LimitPointerSize[x];
APointer.DrawScaleSide := LimitDrawScaleSide[x];
APointer.Color := LimitUpperPointerColor[x];
DrawPointer(Canvas, APointer);
finally
APointer.Free;
end;
end;
if LimitShowLowerPointer[x] then
begin
APointer := TiGaugePointer.Create(nil);
try
APointer.Position := LimitLowerValue[x];
APointer.Margin := LimitPointerMargin[x];
APointer.Size := LimitPointerSize[x];
APointer.DrawScaleSide := LimitDrawScaleSide[x];
APointer.Color := LimitLowerPointerColor[x];
DrawPointer(Canvas, APointer);
finally
APointer.Free;
end;
end;
end;
end;
//****************************************************************************************************************************************************
procedure TiLinearGauge.DrawTicks(Canvas: TCanvas);
begin
ScaleObject.PositionMax := PositionMax;
ScaleObject.PositionMin := PositionMin;
ScaleObject.Orientation := FOrientation;
ScaleObject.OrientationTickMarks := FOrientationTickMarks;
ScaleObject.ReverseTickMinorAlign := True;
ScaleObject.ReverseScale := FReverseScale;
case FOrientation of
ioVertical : begin
ScaleObject.Start := FBarRect.Bottom;
ScaleObject.Stop := FBarRect.Top;
case FOrientationTickMarks of
iosBottomRight : ScaleObject.Edge := FBarRect.Left;
iosTopLeft : ScaleObject.Edge := FBarRect.Right;
end;
end;
ioHorizontal : begin
ScaleObject.Start := FBarRect.Left;
ScaleObject.Stop := FBarRect.Right;
case FOrientationTickMarks of
iosBottomRight : ScaleObject.Edge := FBarRect.Top;
iosTopLeft : ScaleObject.Edge := FBarRect.Bottom;
end;
end;
end;
ScaleObject.Draw(Canvas);
if FShowTicksAxis then
with Canvas, FBarRect do
begin
Pen.Color := TickMajorColor;
case FOrientation of
ioVertical : case FOrientationTickMarks of
iosBottomRight : begin
Line(Canvas, Right, Top, Right, Bottom+1);
Line(Canvas, Right-1, Top, Right-1, Bottom+1);
end;
iosTopLeft : begin
Line(Canvas, Left, Top, Left, Bottom+1);
Line(Canvas, Left+1, Top, Left+1, Bottom+1);
end;
end;
ioHorizontal : case FOrientationTickMarks of
iosBottomRight : begin
Line(Canvas, Left, Bottom, Right+1, Bottom);
Line(Canvas, Left, Bottom-1, Right+1, Bottom-1);
Line(Canvas, Left, Bottom-2, Right+1, Bottom-2);
end;
iosTopLeft : begin
Line(Canvas, Left, Top, Right+1, Top);
Line(Canvas, Left, Top+1, Right+1, Top+1);
Line(Canvas, Left, Top+2, Right+1, Top+2);
end;
end;
end;
end;
end;
//****************************************************************************************************************************************************
procedure TiLinearGauge.iMouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
i : Integer;
begin
if (Button = mbLeft) then
begin
if MinMaxUserCanMove then
begin
FMouseDownX := X;
FMouseDownY := Y;
if ShowMinPointer {$IFDEF iVCL}and (FMinPointer.Region <> 0) and PtInRegion(FMinPointer.Region, X,Y){$ENDIF} then
begin
FMinPointer.MouseDown := True;
FOldCurrentValue := CurrentMin;
end
else if ShowMaxPointer {$IFDEF iVCL}and (FMaxPointer.Region <> 0) and PtInRegion(FMaxPointer.Region, X,Y){$ENDIF} then
begin
FMaxPointer.MouseDown := True;
FOldCurrentValue := CurrentMax;
end;
InvalidateChange;
end;
for i := 0 to PointerCount-1 do
begin
PointerManager.Items[i].MouseDown := True;
if not PointerManager.Items[i].Visible then Continue;
{$IFDEF iVCL}
PointerManager.Items[i].MouseDown := PtInRegion(PointerManager.Items[i].Region, X, Y);
{$ENDIF}
end;
end;
end;
//****************************************************************************************************************************************************
procedure TiLinearGauge.iMouseMove(Shift: TShiftState; X, Y: Integer);
begin
if FMaxPointer.MouseDown then
begin
case Forientation of
ioHorizontal : if FReverseScale then
CurrentMax := FOldCurrentValue + (FMouseDownX - X)/TravelRange*(PositionMax - PositionMin)
else CurrentMax := FOldCurrentValue - (FMouseDownX - X)/TravelRange*(PositionMax - PositionMin);
ioVertical : if FReverseScale then
CurrentMax := FOldCurrentValue - (FMouseDownY - Y)/TravelRange*(PositionMax - PositionMin)
else CurrentMax := FOldCurrentValue + (FMouseDownY - Y)/TravelRange*(PositionMax - PositionMin);
end;
if CurrentMin > CurrentMax then CurrentMin := CurrentMax;
end
else if FMinPointer.MouseDown then
begin
case Forientation of
ioHorizontal : if FReverseScale then
CurrentMin := FOldCurrentValue + (FMouseDownX - X)/TravelRange*(PositionMax - PositionMin)
else CurrentMin := FOldCurrentValue - (FMouseDownX - X)/TravelRange*(PositionMax - PositionMin);
ioVertical : if FReverseScale then
CurrentMin := FOldCurrentValue - (FMouseDownY - Y)/TravelRange*(PositionMax - PositionMin)
else CurrentMin := FOldCurrentValue + (FMouseDownY - Y)/TravelRange*(PositionMax - PositionMin);
end;
if CurrentMax < CurrentMin then CurrentMax := CurrentMin;
end;
end;
//****************************************************************************************************************************************************
procedure TiLinearGauge.iMouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
i : Integer;
begin
FMinPointer.MouseDown := False;
FMaxPointer.MouseDown := False;
for i := 0 to PointerCount-1 do
begin
if not PointerManager.Items[i].Visible then Continue;
if PointerManager.Items[i].MouseDown then
begin
{$IFDEF iVCL}
if PtInRegion(PointerManager.Items[i].Region, X, Y) then if Assigned(OnClickPointer) then OnClickPointer(i);
{$ENDIF}
end;
end;
end;
//****************************************************************************************************************************************************
function TiLinearGauge.GetPointerColor : TColor; begin Result := PointerManager.Items[0].Color; end;
function TiLinearGauge.GetPointerOffSet : Integer; begin Result := PointerManager.Items[0].Margin; end;
function TiLinearGauge.GetPointerSize : Integer; begin Result := PointerManager.Items[0].Size; end;
function TiLinearGauge.GetPointerStyle : TiLinearGaugePointerStyle;begin Result := TiLinearGaugePointerStyle(PointerManager.Items[0].Style); end;
//****************************************************************************************************************************************************
procedure TiLinearGauge.SetPointerOffSet(const Value: Integer); begin PointerManager.Items[0].Margin := Value; end;
procedure TiLinearGauge.SetPointerColor (const Value: TColor); begin PointerManager.Items[0].Color := Value; end;
procedure TiLinearGauge.SetPointerSize (const Value: Integer); begin PointerManager.Items[0].Size := Value; end;
procedure TiLinearGauge.SetPointerStyle (const Value: TiLinearGaugePointerStyle);begin PointerManager.Items[0].Style := ord(Value);end;
//****************************************************************************************************************************************************
function TiLinearGauge.GetPointersOffSet(Index:Integer):Integer; begin Result:=PointerManager.Items[Index].Margin; end;
function TiLinearGauge.GetPointersStyle (Index:Integer):TiLinearGaugePointerStyle;begin Result:=TiLinearGaugePointerStyle(PointerManager.Items[Index].Style);end;
//****************************************************************************************************************************************************
procedure TiLinearGauge.SetPointersOffSet(Index, Value: Integer); begin PointerManager.Items[Index].Margin:=Value; end;
procedure TiLinearGauge.SetPointersStyle (Index: Integer; Value: TiLinearGaugePointerStyle);begin PointerManager.Items[Index].Style :=ord(Value);end;
//****************************************************************************************************************************************************
procedure TiLinearGauge.InitializePointer(iGaugePointer: TiGaugePointer);
begin
iGaugePointer.Size := 10;
iGaugePointer.Color := clBlue;
iGaugePointer.Style := ord(ilgpsPointer);
end;
//****************************************************************************************************************************************************
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -