Esempio n. 1
0
    private void presentRightClickMenu(ContextMenuStrip menu)
    {
        //clear all items currently in the menu
        menu.Items.Clear();

        //is anything selected?
        if (p_Tree.SelectedNode == null)
        {
            return;
        }

        //position the menu where the mouse is
        menu.SetBounds(Cursor.Position.X, Cursor.Position.Y, menu.Width, menu.Height);
        menu.Hide(); menu.Show();

        //get the selected tag
        object tag = p_Tree.SelectedNode.Tag;

        /*Solution entry*/
        if (tag is Solution)
        {
            return;
        }


        /*ProjectEntity/Project items*/
        if (tag is Project || tag is ProjectDirectory)
        {
            ToolStripMenuItem add = (ToolStripMenuItem)menu.Items.Add("Add", null);

            add.DropDownItems.Add(getRightClickItem_Add_NewItem());
            add.DropDownItems.Add(getRightClickItem_Add_ExistingItem());
            add.DropDownItems.Add(getRightClickItem_Add_NewFolder());

            menu.Items.Add(new ToolStripSeparator());
        }

        #region Clipboard
        ToolStripItem cut   = menu.Items.Add("Cut", Icons.GetBitmap("menu.cut", 16), null);
        ToolStripItem copy  = menu.Items.Add("Copy", Icons.GetBitmap("menu.copy", 16), null);
        ToolStripItem paste = menu.Items.Add("Paste", Icons.GetBitmap("menu.paste", 16), null);
        menu.Items.Add(getRightClickItem_Delete());
        menu.Items.Add(new ToolStripSeparator());
        #endregion
    }
