Exemplo n.º 1
0
        /// <summary>
        /// Handles when the mouse moves.
        /// </summary>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        /// <param name="camera">The <see cref="ICamera2D"/> describing the current view.</param>
        /// <returns>True if the <see cref="TransBoxManager"/> handled the event; otherwise false.</returns>
        public bool HandleMouseMove(MouseEventArgs e, ICamera2D camera)
        {
            if (_transBoxes.Count == 0)
            {
                return(false);
            }

            var worldPos = camera.ToWorld(e.Position());

            _lastWorldPos = worldPos;

            // Update what transbox is under the cursor
            if (SelectedTransBox != null)
            {
                UnderCursor = SelectedTransBox;
            }
            else
            {
                UnderCursor = FindBoxAt(worldPos);
            }

            // Update position
            if (SelectedTransBox != null)
            {
                SelectedTransBox.CursorMoved(_lastWorldPos);
            }

            return(SelectedTransBox != null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles when a mouse button is pressed down.
        /// </summary>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        /// <param name="camera">The <see cref="ICamera2D"/> describing the current view.</param>
        /// <returns>True if the <see cref="TransBoxManager"/> handled the event; otherwise false.</returns>
        public bool HandleMouseDown(MouseEventArgs e, ICamera2D camera)
        {
            if (e.Button == DragButton)
            {
                var worldPos = camera.ToWorld(e.Position());

                UnderCursor      = FindBoxAt(worldPos);
                SelectedTransBox = UnderCursor;
                _lastWorldPos    = worldPos;

                if (SelectedTransBox != null)
                {
                    _selectedTransBoxButton = e.Button;
                }
                else
                {
                    _selectedTransBoxButton = MouseButtons.None;
                }
            }

            return(SelectedTransBox != null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Recreates the <see cref="ITransBox"/>es for the current selection.
        /// </summary>
        /// <param name="camera">The camera describing the view area.</param>
        void UpdateTransBoxes(ICamera2D camera)
        {
            SelectedTransBox = null;
            UnderCursor      = null;

            // Clear the old boxes
            _transBoxes.Clear();

            if (_items.Count <= 0)
            {
                // Nothing selected
                return;
            }
            else if (_items.Count == 1)
            {
                // Only one selected
                var item = _items.FirstOrDefault();
                if (item == null)
                {
                    Debug.Fail("How did this happen?");
                    Clear(camera);
                    return;
                }

                var transBoxes = TransBox.SurroundEntity(this, item, camera);
                _transBoxes.AddRange(transBoxes);
            }
            else
            {
                // Multiple selected
                var min    = new Vector2(Items.Min(x => x.Position.X), Items.Min(x => x.Position.Y));
                var max    = new Vector2(Items.Max(x => x.Max.X), Items.Max(x => x.Max.Y));
                var center = min + ((max - min) / 2f).Round();

                var tb = new MoveManyTransBox(this, _items, center, camera);
                _transBoxes.Add(tb);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Recreates the <see cref="ITransBox"/>es for the current selection.
        /// </summary>
        /// <param name="camera">The camera describing the view area.</param>
        void UpdateTransBoxes(ICamera2D camera)
        {
            SelectedTransBox = null;
            UnderCursor = null;

            // Clear the old boxes
            _transBoxes.Clear();

            if (_items.Count <= 0)
            {
                // Nothing selected
                return;
            }
            else if (_items.Count == 1)
            {
                // Only one selected
                var item = _items.FirstOrDefault();
                if (item == null)
                {
                    Debug.Fail("How did this happen?");
                    Clear(camera);
                    return;
                }

                var transBoxes = TransBox.SurroundEntity(this, item, camera);
                _transBoxes.AddRange(transBoxes);
            }
            else
            {
                // Multiple selected
                var min = new Vector2(Items.Min(x => x.Position.X), Items.Min(x => x.Position.Y));
                var max = new Vector2(Items.Max(x => x.Max.X), Items.Max(x => x.Max.Y));
                var center = min + ((max - min) / 2f).Round();

                var tb = new MoveManyTransBox(this, _items, center, camera);
                _transBoxes.Add(tb);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Handles when the mouse moves.
        /// </summary>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        /// <param name="camera">The <see cref="ICamera2D"/> describing the current view.</param>
        /// <returns>True if the <see cref="TransBoxManager"/> handled the event; otherwise false.</returns>
        public bool HandleMouseMove(MouseEventArgs e, ICamera2D camera)
        {
            if (_transBoxes.Count == 0)
                return false;

            var worldPos = camera.ToWorld(e.Position());
            _lastWorldPos = worldPos;

            // Update what transbox is under the cursor
            if (SelectedTransBox != null)
                UnderCursor = SelectedTransBox;
            else
                UnderCursor = FindBoxAt(worldPos);

            // Update position
            if (SelectedTransBox != null)
                SelectedTransBox.CursorMoved(_lastWorldPos);

            return SelectedTransBox != null;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Handles when a mouse button is pressed down.
        /// </summary>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        /// <param name="camera">The <see cref="ICamera2D"/> describing the current view.</param>
        /// <returns>True if the <see cref="TransBoxManager"/> handled the event; otherwise false.</returns>
        public bool HandleMouseDown(MouseEventArgs e, ICamera2D camera)
        {
            if (e.Button == DragButton)
            {
                var worldPos = camera.ToWorld(e.Position());

                UnderCursor = FindBoxAt(worldPos);
                SelectedTransBox = UnderCursor;
                _lastWorldPos = worldPos;

                if (SelectedTransBox != null)
                    _selectedTransBoxButton = e.Button;
                else
                    _selectedTransBoxButton = MouseButtons.None;
            }

            return SelectedTransBox != null;
        }