async Task Viewport_DragDropProcess(EngineNS.PointF mousePt) { var rc = EngineNS.CEngine.Instance.RenderContext; // 计算一次鼠标所在的能够添加子的控件 var uiElement = CalculateCanAddChildableUIElement(ref mousePt); if (uiElement == null) { return; } var mousePos = GetMouseInUserControl(ref mousePt); List <EngineNS.UISystem.UIElement> elemList = new List <EngineNS.UISystem.UIElement>(); foreach (var dragObj in EditorCommon.DragDrop.DragDropManager.Instance.DragedObjectList) { var ctrlView = dragObj as UIEditor.ControlView; if (ctrlView == null) { continue; } var atts = ctrlView.UIControlType.GetCustomAttributes(typeof(EngineNS.UISystem.Editor_UIControlInitAttribute), false); if (atts.Length <= 0) { continue; } var att = atts[0] as EngineNS.UISystem.Editor_UIControlInitAttribute; var init = System.Activator.CreateInstance(att.InitializerType) as EngineNS.UISystem.UIElementInitializer; var uiCtrl = System.Activator.CreateInstance(ctrlView.UIControlType) as EngineNS.UISystem.UIElement; await uiCtrl.Initialize(rc, init); /* * * if (uiElement is EngineNS.UISystem.Controls.Containers.ContentControl) * { * var ctrl = uiElement as EngineNS.UISystem.Controls.Containers.ContentControl; * ctrl.Content = uiCtrl; * var offsetX = mousePos.X;// - ctrl.DesignRect.X; * var offsetY = mousePos.Y;// - ctrl.DesignRect.Y; * var dr = uiCtrl.DesignRect; * var rect = new EngineNS.RectangleF(offsetX, offsetY, dr.Width, dr.Height); * uiCtrl.Slot.ProcessSetContentDesignRect(ref rect); * } * else if (uiElement is EngineNS.UISystem.Controls.Containers.Panel) * { * var ctrl = uiElement as EngineNS.UISystem.Controls.Containers.Panel; * ctrl.AddChild(uiCtrl); * var offsetX = mousePos.X;// - ctrl.DesignRect.X; * var offsetY = mousePos.Y;// - ctrl.DesignRect.Y; * var dr = uiCtrl.DesignRect; * var rect = new EngineNS.RectangleF(offsetX, offsetY, dr.Width, dr.Height); * uiCtrl.Slot.ProcessSetContentDesignRect(ref rect); * }*/ elemList.Add(uiCtrl); } HostDesignPanel.BroadcastAddChildren(this, uiElement, mousePos, elemList.ToArray()); }
async Task SelectProcess(bool mouseUp) { mReSelectOnMouseUp = false; var mouseInViewport = new EngineNS.PointF(mMouseLoc.X, mMouseLoc.Y); // 判断是否在handle上 if (mSelectedUIDatas.Count == 1) { mSlotOperator?.ProcessSelect(mSelectedUIDatas.First().Value, ref mouseInViewport); } if (mSlotOperator == null || (mSlotOperator != null && !mSlotOperator.IsSelectedOperator())) { var pos = GetMouseInUserControl(ref mouseInViewport); bool multi = false; if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) { multi = true; } List <EngineNS.UISystem.UIElement> selectUIs = new List <EngineNS.UISystem.UIElement>(); var element = CheckPointAtUIElement(ref pos, false); if (element != null) { bool find = false; if (multi) { if (mSelectedUIDatas.ContainsKey(element)) { find = true; mSelectedUIDatas.Remove(element); } foreach (var ui in mSelectedUIDatas) { selectUIs.Add(ui.Key); } } else { if (mSelectedUIDatas.ContainsKey(element) && !mouseUp) { find = true; mReSelectOnMouseUp = true; foreach (var ui in mSelectedUIDatas) { selectUIs.Add(ui.Key); } } else { //mSelectedUIDatas.Clear(); selectUIs.Clear(); } } if (find == false) { //var data = new EngineNS.UISystem.Editor.SelectedData(); //data.UI = element; //data.StartRect = element.DesignRect; //var rc = EngineNS.CEngine.Instance.RenderContext; //var showRectInit = new EngineNS.UISystem.Controls.ImageInitializer(); //showRectInit.ImageBrush.ImageName = EngineNS.RName.GetRName("uieditor/uva_selectrect.uvanim", EngineNS.RName.enRNameType.Editor); //showRectInit.ImageBrush.TileMode = EngineNS.UISystem.Brush.enTileMode.None; //var showRect = new EngineNS.UISystem.Controls.Image(); //await showRect.Initialize(rc, showRectInit); //data.ShowRect = showRect; //mSelectedUIDatas[element] = data; selectUIs.Add(element); } // 刷新所有StartDesignRect foreach (var data in mSelectedUIDatas.Values) { data.StartRect = data.UI.DesignRect; } } else if (!multi) { //mSelectedUIDatas.Clear(); selectUIs.Clear(); } //var selectUIs = mSelectedUIDatas.Keys.ToArray(); HostDesignPanel.BroadcastSelectedUI(this, selectUIs.ToArray()); await InitSlotOperator(); UpdateSelectedRectShow(); } else { foreach (var data in mSelectedUIDatas.Values) { data.StartRect = data.UI.DesignRect; } } }