public override void Resize(ResizeLocations location, Point oldPos, Point newPos) { throw new NotImplementedException(); }
/// <summary> /// 对图形进行调整大小的操作 /// </summary> /// <param name="location">缩放的点的位置</param> /// <param name="resizePos">缩放的点的坐标</param> /// <param name="newPos">顶点的新位置</param> public abstract void Resize(ResizeLocations location, Point resizePos, Point newPos);
public override void Resize(ResizeLocations location, Point oldPos, Point newPos) { switch (location) { case ResizeLocations.TopLeft: { double targetWidth = this.Width - (newPos.X - this.Point1X); double targetHeight = this.Height - (newPos.Y - this.Point1Y); if (targetWidth < PadContext.MinimalVisualSize) { } else { this.Width = targetWidth; this.Point1X = newPos.X; } if (targetHeight < PadContext.MinimalVisualSize) { } else { this.Height = targetHeight; this.Point1Y = newPos.Y; } break; } case ResizeLocations.TopRight: { double targetWidth = newPos.X - this.Point1X; double targetHeight = this.Height - (newPos.Y - this.Point1Y); if (targetWidth < PadContext.MinimalVisualSize) { } else { this.Width = targetWidth; } if (targetHeight < PadContext.MinimalVisualSize) { } else { this.Height = targetHeight; this.Point1Y = newPos.Y; } break; } case ResizeLocations.BottomLeft: { double targetWidth = this.Width - (newPos.X - this.Point1X); double targetHeight = newPos.Y - this.Point1Y; if (targetWidth < PadContext.MinimalVisualSize) { } else { this.Width = targetWidth; this.Point1X = newPos.X; } if (targetHeight < PadContext.MinimalVisualSize) { } else { this.Height = targetHeight; } break; } case ResizeLocations.BottomRight: { double targetWidth = newPos.X - this.Point1X; double targetHeight = newPos.Y - this.Point1Y; if (targetWidth < PadContext.MinimalVisualSize) { } else { this.Width = targetWidth; } if (targetHeight < PadContext.MinimalVisualSize) { } else { this.Height = targetHeight; } break; } default: throw new NotImplementedException(); } }
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { base.OnMouseLeftButtonDown(e); this.previouseSelectedVisual = this.selectedVisual; Point cursorPosition = e.GetPosition(this); VisualGraphics visualHit = this.HitTestFirstVisual <ExcludedNullVisual>(cursorPosition); if (visualHit == null) { if (this.selectedVisual != null) { this.selectedVisual.IsSelected = false; this.selectedVisual.IsDrawHandle = false; this.selectedVisual.Render(); this.selectedVisual = null; } // 停止编辑状态 this.StopVisualInputState(this.previouseSelectedVisual); TextBoxEditor.Visibility = Visibility.Collapsed; // 重置到空闲状态 this.visualState = Visuals.VisualState.Idle; return; } this.ProcessSelectedVisualChanged(this.selectedVisual, visualHit); this.selectedVisual = visualHit; this.previousPosition = cursorPosition; if (e.ClickCount == 2) { // 双击图形,那么进入编辑状态 this.visualState = Visuals.VisualState.InputState; this.StartVisualInputState(this.selectedVisual); } else { this.StopVisualInputState(this.previouseSelectedVisual); #region 判断是否点击了连接点 for (int i = 0; i < visualHit.ConnectionHandles; i++) { Rect bounds = visualHit.GetConnectorBounds(i); if (bounds.Contains(cursorPosition)) { Point center = bounds.GetCenter(); ConnectionLocations location = visualHit.GetConnectorLocation(i); this.visualState = Visuals.VisualState.Connecting; GraphicsPolyline graphics = new GraphicsPolyline() { AssociatedGraphics1 = visualHit.ID, Graphics1Handle = i }; this.polyline = this.DrawVisual(graphics) as VisualPolyline; this.firstConnector = center; this.firstConnectorLocation = location; this.firstVisual = visualHit; return; } } #endregion #region 判断是否点击了Reisze点 for (int i = 0; i < visualHit.ResizeHandles; i++) { Rect bounds = visualHit.GetResizeHandleBounds(i); if (bounds.Contains(cursorPosition)) { this.resizeCenter = bounds.GetCenter(); this.resizeLocation = visualHit.Graphics.GetResizeLocation(this.resizeCenter); this.visualState = Visuals.VisualState.Resizing; return; } } #endregion #region 是平移状态 // 获取当前被移动的图形所有的连接点信息 this.associatedPolylines = this.GetAssociatedPolylines(visualHit.Graphics); Console.WriteLine("关联的折线有{0}个", this.associatedPolylines.Count); this.translateVisual = visualHit; this.visualState = Visuals.VisualState.Translate; #endregion } }
/// <summary> /// 对图形做缩放操作 /// </summary> /// <param name="location">缩放的点的坐标</param> /// <param name="newPos">新的坐标</param> public virtual void Resize(ResizeLocations location, Point resizePos, Point newPos) { this.Graphics.Resize(location, resizePos, newPos); this.Render(); }