Beispiel #1
0
 private void RenderingCanvas_KeyDown(object sender, KeyEventArgs e)
 {
     ClearErrorMessage();
     if (e.KeyCode == Keys.Insert)
     {
         _editor.ForEachSelectedCell(AttemptInsertObject);
         _editor.ClearSelection();
     }
     else if (e.KeyCode == Keys.Delete)
     {
         _editor.DeleteSelectedTileObjects();
         _editor.ClearSelection();
     }
 }
Beispiel #2
0
        private void RenderingCanvas_MouseUp(object sender, MouseEventArgs e)
        {
            if (_editor == null)
            {
                return;
            }
            Point?firstSelectionPoint = _firstSelectionPoint;

            _firstSelectionPoint = null;
            _lastMousePosition   = null;

            if (firstSelectionPoint == null)
            {
                return;
            }

            if (e.Button == MouseButtons.Right)
            {
                if (_editor.SelectedCells.Length > 0)
                {
                    _editor?.ClearSelection();
                }
                else
                {
                    ShowContextMenu(e.X, e.Y);
                }

                return;
            }

            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            int firstX = firstSelectionPoint.Value.X;
            int firstY = firstSelectionPoint.Value.Y;
            int lastX  = e.X;
            int lastY  = e.Y;

            if (firstX > lastX)
            {
                int t = lastX;
                lastX  = firstX;
                firstX = t;
            }
            if (firstY > lastY)
            {
                int t = lastY;
                lastY  = firstY;
                firstY = t;
            }

            int delta = lastX - firstX + lastY - firstY;

            if (delta > MouseGrabThreshold)
            {
                _editor.SelectRect(_editor.GetCellRect(firstX, firstY, lastX, lastY));
            }
            else
            {
                AttemptInsertObject(lastX, lastY);
            }
        }