void UpdateUIAssistShow() { var width = Viewport.GetViewPortWidth(); var height = Viewport.GetViewPortHeight(); if (mGridlineImage2D != null) { // GridLine mGridlineImage2D.RenderMatrix = EngineNS.Matrix.Scaling(width, height, 1); var widthDelta = (float)width / mGridDrawSize.Width; var heightDelta = (float)height / mGridDrawSize.Height; var tempPass = mGridlineImage2D.GetPass(); var shaderIdx_tile = mGridlineImage2D.Mesh.FindVar(0, "GridTile"); var shaderIdx_offset = mGridlineImage2D.Mesh.FindVar(0, "UVoffset"); var snapTile = new EngineNS.Vector2(widthDelta, heightDelta); mGridlineImage2D.Mesh.MtlMeshArray[0].CBuffer.SetValue((int)shaderIdx_tile, snapTile, 0); var offset = new EngineNS.Vector2(-mGridDrawSize.X / width, -mGridDrawSize.Y / height); mGridlineImage2D.Mesh.MtlMeshArray[0].CBuffer.SetValue((int)shaderIdx_offset, offset, 0); } // WindowRect if (mWindowRectUIShow != null) { mWindowRectUIShow.SetDesignRect(ref mWindowDrawSize, true); } UpdatePointAtShow(); UpdateSelectedRectShow(); }
//public string ToString(IFormatProvider provider); //string IFormattable.ToString(string format, IFormatProvider provider); //internal string ConvertToString(string format, IFormatProvider provider); /// <summary> /// 带参构造函数 /// </summary> /// <param name="location">对象位置坐标</param> /// <param name="size">对象大小</param> public Rect(EngineNS.Vector2 location, Size size) { _x = location.X; _y = location.Y; _width = size.Width; _height = size.Height; }
// 操作 public void Operation(EngineNS.UISystem.Editor.SelectedData operationUIData, ref EngineNS.Vector2 mouseDelta, float scaleDelta) { if (!mInitialized) { return; } OperationAnchorsHandle(operationUIData, ref mouseDelta, scaleDelta); OperationTransformHandle(operationUIData, ref mouseDelta, scaleDelta); }
private void Viewport_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e) { var delta = 1 + e.Delta * 0.001f; var tempScale = mUIScale * delta; if (tempScale > 10f) { tempScale = 10; delta = tempScale / mUIScale; } else if (tempScale < 0.1f) { tempScale = 0.1f; delta = tempScale / mUIScale; } mUIScale = tempScale; var center = new EngineNS.Vector2(e.Location.X, e.Location.Y); var deltaXY = center * delta; mGridDrawSize.X = (mGridDrawSize.X / center.X) * deltaXY.X + center.X - deltaXY.X; mGridDrawSize.Y = (mGridDrawSize.Y / center.Y) * deltaXY.Y + center.Y - deltaXY.Y; mGridDrawSize.Width = mGridDrawSize.Width * delta; mGridDrawSize.Height = mGridDrawSize.Height * delta; if (mGridDrawSize.Width > 200) { mGridDrawSize.Width /= 2; } else if (mGridDrawSize.Width < 50) { mGridDrawSize.Width *= 2; } if (mGridDrawSize.Height > 200) { mGridDrawSize.Height /= 2; } else if (mGridDrawSize.Height < 50) { mGridDrawSize.Height *= 2; } mWindowDrawSize.X = (mWindowDrawSize.X / center.X) * deltaXY.X + center.X - deltaXY.X; mWindowDrawSize.Y = (mWindowDrawSize.Y / center.Y) * deltaXY.Y + center.Y - deltaXY.Y; mWindowDrawSize.Width = mWindowDrawSize.Width * delta; mWindowDrawSize.Height = mWindowDrawSize.Height * delta; UpdateUIShow(); UpdateUIAssistShow(); }
public static void OnXValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { VectorEditor control = d as VectorEditor; float newValue = (float)e.NewValue; float oldValue = (float)e.OldValue; if (control.VectorType == typeof(EngineNS.Vector2)) { if (System.Math.Abs(newValue - oldValue) > 0.0001f) { var vec = (EngineNS.Vector2)(control.VectorObject); var obj = new EngineNS.Vector2(); obj.X = newValue; obj.Y = vec.Y; // control.YValue; control.VectorObject = obj; } } else if (control.VectorType == typeof(EngineNS.Vector3)) { if (System.Math.Abs(newValue - oldValue) > 0.0001f) { var vec = (EngineNS.Vector3)(control.VectorObject); var obj = new EngineNS.Vector3(); obj.X = newValue; obj.Y = vec.Y; //control.YValue; obj.Z = vec.Z; //control.ZValue; control.VectorObject = obj; } } else if (control.VectorType == typeof(EngineNS.Vector4)) { if (System.Math.Abs(newValue - oldValue) > 0.0001f) { var vec = (EngineNS.Vector4)(control.VectorObject); var obj = new EngineNS.Vector4(); obj.X = newValue; obj.Y = vec.Y; //control.YValue; obj.Z = vec.Z; //control.ZValue; obj.W = vec.W; //control.WValue; control.VectorObject = obj; } } }
void OperationTransformHandle(EngineNS.UISystem.Editor.SelectedData data, ref EngineNS.Vector2 mouseDelta, float scaleDelta) { if (mSelectedHandleType == enTransformOPHandleType.Unknow) { return; } switch (mSelectedHandleType) { case enTransformOPHandleType.Left: { //foreach (var data in mSelectedUIDatas.Values) { var ds = data.UI.DesignRect; var width = data.StartRect.Width - mouseDelta.X * scaleDelta; if (width < 0) { ds.Width = -width; } else { ds.X = data.StartRect.X + mouseDelta.X * scaleDelta; ds.Width = width; } if (data.UI.Slot != null) { data.UI.Slot.ProcessSetContentDesignRect(ref ds); } else { data.UI.SetDesignRect(ref ds); } } } break; case enTransformOPHandleType.LeftTop: { //foreach (var data in mSelectedUIDatas.Values) { var ds = data.UI.DesignRect; var width = data.StartRect.Width - mouseDelta.X * scaleDelta; if (width < 0) { ds.Width = -width; } else { ds.X = data.StartRect.X + mouseDelta.X * scaleDelta; ds.Width = width; } var height = data.StartRect.Height - mouseDelta.Y * scaleDelta; if (height < 0) { ds.Height = -height; } else { ds.Y = data.StartRect.Y + mouseDelta.Y * scaleDelta; ds.Height = height; } if (data.UI.Slot != null) { data.UI.Slot.ProcessSetContentDesignRect(ref ds); } else { data.UI.SetDesignRect(ref ds); } } } break; case enTransformOPHandleType.Top: { //foreach (var data in mSelectedUIDatas.Values) { var ds = data.UI.DesignRect; var height = data.StartRect.Height - mouseDelta.Y * scaleDelta; if (height < 0) { ds.Height = -height; } else { ds.Y = data.StartRect.Y + mouseDelta.Y * scaleDelta; ds.Height = height; } if (data.UI.Slot != null) { data.UI.Slot.ProcessSetContentDesignRect(ref ds); } else { data.UI.SetDesignRect(ref ds); } } } break; case enTransformOPHandleType.RightTop: { //foreach (var data in mSelectedUIDatas.Values) { var ds = data.UI.DesignRect; var height = data.StartRect.Height - mouseDelta.Y * scaleDelta; if (height < 0) { ds.Height = -height; } else { ds.Y = data.StartRect.Y + mouseDelta.Y * scaleDelta; ds.Height = height; } var width = data.StartRect.Width + mouseDelta.X * scaleDelta; if (width < 0) { ds.X = data.StartRect.Left + width; ds.Width = -width; } else { ds.Width = width; } if (data.UI.Slot != null) { data.UI.Slot.ProcessSetContentDesignRect(ref ds); } else { data.UI.SetDesignRect(ref ds); } } } break; case enTransformOPHandleType.Right: { //foreach (var data in mSelectedUIDatas.Values) { var ds = data.UI.DesignRect; var width = data.StartRect.Width + mouseDelta.X * scaleDelta; if (width < 0) { ds.X = data.StartRect.Left + width; ds.Width = -width; } else { ds.Width = width; } if (data.UI.Slot != null) { data.UI.Slot.ProcessSetContentDesignRect(ref ds); } else { data.UI.SetDesignRect(ref ds); } } } break; case enTransformOPHandleType.RightBottom: { //foreach (var data in mSelectedUIDatas.Values) { var ds = data.UI.DesignRect; var width = data.StartRect.Width + mouseDelta.X * scaleDelta; if (width < 0) { ds.X = data.StartRect.Left + width; ds.Width = -width; } else { ds.Width = width; } var height = data.StartRect.Height + mouseDelta.Y * scaleDelta; if (height < 0) { ds.Y = data.StartRect.Top + height; ds.Height = -height; } else { ds.Height = height; } if (data.UI.Slot != null) { data.UI.Slot.ProcessSetContentDesignRect(ref ds); } else { data.UI.SetDesignRect(ref ds); } } } break; case enTransformOPHandleType.Bottom: { //foreach (var data in mSelectedUIDatas.Values) { var ds = data.UI.DesignRect; var height = data.StartRect.Height + mouseDelta.Y * scaleDelta; if (height < 0) { ds.Y = data.StartRect.Top + height; ds.Height = -height; } else { ds.Height = height; } if (data.UI.Slot != null) { data.UI.Slot.ProcessSetContentDesignRect(ref ds); } else { data.UI.SetDesignRect(ref ds); } } } break; case enTransformOPHandleType.LeftBottom: { //foreach (var data in mSelectedUIDatas.Values) { var ds = data.UI.DesignRect; var width = data.StartRect.Width - mouseDelta.X * scaleDelta; if (width < 0) { ds.Width = -width; } else { ds.X = data.StartRect.X + mouseDelta.X * scaleDelta; ds.Width = width; } var height = data.StartRect.Height + mouseDelta.Y * scaleDelta; if (height < 0) { ds.Y = data.StartRect.Top + height; ds.Height = -height; } else { ds.Height = height; } if (data.UI.Slot != null) { data.UI.Slot.ProcessSetContentDesignRect(ref ds); } else { data.UI.SetDesignRect(ref ds); } } } break; } }
void OperationAnchorsHandle(EngineNS.UISystem.Editor.SelectedData operationUIData, ref EngineNS.Vector2 mouseDelta, float scaleDelta) { if (mSelectedAnchorHandleType == enCanvasAnchors.Unknow) { return; } var anchorOp = operationUIData.UI.Slot as EngineNS.UISystem.Controls.Containers.CanvasSlot; if (anchorOp == null) { return; } var parent = operationUIData.UI.Parent; var parentWidth = parent.DesignRect.Width; var parentHeight = parent.DesignRect.Height; var handle = mCanvasAnchorsHandles[(int)mSelectedAnchorHandleType]; var tagDesignRect = operationUIData.UI.DesignRect; switch (mSelectedAnchorHandleType) { case enCanvasAnchors.Left: { var newMinX = handle.StartMin.X + (mouseDelta.X * scaleDelta) / parentWidth; newMinX = GetValidValue(newMinX, 0.0f, anchorOp.Maximum.X); anchorOp.Minimum = new EngineNS.Vector2(newMinX, anchorOp.Minimum.Y); } break; case enCanvasAnchors.Right: { var newMaxX = handle.StartMax.X + (mouseDelta.X * scaleDelta) / parentWidth; newMaxX = GetValidValue(newMaxX, anchorOp.Minimum.X, 1.0f); anchorOp.Maximum = new EngineNS.Vector2(newMaxX, anchorOp.Maximum.Y); } break; case enCanvasAnchors.Top: { var newMinY = handle.StartMin.Y + (mouseDelta.Y * scaleDelta) / parentHeight; newMinY = GetValidValue(newMinY, 0.0f, anchorOp.Maximum.Y); anchorOp.Minimum = new EngineNS.Vector2(anchorOp.Minimum.X, newMinY); } break; case enCanvasAnchors.Bottom: { var newMaxY = handle.StartMax.Y + (mouseDelta.Y * scaleDelta) / parentHeight; newMaxY = GetValidValue(newMaxY, anchorOp.Minimum.Y, 1.0f); anchorOp.Maximum = new EngineNS.Vector2(anchorOp.Maximum.X, newMaxY); } break; case enCanvasAnchors.LeftTop: { var newMinX = handle.StartMin.X + (mouseDelta.X * scaleDelta) / parentWidth; newMinX = GetValidValue(newMinX, 0.0f, anchorOp.Maximum.X); anchorOp.Minimum = new EngineNS.Vector2(newMinX, anchorOp.Minimum.Y); var newMinY = handle.StartMin.Y + (mouseDelta.Y * scaleDelta) / parentHeight; newMinY = GetValidValue(newMinY, 0.0f, anchorOp.Maximum.Y); anchorOp.Minimum = new EngineNS.Vector2(anchorOp.Minimum.X, newMinY); } break; case enCanvasAnchors.RightTop: { var newMaxX = handle.StartMax.X + (mouseDelta.X * scaleDelta) / parentWidth; newMaxX = GetValidValue(newMaxX, anchorOp.Minimum.X, 1.0f); anchorOp.Maximum = new EngineNS.Vector2(newMaxX, anchorOp.Maximum.Y); var newMinY = handle.StartMin.Y + (mouseDelta.Y * scaleDelta) / parentHeight; newMinY = GetValidValue(newMinY, 0.0f, anchorOp.Maximum.Y); anchorOp.Minimum = new EngineNS.Vector2(anchorOp.Minimum.X, newMinY); } break; case enCanvasAnchors.LeftBottom: { var newMinX = handle.StartMin.X + (mouseDelta.X * scaleDelta) / parentWidth; newMinX = GetValidValue(newMinX, 0.0f, anchorOp.Maximum.X); anchorOp.Minimum = new EngineNS.Vector2(newMinX, anchorOp.Minimum.Y); var newMaxY = handle.StartMax.Y + (mouseDelta.Y * scaleDelta) / parentHeight; newMaxY = GetValidValue(newMaxY, anchorOp.Minimum.Y, 1.0f); anchorOp.Maximum = new EngineNS.Vector2(anchorOp.Maximum.X, newMaxY); } break; case enCanvasAnchors.RightBottom: { var newMaxX = handle.StartMax.X + (mouseDelta.X * scaleDelta) / parentWidth; newMaxX = GetValidValue(newMaxX, anchorOp.Minimum.X, 1.0f); anchorOp.Maximum = new EngineNS.Vector2(newMaxX, anchorOp.Maximum.Y); var newMaxY = handle.StartMax.Y + (mouseDelta.Y * scaleDelta) / parentHeight; newMaxY = GetValidValue(newMaxY, anchorOp.Minimum.Y, 1.0f); anchorOp.Maximum = new EngineNS.Vector2(anchorOp.Maximum.X, newMaxY); } break; case enCanvasAnchors.Center: { var valX = handle.StartMin.X + (mouseDelta.X * scaleDelta) / parentWidth; valX = GetValidValue(valX, 0.0f, 1.0f); var valY = handle.StartMin.Y + (mouseDelta.Y * scaleDelta) / parentHeight; valY = GetValidValue(valY, 0.0f, 1.0f); anchorOp.Maximum = new EngineNS.Vector2(float.MaxValue, float.MaxValue); anchorOp.Minimum = new EngineNS.Vector2(valX, valY); anchorOp.Maximum = anchorOp.Minimum; } break; } anchorOp.ProcessSetContentDesignRect(ref tagDesignRect); }
public BezierPoint(LineXBezierControl hostControl, EngineNS.Vector2 pos, EngineNS.Vector2 ctrlPos) : base(pos, ctrlPos) { mHostControl = hostControl; CalculateOpposite(); }
void Viewport_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { var delta = new EngineNS.Vector2(e.Location.X - mMouseLoc.X, e.Location.Y - mMouseLoc.Y); if (e.Button.HasFlag(System.Windows.Forms.MouseButtons.Right) && mDragViewport) { mGridDrawSize.X = mStartDrawSize.X + delta.X; mGridDrawSize.Y = mStartDrawSize.Y + delta.Y; mWindowDrawSize.X = mStartWindowDrawSize.X + delta.X; mWindowDrawSize.Y = mStartWindowDrawSize.Y + delta.Y; UpdateUIShow(); UpdateUIAssistShow(); } else if (e.Button.HasFlag(System.Windows.Forms.MouseButtons.Left) && mDragViewport) { if (System.Math.Abs(delta.X) > 2 || System.Math.Abs(delta.Y) > 2) { mReSelectOnMouseUp = false; } var scaleDelta = mWindowDesignSize.Width / mWindowDrawSize.Width; //if(mSelectedHandleType != enTransformOPHandleType.Unknow) //{ // OperationTransformHandle(ref delta, scaleDelta); //} /*else */ if (mSlotOperator != null && mSlotOperator.IsSelectedOperator()) { if (mSelectedUIDatas.Count == 1) { mSlotOperator?.Operation(mSelectedUIDatas.First().Value, ref delta, scaleDelta); } } //else if (mSelectedAnchorHandleType != enCanvasAnchors.Unknow) //{ // OperationAnchorsHandle(ref delta, scaleDelta); //} else { foreach (var data in mSelectedUIDatas.Values) { var ds = data.UI.DesignRect; ds.X = data.StartRect.X + delta.X * scaleDelta; ds.Y = data.StartRect.Y + delta.Y * scaleDelta; if (data.UI.Slot != null) { data.UI.Slot.ProcessSetContentDesignRect(ref ds); } else { data.UI.SetDesignRect(ref ds); } } } UpdateSelectedRectShow(); } else if (HostDesignPanel.CurrentUI != null) { var mouseInViewport = new EngineNS.PointF(e.Location.X, e.Location.Y); // 判断鼠标是不是在控制点上 //bool isInHandle = ProcessMousePointAtTransformHandles(ref mouseInViewport); //if(isInHandle == false) // isInHandle = ProcessMousePointAtAnchorsHandle(ref mouseInViewport); bool isInHandle = false; if (mSlotOperator != null) { isInHandle = mSlotOperator.ProcessMousePointAt(ref mouseInViewport, (cur) => { switch (cur) { case EngineNS.UISystem.Editor.enCursors.SizeAll: this.Cursor = System.Windows.Input.Cursors.SizeAll; break; case EngineNS.UISystem.Editor.enCursors.SizeWE: this.Cursor = System.Windows.Input.Cursors.SizeWE; break; case EngineNS.UISystem.Editor.enCursors.SizeNS: this.Cursor = System.Windows.Input.Cursors.SizeNS; break; case EngineNS.UISystem.Editor.enCursors.SizeNWSE: this.Cursor = System.Windows.Input.Cursors.SizeNWSE; break; case EngineNS.UISystem.Editor.enCursors.SizeNESW: this.Cursor = System.Windows.Input.Cursors.SizeNESW; break; } }); } if (!isInHandle) { this.Cursor = System.Windows.Input.Cursors.Arrow; // 判断鼠标位于哪个控件上 var pos = GetMouseInUserControl(ref mouseInViewport); mMousePointAtUIElement = CheckPointAtUIElement(ref pos, false); UpdatePointAtShow(); } } }