📄 iswitchslider.pas
字号:
//*************************************************************************************************************************************
procedure TiSwitchSlider.iPaintTo(Canvas: TCanvas);
var
ClientRect : TRect;
begin
ClientRect := Rect(0, 0 ,Width, Height);
CalcPoints;
CalcAutoCenterOffsets;
case FOrientation of
ioVertical : begin
case FOrientationLabels of
iosBottomRight : begin
OffsetRect(FTrackRect, OffsetX, 0);
OffsetRect(FIndicatorRect, OffsetX, 0);
OffsetRect(FTrackRect, FCenterOffsetX, 0);
OffsetRect(FIndicatorRect, FCenterOffsetX, 0);
end;
iosTopLeft : begin
OffsetRect(FTrackRect, -OffsetX, 0);
OffsetRect(FIndicatorRect, -OffsetX, 0);
OffsetRect(FTrackRect, -FCenterOffsetX, 0);
OffsetRect(FIndicatorRect, -FCenterOffsetX, 0);
end;
end;
end;
ioHorizontal : begin
case FOrientationLabels of
iosBottomRight : begin
OffsetRect(FTrackRect, 0, OffsetY);
OffsetRect(FIndicatorRect, 0, OffsetY);
OffsetRect(FTrackRect, 0, FCenterOffsetY);
OffsetRect(FIndicatorRect, 0, FCenterOffsetY);
end;
iosTopLeft : begin
OffsetRect(FTrackRect, 0, -OffsetY);
OffsetRect(FIndicatorRect, 0, -OffsetY);
OffsetRect(FTrackRect, 0, -FCenterOffsetY);
OffsetRect(FIndicatorRect, 0, -FCenterOffsetY);
end;
end;
end;
end;
DrawBackGround(Canvas, BackGroundColor);
DrawTrack (Canvas, FTrackRect );
DrawTicks (Canvas, FTrackRect );
DrawIndicator (Canvas, FIndicatorRect);
if ShowFocusRect and HasFocus then iDrawFocusRect(Canvas, ClientRect, BackGroundColor);
end;
//*************************************************************************************************************************************
procedure TiSwitchSlider.DrawTrack(Canvas: TCanvas; TrackRect: TRect);
begin
with Canvas do
begin
with TrackRect do
begin
case FTrackStyle of
istsBox : begin
Brush.Color := FTrackColor;
FillRect(TrackRect);
Pen.Color := clBtnShadow;
PolyLine([Point(Right,Top), Point (Left, Top), Point(Left, Bottom)]);
if BackGroundColor = clWhite then Pen.Color := clBtnShadow;
PolyLine([Point(Right-1,Top+1), Point (Left+1, Top+1), Point(Left+1, Bottom-1)]);
Pen.Color := clBtnHighlight;
PolyLine([Point(Right-1,Top), Point (Right-1, Bottom-1), Point(Left, Bottom-1)]);
Pen.Color := clBtnFace;
PolyLine([Point(Right-2,Top+2), Point (Right-2, Bottom-2), Point(Left, Bottom-2)]);
end;
istsLine : begin
case FOrientation of
ioHorizontal : begin
Pen.Color := FTrackColor;
PolyLine([Point(Left + FTrack3DMargin, (Top + Bottom) div 2), Point(Right - FTrack3DMargin, (Top + Bottom) div 2)]);
end;
ioVertical : begin
Pen.Color := FTrackColor;
PolyLine([Point((Left + Right) div 2, Top + FTrack3DMargin), Point((Left + Right) div 2, Bottom - FTrack3DMargin)]);
end;
end;
end;
istsBevelLowered : begin
case FOrientation of
ioHorizontal : begin
Pen.Color := clBtnShadow;
PolyLine([Point(Left + FTrack3DMargin, (Top + Bottom) div 2-2), Point(Right - FTrack3DMargin, (Top + Bottom) div 2-2)]);
PolyLine([Point(Left + FTrack3DMargin, (Top + Bottom) div 2-1), Point(Right - FTrack3DMargin, (Top + Bottom) div 2-1)]);
Pen.Color := clBtnHighlight;
PolyLine([Point(Left + FTrack3DMargin, (Top + Bottom) div 2+0), Point(Right - FTrack3DMargin, (Top + Bottom) div 2+0)]);
PolyLine([Point(Left + FTrack3DMargin, (Top + Bottom) div 2+1), Point(Right - FTrack3DMargin, (Top + Bottom) div 2+1)]);
end;
ioVertical : begin
Pen.Color := clBtnShadow;
PolyLine([Point((Left + Right) div 2-2, Top + FTrack3DMargin), Point((Left + Right) div 2-2, Bottom - FTrack3DMargin)]);
PolyLine([Point((Left + Right) div 2-1, Top + FTrack3DMargin), Point((Left + Right) div 2-1, Bottom - FTrack3DMargin)]);
Pen.Color := clBtnHighlight;
PolyLine([Point((Left + Right) div 2+0, Top + FTrack3DMargin), Point((Left + Right) div 2+0, Bottom - FTrack3DMargin)]);
PolyLine([Point((Left + Right) div 2+1, Top + FTrack3DMargin), Point((Left + Right) div 2+1, Bottom - FTrack3DMargin)]);
end;
end;
end;
istsBevelRasied : begin
case FOrientation of
ioHorizontal : begin
Pen.Color := clBtnHighlight;
PolyLine([Point(Left + FTrack3DMargin, (Top + Bottom) div 2-2), Point(Right - FTrack3DMargin, (Top + Bottom) div 2-2)]);
PolyLine([Point(Left + FTrack3DMargin, (Top + Bottom) div 2-1), Point(Right - FTrack3DMargin, (Top + Bottom) div 2-1)]);
Pen.Color := clBtnShadow;
PolyLine([Point(Left + FTrack3DMargin, (Top + Bottom) div 2+0), Point(Right - FTrack3DMargin, (Top + Bottom) div 2+0)]);
PolyLine([Point(Left + FTrack3DMargin, (Top + Bottom) div 2+1), Point(Right - FTrack3DMargin, (Top + Bottom) div 2+1)]);
end;
ioVertical : begin
Pen.Color := clBtnHighlight;
PolyLine([Point((Left + Right) div 2-2, Top + FTrack3DMargin), Point((Left + Right) div 2-2, Bottom - FTrack3DMargin)]);
PolyLine([Point((Left + Right) div 2-1, Top + FTrack3DMargin), Point((Left + Right) div 2-1, Bottom - FTrack3DMargin)]);
Pen.Color := clBtnShadow;
PolyLine([Point((Left + Right) div 2+0, Top + FTrack3DMargin), Point((Left + Right) div 2+0, Bottom - FTrack3DMargin)]);
PolyLine([Point((Left + Right) div 2+1, Top + FTrack3DMargin), Point((Left + Right) div 2+1, Bottom - FTrack3DMargin)]);
end;
end;
end;
end;
end;
end;
end;
//*************************************************************************************************************************************
procedure TiSwitchSlider.DrawIndicator(Canvas: TCanvas; IndicatorRect: TRect);
var
Point1 : TPoint;
Point2 : TPoint;
Point3 : TPoint;
Point4 : TPoint;
Point5 : TPoint;
IndicatorInnerRect : TRect;
begin
with Canvas do
begin
Brush.Style := bsSolid;
Pen.Style := psSolid;
with IndicatorRect do
case FPointerStyle of
ispsLed : begin
Pen.Color := clBtnFace;
Brush.Color := clBtnFace;
Rectangle(Left, Top, Right, Bottom);
if FMouseDown or FKeyDown then
begin
Pen.Color := FPointerIndicatorActiveColor;
Brush.Color := FPointerIndicatorActiveColor;
end
else
begin
Pen.Color := FPointerIndicatorInactiveColor;
Brush.Color := FPointerIndicatorInactiveColor;
end;
IndicatorInnerRect := Rect(Left+1, Top+1, Right-2, Bottom-2);
with IndicatorInnerRect do
begin
Rectangle(Left, Top, Right, Bottom);
Pen.Color := clGray; Polyline([Point(Left, Bottom), Point(Left, Top), Point(Right, Top)]); // Draw Indicator 3D Sunken;
Pen.Color := clWhite; Polyline([Point(Left + 2, Top + 2), Point(Left + 4, Top + 2)]); // Draw Indicator Reflection
end;
end;
ispsBar : begin
Pen.Color := clBtnFace;
if FMouseDown or FKeyDown then Brush.Color := FPointerHighLightColor else Brush.Color := FPointerColor;
Rectangle(Left, Top, Right, Bottom);
Pen.Color := clWhite; PolyLine([Point(Left, Bottom), Point(Left, Top ), Point(Right, Top )]);
Pen.Color := clBlack; PolyLine([Point(Right, Top ), Point(Right, Bottom), Point(Left, Bottom)]);
end;
ispsBarColor :begin
Pen.Color := clBtnFace;
if FMouseDown or FKeyDown then Brush.Color := PointerIndicatorActiveColor else Brush.Color := PointerIndicatorInactiveColor;
Rectangle(Left, Top, Right, Bottom);
Pen.Color := clWhite; PolyLine([Point(Left, Bottom), Point(Left, Top ), Point(Right, Top )]);
Pen.Color := clBlack; PolyLine([Point(Right, Top ), Point(Right, Bottom), Point(Left, Bottom)]);
end;
ispsLightBar :begin
Pen.Color := clBtnFace;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -