Exemplo n.º 1
0
        /// <summary>
        /// Event handler called when the mouse is moved. Asks each control to
        /// check its mouse status (whether the mouse is over or not). Control
        /// invokes the MouseOut event, while this method invokes the MouseOver
        /// event.
        /// </summary>
        /// <param name="args">Mouse event arguments.</param>
        private void CheckMouseStatus(MouseEventArgs args)
        {
            UIComponent result = null;

            // Ask each control to checks its mouse status
            foreach (UIComponent control in this.controls)
            {
                // Early out if any control is animating (moving or resizing)
                if (control.IsAnimating)
                {
                    return;
                }

                UIComponent temp = control.CheckMouseStatus(args);
                // When modal, only allow modal control, its children, and null through
                if (temp != null && (this.modalControl == null || this.modalControl.IsChild(temp)))
                {
                    // MouseOut last result
                    if (result != null && result.IsMouseOver)
                    {
                        result.InvokeMouseOut(args);
                    }

                    result = temp;
                }
            }

            if (result != null)
            {
                // Indirectly invoke MouseOver event
                if (!result.IsMouseOver)
                {
                    result.InvokeMouseOver(args);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Asks children for their mouse status, and invokes MouseOut event
        /// for this control if necessary.
        /// </summary>
        /// <param name="args">Mouse event arguments.</param>
        /// <returns>Control asking for MouseOver event, otherwise null.</returns>
        internal UIComponent CheckMouseStatus(MouseEventArgs args)
        {
            UIComponent result = null;

            // Check if control can receive MouseOver and MouseOut events
            if (this.Visible)
            {
                // Check if MouseOut event should be invoked
                bool mouseOver = CheckCoordinates(args.Position.X, args.Position.Y);
                if (this.isMouseOver)
                {
                    if (!mouseOver)
                    {
                        this.isMouseOver = false;
                        MouseOut.Invoke(args);
                    }
                }

                if (mouseOver)
                {
                    float zTemp = 0.0f;

                    // Ask each child to check its mouse status
                    foreach (UIComponent control in this.controls)
                    {
                        // Keep track of highest z-order
                        if (control.ZOrder >= zTemp)
                        {
                            UIComponent child = control.CheckMouseStatus(args);

                            if (child != null)
                            {
                                // MouseOut last result
                                if (result != null && result.IsMouseOver)
                                {
                                    result.InvokeMouseOut(args);
                                }

                                // Set result and update highest z-order
                                result = child;
                                zTemp  = control.ZOrder;
                            }
                        }
                    }

                    // If no child requires the event, see if this control can
                    // take it.
                    if (result == null && this.canHaveFocus)
                    {
                        result = this;
                    }
                }
                else
                {
                    // Ensure each control can receive MouseOut event
                    foreach (UIComponent control in this.controls)
                    {
                        control.CheckMouseStatus(args);
                    }
                }
            }

            return(result);
        }