示例#1
0
 internal dfDragEventArgs(dfControl source, dfDragDropState state, object data, UnityEngine.Ray ray, Vector2 position) : base(source)
 {
     this.Data     = data;
     this.State    = state;
     this.Position = position;
     this.Ray      = ray;
 }
示例#2
0
        private void setActive(dfControl control, Vector2 position, Ray ray)
        {
            dfMouseEventArgs dfMouseEventArg;

            if (this.activeControl != null && this.activeControl != control)
            {
                dfControl _dfControl = this.activeControl;
                dfMouseEventArg = new dfMouseEventArgs(this.activeControl)
                {
                    Position = position,
                    Ray      = ray
                };
                _dfControl.OnMouseLeave(dfMouseEventArg);
            }
            if (control != null && control != this.activeControl)
            {
                this.lastClickTime = 0f;
                this.lastHoverTime = Time.realtimeSinceStartup + 0.25f;
                dfMouseEventArg    = new dfMouseEventArgs(control)
                {
                    Position = position,
                    Ray      = ray
                };
                control.OnMouseEnter(dfMouseEventArg);
            }
            this.activeControl = control;
            this.lastPosition  = position;
            this.dragState     = dfDragDropState.None;
        }
        private void setActive( dfInputManager manager, dfControl control, Vector2 position, Ray ray )
        {
            if( activeControl != null && activeControl != control )
            {
                activeControl.OnMouseLeave( new dfMouseEventArgs( activeControl ) { Position = position, Ray = ray } );
            }

            if( control != null && control != activeControl )
            {
                lastClickTime = 0f;
                lastHoverTime = Time.realtimeSinceStartup + manager.hoverStartDelay;
                control.OnMouseEnter( new dfMouseEventArgs( control ) { Position = position, Ray = ray } );
            }

            activeControl = control;
            activeControlPosition = ( control != null ) ? control.transform.position : Vector3.one * float.MinValue;
            lastPosition = position;
            dragState = dfDragDropState.None;
        }
            public void ProcessInput( dfInputManager manager, IInputAdapter adapter, Ray ray, dfControl control, bool retainFocusSetting )
            {

            var position = adapter.GetMousePosition();

            buttonsDown = dfMouseButtons.None;
            buttonsReleased = dfMouseButtons.None;
            buttonsPressed = dfMouseButtons.None;

            getMouseButtonInfo( adapter, ref buttonsDown, ref buttonsReleased, ref buttonsPressed );

            float scroll = adapter.GetAxis( scrollAxisName );
            if( !Mathf.Approximately( scroll, 0f ) )
            {
                // By default the mouse wheel is reported in increments of 0.1f,
                // which is just a useless number for UI, but this can be changed
                // by the user in the Unity Input Manager. We'll assume that if the
                // number reported is less than 1 then it is probably safe to
                // assume that we can massage it for UI purposes.
                scroll = Mathf.Sign( scroll ) * Mathf.Max( 1, Mathf.Abs( scroll ) );
            }

            mouseMoveDelta = position - lastPosition;
            lastPosition = position;

            #region Drag and drop

            if( dragState == dfDragDropState.Dragging )
            {

                if( buttonsReleased == dfMouseButtons.None )
                {

                    // Do nothing if the drag operation is over the source control
                    // and no buttons have been released.
                    if( control == activeControl )
                        return;

                    if( control != lastDragControl )
                    {

                        if( lastDragControl != null )
                        {
                            var dragArgs = new dfDragEventArgs( lastDragControl, dragState, dragData, ray, position );
                            lastDragControl.OnDragLeave( dragArgs );
                        }

                        if( control != null )
                        {
                            var dragArgs = new dfDragEventArgs( control, dragState, dragData, ray, position );
                            control.OnDragEnter( dragArgs );
                        }

                        lastDragControl = control;

                        return;

                    }

                    if( control != null )
                    {

                        if( mouseMoveDelta.magnitude > 1.0f )
                        {
                            var dragArgs = new dfDragEventArgs( control, dragState, dragData, ray, position );
                            control.OnDragOver( dragArgs );
                        }

                    }

                    return;

                }

                if( control != null && control != activeControl )
                {

                    var dragArgs = new dfDragEventArgs( control, dfDragDropState.Dragging, dragData, ray, position );
                    control.OnDragDrop( dragArgs );

                    // If there was no event consumer, or if the event consumer did not
                    // change the state from Dragging (which is not a valid state for
                    // a drop event) then just cancel the operation
                    if( !dragArgs.Used || dragArgs.State == dfDragDropState.Dragging )
                        dragArgs.State = dfDragDropState.Cancelled;

                    dragArgs = new dfDragEventArgs( activeControl, dragArgs.State, dragArgs.Data, ray, position );
                    dragArgs.Target = control;
                    activeControl.OnDragEnd( dragArgs );

                }
                else
                {
                    var cancelState = ( control == null ) ? dfDragDropState.CancelledNoTarget : dfDragDropState.Cancelled;
                    var dragArgs = new dfDragEventArgs( activeControl, cancelState, dragData, ray, position );
                    activeControl.OnDragEnd( dragArgs );
                }

                dragState = dfDragDropState.None;
                lastDragControl = null;
                activeControl = null;
                lastClickTime = 0f;
                lastHoverTime = 0f;
                lastPosition = position;

                return;

            }

            #endregion

            #region Mouse button pressed

            if( buttonsPressed != dfMouseButtons.None )
            {

                lastHoverTime = Time.realtimeSinceStartup + manager.hoverStartDelay;

                if( activeControl != null )
                {
                    // If a control has capture, forward all events to it
                    if( activeControl.transform.IsChildOf( manager.transform ) )
                    {
                        activeControl.OnMouseDown( new dfMouseEventArgs( activeControl, buttonsPressed, 0, ray, position, scroll ) );
                    }
                }
                else if( control == null || control.transform.IsChildOf( manager.transform ) )
                {

                    setActive( manager, control, position, ray );
                    if( control != null )
                    {
                        dfGUIManager.SetFocus( control );
                        control.OnMouseDown( new dfMouseEventArgs( control, buttonsPressed, 0, ray, position, scroll ) );
                    }
                    else if( !retainFocusSetting )
                    {
                        var focusControl = dfGUIManager.ActiveControl;
                        if( focusControl != null && focusControl.transform.IsChildOf( manager.transform ) )
                        {
                            focusControl.Unfocus();
                        }
                    }

                }

                if( buttonsReleased == dfMouseButtons.None )
                    return;

            }

            #endregion

            #region Mouse button released

            if( buttonsReleased != dfMouseButtons.None )
            {

                lastHoverTime = Time.realtimeSinceStartup + manager.hoverStartDelay;

                // Mouse up without a control having capture is ignored
                if( activeControl == null )
                {
                    setActive( manager, control, position, ray );
                    return;
                }

                // If the mouse button is released over the same control it was pressed on,
                // the Click event gets generated (in addition to MouseUp)
                if( activeControl == control && buttonsDown == dfMouseButtons.None )
                {

                    var p2u = activeControl.PixelsToUnits();
                    var startPosition = activeControlPosition / p2u;
                    var currentPosition = activeControl.transform.position / p2u;

                    // Don't fire click events if the control has been moved since the mouse was down
                    if( Vector3.Distance( startPosition, currentPosition ) <= 1 )
                    {

                        if( Time.realtimeSinceStartup - lastClickTime < DOUBLECLICK_TIME )
                        {
                            lastClickTime = 0f;
                            activeControl.OnDoubleClick( new dfMouseEventArgs( activeControl, buttonsReleased, 1, ray, position, scroll ) );
                        }
                        else
                        {
                            lastClickTime = Time.realtimeSinceStartup;
                            activeControl.OnClick( new dfMouseEventArgs( activeControl, buttonsReleased, 1, ray, position, scroll ) );
                        }

                    }

                }

                // Let the last control know that the button was released whether it was
                // released over the control or not
                activeControl.OnMouseUp( new dfMouseEventArgs( activeControl, buttonsReleased, 0, ray, position, scroll ) );

                // If all buttons are up, then we need to reset the mouse state
                if( buttonsDown == dfMouseButtons.None && activeControl != control )
                {
                    setActive( manager, null, position, ray );
                }

                return;

            }

            #endregion

            #region Doesn't matter if buttons are down or not

            if( activeControl != null && activeControl == control )
            {

                if( mouseMoveDelta.magnitude == 0 && Time.realtimeSinceStartup - lastHoverTime > manager.hoverNotifactionFrequency )
                {
                    activeControl.OnMouseHover( new dfMouseEventArgs( activeControl, buttonsDown, 0, ray, position, scroll ) );
                    lastHoverTime = Time.realtimeSinceStartup;
                }

            }

            #endregion

            #region No buttons down

            if( buttonsDown == dfMouseButtons.None )
            {

                if( scroll != 0 && control != null )
                {
                    setActive( manager, control, position, ray );
                    control.OnMouseWheel( new dfMouseEventArgs( control, buttonsDown, 0, ray, position, scroll ) );
                    return;
                }

                setActive( manager, control, position, ray );

            }

            #endregion

            #region Some buttons down

            else if( buttonsDown != dfMouseButtons.None ) // Some buttons are down
            {

                if( activeControl != null )
                {

                    // Special case: Another control with a higher RenderOrder is now under the mouse.
                    // This can happen when a control moves, such as when you click on a slider and the
                    // thumb position is updated to be under the mouse (when it wasn't previously)
                    if( control != null && control.RenderOrder > activeControl.RenderOrder )
                    {
                        // TODO: What to do about this when a control has capture?
                    }

                    // If the mouse was moved notify the control, otherwise nothing to do
                    // NOTE: This is similar to "mouse capture" on Windows Forms
                    if( mouseMoveDelta.magnitude >= DRAG_START_DELTA )
                    {

                        if( ( buttonsDown & ( dfMouseButtons.Left | dfMouseButtons.Right ) ) != 0 && dragState != dfDragDropState.Denied )
                        {
                            var dragArgs = new dfDragEventArgs( activeControl ) { Position = position };
                            activeControl.OnDragStart( dragArgs );
                            if( dragArgs.State == dfDragDropState.Dragging )
                            {
                                dragState = dfDragDropState.Dragging;
                                dragData = dragArgs.Data;
                                return;
                            }
                            else
                            {
                                dragState = dfDragDropState.Denied;
                            }
                        }

                    }

                }

            }

            #endregion

            if( activeControl != null && mouseMoveDelta.magnitude >= 1 )
            {
                var moveArgs = new dfMouseEventArgs( activeControl, buttonsDown, 0, ray, position, scroll ) { MoveDelta = mouseMoveDelta };
                activeControl.OnMouseMove( moveArgs );
            }
        }
            /// <summary>
            /// Processes touch information for a single control
            /// </summary>
            /// <param name="info">The touch/raycast data to be processed</param>
            /// <returns>Returns TRUE if the touch information was processed</returns>
            public bool Process( TouchRaycast info )
            {

                #region Drag / Drop

                if( IsDragging )
                {

                    // Not interested in any fingers other than the one that
                    // started the drag operation
                    if( !capture.Contains( info.FingerID ) )
                        return false;

                    // Nothing to do if there's no user action
                    if( info.Phase == TouchPhase.Stationary )
                        return true;

                    // If the touch was cancelled, raise OnDragEnd event
                    if( info.Phase == TouchPhase.Canceled )
                    {

                        control.OnDragEnd( new dfDragEventArgs( control, dfDragDropState.Cancelled, dragData, info.ray, info.position ) );
                        dragState = dfDragDropState.None;

                        touches.Clear();
                        capture.Clear();

                        return true;
                    }

                    // If the finger was lifted, attempt drop
                    if( info.Phase == TouchPhase.Ended )
                    {

                        // Dropped on nothing
                        if( info.control == null || info.control == control )
                        {

                            control.OnDragEnd( new dfDragEventArgs( control, dfDragDropState.CancelledNoTarget, dragData, info.ray, info.position ) );
                            dragState = dfDragDropState.None;

                            touches.Clear();
                            capture.Clear();

                            return true;

                        }

                        // Dropped on another control
                        var dropArgs = new dfDragEventArgs( info.control, dfDragDropState.Dragging, dragData, info.ray, info.position );
                        info.control.OnDragDrop( dropArgs );

                        // If there was no event consumer, or if the event consumer did not
                        // change the state from Dragging (which is not a valid state for
                        // a drop event) then just cancel the operation
                        if( !dropArgs.Used || dropArgs.State != dfDragDropState.Dropped )
                        {
                            dropArgs.State = dfDragDropState.Cancelled;
                        }

                        // Let the control know that it is no longer being dragged
                        var endArgs = new dfDragEventArgs( control, dropArgs.State, dragData, info.ray, info.position );
                        endArgs.Target = info.control;
                        control.OnDragEnd( endArgs );

                        // Clear state
                        dragState = dfDragDropState.None;
                        touches.Clear();
                        capture.Clear();

                        return true;

                    }

                    return true;

                }

                #endregion

                #region New touch for this control

                if( !touches.ContainsKey( info.FingerID ) )
                {

                    // Touch is not over control, and is not "captured" by control
                    if( info.control != control )
                        return false;

                    // Start tracking this finger
                    touches[ info.FingerID ] = info;

                    // See if this is the first touch to be tracked for this control
                    if( touches.Count == 1 )
                    {

                        // This is the first Touch to be associated with the control
                        control.OnMouseEnter( info );

                        // If the touch was also started while over the control,
                        // then raise the OnMouseDown event
                        if( info.Phase == TouchPhase.Began )
                        {

                            capture.Add( info.FingerID );
                            controlStartPosition = control.transform.position;

                            control.OnMouseDown( info );

                            // Prevent "click-through"
                            if( Event.current != null )
                                Event.current.Use();

                        }

                        return true;

                    }

                    // Switch control to "multi-touch" mode if touch began on control,
                    // otherwise ignore the new touch info
                    if( info.Phase == TouchPhase.Began )
                    {

                        // Send multi-touch event
                        var activeTouches = getActiveTouches();
                        var multiTouchArgs = new dfTouchEventArgs( control, activeTouches, info.ray );
                        control.OnMultiTouch( multiTouchArgs );

                    }

                    return true;

                }

                #endregion

                #region Previously tracked touch has now ended

                if( info.Phase == TouchPhase.Canceled || info.Phase == TouchPhase.Ended )
                {

                    var phase = info.Phase;
                    var touch = touches[ info.FingerID ];

                    // Remove the finger from the list of touches
                    touches.Remove( info.FingerID );

                    if( touches.Count == 0 && phase != TouchPhase.Canceled )
                    {

                        if( capture.Contains( info.FingerID ) )
                        {

                            if( canFireClickEvent( info, touch ) )
                            {

                                if( info.control == this.control )
                                {
                                    if( info.touch.tapCount > 1 )
                                        control.OnDoubleClick( info );
                                    else
                                        control.OnClick( info );
                                }

                            }

                            info.control = this.control;
                            this.control.OnMouseUp( info );

                        }

                        capture.Remove( info.FingerID );

                        return true;

                    }
                    else
                    {
                        capture.Remove( info.FingerID );
                    }

                    if( touches.Count == 1 )
                    {

                        // Explicitly notify control that multi-touch state has ended
                        control.OnMultiTouchEnd();

                        return true;

                    }

                }

                #endregion

                #region Multi-touch events

                // If there is more than one touch active for this control,
                // then raise the OnMultiTouch event instead of converting
                // the touch info to mouse events
                if( touches.Count > 1 )
                {

                    var activeTouches = getActiveTouches();
                    var multiTouchArgs = new dfTouchEventArgs( control, activeTouches, info.ray );

                    control.OnMultiTouch( multiTouchArgs );

                    return true;

                }

                #endregion

                // If the touch has not moved, send hover message
                if( !IsDragging && info.Phase == TouchPhase.Stationary )
                {
                    if( info.control == this.control )
                    {
                        control.OnMouseHover( info );
                        return true;
                    }
                    return false;
                }

                #region See if the control supports (and allows) drag-and-drop

                var canStartDrag =
                    capture.Contains( info.FingerID ) &&
                    dragState == dfDragDropState.None &&
                    info.Phase == TouchPhase.Moved;

                if( canStartDrag )
                {

                    // Query the control to see if drag-and-drop is allowed
                    var dragStartArgs = (dfDragEventArgs)info;
                    control.OnDragStart( dragStartArgs );

                    // If control set State and Used properties to the correct values,
                    // enter drag-and-drop mode
                    if( dragStartArgs.State == dfDragDropState.Dragging && dragStartArgs.Used )
                    {

                        this.dragState = dfDragDropState.Dragging;
                        this.dragData = dragStartArgs.Data;

                        return true;

                    }

                    // Flag that we've already tried drag and drop
                    this.dragState = dfDragDropState.Denied;

                }

                #endregion

                // Check for mouse leave
                if( info.control != this.control )
                {

                    // If "capture" is not active, fire the OnMouseLeave event
                    if( !capture.Contains( info.FingerID ) )
                    {

                        info.control = this.control;
                        this.control.OnMouseLeave( info );

                        this.touches.Remove( info.FingerID );

                        return true;

                    }

                }

                // At this point, the only remaining option is to send OnMouseMove event
                info.control = this.control;
                this.control.OnMouseMove( info );

                return true;

            }
示例#6
0
        private void setActive( dfControl control, Vector2 position, Ray ray )
        {
            if( activeControl != null && activeControl != control )
            {
                activeControl.OnMouseLeave( new dfMouseEventArgs( activeControl ) { Position = position, Ray = ray } );
            }

            if( control != null && control != activeControl )
            {
                lastClickTime = 0f;
                lastHoverTime = Time.realtimeSinceStartup + HOVER_NOTIFICATION_BEGIN;
                control.OnMouseEnter( new dfMouseEventArgs( control ) { Position = position, Ray = ray } );
            }

            activeControl = control;
            lastPosition = position;
            dragState = dfDragDropState.None;
        }
示例#7
0
 internal dfDragEventArgs( dfControl source, dfDragDropState state, object data, Ray ray, Vector2 position )
     : base(source)
 {
     this.Data = data;
     this.State = state;
     this.Position = position;
     this.Ray = ray;
 }
示例#8
0
 public bool Process(dfInputManager.TouchInputManager.TouchRaycast info)
 {
     if (this.IsDragging)
     {
         if (!this.capture.Contains(info.FingerID))
         {
             return(false);
         }
         if (info.Phase == TouchPhase.Stationary)
         {
             return(true);
         }
         if (info.Phase == TouchPhase.Canceled)
         {
             this.control.OnDragEnd(new dfDragEventArgs(this.control, dfDragDropState.Cancelled, this.dragData, info.ray, info.position));
             this.dragState = dfDragDropState.None;
             this.touches.Clear();
             this.capture.Clear();
             return(true);
         }
         if (info.Phase != TouchPhase.Ended)
         {
             return(true);
         }
         if (info.control == null || info.control == this.control)
         {
             this.control.OnDragEnd(new dfDragEventArgs(this.control, dfDragDropState.CancelledNoTarget, this.dragData, info.ray, info.position));
             this.dragState = dfDragDropState.None;
             this.touches.Clear();
             this.capture.Clear();
             return(true);
         }
         dfDragEventArgs dfDragEventArg = new dfDragEventArgs(info.control, dfDragDropState.Dragging, this.dragData, info.ray, info.position);
         info.control.OnDragDrop(dfDragEventArg);
         if (!dfDragEventArg.Used || dfDragEventArg.State != dfDragDropState.Dropped)
         {
             dfDragEventArg.State = dfDragDropState.Cancelled;
         }
         dfDragEventArgs dfDragEventArg1 = new dfDragEventArgs(this.control, dfDragEventArg.State, this.dragData, info.ray, info.position)
         {
             Target = info.control
         };
         this.control.OnDragEnd(dfDragEventArg1);
         this.dragState = dfDragDropState.None;
         this.touches.Clear();
         this.capture.Clear();
         return(true);
     }
     if (!this.touches.ContainsKey(info.FingerID))
     {
         if (info.control != this.control)
         {
             return(false);
         }
         this.touches[info.FingerID] = info;
         if (this.touches.Count == 1)
         {
             this.control.OnMouseEnter(info);
             if (info.Phase == TouchPhase.Began)
             {
                 this.capture.Add(info.FingerID);
                 this.control.OnMouseDown(info);
             }
             return(true);
         }
         if (info.Phase == TouchPhase.Began)
         {
             this.control.OnMouseUp(info);
             this.control.OnMouseLeave(info);
             List <Touch>     activeTouches   = this.getActiveTouches();
             dfTouchEventArgs dfTouchEventArg = new dfTouchEventArgs(this.control, activeTouches, info.ray);
             this.control.OnMultiTouch(dfTouchEventArg);
         }
         return(true);
     }
     if (info.Phase == TouchPhase.Canceled || info.Phase == TouchPhase.Ended)
     {
         dfInputManager.TouchInputManager.TouchRaycast item = this.touches[info.FingerID];
         this.touches.Remove(info.FingerID);
         if (this.touches.Count == 0)
         {
             if (this.capture.Contains(info.FingerID))
             {
                 if (this.canFireClickEvent(info, item) && info.control == this.control)
                 {
                     if (info.touch.tapCount <= 1)
                     {
                         this.control.OnClick(info);
                     }
                     else
                     {
                         this.control.OnDoubleClick(info);
                     }
                 }
                 this.control.OnMouseUp(info);
             }
             this.control.OnMouseLeave(info);
             this.capture.Remove(info.FingerID);
             return(true);
         }
         this.capture.Remove(info.FingerID);
         if (this.touches.Count == 1)
         {
             dfTouchEventArgs dfTouchEventArg1 = this.touches.Values.First <dfInputManager.TouchInputManager.TouchRaycast>();
             this.control.OnMouseEnter(dfTouchEventArg1);
             this.control.OnMouseDown(dfTouchEventArg1);
             return(true);
         }
     }
     if (this.touches.Count > 1)
     {
         List <Touch>     touches          = this.getActiveTouches();
         dfTouchEventArgs dfTouchEventArg2 = new dfTouchEventArgs(this.control, touches, info.ray);
         this.control.OnMultiTouch(dfTouchEventArg2);
         return(true);
     }
     if (!this.IsDragging && info.Phase == TouchPhase.Stationary)
     {
         if (info.control != this.control)
         {
             return(false);
         }
         this.control.OnMouseHover(info);
         return(true);
     }
     if ((!this.capture.Contains(info.FingerID) || this.dragState != dfDragDropState.None ? false : info.Phase == TouchPhase.Moved))
     {
         dfDragEventArgs dfDragEventArg2 = info;
         this.control.OnDragStart(dfDragEventArg2);
         if (dfDragEventArg2.State == dfDragDropState.Dragging && dfDragEventArg2.Used)
         {
             this.dragState = dfDragDropState.Dragging;
             this.dragData  = dfDragEventArg2.Data;
             return(true);
         }
         this.dragState = dfDragDropState.Denied;
     }
     if (!(info.control != this.control) || this.capture.Contains(info.FingerID))
     {
         this.control.OnMouseMove(info);
         return(true);
     }
     this.control.OnMouseLeave(info);
     this.touches.Remove(info.FingerID);
     return(true);
 }
