Ejemplo n.º 1
0
        public static void OnMouseMoved(Base hoveredControl, int x, int y, Renderer.Base renderer)
        {
            // Always keep these up to date, they're used to draw the dragged control.
            m_MouseX = x;
            m_MouseY = y;

            // If we're not carrying anything, then check to see if we should
            // pick up from a control that we're holding down. If not, then forget it.
            if (CurrentPackage == null && !ShouldStartDraggingControl(x, y))
            {
                return;
            }

            // Swap to this new hovered control and notify them of the change.
            UpdateHoveredControl(hoveredControl, x, y, renderer);

            if (HoveredControl == null)
            {
                return;
            }

            // Update the hovered control every mouse move, so it can show where
            // the dropped control will land etc..
            HoveredControl.DragAndDrop_Hover(CurrentPackage, x, y);

            // Override the cursor - since it might have been set my underlying controls
            // Ideally this would show the 'being dragged' control. TODO
            renderer.SetCursor(CursorType.Arrow);

            hoveredControl.Redraw();
        }
Ejemplo n.º 2
0
        private static void UpdateHoveredControl(Base control, int x, int y, Renderer.Base renderer)
        {
            //
            // We use this global variable to represent our hovered control
            // That way, if the new hovered control gets deleted in one of the
            // Hover callbacks, we won't be left with a hanging pointer.
            // This isn't ideal - but it's minimal.
            //
            m_NewHoveredControl = control;

            // Nothing to change..
            if (HoveredControl == m_NewHoveredControl)
            {
                return;
            }

            // We changed - tell the old hovered control that it's no longer hovered.
            if (HoveredControl != null && HoveredControl != m_NewHoveredControl)
            {
                HoveredControl.DragAndDrop_HoverLeave(CurrentPackage);
            }

            // If we're hovering where the control came from, just forget it.
            // By changing it to null here we're not going to show any error cursors
            // it will just do nothing if you drop it.
            if (m_NewHoveredControl == SourceControl)
            {
                m_NewHoveredControl = null;
            }

            // Check to see if the new potential control can accept this type of package.
            // If not, ignore it and show an error cursor.
            while (m_NewHoveredControl != null && !m_NewHoveredControl.DragAndDrop_CanAcceptPackage(CurrentPackage))
            {
                // We can't drop on this control, so lets try to drop
                // onto its parent..
                m_NewHoveredControl = m_NewHoveredControl.Parent;

                // Its parents are dead. We can't drop it here.
                // Show the NO WAY cursor.
                if (m_NewHoveredControl == null)
                {
                    renderer.SetCursor(CursorType.No);
                }
            }

            // Become out new hovered control
            HoveredControl = m_NewHoveredControl;

            // If we exist, tell us that we've started hovering.
            if (HoveredControl != null)
            {
                HoveredControl.DragAndDrop_HoverEnter(CurrentPackage, x, y);
            }

            m_NewHoveredControl = null;
        }