void ShotForm_MouseDown(object sender, MouseEventArgs e) { var mp = this.PointToClient(Control.MousePosition); if (this.MouseDownPoint == Point.Empty && this.SelectedRect == Rectangle.Empty) { this.IsMouseDown = true; this.MouseDownPoint = mp; this.SelectedRect = Rectangle.Empty; this.GuideLines[0] = new Point[] { new Point(0, this.MouseDownPoint.Y), new Point(Screen.PrimaryScreen.Bounds.Width, this.MouseDownPoint.Y) }; this.GuideLines[1] = new Point[] { new Point(this.MouseDownPoint.X, 0), new Point(this.MouseDownPoint.X, Screen.PrimaryScreen.Bounds.Height) }; } else if (this.SelectedRect != Rectangle.Empty && this.SelectedRect.Contains(mp)) { //在选择区域内按下鼠标,代表想移动所选区域 this.IsMoveRegion = true; this.IsResize = false; this.MoveRegionStartPoint = this.PointToClient(Control.MousePosition); } else if (this.SelectedRect != Rectangle.Empty && this.TouchPoints.FirstOrDefault(p => p.Contains(mp)) != Rectangle.Empty) { // Resize var point = this.TouchPoints.FirstOrDefault(p => p.Contains(mp)); var idx = this.TouchPoints.ToList().FindIndex(p => p.Equals(point)); this.IsResize = true; this.IsMoveRegion = false; this.ResizeStartPoint = mp; this.ResizeType = this.CanResizeType.ElementAt(idx); } }
private void SetResize(ref Rectangle rect, int offsetX, int offsetY, ResizeTypes type) { //this.Text = type.ToString(); if ((type & ResizeTypes.Width) == ResizeTypes.Width) { rect.Width += offsetX; } if ((type & ResizeTypes.Height) == ResizeTypes.Height) { rect.Height += offsetY; } if ((type & ResizeTypes.X) == ResizeTypes.X) { rect.X += offsetX; rect.Width -= offsetX; } if ((type & ResizeTypes.Y) == ResizeTypes.Y) { rect.Y += offsetY; rect.Height -= offsetY; } }
private ResizeTypes GetResizeType(Vector2 mousePos) { // Calculate which part of the resize area we're in, if any. ResizeTypes mask = 0; if (m_resizeMask[ResizeTypes.Top].Contains(mousePos)) { mask |= ResizeTypes.Top; } else if (m_resizeMask[ResizeTypes.Bottom].Contains(mousePos)) { mask |= ResizeTypes.Bottom; } if (m_resizeMask[ResizeTypes.Left].Contains(mousePos)) { mask |= ResizeTypes.Left; } else if (m_resizeMask[ResizeTypes.Right].Contains(mousePos)) { mask |= ResizeTypes.Right; } return(mask); }
public static Image Resize(Image source, ResizeTypes resizeType, int width, int height) { ResizeModel model = new ResizeModel(); model.Source = source; model.ResizeType = resizeType; model.Width = width; model.Height = height; return(Resize(model)); }
public void OnHoverResize(ResizeTypes resizeType) { if (WasHoveringResize && m_lastResizeHoverType == resizeType) { return; } // we are entering resize, or the resize type has changed. WasHoveringResize = true; m_lastResizeHoverType = resizeType; s_resizeCursorImage.SetActive(true); // set the rotation for the resize icon float iconRotation = 0f; switch (resizeType) { case ResizeTypes.TopRight: case ResizeTypes.BottomLeft: iconRotation = 45f; break; case ResizeTypes.Top: case ResizeTypes.Bottom: iconRotation = 90f; break; case ResizeTypes.TopLeft: case ResizeTypes.BottomRight: iconRotation = 135f; break; } Quaternion rot = s_resizeCursorImage.transform.rotation; rot.eulerAngles = new Vector3(0, 0, iconRotation); s_resizeCursorImage.transform.rotation = rot; UpdateHoverImagePos(); }
/// <summary> /// 设置要绘制的区域 /// </summary> private void SetRects(Point?endPoint, int offsetX = 0, int offsetY = 0, ResizeTypes resizeType = ResizeTypes.None) { if (endPoint.HasValue) { var x = Math.Min(endPoint.Value.X, this.MouseDownPoint.X); var y = Math.Min(endPoint.Value.Y, this.MouseDownPoint.Y); var width = Math.Abs(endPoint.Value.X - this.MouseDownPoint.X); var height = Math.Abs(endPoint.Value.Y - this.MouseDownPoint.Y); this.SelectedRect = new Rectangle(x, y, width, height); } if (resizeType == ResizeTypes.None) { this.SelectedRect.Offset(offsetX, offsetY); } else { this.SetResize(ref this.SelectedRect, offsetX, offsetY, resizeType); } this.SetTouchPoints(); this.SetGuideLines(); }
public bool ChangeSize(decimal change, ResizeTypes type, ResizeDirections dir, out decimal pctChange) { bool success = true; pctChange = 0; int newHeight = AlteredImg.Height; int newWidth = AlteredImg.Width; if (type == ResizeTypes.Percent) { decimal multiplier = 1.00m + (change / 100); if (dir == ResizeDirections.Vertical) { decimal decNewHeight = (StartImg.Height * multiplier); decimal decNewWidth = (StartImg.Width * multiplier); newHeight = (int)decNewHeight; newWidth = (int)decNewWidth; pctChange = change; } } else if (type == ResizeTypes.Pixels) { if (dir == ResizeDirections.Vertical) { newHeight = AlteredImg.Height + (int)change; decimal newHeightPct = ((decimal)newHeight / (decimal)AlteredImg.Height); newWidth = (int)Math.Round(AlteredImg.Width * newHeightPct); } else if (dir == ResizeDirections.Horizontal) { newWidth = AlteredImg.Width + (int)change; decimal newWidthPct = ((decimal)newWidth / (decimal)AlteredImg.Width); newHeight = (int)Math.Round(AlteredImg.Height * newWidthPct); } pctChange = (((decimal)newHeight / (decimal)StartImg.Height) - 1) * 100.0m; } if (HasCrop) { if (change < 0) // Decreasing image size { if (Crop.GetRectangle().Bottom >= this.GetRectangle().Bottom || Crop.GetRectangle().Right >= this.GetRectangle().Right) success = false; } } if (success) { AlteredImg.Dispose(); AlteredImg = new Bitmap(StartImg, new Size { Width = newWidth, Height = newHeight }); } return success; }
public void OnBeginResize(ResizeTypes resizeType) { m_currentResizeType = resizeType; m_lastResizePos = InputManager.MousePosition; WasResizing = true; }