示例#9
0
        public void ProcessInput(IInputAdapter adapter, Ray ray, dfControl control, bool retainFocusSetting)
        {
            Vector2 mousePosition = adapter.GetMousePosition();

            this.buttonsDown     = dfMouseButtons.None;
            this.buttonsReleased = dfMouseButtons.None;
            this.buttonsPressed  = dfMouseButtons.None;
            dfInputManager.MouseInputManager.getMouseButtonInfo(adapter, ref this.buttonsDown, ref this.buttonsReleased, ref this.buttonsPressed);
            float axis = adapter.GetAxis("Mouse ScrollWheel");

            if (!Mathf.Approximately(axis, 0f))
            {
                axis = Mathf.Sign(axis) * Mathf.Max(1f, Mathf.Abs(axis));
            }
            this.mouseMoveDelta = mousePosition - this.lastPosition;
            this.lastPosition   = mousePosition;
            if (this.dragState == dfDragDropState.Dragging)
            {
                if (this.buttonsReleased == dfMouseButtons.None)
                {
                    if (control == this.activeControl)
                    {
                        return;
                    }
                    if (control == this.lastDragControl)
                    {
                        if (control != null && Vector2.Distance(mousePosition, this.lastPosition) > 1f)
                        {
                            dfDragEventArgs dfDragEventArg = new dfDragEventArgs(control, this.dragState, this.dragData, ray, mousePosition);
                            control.OnDragOver(dfDragEventArg);
                        }
                        return;
                    }
                    if (this.lastDragControl != null)
                    {
                        dfDragEventArgs dfDragEventArg1 = new dfDragEventArgs(this.lastDragControl, this.dragState, this.dragData, ray, mousePosition);
                        this.lastDragControl.OnDragLeave(dfDragEventArg1);
                    }
                    if (control != null)
                    {
                        dfDragEventArgs dfDragEventArg2 = new dfDragEventArgs(control, this.dragState, this.dragData, ray, mousePosition);
                        control.OnDragEnter(dfDragEventArg2);
                    }
                    this.lastDragControl = control;
                    return;
                }
                if (!(control != null) || !(control != this.activeControl))
                {
                    dfDragDropState _dfDragDropState = (control != null ? dfDragDropState.Cancelled : dfDragDropState.CancelledNoTarget);
                    dfDragEventArgs dfDragEventArg3  = new dfDragEventArgs(this.activeControl, _dfDragDropState, this.dragData, ray, mousePosition);
                    this.activeControl.OnDragEnd(dfDragEventArg3);
                }
                else
                {
                    dfDragEventArgs dfDragEventArg4 = new dfDragEventArgs(control, dfDragDropState.Dragging, this.dragData, ray, mousePosition);
                    control.OnDragDrop(dfDragEventArg4);
                    if (!dfDragEventArg4.Used || dfDragEventArg4.State == dfDragDropState.Dragging)
                    {
                        dfDragEventArg4.State = dfDragDropState.Cancelled;
                    }
                    dfDragEventArg4 = new dfDragEventArgs(this.activeControl, dfDragEventArg4.State, dfDragEventArg4.Data, ray, mousePosition)
                    {
                        Target = control
                    };
                    this.activeControl.OnDragEnd(dfDragEventArg4);
                }
                this.dragState       = dfDragDropState.None;
                this.lastDragControl = null;
                this.activeControl   = null;
                this.lastClickTime   = 0f;
                this.lastHoverTime   = 0f;
                this.lastPosition    = mousePosition;
                return;
            }
            if (this.buttonsReleased != dfMouseButtons.None)
            {
                this.lastHoverTime = Time.realtimeSinceStartup + 0.25f;
                if (this.activeControl == null)
                {
                    this.setActive(control, mousePosition, ray);
                    return;
                }
                if (this.activeControl == control && this.buttonsDown == dfMouseButtons.None)
                {
                    if (Time.realtimeSinceStartup - this.lastClickTime >= 0.25f)
                    {
                        this.lastClickTime = Time.realtimeSinceStartup;
                        this.activeControl.OnClick(new dfMouseEventArgs(this.activeControl, this.buttonsReleased, 1, ray, mousePosition, axis));
                    }
                    else
                    {
                        this.lastClickTime = 0f;
                        this.activeControl.OnDoubleClick(new dfMouseEventArgs(this.activeControl, this.buttonsReleased, 1, ray, mousePosition, axis));
                    }
                }
                this.activeControl.OnMouseUp(new dfMouseEventArgs(this.activeControl, this.buttonsReleased, 0, ray, mousePosition, axis));
                if (this.buttonsDown == dfMouseButtons.None && this.activeControl != control)
                {
                    this.setActive(null, mousePosition, ray);
                }
                return;
            }
            if (this.buttonsPressed != dfMouseButtons.None)
            {
                this.lastHoverTime = Time.realtimeSinceStartup + 0.25f;
                if (this.activeControl == null)
                {
                    this.setActive(control, mousePosition, ray);
                    if (control != null)
                    {
                        control.OnMouseDown(new dfMouseEventArgs(control, this.buttonsPressed, 0, ray, mousePosition, axis));
                    }
                    else if (!retainFocusSetting)
                    {
                        dfControl activeControl = dfGUIManager.ActiveControl;
                        if (activeControl != null)
                        {
                            activeControl.Unfocus();
                        }
                    }
                }
                else
                {
                    this.activeControl.OnMouseDown(new dfMouseEventArgs(this.activeControl, this.buttonsPressed, 0, ray, mousePosition, axis));
                }
                return;
            }
            if (this.activeControl != null && this.activeControl == control && this.mouseMoveDelta.magnitude == 0f && Time.realtimeSinceStartup - this.lastHoverTime > 0.1f)
            {
                this.activeControl.OnMouseHover(new dfMouseEventArgs(this.activeControl, this.buttonsDown, 0, ray, mousePosition, axis));
                this.lastHoverTime = Time.realtimeSinceStartup;
            }
            if (this.buttonsDown == dfMouseButtons.None)
            {
                if (axis != 0f && control != null)
                {
                    this.setActive(control, mousePosition, ray);
                    control.OnMouseWheel(new dfMouseEventArgs(control, this.buttonsDown, 0, ray, mousePosition, axis));
                    return;
                }
                this.setActive(control, mousePosition, ray);
            }
            else if (this.activeControl != null)
            {
                if (control != null)
                {
                    control.RenderOrder <= this.activeControl.RenderOrder;
                }
                if (this.mouseMoveDelta.magnitude >= 2f && (this.buttonsDown & (dfMouseButtons.Left | dfMouseButtons.Right)) != dfMouseButtons.None && this.dragState != dfDragDropState.Denied)
                {
                    dfDragEventArgs dfDragEventArg5 = new dfDragEventArgs(this.activeControl)
                    {
                        Position = mousePosition
                    };
                    this.activeControl.OnDragStart(dfDragEventArg5);
                    if (dfDragEventArg5.State == dfDragDropState.Dragging)
                    {
                        this.dragState = dfDragDropState.Dragging;
                        this.dragData  = dfDragEventArg5.Data;
                        return;
                    }
                    this.dragState = dfDragDropState.Denied;
                }
            }
            if (this.activeControl != null && this.mouseMoveDelta.magnitude >= 1f)
            {
                dfMouseEventArgs dfMouseEventArg = new dfMouseEventArgs(this.activeControl, this.buttonsDown, 0, ray, mousePosition, axis)
                {
                    MoveDelta = this.mouseMoveDelta
                };
                this.activeControl.OnMouseMove(dfMouseEventArg);
            }
        }