Example #1
0
        void AssertShiftPixels(IndexedImage image, int dx, int dy, bool shouldBeSame)
        {
            var sourcePixels = new int[image.Pixels.Length];

            image.Pixels.CopyTo(sourcePixels, 0);

            ImageShifter.ShiftPixels(image, dx, dy);

            for (int y = 0; y < image.Size.Height; y++)
            {
                for (int x = 0; x < image.Size.Width; x++)
                {
                    var srcIndex = y * image.Size.Width + x;

                    if (shouldBeSame)
                    {
                        Assert.AreEqual(sourcePixels[srcIndex], image.Pixels[srcIndex]);
                    }
                    else
                    {
                        var sy = y + dy;
                        var sx = x + dx;
                        if (sy >= 0 && sy < image.Size.Height && sx >= 0 && sx < image.Size.Width)
                        {
                            var dstIndex = sy * image.Size.Width + sx;
                            Assert.AreEqual(sourcePixels[srcIndex], image.Pixels[dstIndex]);
                        }
                    }
                }
            }
        }
        internal void ShiftImageAndUpdateRest(IPainter painter, IndexedImage canvas, Point imageStartPoint, Size shiftDelta)
        {
            var pixelShift = new Size(shiftDelta.Width * CellSize, shiftDelta.Height * CellSize);

            ImageShifter.ShiftPixels(canvas, -pixelShift.Width, -pixelShift.Height);

            if (shiftDelta.Height != 0)
            {
                if (shiftDelta.Height < 0)                 // Shifting down - repaint rows at top
                {
                    using (painter.Clip(new Rectangle(0, 0, canvas.Size.Width, RulerWidth - pixelShift.Height)))
                    {
                        Paint(painter, canvas.Size, painter.ClipRect, imageStartPoint);
                    }
                }
                else                 // Shifting up - repaint rows at bottom
                {
                    using (painter.Clip(new Rectangle(0, canvas.Size.Height - pixelShift.Height, canvas.Size.Width, pixelShift.Height)))
                    {
                        Paint(painter, canvas.Size, painter.ClipRect, imageStartPoint);
                    }
                    if (ShowRulers)
                    {
                        using (painter.Clip(new Rectangle(0, 0, canvas.Size.Width, RulerWidth)))
                        {
                            Paint(painter, canvas.Size, painter.ClipRect, imageStartPoint);
                        }
                    }
                }
            }

            if (shiftDelta.Width != 0)
            {
                if (shiftDelta.Width < 0)                 // Shifting right - repaint columns at left
                {
                    using (painter.Clip(new Rectangle(0, 0, RulerWidth - pixelShift.Width, canvas.Size.Height)))
                    {
                        Paint(painter, canvas.Size, painter.ClipRect, imageStartPoint);
                    }
                }
                else                 // Shift left - repaint columns at right
                {
                    using (painter.Clip(new Rectangle(canvas.Size.Width - pixelShift.Width, 0, pixelShift.Width, canvas.Size.Height)))
                    {
                        Paint(painter, canvas.Size, painter.ClipRect, imageStartPoint);
                    }
                    if (ShowRulers)
                    {
                        using (painter.Clip(new Rectangle(0, 0, RulerWidth, canvas.Size.Height)))
                        {
                            Paint(painter, canvas.Size, painter.ClipRect, imageStartPoint);
                        }
                    }
                }
            }
        }
 public void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     else
     {
         Destroy(gameObject);
     }
 }
Example #4
0
        void ShiftImageAndUpdateRest(int shiftDelta)
        {
            ImageShifter.ShiftPixels(VisualImage, 0, -shiftDelta);

            int firstDirtyRow, lastDirtyRow;

            if (shiftDelta < 0)             // Shifting down - repaint rows at top
            {
                firstDirtyRow = VerticalShift / CellSize;
                lastDirtyRow  = (VerticalShift - shiftDelta) / CellSize;
            }
            else             // Shifting up - repaint rows at bottom
            {
                firstDirtyRow = (VerticalShift - shiftDelta + VisualImage.Size.Height - 1) / CellSize;
                lastDirtyRow  = (VerticalShift + VisualImage.Size.Height - 1) / CellSize;
            }

            UpdateImageQuick(firstDirtyRow * ColumnsCount, (lastDirtyRow + 1) * ColumnsCount);
        }