⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iswitchrotary.pas

📁 iocopm3.04源码,一套很好的工控开发工具
💻 PAS
📖 第 1 页 / 共 2 页
字号:

  Result := Point(CenterPoint.x - Round((MaxX + MinX)/2), CenterPoint.y - Round((MaxY + MinY)/2));

  FCenterPoint := Result;
end;
//*************************************************************************************************************************************
procedure TiSwitchRotary.iPaintTo(Canvas: TCanvas);
var
  DrawRect    : TRect;
  Angle       : Double;
  CenterPoint : TPoint;
begin
  case FRotationDesiredSpacing of
    irds22p5 : FDegreesStep := 22.5;
    irds45   : FDegreesStep := 45;
    irds90   : FDegreesStep := 90;
  end;

  if PositionLabelCount > 4 then if FDegreesStep > 45   then FDegreesStep := 45;
  if PositionLabelCount > 8 then if FDegreesStep > 22.5 then FDegreesStep := 22.5;

  CenterPoint := GetCenterPoint(Canvas);
  DrawRect := Rect(0,0,Width-1, Height-1);

  Angle := AngleOffset - (Position)*FDegreesStep;

  if Angle >= 360 then Angle := Angle - 360;
  if Angle <    0 then Angle := Angle + 360;
                                                        
  DrawBackGround(Canvas, BackGroundColor);
  DrawIndicator (Canvas, CenterPoint, Angle);
  DrawTicks     (Canvas, CenterPoint, AngleOffset);

  if ShowFocusRect and HasFocus then iDrawFocusRect(Canvas, ClientRect, BackGroundColor);
end;
//*************************************************************************************************************************************
procedure TiSwitchRotary.DrawIndicator(Canvas: TCanvas; CenterPoint: TPoint; Angle: Double);
begin
  case FPointerStyle of
    isrpsPointer   : DrawIndicatorPointer  (Canvas, CenterPoint, Angle);
    isrpsRectangle : DrawIndicatorRectangle(Canvas, CenterPoint, Angle);
  end;
end;
//*************************************************************************************************************************************
procedure TiSwitchRotary.DrawIndicatorRectangle(Canvas: TCanvas; CenterPoint: TPoint; Angle: Double);
var
  Point1          : TPoint;
  Point2          : TPoint;
  Point3          : TPoint;
  Point4          : TPoint;
  TempCenterPoint : TPoint;
  IndicatorPoint1 : TPoint;
  IndicatorPoint2 : TPoint;
begin
  CenterPoint := GetCenterPoint(Canvas);
  with Canvas, CenterPoint do
    begin
      TempCenterPoint  := GetXYRadPoint(Angle,       FPointerLength, CenterPoint);
      Point1           := GetXYRadPoint(Angle - 270, FPointerHeight, TempCenterPoint);
      Point2           := GetXYRadPoint(Angle -  90, FPointerHeight, TempCenterPoint);

      IndicatorPoint1  := GetXYRadPoint(Angle,       FPointerLength,     CenterPoint);
      IndicatorPoint2  := GetXYRadPoint(Angle,       FPointerLength - 8, CenterPoint);

      TempCenterPoint  := GetXYRadPoint(Angle - 180, FPointerLength, CenterPoint);
      Point3           := GetXYRadPoint(Angle -  90, FPointerHeight, TempCenterPoint);
      Point4           := GetXYRadPoint(Angle - 270, FPointerHeight, TempCenterPoint);
                                   
      Brush.Style := bsSolid;
      Pen.Color   := clWhite;
      if FMouseDown or FKeyDown then Brush.Color := FPointerHighLightColor else Brush.Color := FPointerColor;

      Polygon([Point1, Point2, Point3, Point4]);

      Pen.Color := clBlack;

      if      Angle =   0.0 then Polyline([Point1, Point2, Point3])
      else if Angle = 337.5 then Polyline([Point1, Point2, Point3])
      else if Angle = 315.0 then Polyline([Point1, Point2, Point3])
      else if Angle = 292.5 then Polyline([Point1, Point2, Point3])

      else if Angle = 270.0 then Polyline([Point4, Point1, Point2])
      else if Angle = 247.5 then Polyline([Point4, Point1, Point2])
      else if Angle = 225.0 then Polyline([Point4, Point1, Point2])
      else if Angle = 202.5 then Polyline([Point4, Point1, Point2])

      else if Angle = 180.0 then Polyline([Point3, Point4, Point1])
      else if Angle = 157.5 then Polyline([Point3, Point4, Point1])
      else if Angle = 135.0 then Polyline([Point3, Point4, Point1])
      else if Angle = 112.5 then Polyline([Point3, Point4, Point1])

      else if Angle =  90.0 then Polyline([Point2, Point3, Point4])
      else if Angle =  67.5 then Polyline([Point2, Point3, Point4])
      else if Angle =  45.0 then Polyline([Point2, Point3, Point4])
      else if Angle =  22.5 then Polyline([Point2, Point3, Point4]);

      if      (Angle =   0) or (Angle = 180) then
        begin
          PolyLine([Point(IndicatorPoint1.x + 0, IndicatorPoint1.y - 1), Point(IndicatorPoint2.x + 0, IndicatorPoint2.y - 1)]);
          PolyLine([Point(IndicatorPoint1.x + 0, IndicatorPoint1.y + 0), Point(IndicatorPoint2.x + 0, IndicatorPoint2.y + 0)]);
          Pen.Color := clWhite;
          PolyLine([Point(IndicatorPoint1.x + 0, IndicatorPoint1.y + 1), Point(IndicatorPoint2.x + 0, IndicatorPoint2.y + 1)]);
        end
      else if (Angle = 135) or (Angle = 112.5)  or (Angle = 157.5)  or (Angle = 315)  or (Angle = 292.5)  or (Angle = 337.5) then
        begin
          PolyLine([Point(IndicatorPoint1.x + 1, IndicatorPoint1.y - 1), Point(IndicatorPoint2.x + 1, IndicatorPoint2.y - 1)]);
          PolyLine([Point(IndicatorPoint1.x + 0, IndicatorPoint1.y + 0), Point(IndicatorPoint2.x + 0, IndicatorPoint2.y + 0)]);
          Pen.Color := clWhite;
          PolyLine([Point(IndicatorPoint1.x - 1, IndicatorPoint1.y + 1), Point(IndicatorPoint2.x - 1, IndicatorPoint2.y + 1)]);
        end
      else if (Angle =  90) or (Angle = 270) then
        begin
          PolyLine([Point(IndicatorPoint1.x - 1, IndicatorPoint1.y + 0), Point(IndicatorPoint2.x - 1, IndicatorPoint2.y + 0)]);
          PolyLine([Point(IndicatorPoint1.x + 0, IndicatorPoint1.y + 0), Point(IndicatorPoint2.x + 0, IndicatorPoint2.y + 0)]);
          Pen.Color := clWhite;
          PolyLine([Point(IndicatorPoint1.x + 1, IndicatorPoint1.y + 0), Point(IndicatorPoint2.x + 1, IndicatorPoint2.y + 0)]);
        end
      else if (Angle =  45) or (Angle = 22.5)  or (Angle = 67.5)  or (Angle = 225)  or (Angle = 202.5)  or (Angle = 247.5) then
        begin
          PolyLine([Point(IndicatorPoint1.x - 1, IndicatorPoint1.y - 1), Point(IndicatorPoint2.x - 1, IndicatorPoint2.y - 1)]);
          PolyLine([Point(IndicatorPoint1.x + 0, IndicatorPoint1.y + 0), Point(IndicatorPoint2.x + 0, IndicatorPoint2.y + 0)]);
          Pen.Color := clWhite;
          PolyLine([Point(IndicatorPoint1.x + 1, IndicatorPoint1.y + 1), Point(IndicatorPoint2.x + 1, IndicatorPoint2.y + 1)]);
        end;
    end;
end;
//*************************************************************************************************************************************
procedure TiSwitchRotary.DrawIndicatorPointer(Canvas: TCanvas; CenterPoint: TPoint; Angle: Double);
var
  Point1          : TPoint;
  Point2          : TPoint;
  Point3          : TPoint;
  Point4          : TPoint;
  Point5          : TPoint;
  TempCenterPoint : TPoint;
begin
  with Canvas, CenterPoint do
    begin
      TempCenterPoint  := GetXYRadPoint(Angle,       FPointerLength - 2*FPointerHeight, CenterPoint);
      Point1           := GetXYRadPoint(Angle - 270, FPointerHeight, TempCenterPoint);
      Point2           := GetXYRadPoint(Angle,       FPointerLength, CenterPoint);
      Point3           := GetXYRadPoint(Angle -  90, FPointerHeight, TempCenterPoint);

      TempCenterPoint  := GetXYRadPoint(Angle - 180, FPointerLength, CenterPoint);
      Point4           := GetXYRadPoint(Angle -  90, FPointerHeight, TempCenterPoint);
      Point5           := GetXYRadPoint(Angle - 270, FPointerHeight, TempCenterPoint);

      Brush.Style := bsSolid;
      if FMouseDown or FKeyDown then Brush.Color := FPointerHighLightColor else Brush.Color := FPointerColor;

      Pen.Style   := psClear;
      Polygon([Point1, Point2, Point3, Point4, Point5]);

      Pen.Style   := psSolid;

      if Angle = 0 then
        begin
          Pen.Color := clBlack; Polyline([Point2, Point3, Point4]);
          Pen.Color := clWhite; Polyline([Point4, Point5, Point1, Point2]);
        end
      else if (Angle = 337.5) or (Angle = 315) or (Angle = 292.5) then
        begin
          Pen.Color := clBlack; Polyline([Point2, Point3, Point4]);
          Pen.Color := clWhite; Polyline([Point4, Point5, Point1, Point2]);
        end
      else if Angle = 270 then
        begin
          Pen.Color := clBlack; Polyline([Point5, Point1, Point2]);
          Pen.Color := clWhite; Polyline([Point2, Point3, Point4, Point5]);
        end
      else if (Angle = 247.5) or (Angle = 225) or (Angle = 202.5) then
        begin
          Pen.Color := clBlack; Polyline([Point4, Point5, Point1, Point2]);
            Pen.Color := clWhite; Polyline([Point2, Point3, Point4]);
        end
      else if Angle = 180 then
        begin
          Pen.Color := clWhite; Polyline([Point2, Point3, Point4]);
          Pen.Color := clBlack; Polyline([Point4, Point5, Point1, Point2]);
        end
      else if (Angle = 157.5) or (Angle = 135) or (Angle = 112.5) then
        begin
          Pen.Color := clWhite; Polyline([Point2, Point3, Point4]);
          Pen.Color := clBlack; Polyline([Point4, Point5, Point1, Point2]);
        end
      else if Angle = 90 then
        begin
          Pen.Color := clBlack; Polyline([Point2, Point3, Point4, Point5]);
          Pen.Color := clWhite; Polyline([Point5, Point1, Point2]);
        end
      else if (Angle = 67.5) or (Angle = 45) or (Angle = 22.5) then
        begin
          Pen.Color := clWhite; Polyline([Point4, Point5, Point1, Point2]);
          Pen.Color := clBlack; Polyline([Point2, Point3, Point4]);
        end;
    end;
end;
//*************************************************************************************************************************************
procedure TiSwitchRotary.DrawTicks(Canvas: TCanvas; CenterPoint: TPoint; AngleOffset: Double);
var
  TextRadius     : Double;
  ATextRect      : TRect;
  TextPoint      : TPoint;
  AText          : String;
  IndicatorPoint : TPoint;
  IndicatorRect  : TRect;
  x              : Integer;
  Angle          : Double;
begin
  with Canvas do
    begin
      Brush.Style := bsClear;

     for x := 0 to PositionLabelsList.Count-1 do
       begin
         Angle := AngleOffset - (x)*FDegreesStep;
         if Angle >= 360 then Angle := Angle - 360;
         if Angle <    0 then Angle := Angle + 360;

         if x <= PositionLabelsList.Count-1 then AText  := PositionLabelsList.Strings[x] else AText := '???';
         TextRadius  := FPointerLength + PositionLabelMargin + 4;
         if ShowPositionIndicators then TextRadius := TextRadius + PositionIndicatorMargin + PositionIndicatorSize;
         TextPoint   := GetXYRadPoint(Angle, TextRadius, CenterPoint);

         if ShowPositionIndicators then
           begin
             IndicatorPoint := GetXYRadPoint(Angle, FPointerLength + PositionIndicatorMargin + PositionIndicatorSize/2, CenterPoint);
             IndicatorRect  := Rect(IndicatorPoint.x - PositionIndicatorSize, IndicatorPoint.y - PositionIndicatorSize,
                                    IndicatorPoint.x + PositionIndicatorSize, IndicatorPoint.y + PositionIndicatorSize);
             with IndicatorRect do
               begin
                 Pen.Style   := psClear;
                 Brush.Color := PositionIndicatorColor;
                 Brush.Style := bsSolid;
                 Ellipse(Left, Top, Right, Bottom);
                 Pen.Style   := psSolid;
                 case PositionIndicatorBevelStyle of
                   ibsRaised  : begin
                                  Pen.Color := clWhite;
                                  Arc(Left, Top, Right, Bottom, Right, Top, Left, Bottom);
                                  Pen.Color := clGray;
                                  Arc(Left, Top, Right, Bottom, Left, Bottom, Right, Top);
                                end;
                   ibsLowered : begin
                                  Pen.Color := clGray;
                                  Arc(Left, Top, Right, Bottom, Right, Top, Left, Bottom);
                                  Pen.Color := clWhite;
                                  Arc(Left, Top, Right, Bottom, Left, Bottom, Right, Top);
                                end;
                 end;    
               end;
           end;

         Brush.Style := bsClear;

         if ShowPositionLabels then
           begin
             if Position <> x then Font.Assign(PositionLabelInactiveFont) else Font.Assign(PositionLabelActiveFont);

             case FPositionLabelAlignment of
               ilaCenter    : TextOut(TextPoint.x - TextWidth (AText) div 2, TextPoint.y - TextHeight(AText) div 2, AText);
               ilaJustified : begin
                                ATextRect := Rect(TextPoint.x,TextPoint.y-TextHeight(AText)div 2,TextPoint.x+1,TextPoint.y+TextHeight(AText)div 2);
                                if (Angle > 90) and (Angle < 270) then
                                  begin
                                    ATextRect := Rect(TextPoint.x - TextWidth(AText),        TextPoint.y - TextHeight(AText) div 2,
                                                      TextPoint.x,                           TextPoint.y + TextHeight(AText) div 2);

                                  end
                                else if Angle = 90 then
                                  begin
                                    ATextRect := Rect(TextPoint.x - TextWidth(AText)  div 2, TextPoint.y - TextHeight(AText),
                                                      TextPoint.x + TextWidth (AText) div 2, TextPoint.y);
                                  end
                                else if Angle = 270 then
                                  begin
                                    ATextRect := Rect(TextPoint.x - TextWidth(AText)  div 2, TextPoint.y,
                                                      TextPoint.x + TextWidth (AText) div 2, TextPoint.y + TextHeight(AText));
                                  end
                                else
                                  begin
                                    ATextRect := Rect(TextPoint.x,                           TextPoint.y - TextHeight(AText) div 2,
                                                      TextPoint.x + TextWidth (AText),       TextPoint.y + TextHeight(AText) div 2);
                                  end;

                                with ATextRect do
                                  TextOut((Left + Right) div 2 - TextWidth(AText) div 2, (Top + Bottom) div 2 - TextHeight(AText) div 2, AText);
                              end;
             end;
           end;
       end;
    end;
end;
//*************************************************************************************************************************************
procedure TiSwitchRotary.iDoKillFocus;
begin
  FMouseDown := False;
  FKeyDown   := False;
  inherited;
end;
//*************************************************************************************************************************************
end.


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -