public Document(int width, int height) : this() { Width = width; Height = height; DocumentSizeChanged?.Invoke(this, new DocumentSizeChangedEventArgs(0, 0, width, height)); }
public Document(int width, int height) : this() { if (width <= 0 || height <= 0) { throw new ArgumentException("Document dimensions must be greater than 0"); } Width = width; Height = height; Renderer = new LayerStackRenderer(layers, layerStructure, Width, Height); DocumentSizeChanged?.Invoke(this, new DocumentSizeChangedEventArgs(1, 1, width, height)); }
private void ResizeCanvasProcess(object[] arguments) { int oldWidth = Width; int oldHeight = Height; Thickness[] offset = (Thickness[])arguments[0]; int width = (int)arguments[1]; int height = (int)arguments[2]; ResizeCanvas(offset, width, height); DocumentSizeChanged?.Invoke(this, new DocumentSizeChangedEventArgs(oldWidth, oldHeight, width, height)); }
private void RestoreDocumentLayersProcess(Layer[] layers, UndoLayer[] data, object[] args) { int oldWidth = Width; int oldHeight = Height; Width = (int)args[0]; Height = (int)args[1]; DocumentSizeChanged?.Invoke( this, new DocumentSizeChangedEventArgs(oldWidth, oldHeight, Width, Height)); Layers.Clear(); Layers.AddRange(layers); }
private void RotateDocumentProcess(object[] parameters) { float degrees = (float)parameters[0]; int oldWidth = Width; int oldHeight = Height; int biggerMaxSize = Math.Max(Width, Height); // TODO: Fix v0.2 foreach (var layer in Layers) { using (new SKAutoCanvasRestore(layer.LayerBitmap.SkiaSurface.Canvas, true)) { var copy = layer.LayerBitmap.SkiaSurface.Snapshot(); double radians = Math.PI * degrees / 180; float sine = (float)Math.Abs(Math.Sin(radians)); float cosine = (float)Math.Abs(Math.Cos(radians)); int originalWidth = layer.Width; int originalHeight = layer.Height; int rotatedWidth = (int)(cosine * originalWidth + sine * originalHeight); int rotatedHeight = (int)(cosine * originalHeight + sine * originalWidth); layer.CreateNewBitmap(rotatedWidth, rotatedHeight); var surface = layer.LayerBitmap.SkiaSurface.Canvas; surface.Translate(rotatedWidth / 2, rotatedHeight / 2); surface.RotateDegrees((float)degrees); surface.Translate(-originalWidth / 2, -originalHeight / 2); surface.DrawImage(copy, default(SKPoint)); layer.MaxHeight = oldWidth; layer.MaxWidth = oldHeight; copy.Dispose(); } layer.InvokeLayerBitmapChange(); } Height = oldWidth; Width = oldHeight; DocumentSizeChanged?.Invoke( this, new DocumentSizeChangedEventArgs(oldWidth, oldHeight, Width, Height)); }
private void ResizeDocument(int newWidth, int newHeight) { int oldWidth = Width; int oldHeight = Height; for (int i = 0; i < Layers.Count; i++) { float widthRatio = (float)newWidth / Width; float heightRatio = (float)newHeight / Height; int layerWidth = Math.Max(1, (int)(Layers[i].Width * widthRatio)); int layerHeight = Math.Max(1, (int)(Layers[i].Height * heightRatio)); Layers[i].Resize(layerWidth, layerHeight, newWidth, newHeight); Layers[i].Offset = new Thickness(Math.Floor(Layers[i].OffsetX * widthRatio), Math.Floor(Layers[i].OffsetY * heightRatio), 0, 0); } Height = newHeight; Width = newWidth; DocumentSizeChanged?.Invoke( this, new DocumentSizeChangedEventArgs(oldWidth, oldHeight, newWidth, newHeight)); }
/// <summary> /// Resizes canvas to specified width and height to selected anchor. /// </summary> /// <param name="width">New width of canvas.</param> /// <param name="height">New height of canvas.</param> /// <param name="anchor"> /// Point that will act as "starting position" of resizing. Use pipe to connect horizontal and /// vertical. /// </param> public void ResizeCanvas(int width, int height, AnchorPoint anchor, bool addToUndo = true) { int oldWidth = Width; int oldHeight = Height; int offsetX = GetOffsetXForAnchor(Width, width, anchor); int offsetY = GetOffsetYForAnchor(Height, height, anchor); Thickness[] newOffsets = Layers.Select(x => new Thickness(offsetX + x.OffsetX, offsetY + x.OffsetY, 0, 0)) .ToArray(); object[] processArgs = { newOffsets, width, height }; object[] reverseProcessArgs = { Width, Height }; if (addToUndo) { StorageBasedChange change = new(this, Layers); ResizeCanvas(newOffsets, width, height); UndoManager.AddUndoChange(change.ToChange( RestoreDocumentLayersProcess, reverseProcessArgs, ResizeCanvasProcess, processArgs, "Resize canvas")); } else { ResizeCanvas(newOffsets, width, height); } if (oldWidth == Width && Height == oldHeight) { return; } DocumentSizeChanged?.Invoke(this, new DocumentSizeChangedEventArgs(oldWidth, oldHeight, width, height)); }
/// <summary> /// Resizes canvas to specified width and height to selected anchor. /// </summary> /// <param name="width">New width of canvas.</param> /// <param name="height">New height of canvas.</param> /// <param name="anchor"> /// Point that will act as "starting position" of resizing. Use pipe to connect horizontal and /// vertical. /// </param> public void ResizeCanvas(int width, int height, AnchorPoint anchor) { int oldWidth = Width; int oldHeight = Height; int offsetX = GetOffsetXForAnchor(Width, width, anchor); int offsetY = GetOffsetYForAnchor(Height, height, anchor); Thickness[] oldOffsets = Layers.Select(x => x.Offset).ToArray(); Thickness[] newOffsets = Layers.Select(x => new Thickness(offsetX + x.OffsetX, offsetY + x.OffsetY, 0, 0)) .ToArray(); object[] processArgs = { newOffsets, width, height }; object[] reverseProcessArgs = { oldOffsets, Width, Height }; ResizeCanvas(newOffsets, width, height); UndoManager.AddUndoChange(new Change( ResizeCanvasProcess, reverseProcessArgs, ResizeCanvasProcess, processArgs, "Resize canvas")); DocumentSizeChanged?.Invoke(this, new DocumentSizeChangedEventArgs(oldWidth, oldHeight, width, height)); }