Nothing Special   »   [go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pixel grid replacement on common grid with grid autoscale and minor and major lines #13

Open
k-samsonov opened this issue Oct 25, 2016 · 1 comment

Comments

@k-samsonov
Copy link
    protected virtual void DrawPixelGrid2(Graphics g)
    {
      float gridSize;


      Rectangle imageViewport = this.GetImageViewPort();
      int smallGridFillFactor = 1;


      if ((float)this.ZoomFactor <= 0.5f)
        smallGridFillFactor = 100;
      else if ((float)this.ZoomFactor <= 5)
        smallGridFillFactor = 10;
      else if ((float)this.ZoomFactor > 5)
        smallGridFillFactor = 1;

      float smallGridCell = (float)this.ZoomFactor * smallGridFillFactor;

      int largeGridFillFactor = smallGridFillFactor * 10;
      float largeGridCell = (float)this.ZoomFactor * largeGridFillFactor;


      float smallGridoffsetX = Math.Abs(this.AutoScrollPosition.X) % smallGridCell;
      float smallGridoffsetY = Math.Abs(this.AutoScrollPosition.Y) % smallGridCell;

      float largeGridoffsetX = Math.Abs(this.AutoScrollPosition.X) % largeGridCell;
      float largeGridoffsetY = Math.Abs(this.AutoScrollPosition.Y) % largeGridCell;
      Debug.WriteLine(string.Format("Small GridCell: {0}", smallGridCell));
      Debug.WriteLine(string.Format("Large GridCell: {0}", largeGridCell));

      Pen majorPen = GetMajorPen();
      Pen minorPen = GetMinorPen();


      for (float x = imageViewport.Left - smallGridoffsetX; x < imageViewport.Right; x += smallGridCell)
      {
        g.DrawLine(minorPen, x, imageViewport.Top, x, imageViewport.Bottom);
      }
      for (float y = imageViewport.Top - smallGridoffsetY; y < imageViewport.Bottom; y += smallGridCell)
      {
        g.DrawLine(minorPen, imageViewport.Left, y, imageViewport.Right, y);
      }


      for (float x = imageViewport.Left - largeGridoffsetX; x < imageViewport.Right; x += largeGridCell)
      {
        g.DrawLine(majorPen, x, imageViewport.Top, x, imageViewport.Bottom);
      }
      for (float y = imageViewport.Top - largeGridoffsetY; y < imageViewport.Bottom; y += largeGridCell)
      {
        g.DrawLine(majorPen, imageViewport.Left, y, imageViewport.Right, y);
      }

      g.DrawRectangle(minorPen, imageViewport);


      majorPen.Dispose();
      minorPen.Dispose();
      return;
    }
@cyotek
Copy link
Owner
cyotek commented Feb 28, 2017

Hello,

This is actually something I've considered adding in the past as it's something I wanted for a project but never had the time to implement it. Thanks for the suggestion, and the sample code - I like how your "major" lines are present even when zoomed out.

Many thanks for the suggestion!

Regards;
Richard Moss

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants