📄 iswitchslider.pas
字号:
SetFocus;
FMouseDown := True;
FPositionOld := Position;
MouseMove(Shift, X, Y);
InvalidateChange;
end;
end;
//*************************************************************************************************************************************
procedure TiSwitchSlider.iMouseMove(Shift: TShiftState; X, Y: Integer);
begin
if FMouseDown then
begin
UserGenerated := True;
try
case Forientation of
ioHorizontal : Position := Round((X - (EndsMargin + FTrack3DMargin + FPointerHeight div 2)) /(TravelRange/(PositionLabelsList.Count-1)));
ioVertical : Position := Round((Height - Y - (EndsMargin + FTrack3DMargin + FPointerHeight div 2)) /(TravelRange/(PositionLabelsList.Count-1)));
end;
finally
UserGenerated := False;
end;
end;
end;
//*************************************************************************************************************************************
procedure TiSwitchSlider.iMouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
InvalidateChange;
if FMouseDown then
begin
FMouseDown := False;
DoPositionChangeFinished;
end;
end;
//*************************************************************************************************************************************
procedure TiSwitchSlider.SetOrientation(const Value: TiOrientation);
var
TempWidth : Integer;
begin
if FOrientation <> Value then
begin
FOrientation := Value;
if not Loading then
begin
TempWidth := Width;
Width := Height;
Height := TempWidth;
if Assigned(FOnAutoSize) then FOnAutoSize(Self);
end;
InvalidateChange;
end;
end;
//*************************************************************************************************************************************
procedure TiSwitchSlider.SetPointerStyle(const Value: TiSliderPointerStyle);
begin
if FPointerStyle <> Value then
begin
FPointerStyle := Value;
case FPointerStyle of
ispsLed : FTrack3DMargin := 2;
ispsPointer : FTrack3DMargin := 0;
ispsBitmap : FTrack3DMargin := 0;
ispsBar : FTrack3DMargin := 0;
ispsBarColor : FTrack3DMargin := 0;
ispsLightBar : FTrack3DMargin := 0;
end;
InvalidateChange;
end;
end;
//*************************************************************************************************************************************
function TiSwitchSlider.GetTravelRange: Integer;
var
DrawRect : TRect;
begin
DrawRect := Rect(0, 0 ,Width, Height);
with DrawRect do
case Forientation of
ioHorizontal : Result := Right - Left - FPointerHeight - (2 * FEndsMargin) - (2 * FTrack3DMargin);
ioVertical : Result := Bottom - Top - FPointerHeight - (2 * FEndsMargin) - (2 * FTrack3DMargin);
else Result := 0;
end;
end;
//*************************************************************************************************************************************
procedure TiSwitchSlider.CalcPoints;
var
ClientRect : TRect;
TrackWidth : Integer;
TrackOffet : Integer;
IndicatorOffset : Integer;
begin
ClientRect := Rect(0, 0 ,Width, Height);
case FPointerStyle of
ispsLed : begin FIndicatorOverlap := 0; TrackOffet := 0; end;
ispsPointer : begin FIndicatorOverlap := 4; TrackOffet := 5; end;
ispsBitmap : begin FIndicatorOverlap := 4; TrackOffet := 5; end;
ispsBar : begin FIndicatorOverlap := 4; TrackOffet := 5; end;
ispsBarColor : begin FIndicatorOverlap := 4; TrackOffet := 5; end;
ispsLightBar : begin FIndicatorOverlap := 4; TrackOffet := 5; end;
else begin FIndicatorOverlap := 0; TrackOffet := 0; end;
end;
IndicatorOffset := Round(TravelRange /(PositionLabelsList.Count-1) * (Position));
with ClientRect do
begin
TrackWidth := FPointerWidth + 2*FTrack3DMargin;
case FOrientation of
ioVertical : begin
case FOrientationLabels of
iosTopLeft : FTrackRect := Rect(Right - TrackOffet - TrackWidth , Top + FEndsMargin, Right - TrackOffet, Bottom - FEndsMargin);
iosBottomRight : FTrackRect := Rect(Left + TrackOffet , Top + FEndsMargin, Left + TrackOffet + TrackWidth, Bottom - FEndsMargin);
end;
with FTrackRect do
case FPointerStyle of
ispsLed : FIndicatorRect:=Rect(Left+FTrack3DMargin, Bottom-FTrack3DMargin-IndicatorOffset-FPointerHeight,Right-FTrack3DMargin, Bottom-FTrack3DMargin-IndicatorOffset);
ispsPointer : FIndicatorRect:=Rect(Left-FIndicatorOverlap,Bottom-FTrack3DMargin-IndicatorOffset-FPointerHeight,Right+FIndicatorOverlap,Bottom-FTrack3DMargin-IndicatorOffset);
ispsBitmap : FIndicatorRect:=Rect(Left-FIndicatorOverlap,Bottom-FTrack3DMargin-IndicatorOffset-FPointerHeight,Right+FIndicatorOverlap,Bottom-FTrack3DMargin-IndicatorOffset);
ispsBar : FIndicatorRect:=Rect(Left-FIndicatorOverlap,Bottom-FTrack3DMargin-IndicatorOffset-FPointerHeight,Right+FIndicatorOverlap,Bottom-FTrack3DMargin-IndicatorOffset);
ispsBarColor : FIndicatorRect:=Rect(Left-FIndicatorOverlap,Bottom-FTrack3DMargin-IndicatorOffset-FPointerHeight,Right+FIndicatorOverlap,Bottom-FTrack3DMargin-IndicatorOffset);
ispsLightBar : FIndicatorRect:=Rect(Left-FIndicatorOverlap,Bottom-FTrack3DMargin-IndicatorOffset-FPointerHeight,Right+FIndicatorOverlap,Bottom-FTrack3DMargin-IndicatorOffset);
end;
end;
else begin
case FOrientationLabels of
iosTopLeft : FTrackRect := Rect(Left + FEndsMargin, Bottom - TrackWidth - TrackOffet, Right - FEndsMargin, Bottom - TrackOffet );
iosBottomRight : FTrackRect := Rect(Left + FEndsMargin, Top + TrackOffet, Right - FEndsMargin, Top + TrackWidth + TrackOffet);
end;
with FTrackRect do
case FPointerStyle of
ispsLed : FIndicatorRect:=Rect(Left+FTrack3DMargin+IndicatorOffset,Top+FTrack3DMargin, Left+FTrack3DMargin+IndicatorOffset+FPointerHeight,Bottom-FTrack3DMargin);
ispsPointer : FIndicatorRect:=Rect(Left+FTrack3DMargin+IndicatorOffset,Top-FIndicatorOverlap,Left+FTrack3DMargin+IndicatorOffset+FPointerHeight,Bottom+FIndicatorOverlap);
ispsBitmap : FIndicatorRect:=Rect(Left+FTrack3DMargin+IndicatorOffset,Top-FIndicatorOverlap,Left+FTrack3DMargin+IndicatorOffset+FPointerHeight,Bottom+FIndicatorOverlap);
ispsBar : FIndicatorRect:=Rect(Left+FTrack3DMargin+IndicatorOffset,Top-FIndicatorOverlap,Left+FTrack3DMargin+IndicatorOffset+FPointerHeight,Bottom+FIndicatorOverlap);
ispsBarColor : FIndicatorRect:=Rect(Left+FTrack3DMargin+IndicatorOffset,Top-FIndicatorOverlap,Left+FTrack3DMargin+IndicatorOffset+FPointerHeight,Bottom+FIndicatorOverlap);
ispsLightBar : FIndicatorRect:=Rect(Left+FTrack3DMargin+IndicatorOffset,Top-FIndicatorOverlap,Left+FTrack3DMargin+IndicatorOffset+FPointerHeight,Bottom+FIndicatorOverlap);
end;
end;
end;
end;
end;
//*************************************************************************************************************************************
procedure TiSwitchSlider.CalcAutoCenterOffsets;
var
x : Integer;
MaxTextWidth : Integer;
TotalWidth : Integer;
begin
FCenterOffsetX := 0;
FCenterOffsetY := 0;
if not FAutoCenter then Exit;
TotalWidth := 0;
if ShowPositionLabels then
begin
with Canvas do
begin
MaxTextWidth := 0;
for x := 0 to PositionLabelsList.Count-1 do
begin
Canvas.Font.Assign(PositionLabelActiveFont);
case Orientation of
ioVertical : if TextWidth (PositionLabelsList.Strings[x]) > MaxTextWidth then MaxTextWidth := TextWidth (PositionLabelsList.Strings[x]);
else if TextHeight(PositionLabelsList.Strings[x]) > MaxTextWidth then MaxTextWidth := TextHeight(PositionLabelsList.Strings[x]);
end;
Font.Assign(PositionLabelInactiveFont);
case Orientation of
ioVertical : if TextWidth (PositionLabelsList.Strings[x]) > MaxTextWidth then MaxTextWidth := TextWidth (PositionLabelsList.Strings[x]);
else if TextHeight(PositionLabelsList.Strings[x]) > MaxTextWidth then MaxTextWidth := TextHeight(PositionLabelsList.Strings[x]);
end;
end;
end;
TotalWidth := TotalWidth + PositionLabelMargin + MaxTextWidth;
end;
if ShowPositionIndicators then TotalWidth := TotalWidth + PositionIndicatorMargin + PositionIndicatorSize;
case FOrientation of
ioVertical : begin
TotalWidth := TotalWidth + FTrackRect.Right - FTrackRect.Left + FIndicatorOverlap;
FCenterOffsetX := (Width - TotalWidth) div 2;
end;
ioHorizontal : begin
TotalWidth := TotalWidth + FTrackRect.Bottom - FTrackRect.Top + FIndicatorOverlap;
FCenterOffsetY := (Height - TotalWidth) div 2;
end;
end;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -