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

📄 ezpreview.pas

📁 很管用的GIS控件
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  If FPreviewBox = Nil Then Exit;
  With Canvas Do
  Begin
    Pen.Mode := AMode;
    Pen.Color := ColorToRGB( FRubberPenColor ) Xor ColorToRGB( Self.Color );
    MoveTo( p.X, 0 );
    LineTo( p.X, Height );
    Pen.Mode := pmCopy;
  End;
End;

Procedure TEzHRuler.Notification( AComponent: TComponent; Operation: TOperation );
Begin
  Inherited Notification( AComponent, Operation );
  If ( Operation = opRemove ) And ( AComponent = FPreviewBox ) Then
    FPreviewBox := Nil;
End;

Procedure TEzHRuler.Paint;
Var
  ULColor, LRColor: TColor;
  R: TRect;
  i, W: integer;
  Text: String;
  N: Integer;
  pt: TPoint;
  TmpPt: TEzPoint;
  XM, XLeft, MinSep, MaxSep: Double;
  EffectiveH, m, Y, DY: Cardinal;

  Procedure DrawSides( Const Rect: TRect );
  Begin
    With Canvas, Rect Do
    Begin
      Pen.Color := LRColor;
      MoveTo( Left, Top );
      LineTo( Left, Bottom );

      MoveTo( Left, Top );
      LineTo( Right, Top );

      Pen.Color := ULColor;
      MoveTo( Right - 1, Top );
      LineTo( Right - 1, Bottom );

      MoveTo( Left, Bottom - 1 );
      LineTo( Right, Bottom - 1 );
    End;
  End;

Begin
  Inherited Paint;

  If ( csDesigning In ComponentState ) Or ( FPreviewBox = Nil ) Then Exit;

  DrawRulerPosition( FLastMousePosInRuler, pmNotXor );

  ULColor := clBtnShadow;
  LRColor := clBtnHighlight;
  With Canvas Do
  Begin
    // first, paint the borders
    Font.Assign( Self.Font );
    Brush.Style := bsSolid;
    Brush.Color := Self.Color;
    FillRect( ClientRect );
    Brush.Style := bsClear;
    Pen.Mode := pmCopy;
    Pen.Width := 1;
    R := ClientRect;
    W := 2;
    For I := 1 To W Do
    Begin
      DrawSides( R );
      InflateRect( R, -1, -1 );
    End;
    Pen.Color := FMarksColor;

    { calc min and max separators }
    MaxMinSeparation( FPreviewBox, MaxSep, MinSep );

    If FPreviewBox.Grapher.RealToDistX(maxsep) < 10 then exit;

    //PixelsSep:= FPreviewBox.Grapher.RealToDistX(MinSep);
    //if (PixelsSep < 3) or (PixelsSep >= FPreviewBox.Width) then Exit;

    { Calc the zero point }
    TmpPt := Point2d( 0, 0 );
    pt := Self.ScreenToClient(
      FPreviewBox.ClientToScreen( FPreviewBox.Grapher.RealToPoint( TmpPt ) ) );

    {calc the begining of ruler...}
    If pt.X > 0 Then
    Begin
      While pt.X >= 0 Do
      Begin
        TmpPt.X := TmpPt.X - MaxSep;
        pt := Self.ScreenToClient(
          FPreviewBox.ClientToScreen( FPreviewBox.Grapher.RealToPoint( TmpPt ) ) );
      End;
    End
    Else If pt.X < 0 Then
    Begin
      While pt.X <= 0 Do
      Begin
        TmpPt.X := TmpPt.X + MaxSep;
        pt := Self.ScreenToClient(
          FPreviewBox.ClientToScreen( FPreviewBox.Grapher.RealToPoint( TmpPt ) ) );
      End;
      If pt.X >= Self.Width Then
      Begin
        TmpPt.X := TmpPt.X - MaxSep;
        pt := Self.ScreenToClient(
          FPreviewBox.ClientToScreen( FPreviewBox.Grapher.RealToPoint( TmpPt ) ) );
      End;
    End;
    TmpPt.X := TmpPt.X - MaxSep;

    {...and draw it}
    XLeft := TmpPt.X;
    m := 0;
    While pt.X < Self.Width Do
    Begin
      TmpPt.X := XLeft + m * MaxSep;
      pt := Self.ScreenToClient(
        FPreviewBox.ClientToScreen( FPreviewBox.Grapher.RealToPoint( TmpPt ) ) );

      { If FPreviewBox.PaperUnits = suMms Then
        Text := FloatToStr( round( abs( TmpPt.X + FPreviewBox.MarginLeft ) ) / 1  )
      Else If FPreviewBox.PaperUnits = suMms Then
        Text := FloatToStr( round( abs( TmpPt.X + FPreviewBox.MarginLeft ) ) / 1  )
      Else
        Text := FloatToStr( round( abs( TmpPt.X + FPreviewBox.MarginLeft ) ) );  }

      Text := FloatToStr( round( abs( TmpPt.X + FPreviewBox.MarginLeft ) ) );

      { Draw the mayor scale }
      MoveTo( pt.X, 2 );
      LineTo( pt.X, Self.Height - 2 );

      {Draw the text}
      TextOut( pt.X + 1, 2, Text );

      {draw the minor scale}
      XM := MinSep;
      n := 0;
      While XM < MaxSep Do
      Begin
        pt := Self.ScreenToClient(
          FPreviewBox.ClientToScreen( FPreviewBox.Grapher.RealToPoint( Point2d( TmpPt.X + XM, 0 ) ) ) );
        Inc( n );
        EffectiveH := ( Self.Height - 4 );
        DY := 0;
        If FPreviewBox.FPaperUnits = suMms Then
        Begin
          If XM = MaxSep / 2 Then
            DY := EffectiveH Div 2
          Else
            DY := EffectiveH Div 4;
        End Else If FPreviewBox.FPaperUnits = suCms Then
        Begin
          If XM = MaxSep / 2 Then
            DY := EffectiveH Div 2
          Else
            DY := EffectiveH Div 4;
        End
        Else
        Begin
          If MinSep = 1 / 2 Then
          Begin
            If n * MinSep = int( n * MinSep ) Then
              DY := EffectiveH Div 2
            Else
              DY := EffectiveH Div 4;
          End
          Else If MinSep = 1 / 8 Then
          Begin
            If n = 4 Then
              DY := EffectiveH Div 2
            Else
              DY := EffectiveH Div 4
          End
          Else If MinSep = 1 / 16 Then
          Begin
            If n = 8 Then
              DY := EffectiveH Div 2
            Else If n Mod 2 = 0 Then
              DY := EffectiveH Div 3
            Else
              DY := EffectiveH Div 5;
          End;
        End;
        Y := Self.Height - 2;
        MoveTo( pt.X, Y );
        LineTo( pt.X, Y - DY );

        XM := XM + MinSep;
      End;

      Inc( m );
    End;
  End;
  DrawRulerPosition( FLastMousePosInRuler, pmNotXor );
