Pixel grid

This commit is contained in:
2026-03-29 18:06:00 +03:00
parent 0484aeae31
commit 415b1a41fc
2 changed files with 11 additions and 5 deletions

View File

@@ -125,7 +125,7 @@ public class PixelCanvas : Control
RenderOptions.SetBitmapInterpolationMode(this, BitmapInterpolationMode.None);
context.DrawImage(bmp, srcRect, destRect);
if (ShowGrid && _viewport.Zoom >= 4)
if (ShowGrid)
DrawPixelGrid(context, imgW, imgH);
DrawToolPreview(context, imgW, imgH);
@@ -167,7 +167,11 @@ public class PixelCanvas : Control
private void DrawPixelGrid(DrawingContext context, int imgW, int imgH)
{
var pen = new Pen(new SolidColorBrush(Color.FromArgb(60, 255, 255, 255)), 1);
double zoom = _viewport.Zoom;
if (zoom < 4) return;
var pen = new Pen(Brushes.Black, 1);
var clip = new Rect(0, 0, Bounds.Width, Bounds.Height);
var imgRect = _viewport.ImageScreenRect(imgW, imgH);
var visible = imgRect.Intersect(clip);
@@ -185,12 +189,14 @@ public class PixelCanvas : Control
for (int px = startPx; px <= endPx; px++)
{
var (sx, _) = _viewport.PixelToScreen(px, 0);
context.DrawLine(pen, new Point(sx, visible.Top), new Point(sx, visible.Bottom));
double x = Math.Floor(sx) + 0.5;
context.DrawLine(pen, new Point(x, visible.Top), new Point(x, visible.Bottom));
}
for (int py = startPy; py <= endPy; py++)
{
var (_, sy) = _viewport.PixelToScreen(0, py);
context.DrawLine(pen, new Point(visible.Left, sy), new Point(visible.Right, sy));
double y = Math.Floor(sy) + 0.5;
context.DrawLine(pen, new Point(visible.Left, y), new Point(visible.Right, y));
}
}
}

View File

@@ -45,7 +45,7 @@
</MenuItem>
<MenuItem Header="_View">
<MenuItem Header="Pixel _Grid" ToggleType="CheckBox"
IsChecked="{Binding Editor.ShowGrid}" HotKey="Ctrl+G"/>
IsChecked="{Binding Editor.ShowGrid, Mode=TwoWay}" HotKey="Ctrl+G"/>
</MenuItem>
</Menu>