Beispiel #1
0
 private IEnumerator <object> MainTask()
 {
     while (true)
     {
         var pressedPosition = inputWidget.LocalMousePosition();
         if (input.WasMousePressed())
         {
             if (placement.Root == placement.Parent)
             {
                 WindowDragBehaviour.CreateFor(placement, pressedPosition);
             }
             else
             {
                 var size            = inputWidget.Parent.AsWidget.Size;
                 var initialPosition = LocalMousePosition;
                 while (input.IsMousePressed() &&
                        LocalMousePosition.X > -Offset &&
                        LocalMousePosition.X < size.X + Offset &&
                        Mathf.Abs(LocalMousePosition.Y - initialPosition.Y) < Offset
                        )
                 {
                     yield return(null);
                 }
                 if (input.IsMousePressed())
                 {
                     OnUndock?.Invoke(pressedPosition, Application.DesktopMousePosition - (input.MousePosition - contentWidget.GlobalPosition));
                 }
             }
         }
         yield return(null);
     }
 }
Beispiel #2
0
        private IEnumerator <object> MainTask()
        {
            while (true)
            {
                if (input.WasMousePressed())
                {
                    var  pressedPosition = inputWidget.LocalMousePosition();
                    var  windowPlacement = (WindowPlacement)placement.Root;
                    bool doUndock        = windowPlacement != placement &&
                                           (placement.Parent != windowPlacement || windowPlacement.Placements.Count > 1);
                    if (!doUndock)
                    {
                        var panelWindow = (WindowWidget)contentWidget.GetRoot();
                        var window      = panelWindow.Window;
                        if (window.State == WindowState.Maximized)
                        {
                            var initialPosition = LocalMousePosition;
                            while (input.IsMousePressed())
                            {
                                var diff = Mathf.Abs(LocalMousePosition - initialPosition);
                                if (diff.X >= DragThreshold || diff.Y >= DragThreshold)
                                {
                                    window.State    = WindowState.Normal;
                                    pressedPosition = new Vector2(window.ClientSize.X / 2, 10);
                                    WindowDragBehaviour.CreateFor(placement, pressedPosition);
                                    break;
                                }
                                yield return(null);
                            }
                            yield return(null);

                            continue;
                        }
                        WindowDragBehaviour.CreateFor(placement, pressedPosition);
                    }
                    else
                    {
                        var size            = inputWidget.Parent.AsWidget.Size;
                        var initialPosition = LocalMousePosition;
                        while (input.IsMousePressed() &&
                               LocalMousePosition.X > -DragThreshold &&
                               LocalMousePosition.X < size.X + DragThreshold &&
                               Mathf.Abs(LocalMousePosition.Y - initialPosition.Y) < DragThreshold
                               )
                        {
                            yield return(null);
                        }
                        if (input.IsMousePressed())
                        {
                            OnUndock?.Invoke(pressedPosition, Application.DesktopMousePosition - (input.MousePosition - contentWidget.GlobalPosition));
                        }
                    }
                }
                yield return(null);
            }
        }
Beispiel #3
0
        private IEnumerator <object> DragTask(Widget panelContainer, WidgetInput input, int rowIndex, int panelIndex)
        {
            var rootWidget    = widget.GetRoot().AsWidget;
            var newRowIndex   = rowIndex;
            var newPanelIndex = panelIndex;
            var presenter     = new SyncDelegatePresenter <Widget>(w => {
                w.PrepareRendererState();
                if (panelContainer == null)
                {
                    return;
                }
                var aabb = panelContainer.CalcAABBInSpaceOf(rootWidget);
                Renderer.DrawRect(aabb.A, aabb.B, ColorTheme.Current.Toolbar.PanelPlacementHighlightBackground);
                Renderer.DrawRectOutline(aabb.A, aabb.B, ColorTheme.Current.Toolbar.PanelPlacementHighlightBorder);
            });

            while (true)
            {
                if (!input.WasMousePressed() || Core.Project.Current == Core.Project.Null)
                {
                    yield return(null);

                    continue;
                }
                rootWidget.CompoundPostPresenter.Add(presenter);
                while (input.IsMousePressed())
                {
                    Vector2 pos;
                    Utils.ChangeCursorIfDefault(MouseCursor.Hand);
                    for (var i = 0; i < widget.Nodes.Count; ++i)
                    {
                        var rowWidget = (Widget)widget.Nodes[i];
                        if (!IsMouseOver(rowWidget, out pos))
                        {
                            continue;
                        }
                        for (var j = 0; j < rowWidget.Nodes.Count; ++j)
                        {
                            var panelWidget = (Widget)rowWidget.Nodes[j];
                            if (!IsMouseOver(panelWidget, out pos))
                            {
                                continue;
                            }
                            if ((newRowIndex != i || newPanelIndex != j) && (rowIndex != i || j != rowWidget.Nodes.Count - 1))
                            {
                                panelContainer = panelWidget;
                                newRowIndex    = i;
                                newPanelIndex  = j;
                            }
                            goto Next;
                        }
                    }

                    panelContainer = null;
                    if (!IsMouseOver(widget, out pos))
                    {
                        newPanelIndex = 0;
                        if (pos.Y < 0)
                        {
                            newRowIndex = -1;
                        }
                        if (pos.Y > widget.Height)
                        {
                            newRowIndex = toolbarModel.Rows.Count;
                        }
                    }
Next:
                    yield return(null);
                }
                rootWidget.CompoundPostPresenter.Remove(presenter);
                if (newRowIndex == rowIndex && newPanelIndex == panelIndex)
                {
                    continue;
                }
                ToolbarModel.ToolbarRow row;
                if (newRowIndex < 0 || newRowIndex == toolbarModel.Rows.Count)
                {
                    row = new ToolbarModel.ToolbarRow();
                    toolbarModel.InsertRow(row, newRowIndex < 0 ? 0 : newRowIndex);
                    if (newRowIndex < 0)
                    {
                        ++rowIndex;
                    }
                }
                else
                {
                    row = toolbarModel.Rows[newRowIndex];
                }
                var oldRow = toolbarModel.Rows[rowIndex];
                var panel  = oldRow.Panels[panelIndex];
                if (newRowIndex != rowIndex)
                {
                    toolbarModel.RemovePanel(panel);
                    toolbarModel.InsertPanel(row, panel, newPanelIndex);
                }
                else
                {
                    toolbarModel.SwapPanels(row.Panels[newPanelIndex], panel);
                }
                if (oldRow.Panels.Count == 0)
                {
                    toolbarModel.RemoveRow(oldRow);
                }
                toolbarModel.RefreshAfterLoad();
                Rebuild();
                yield break;
            }
        }