Esempio n. 2
0
        protected void HandleMouseEvents()
        {
            bool holdingLeftClick  = Input.GetMouseButton(0);
            bool holdingRightClick = Input.GetMouseButton(1);

            Vector3 mousePos = Input.mousePosition;

            // Close the context menu when we click anywhere within the bounds of the application
            if (!_mouseHeld && (holdingLeftClick || holdingRightClick))
            {
                if (_menuStrip != null && mousePos.x > 0 && mousePos.x < Screen.width && mousePos.y > 0 && mousePos.y < Screen.height)
                {
                    CloseContextMenu();
                }
            }

            _isTopmostAtCursorPos = IsTopmostRenderAreaAtPos(mousePos);
            // Only evaluate mouse events for the topmost render target at the mouse position
            if (!_mouseHeld && !_isTopmostAtCursorPos)
            {
                return;
            }

            int  tolerance          = 5;
            bool cursorWithinBorder = Utils.WithinRange((int)mousePos.x, -tolerance, tolerance) || Utils.WithinRange((int)mousePos.y, -tolerance, tolerance) ||
                                      Utils.WithinRange((int)mousePos.x, Config.screenPosX + Config.screenWidth - tolerance, Config.screenPosX + Config.screenWidth + tolerance) ||
                                      Utils.WithinRange((int)mousePos.x, Config.screenPosX - tolerance, Config.screenPosX + tolerance) ||
                                      Utils.WithinRange((int)mousePos.y, Config.screenPosY + Config.screenHeight - tolerance, Config.screenPosY + Config.screenHeight + tolerance) ||
                                      Utils.WithinRange((int)mousePos.y, Config.screenPosY - tolerance, Config.screenPosY + tolerance);

            float currentMouseOffsetX = mousePos.x - Config.screenPosX;
            float currentMouseOffsetY = mousePos.y - Config.screenPosY;

            if (!_mouseHeld)
            {
                if (cursorWithinBorder)
                {
                    var isLeft   = currentMouseOffsetX <= Config.screenWidth / 2;
                    var isBottom = currentMouseOffsetY <= Config.screenHeight / 2;
                    var centerX  = Config.screenPosX + (Config.screenWidth / 2);
                    var centerY  = Config.screenPosY + (Config.screenHeight / 2);
                    var offsetX  = Config.screenWidth / 2 - tolerance;
                    var offsetY  = Config.screenHeight / 2 - tolerance;
                    _xAxisLocked = Utils.WithinRange((int)mousePos.x, centerX - offsetX + 1, centerX + offsetX - 1);
                    _yAxisLocked = Utils.WithinRange((int)mousePos.y, centerY - offsetY + 1, centerY + offsetY - 1);

                    if (!Config.fitToCanvas)
                    {
                        if (_xAxisLocked)
                        {
                            SetCursor(CursorType.Vertical);
                        }
                        else if (_yAxisLocked)
                        {
                            SetCursor(CursorType.Horizontal);
                        }
                        else if (isLeft && isBottom || !isLeft && !isBottom)
                        {
                            SetCursor(CursorType.DiagonalLeft);
                        }
                        else if (isLeft && !isBottom || !isLeft && isBottom)
                        {
                            SetCursor(CursorType.DiagonalRight);
                        }
                    }
                    wasWithinBorder = true;
                }
                else if (!cursorWithinBorder && wasWithinBorder)
                {
                    SetCursor(CursorType.None);
                    wasWithinBorder = false;
                }
            }

            if (holdingLeftClick && !Config.fitToCanvas)
            {
                if (!_mouseHeld)
                {
                    _initialOffset.x = currentMouseOffsetX;
                    _initialOffset.y = currentMouseOffsetY;

                    _lastScreenPos = Config.ScreenPosition;
                    _lastGrabPos   = new Vector2(mousePos.x, mousePos.y);

                    _isLeft         = _initialOffset.x <= Config.screenWidth / 2;
                    _isBottom       = _initialOffset.y <= Config.screenHeight / 2;
                    anyInstanceBusy = true;
                }
                _mouseHeld = true;

                if (!_isMoving && (_isResizing || cursorWithinBorder))
                {
                    _isResizing = true;
                    if (!_xAxisLocked)
                    {
                        int changeX = _isLeft ? (int)(_lastGrabPos.x - mousePos.x) : (int)(mousePos.x - _lastGrabPos.x);
                        Config.screenWidth += changeX;
                        Config.screenPosX   = ((int)_lastScreenPos.x - (_isLeft ? changeX : 0));
                    }
                    if (!_yAxisLocked)
                    {
                        int changeY = _isBottom ? (int)(mousePos.y - _lastGrabPos.y) : (int)(_lastGrabPos.y - mousePos.y);
                        Config.screenHeight -= changeY;
                        Config.screenPosY    = ((int)_lastScreenPos.y + (_isBottom ? changeY : 0));
                    }
                    _lastGrabPos   = mousePos;
                    _lastScreenPos = Config.ScreenPosition;
                }
                else
                {
                    _isMoving         = true;
                    Config.screenPosX = (int)mousePos.x - (int)_initialOffset.x;
                    Config.screenPosY = (int)mousePos.y - (int)_initialOffset.y;
                }
                Config.screenWidth  = Mathf.Clamp(Config.screenWidth, 100, Screen.width);
                Config.screenHeight = Mathf.Clamp(Config.screenHeight, 100, Screen.height);
                Config.screenPosX   = Mathf.Clamp(Config.screenPosX, 0, Screen.width - Config.screenWidth);
                Config.screenPosY   = Mathf.Clamp(Config.screenPosY, 0, Screen.height - Config.screenHeight);

                CreateScreenRenderTexture();
            }
            else if (holdingRightClick && _contextMenuEnabled)
            {
                if (_mouseHeld)
                {
                    return;
                }
                if (_menuStrip == null)
                {
                    DisplayContextMenu();
                    _contextMenuOpen = true;
                }
                _menuStrip.SetBounds(Cursor.Position.X, Cursor.Position.Y, 0, 0);
                if (!_menuStrip.Visible)
                {
                    _menuStrip.Show();
                }
                anyInstanceBusy = true;
                _mouseHeld      = true;
            }
            else if (_isResizing || _isMoving || _mouseHeld)
            {
                if (!_contextMenuOpen)
                {
                    if (!_isCameraDestroyed)
                    {
                        Config.Save();
                    }
                }
                _isResizing     = false;
                _isMoving       = false;
                _mouseHeld      = false;
                anyInstanceBusy = false;
            }
        }
Esempio n. 3
0
    private void presentRightClickMenu(ContextMenuStrip menu)
    {
        //clear all items currently in the menu
        menu.Items.Clear();

        //is anything selected?
        if (p_Tree.SelectedNode == null) { return; }

        //position the menu where the mouse is
        menu.SetBounds(Cursor.Position.X, Cursor.Position.Y, menu.Width, menu.Height);
        menu.Hide(); menu.Show();

        //get the selected tag
        object tag = p_Tree.SelectedNode.Tag;

        /*Solution entry*/
        if (tag is Solution) {
            return;
        }

        /*ProjectEntity/Project items*/
        if (tag is Project || tag is ProjectDirectory) {
            ToolStripMenuItem add = (ToolStripMenuItem)menu.Items.Add("Add", null);

            add.DropDownItems.Add(getRightClickItem_Add_NewItem());
            add.DropDownItems.Add(getRightClickItem_Add_ExistingItem());
            add.DropDownItems.Add(getRightClickItem_Add_NewFolder());

            menu.Items.Add(new ToolStripSeparator());
        }

        #region Clipboard
        ToolStripItem cut = menu.Items.Add("Cut", Icons.GetBitmap("menu.cut", 16), null);
        ToolStripItem copy = menu.Items.Add("Copy", Icons.GetBitmap("menu.copy", 16), null);
        ToolStripItem paste = menu.Items.Add("Paste", Icons.GetBitmap("menu.paste", 16), null);
        menu.Items.Add(getRightClickItem_Delete());
        menu.Items.Add(new ToolStripSeparator());
        #endregion
    }