End;

Procedure TEzHRuler.SetRubberPenColor( Const Value: TColor );
Begin
  FRubberPenColor := Value;
  Invalidate;
End;

Procedure TEzHRuler.SetMarksColor( Const Value: TColor );
Begin
  FMarksColor := Value;
  Invalidate;
End;

{$IFDEF BCB}
function TEzHRuler.GetMarksColor: TColor;
begin
  Result := FMarksColor;
end;

function TEzHRuler.GetPreviewBox: TEzPreviewBox;
begin
  Result := FPreviewBox;
end;

function TEzHRuler.GetRubberPenColor: TColor;
begin
  Result := FRubberPenColor;
end;
{$ENDIF}

function TEzHRuler.GetAbout: TEzAbout;
begin
  Result:= SEz_GisVersion;
end;

procedure TEzHRuler.SetAbout(const Value: TEzAbout);
begin
end;

{ TEzVRuler }

Constructor TEzVRuler.Create( AOwner: TComponent );
Begin
  Inherited Create( AOwner );
  Align := alLeft;
  FRubberPenColor := clAqua;
  FMarksColor := clOlive;
End;

Procedure TEzVRuler.SetPreviewBox( Value: TEzPreviewBox );
Begin
{$IFDEF LEVEL5}
  if Assigned( FPreviewBox ) then FPreviewBox.RemoveFreeNotification( Self );
{$ENDIF}
  If ( Value <> Nil ) And ( Value <> FPreviewBox ) Then
  Begin
    Value.FreeNotification( Self );
    If FPreviewBox <> Nil Then
      With FPreviewBox Do
      Begin
        OnMouseMove := FBoxOnMouseMove;
        OnPaint := FBoxOnPaint;
      End;
    If Value <> Nil Then
      With value Do
      Begin
        FBoxOnMouseMove := OnMouseMove;
        FBoxOnPaint := OnPaint;

        OnMouseMove := MyOnMouseMove;
        OnPaint := MyOnPaint;
      End;
  End;
  FPreviewBox := value;
  Invalidate;
End;

Procedure TEzVRuler.MyOnMouseMove( Sender: TObject; Shift: TShiftState;
  X, Y: Integer );
Begin
  If Assigned( FBoxOnMouseMove ) Then
    FBoxOnMouseMove( Sender, Shift, X, Y );
  If FPreviewBox = Nil Then
    Exit;
  DrawRulerPosition( FLastMousePosInRuler, pmXor );
  FLastMousePosInRuler := ScreenToClient( FPreviewBox.ClientToScreen( Point( X, Y ) ) );
  DrawRulerPosition( FLastMousePosInRuler, pmXor );
End;

Procedure TEzVRuler.MyOnPaint( Sender: TObject );
Begin
  If Assigned( FBoxOnPaint ) Then
    FBoxOnPaint( Sender );
  Self.Paint;
End;

