public virtual void OnResized(Rect newRect, ResizeFlags resizeWhat) { if (resizeWhat != ResizeFlags.None) { Store.Dispatch(new ResizeStickyNoteAction(StickyNoteModel, newRect, resizeWhat)); } }
public ResizeTransform(Unit width, Unit height, CropAnchor?anchor, ResizeFlags flags) { if (width < 0 || width > Constants.MaxWidth) { throw new ArgumentOutOfRangeException(nameof(width), width, message: "Must be between 0 and 16,383"); } if (height < 0 || height > Constants.MaxHeight) { throw new ArgumentOutOfRangeException(nameof(height), height, message: "Must be between 0 and 16,383"); } this.width = width; this.height = height; Anchor = anchor; Flags = flags; }
private void GetNewSize(ResizeFlags resizeFlags, out int newWidth, out int newHeight) { newWidth = this.Width; newHeight = this.Height; newWidth += resizeFlags.HasFlag(ResizeFlags.InsertLeftColumn) ? 1 : 0; newWidth += resizeFlags.HasFlag(ResizeFlags.InsertRightColumn) ? 1 : 0; newHeight += resizeFlags.HasFlag(ResizeFlags.InsertTopRow) ? 1 : 0; newHeight += resizeFlags.HasFlag(ResizeFlags.InsertBottomRow) ? 1 : 0; }
public static string ToLower(this ResizeFlags flags) { var result = flags.ToString(); return(flags.ToString().Replace(", ", "|").ToLower()); }
void OnMouseMove(MouseMoveEvent e) { if (!m_Active) { return; } VisualElement resizedTarget = resizedElement.parent; VisualElement resizedBase = resizedTarget.parent; Vector2 mousePos = resizedBase.WorldToLocal(e.mousePosition); if (!m_DragStarted) { m_DragStarted = true; } // PF: once we remove all calls to SetLayout(), we can remove this if and keep the else. if (resizedTarget.IsLayoutManual()) { m_NewRect = resizedTarget.layout; if ((direction & ResizerDirection.Right) != 0) { m_NewRect.width = Mathf.Min(m_MaxSize.x, Mathf.Max(m_MinSize.x, m_StartSize.x + mousePos.x - m_StartMouse.x)); } else if ((direction & ResizerDirection.Left) != 0) { float delta = mousePos.x - m_StartMouse.x; if (m_StartSize.x - delta < m_MinSize.x) { delta = -m_MinSize.x + m_StartSize.x; } else if (m_StartSize.x - delta > m_MaxSize.x) { delta = -m_MaxSize.x + m_StartSize.x; } m_NewRect.xMin = delta + m_StartPosition.x; m_NewRect.width = -delta + m_StartSize.x; } if ((direction & ResizerDirection.Bottom) != 0) { m_NewRect.height = Mathf.Min(m_MaxSize.y, Mathf.Max(m_MinSize.y, m_StartSize.y + mousePos.y - m_StartMouse.y)); } else if ((direction & ResizerDirection.Top) != 0) { float delta = mousePos.y - m_StartMouse.y; if (m_StartSize.y - delta < m_MinSize.y) { delta = -m_MinSize.y + m_StartSize.y; } else if (m_StartSize.y - delta > m_MaxSize.y) { delta = -m_MaxSize.y + m_StartSize.y; } m_NewRect.yMin = delta + m_StartPosition.y; m_NewRect.height = -delta + m_StartSize.y; } if (direction != 0) { resizedTarget.SetLayout(m_NewRect); } } else { m_ResizeFlags = ResizeFlags.None; m_NewRect = new Rect(); if ((direction & ResizerDirection.Right) != 0) { m_ResizeFlags |= ResizeFlags.Width; m_NewRect.width = Mathf.Min(m_MaxSize.x, Mathf.Max(m_MinSize.x, m_StartSize.x + mousePos.x - m_StartMouse.x)); resizedTarget.style.width = m_NewRect.width; } else if ((direction & ResizerDirection.Left) != 0) { float delta = mousePos.x - m_StartMouse.x; if (m_StartSize.x - delta < m_MinSize.x) { delta = -m_MinSize.x + m_StartSize.x; } else if (m_StartSize.x - delta > m_MaxSize.x) { delta = -m_MaxSize.x + m_StartSize.x; } m_ResizeFlags |= ResizeFlags.Left; m_ResizeFlags |= ResizeFlags.Width; m_NewRect.x = delta + m_StartPosition.x; m_NewRect.width = -delta + m_StartSize.x; resizedTarget.style.left = m_NewRect.x; resizedTarget.style.width = m_NewRect.width; } if ((direction & ResizerDirection.Bottom) != 0) { m_ResizeFlags |= ResizeFlags.Height; m_NewRect.height = Mathf.Min(m_MaxSize.y, Mathf.Max(m_MinSize.y, m_StartSize.y + mousePos.y - m_StartMouse.y)); resizedTarget.style.height = m_NewRect.height; } else if ((direction & ResizerDirection.Top) != 0) { float delta = mousePos.y - m_StartMouse.y; if (m_StartSize.y - delta < m_MinSize.y) { delta = -m_MinSize.y + m_StartSize.y; } else if (m_StartSize.y - delta > m_MaxSize.y) { delta = -m_MaxSize.y + m_StartSize.y; } m_ResizeFlags |= ResizeFlags.Top; m_ResizeFlags |= ResizeFlags.Height; m_NewRect.y = delta + m_StartPosition.y; m_NewRect.height = -delta + m_StartSize.y; resizedTarget.style.top = m_NewRect.y; resizedTarget.style.height = m_NewRect.height; } } e.StopPropagation(); }
public ResizeStickyNoteAction(IGTFStickyNoteModel stickyNoteModel, Rect position, ResizeFlags resizeWhat) : base(new[] { stickyNoteModel }, position) { ResizeWhat = resizeWhat; }
/// <summary> /// Resizes an image to a new size. Resizing neither stretches nor enlarges a picture by default. /// </summary> /// <remarks>Set both newWidth and newHeight to 0 to prevent resizing.</remarks> /// <param name="originalImage">The original image to resize</param> /// <param name="newWidth">The new width of the image. Set to 0 to let the height decide.</param> /// <param name="newHeight">The new height of the image. Set to 0 to let the width decide.</param> /// <param name="resizeFlags">Specify the different flags in the ResizeFlags enumeration to deviate from the default behaviour.</param> /// <param name="smoothingMode">Specifies the smoothing mode.</param> /// <param name="interpolationMode">Specifies the interpolation mode.</param> /// <param name="pixelOffsetMode">Specifies the pixel offset mode.</param> /// <returns>A memory stream containing the resized image. /// Returns null if the original file was neither an image nor found. /// </returns> public static MemoryStream Resize(Image originalImage, int newWidth, int newHeight, ResizeFlags resizeFlags, SmoothingMode smoothingMode, InterpolationMode interpolationMode, PixelOffsetMode pixelOffsetMode, CompositingQuality compositingQuality) { MemoryStream ms = new MemoryStream(); Resize(originalImage, ms, newWidth, newHeight, resizeFlags, smoothingMode, interpolationMode, pixelOffsetMode, compositingQuality); return(ms); }
void FitText(bool onlyIfSmaller) { Vector2 preferredTitleSize = Vector2.zero; if (!string.IsNullOrEmpty(m_Title.text)) { preferredTitleSize = m_Title.MeasureTextSize(m_Title.text, 0, MeasureMode.Undefined, 0, MeasureMode.Undefined); // This is the size of the string with the current title font and such } preferredTitleSize += AllExtraSpace(m_Title); preferredTitleSize.x += m_Title.ChangeCoordinatesTo(this, Vector2.zero).x + resolvedStyle.width - m_Title.ChangeCoordinatesTo(this, new Vector2(m_Title.layout.width, 0)).x; Vector2 preferredContentsSizeOneLine = m_Content.MeasureTextSize(m_Content.text, 0, MeasureMode.Undefined, 0, MeasureMode.Undefined); Vector2 contentExtraSpace = AllExtraSpace(m_Content); preferredContentsSizeOneLine += contentExtraSpace; Vector2 extraSpace = new Vector2(resolvedStyle.width, resolvedStyle.height) - m_Content.ChangeCoordinatesTo(this, new Vector2(m_Content.layout.width, m_Content.layout.height)); extraSpace += m_Title.ChangeCoordinatesTo(this, Vector2.zero); preferredContentsSizeOneLine += extraSpace; float width = 0; float height = 0; // The content in one line is smaller than the current width. // Set the width to fit both title and content. // Set the height to have only one line in the content if (preferredContentsSizeOneLine.x < Mathf.Max(preferredTitleSize.x, resolvedStyle.width)) { width = Mathf.Max(preferredContentsSizeOneLine.x, preferredTitleSize.x); height = preferredContentsSizeOneLine.y + preferredTitleSize.y; } else // The width is not enough for the content: keep the width or use the title width if bigger. { width = Mathf.Max(preferredTitleSize.x + extraSpace.x, resolvedStyle.width); float contextWidth = width - extraSpace.x - contentExtraSpace.x; Vector2 preferredContentsSize = m_Content.MeasureTextSize(m_Content.text, contextWidth, MeasureMode.Exactly, 0, MeasureMode.Undefined); preferredContentsSize += contentExtraSpace; height = preferredTitleSize.y + preferredContentsSize.y + extraSpace.y; } ResizeFlags resizeWhat = ResizeFlags.None; if (!onlyIfSmaller || resolvedStyle.width < width) { resizeWhat |= ResizeFlags.Width; style.width = width; } if (!onlyIfSmaller || resolvedStyle.height < height) { resizeWhat |= ResizeFlags.Height; style.height = height; } if (this is IResizable && resizeWhat != ResizeFlags.None) { Rect newRect = new Rect(0, 0, width, height); (this as IResizable).OnResized(newRect, resizeWhat); } }
/// <summary> /// Resizes an image to a new size. Resizing neither stretches nor enlarges a picture by default. /// </summary> /// <param name="imageStream">The stream containing the image to resize.</param> /// <param name="outputStream">The stream containing the resized image.</param> /// <param name="newWidth">The new width of the image. Set to 0 to let the height decide.</param> /// <param name="newHeight">The new height of the image. Set to 0 to let the width decide.</param> /// <param name="resizeFlags">Specify the different flags in the ResizeFlags enumeration to deviate from the default behaviour.</param> /// <param name="smoothingMode">Specifies the smoothing mode.</param> /// <param name="interpolationMode">Specifies the interpolation mode.</param> /// <param name="pixelOffsetMode">Specifies the pixel offset mode.</param> public static void Resize(Stream imageStream, Stream outputStream, int newWidth, int newHeight, ResizeFlags resizeFlags, SmoothingMode smoothingMode, InterpolationMode interpolationMode, PixelOffsetMode pixelOffsetMode, CompositingQuality compositingQuality, bool useEmbeddedColorManagement) { using (Image origImage = Image.FromStream(imageStream, useEmbeddedColorManagement)) { Resize(origImage, outputStream, newWidth, newHeight, resizeFlags, smoothingMode, interpolationMode, pixelOffsetMode, compositingQuality); } }
/// <summary> /// Resizes an image to a new size. Resizing neither stretches nor enlarges a picture by default. /// </summary> /// <param name="imageStream">The stream containing the image to resize.</param> /// <param name="outputStream">The stream containing the resized image.</param> /// <param name="newWidth">The new width of the image. Set to 0 to let the height decide.</param> /// <param name="newHeight">The new height of the image. Set to 0 to let the width decide.</param> /// <param name="resizeFlags">Specify the different flags in the ResizeFlags enumeration to deviate from the default behaviour.</param> public static void Resize(Stream imageStream, Stream outputStream, int newWidth, int newHeight, ResizeFlags resizeFlags) { Resize(imageStream, outputStream, newWidth, newHeight, resizeFlags, SmoothingMode.Default, InterpolationMode.Default, PixelOffsetMode.Default, CompositingQuality.Default, false); }
/// <summary> /// Resizes an image to a new size. Resizing neither stretches nor enlarges a picture by default. /// </summary> /// <remarks>Set both newWidth and newHeight to 0 to prevent resizing.</remarks> /// <param name="imageStream">The stream containing the image to resize.</param> /// <param name="newWidth">The new width of the image. Set to 0 to let the height decide.</param> /// <param name="newHeight">The new height of the image. Set to 0 to let the width decide.</param> /// <param name="resizeFlags">Specify the different flags in the ResizeFlags enumeration to deviate from the default behaviour.</param> /// <param name="smoothingMode">Specifies the smoothing mode.</param> /// <param name="interpolationMode">Specifies the interpolation mode.</param> /// <param name="pixelOffsetMode">Specifies the pixel offset mode.</param> /// <returns>A memory stream containing the resized image. /// Returns null if the original file was neither an image nor found. /// </returns> public static MemoryStream Resize(Stream imageStream, int newWidth, int newHeight, ResizeFlags resizeFlags, SmoothingMode smoothingMode, InterpolationMode interpolationMode, PixelOffsetMode pixelOffsetMode, CompositingQuality compositingQuality, bool useEmbeddedColorManagement) { try { MemoryStream ms = new MemoryStream(); Resize(imageStream, ms, newWidth, newHeight, resizeFlags, smoothingMode, interpolationMode, pixelOffsetMode, compositingQuality, useEmbeddedColorManagement); return(ms); } catch (OutOfMemoryException) { // If not image } return(null); }
/// <summary> /// Resizes an image to a new size. Resizing neither stretches nor enlarges a picture by default. /// </summary> /// <param name="imageStream">The stream containing the image to resize.</param> /// <param name="newWidth">The new width of the image. Set to 0 to let the height decide.</param> /// <param name="newHeight">The new height of the image. Set to 0 to let the width decide.</param> /// <param name="resizeFlags">Specify the different flags in the ResizeFlags enumeration to deviate from the default behaviour.</param> /// <returns>A memory stream containing the resized image. /// Returns null if the original file was neither an image nor found. /// </returns> public static MemoryStream Resize(Stream imageStream, int newWidth, int newHeight, ResizeFlags resizeFlags) { return(Resize(imageStream, newWidth, newHeight, resizeFlags, SmoothingMode.Default, InterpolationMode.Default, PixelOffsetMode.Default, CompositingQuality.Default, false)); }
/// <summary> /// Resizes an image to a new size. Resizing neither stretches nor enlarges a picture by default. /// </summary> /// <param name="originalImage">The original image to resize</param> /// <param name="outputStream">The stream containing the resized image.</param> /// <param name="newWidth">The new width of the image. Set to 0 to let the height decide.</param> /// <param name="newHeight">The new height of the image. Set to 0 to let the width decide.</param> /// <param name="resizeFlags">Specify the different flags in the ResizeFlags enumeration to deviate from the default behaviour.</param> /// <param name="smoothingMode">Specifies the smoothing mode.</param> /// <param name="interpolationMode">Specifies the interpolation mode.</param> /// <param name="pixelOffsetMode">Specifies the pixel offset mode.</param> public static void Resize(Image originalImage, Stream outputStream, int newWidth, int newHeight, ResizeFlags resizeFlags, SmoothingMode smoothingMode, InterpolationMode interpolationMode, PixelOffsetMode pixelOffsetMode, CompositingQuality compositingQuality) { if (originalImage == null) { throw new ArgumentNullException("originalImage"); } Size originalSize = originalImage.PhysicalDimension.ToSize(); Size newSize; if ((resizeFlags & ResizeFlags.AllowStretching) > 0) { newSize = GetNonProportionalImageSize(originalSize, newWidth, newHeight, (resizeFlags & ResizeFlags.AllowEnlarging) > 0); } else { newSize = GetProportionalImageSize(originalSize, newWidth, newHeight, (resizeFlags & ResizeFlags.AllowEnlarging) > 0); } using (MemoryStream memoryStream = new MemoryStream()) { if (newSize.Equals(originalSize)) { // Keep original size. Only make a copy originalImage.Save(memoryStream, new ImageFormat(originalImage.RawFormat.Guid)); } else { // Create new pic. using (Bitmap bitmap = new Bitmap(newSize.Width, newSize.Height)) { bitmap.SetResolution(originalImage.HorizontalResolution, originalImage.VerticalResolution); using (Graphics graphics = Graphics.FromImage(bitmap)) { graphics.SmoothingMode = smoothingMode; graphics.InterpolationMode = interpolationMode; graphics.PixelOffsetMode = pixelOffsetMode; graphics.CompositingQuality = compositingQuality; graphics.DrawImage(originalImage, new Rectangle(0, 0, bitmap.Width, bitmap.Height), new Rectangle(0, 0, originalImage.Width, originalImage.Height), GraphicsUnit.Pixel); bitmap.Save(memoryStream, originalImage.RawFormat); } } } memoryStream.WriteTo(outputStream); } }
/// <summary> /// Resizes an image to a new size. Resizing neither stretches nor enlarges a picture by default. /// </summary> /// <param name="originalImage">The original image to resize</param> /// <param name="outputStream">The stream containing the resized image.</param> /// <param name="newWidth">The new width of the image. Set to 0 to let the height decide.</param> /// <param name="newHeight">The new height of the image. Set to 0 to let the width decide.</param> /// <param name="resizeFlags">Specify the different flags in the ResizeFlags enumeration to deviate from the default behaviour.</param> public static void Resize(Image originalImage, Stream outputStream, int newWidth, int newHeight, ResizeFlags resizeFlags) { Resize(originalImage, outputStream, newWidth, newHeight, resizeFlags, SmoothingMode.Default, InterpolationMode.Default, PixelOffsetMode.Default, CompositingQuality.Default); }
private void Resize(ResizeFlags resizeFlags) { int newWidth; int newHeight; GetNewSize(resizeFlags, out newWidth, out newHeight); if (newWidth != Width || newHeight != Height) { bool[,] newCells = new bool[newHeight, newWidth]; Cells = newCells; } else { Array.Clear(Cells, 0, Cells.Length); } }
public ChangePlacematPositionAction(Rect position, ResizeFlags resizeWhat, params IGTFPlacematModel[] placematModels) : base(placematModels, position) { ResizeFlags = resizeWhat; }
// 100×100 // 100x100 // 100x100,contain // 100x100-c // resize(100,100,contain) public static ResizeTransform Parse(string segment) { int argStart = segment.IndexOf('(') + 1; if (argStart > 0) { segment = segment.Substring(argStart, segment.Length - argStart - 1); } int dashIndex = segment.IndexOf('-'); // {width}x{height}-{anchor} // e.g. 100x100-c if (dashIndex > -1) { return(new ResizeTransform( size: SizeHelper.Parse(segment.Substring(0, dashIndex)), anchor: CropAnchorHelper.Parse(segment.Substring(dashIndex + 1)) )); } else if (segment.IndexOf(',') > -1) { var args = ArgumentList.Parse(segment); Unit width = default; Unit height = default; ResizeFlags flags = default; CropAnchor? anchor = null; for (int i = 0; i < args.Length; i++) { ref Argument arg = ref args[i]; int xIndex = arg.Value.ToString().IndexOf('x'); if (i == 0 && xIndex > -1) { width = Unit.Parse(arg.Value.ToString().Substring(0, xIndex)); height = Unit.Parse(arg.Value.ToString().Substring(xIndex + 1)); continue; } if (i == 0 && width == default) { width = Unit.Parse(arg.Value.ToString()); } else if (i == 1 && height == default) { height = Unit.Parse(arg.Value.ToString()); } else { switch (arg.Name) { case "anchor": anchor = CropAnchorHelper.Parse(arg.Value.ToString()); break; case null: flags = ResizeFlagsHelper.Parse(arg.Value.ToString()); break; default: throw new Exception("Invalid resize argument:" + arg.Name); } } } return(new ResizeTransform(width, height, anchor, flags)); }
public ResizeTransform(Unit width, Unit height, ResizeFlags flags = default) : this(width, height, null, flags) { }
/// <summary> /// Resizes an image to a new size. Resizing neither stretches nor enlarges a picture by default. /// </summary> /// <param name="originalImage">The original image to resize</param> /// <param name="newWidth">The new width of the image. Set to 0 to let the height decide.</param> /// <param name="newHeight">The new height of the image. Set to 0 to let the width decide.</param> /// <param name="resizeFlags">Specify the different flags in the ResizeFlags enumeration to deviate from the default behaviour.</param> /// <returns>A memory stream containing the resized image. /// Returns null if the original file was neither an image nor found. /// </returns> public static MemoryStream Resize(Image originalImage, int newWidth, int newHeight, ResizeFlags resizeFlags) { return(Resize(originalImage, newWidth, newHeight, resizeFlags, SmoothingMode.Default, InterpolationMode.Default, PixelOffsetMode.Default, CompositingQuality.Default)); }