Example #1
0
        public void Update( )
        {
            //get item under mouse cursor

            var model = ObjectFactory.GetInstance <IModel>( );

            ItemEditor item = _canvas.ItemUnderMouse;

            bool controlButtonPressed = KeyboardStatus.IsKeyDown(Keys.LeftControl);

            if (item != null)
            {
                _mainForm.SetToolStripStatusLabel1(item.ItemProperties.Name);

                item.OnMouseOver(MouseStatus.WorldPosition);

                if (controlButtonPressed)
                {
                    _mainForm.SetCursorForCanvas(_cursorDuplicate);
                }
            }
            else
            {
                _mainForm.SetToolStripStatusLabel1(string.Empty);
            }

            if (item != _lastItem && _lastItem != null)
            {
                _lastItem.OnMouseOut( );
            }

            _lastItem = item;

            IEnumerable <ITreeItem> editors = selectedEditors( ).ToList(  );

            if (MouseStatus.IsNewLeftMouseButtonClick() || KeyboardStatus.IsNewKeyPress(Keys.D1))
            {
                if (item != null)
                {
                    item.OnMouseButtonDown(MouseStatus.WorldPosition);
                }

                if (controlButtonPressed && item != null)
                {
                    _canvas.StartCopyingSelectedItems( );
                }
                else if (KeyboardStatus.IsKeyDown(Keys.LeftShift) && item != null)
                {
                    model.ToggleSelectionOnItem(item);
                }
                else if (editors.Contains(item))
                {
                    _canvas.StartMovingSelectedItems( );
                }
                else if (!selectedEditors().Contains(item))
                {
                    if (item != null)
                    {
                        _model.SelectEditor(item);
                        _canvas.StartMovingSelectedItems(  );
                    }
                    else
                    {
                        _canvas.CreateSelectionRectangle( );
                    }
                }
            }

            //MIDDLE MOUSE BUTTON CLICK
            bool anyEditorsSelected = editors.Any();

            if (MouseStatus.IsNewMiddleMouseButtonClick( ) || KeyboardStatus.IsNewKeyPress(Keys.D2))
            {
                if (item != null)
                {
                    item.OnMouseOut( );
                }

                if (controlButtonPressed)
                {
                    _canvas.StartMovingCamera( );
                }
                else
                {
                    if (anyEditorsSelected)
                    {
                        _canvas.StartRotatingItems( );
                    }
                }
            }

            //RIGHT MOUSE BUTTON CLICK
            if (MouseStatus.IsNewRightMouseButtonClick( ) || KeyboardStatus.IsNewKeyPress(Keys.D3))
            {
                if (item != null)
                {
                    item.OnMouseOut( );
                }

                if (anyEditorsSelected)
                {
                    _canvas.StartScalingSelectedItems( );
                }
            }

            selectedEditors(  ).ForEach(e => e.HandleKeyPressWhenFocused());
        }