Procedure TEzVRuler.DrawRulerPosition( p: TPoint; AMode: TPenMode );
Begin
  If FPreviewBox = Nil Then
    Exit;
  With Canvas Do
  Begin
    Pen.Mode := AMode;
    Pen.Color := ColorToRGB( FRubberPenColor ) Xor ColorToRGB( Self.Color );
    MoveTo( 0, p.Y );
    LineTo( Width, p.Y );
    Pen.Mode := pmCopy;
  End;
End;

Procedure TEzVRuler.Notification( AComponent: TComponent; Operation: TOperation );
Begin
  Inherited Notification( AComponent, Operation );
  If ( Operation = opRemove ) And ( AComponent = FPreviewBox ) Then
    FPreviewBox := Nil;
End;

Procedure TEzVRuler.Paint;
Var
  ULColor, LRColor: TColor;
  R: TRect;
  i, W: integer;
  Text: String;
  N: Integer;
  pt: TPoint;
  TmpPt: TEzPoint;
  YM, YTop, MinSep, MaxSep: Double;
  EffectiveW, m, X, DX: Cardinal;

  Procedure DrawSides( Rect: TRect );
  Begin
    With Canvas, Rect Do
    Begin
      Pen.Color := LRColor;
      MoveTo( Left, Top );
      LineTo( Left, Bottom );

      MoveTo( Left, Top );
      LineTo( Right, Top );

      Pen.Color := ULColor;
      MoveTo( Right - 1, Top );
      LineTo( Right - 1, Bottom );

      MoveTo( Left, Bottom - 1 );
      LineTo( Right, Bottom - 1 );
    End;
  End;

Begin
  Inherited Paint;
  If ( csDesigning In ComponentState ) Or ( FPreviewBox = Nil ) Then
    Exit;
  DrawRulerPosition( FLastMousePosInRuler, pmNotXor );

  ULColor := clBtnShadow;
  LRColor := clBtnHighlight;
  With Canvas Do
  Begin
    Brush.Style := bsSolid;
    Brush.Color := Self.Color;
    FillRect( ClientRect );
    Brush.Style := bsClear;
    Pen.Mode := pmCopy;
    Pen.Width := 1;
    R := ClientRect;
    W := 2;
    For I := 1 To W Do
    Begin
      DrawSides( R );
      InflateRect( R, -1, -1 );
    End;
    Pen.Color := FMarksColor;

    {calc min and max separators}
    MaxMinSeparation( FPreviewBox, MaxSep, MinSep );

    If FPreviewBox.Grapher.RealToDistY(maxsep) < 10 then exit;

    {Calc the zero point}
    TmpPt := Point2d( 0, 0 );
    pt := ScreenToClient(
      FPreviewBox.ClientToScreen( FPreviewBox.Grapher.RealToPoint( TmpPt ) ) );
    Inc( pt.Y );

    { calc the begining of ruler... }
    If pt.Y < 0 Then
    Begin
      While pt.Y <= 0 Do
      Begin
        TmpPt.Y := TmpPt.Y - MaxSep;
        pt := ScreenToClient(
          FPreviewBox.ClientToScreen( FPreviewBox.Grapher.RealToPoint( TmpPt ) ) );
      End;
      If pt.Y >= Height Then
      Begin
        TmpPt.Y := TmpPt.Y + MaxSep;
        pt := ScreenToClient(
          FPreviewBox.ClientToScreen( FPreviewBox.Grapher.RealToPoint( TmpPt ) ) );
      End;
    End
    Else If pt.Y > 0 Then
    Begin
      While pt.Y >= 0 Do
      Begin
        TmpPt.Y := TmpPt.Y + MaxSep;
        pt := ScreenToClient(
          FPreviewBox.ClientToScreen( FPreviewBox.Grapher.RealToPoint( TmpPt ) ) );
      End;
    End;
    TmpPt.Y := TmpPt.Y + MaxSep;

    { ...and draw it }
    YTop := TmpPt.Y;
    m := 0;
    While pt.Y < Height Do
    Begin
      TmpPt.Y := YTop - m * MaxSep;
      pt := ScreenToClient(
        FPreviewBox.ClientToScreen( FPreviewBox.Grapher.RealToPoint( TmpPt ) ) );
      {If FPreviewBox.FPaperUnits = suMms Then
        Text := FloatToStr( round( abs( TmpPt.Y - FPreviewBox.MarginTop ) ) / 1 )
      Else
        Text := FloatToStr( round( abs( TmpPt.Y - FPreviewBox.MarginTop ) ) );  }

      Text := FloatToStr( round( abs( TmpPt.Y - FPreviewBox.MarginTop ) ) );

      {draw the mayor scale}
      MoveTo( 2, pt.Y );
      LineTo( Width - 2, pt.Y );

      {Draw the text}
      TextOut( 2, pt.Y + 1, Text );

      {draw the minor scale}
      YM := MinSep;
      n := 0;
      While YM < MaxSep Do
      Begin
        pt := ScreenToClient(
          FPreviewBox.ClientToScreen( FPreviewBox.Grapher.RealToPoint( Point2d( 0, TmpPt.Y - YM ) ) ) );
        Inc( n );

⌨️ 快捷键说明

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