コード例 #1
0
ファイル: GUIContext.cs プロジェクト: xdinos/SDL2Experiments
        private bool handleCursorMoveEvent(SemanticInputEvent @event)
        {
            var new_position = new Lunatics.Mathematics.Vector2(
                @event.d_payload.array[0],
                @event.d_payload.array[1]);

            // setup cursor movement event args object.
            var ciea = new CursorInputEventArgs(null);

            ciea.moveDelta = new_position - _cursor.GetPosition();

            // no movement means no event
            if ((ciea.moveDelta.X == 0) && (ciea.moveDelta.Y == 0))
            {
                return(false);
            }

            ciea.scroll = 0;
            ciea.Source = CursorInputSource.None;
            ciea.state  = d_cursorsState;

            // move cursor to new position
            _cursor.SetPosition(new_position);
            // update position in args (since actual position may be constrained)
            ciea.Position = _cursor.GetPosition();

            return(HandleCursorMoveImpl(ciea));
        }
コード例 #2
0
ファイル: GUIContext.cs プロジェクト: xdinos/SDL2Experiments
        private bool handleCursorActivateEvent(SemanticInputEvent @event)
        {
            var ciea = new CursorInputEventArgs(null);

            ciea.Position  = _cursor.GetPosition();
            ciea.moveDelta = Lunatics.Mathematics.Vector2.Zero;
            ciea.Source    = @event.d_payload.source;
            ciea.scroll    = 0;
            ciea.Window    = GetTargetWindow(ciea.Position, false);
            // make cursor position sane for this target window
            if (ciea.Window != null)
            {
                ciea.Position = ciea.Window.GetUnprojectedPosition(ciea.Position);
            }

            // if there is no target window, input can not be handled.
            if (ciea.Window == null)
            {
                return(false);
            }

            if (d_windowNavigator != null)
            {
                d_windowNavigator.SetCurrentFocusedWindow(ciea.Window);
            }

            ciea.Window.OnCursorActivate(ciea);
            return(ciea.handled != 0);
        }
コード例 #3
0
ファイル: GUIContext.cs プロジェクト: xdinos/SDL2Experiments
        /// <summary>
        /// returns whether the window containing the mouse had changed.
        /// </summary>
        /// <returns></returns>
        protected bool UpdateWindowContainingCursorImpl()
        {
            var ciea       = new CursorInputEventArgs(null);
            var cursor_pos = _cursor.GetPosition();

            var window_with_cursor = GetTargetWindow(cursor_pos, true);

            // exit if window containing cursor has not changed.
            if (window_with_cursor == d_windowContainingCursor)
            {
                return(false);
            }

            ciea.scroll = 0;
            ciea.Source = CursorInputSource.None;

            var oldWindow = d_windowContainingCursor;

            d_windowContainingCursor = window_with_cursor;

            // inform previous window the cursor has left it
            if (oldWindow != null)
            {
                ciea.Window   = oldWindow;
                ciea.Position = oldWindow.GetUnprojectedPosition(cursor_pos);
                oldWindow.OnCursorLeaves(ciea);
            }

            // inform window containing cursor that cursor has entered it
            if (d_windowContainingCursor != null)
            {
                ciea.handled  = 0;
                ciea.Window   = d_windowContainingCursor;
                ciea.Position = d_windowContainingCursor.GetUnprojectedPosition(cursor_pos);
                d_windowContainingCursor.OnCursorEnters(ciea);
            }

            // do the 'area' version of the events
            var root = GetCommonAncestor(oldWindow, d_windowContainingCursor);

            if (oldWindow != null)
            {
                NotifyCursorTransition(root, oldWindow, (w, a) => w.OnCursorLeavesArea(a), ciea);
            }

            if (d_windowContainingCursor != null)
            {
                NotifyCursorTransition(root, d_windowContainingCursor, (w, a) => w.OnCursorEntersArea(a), ciea);
            }

            return(true);
        }
コード例 #4
0
ファイル: GUIContext.cs プロジェクト: xdinos/SDL2Experiments
        private bool handleCursorLeave(SemanticInputEvent @event)
        {
            if (GetWindowContainingCursor() == null)
            {
                return(false);
            }

            var ciea = new CursorInputEventArgs(null);

            ciea.Position  = GetWindowContainingCursor().GetUnprojectedPosition(_cursor.GetPosition());
            ciea.moveDelta = Lunatics.Mathematics.Vector2.Zero;
            ciea.Source    = CursorInputSource.None;
            ciea.scroll    = 0;
            ciea.Window    = GetWindowContainingCursor();

            GetWindowContainingCursor().OnCursorLeaves(ciea);
            ResetWindowContainingCursor();

            return(ciea.handled != 0);
        }
コード例 #5
0
ファイル: GUIContext.cs プロジェクト: xdinos/SDL2Experiments
        private bool HandleCursorMoveImpl(CursorInputEventArgs pa)
        {
            UpdateWindowContainingCursor();

            // input can't be handled if there is no window to handle it.
            if (GetWindowContainingCursor() == null)
            {
                return(false);
            }

            // make cursor position sane for this target window
            pa.Position = GetWindowContainingCursor().GetUnprojectedPosition(pa.Position);
            // inform window about the input.
            pa.Window  = GetWindowContainingCursor();
            pa.handled = 0;
            pa.Window.OnCursorMove(pa);

            // return whether window handled the input.
            return(pa.handled != 0);
        }
コード例 #6
0
ファイル: GUIContext.cs プロジェクト: xdinos/SDL2Experiments
        private bool handleScrollEvent(SemanticInputEvent @event)
        {
            CursorInputEventArgs ciea = new CursorInputEventArgs(null);

            ciea.Position  = _cursor.GetPosition();
            ciea.moveDelta = Lunatics.Mathematics.Vector2.Zero;
            ciea.Source    = CursorInputSource.None;
            ciea.scroll    = @event.d_payload.single;
            ciea.Window    = GetTargetWindow(ciea.Position, false);
            // make cursor position sane for this target window
            if (ciea.Window != null)
            {
                ciea.Position = ciea.Window.GetUnprojectedPosition(ciea.Position);
            }

            // if there is no target window, input can not be handled.
            if (ciea.Window == null)
            {
                return(false);
            }

            ciea.Window.OnScroll(ciea);
            return(ciea.handled != 0);
        }
コード例 #7
0
ファイル: GUIContext.cs プロジェクト: xdinos/SDL2Experiments
        /// <summary>
        /// call some function for a chain of windows: (top, bottom]
        /// </summary>
        /// <param name="top"></param>
        /// <param name="bottom"></param>
        /// <param name="func"></param>
        /// <param name="args"></param>
        protected void NotifyCursorTransition(Window top, Window bottom, Action <Window, CursorInputEventArgs> func, CursorInputEventArgs args)
        {
            if (top == bottom)
            {
                return;
            }

            var parent = bottom.GetParent();

            if (parent != null && parent != top)
            {
                NotifyCursorTransition(top, parent, func, args);
            }

            args.handled = 0;
            args.Window  = bottom;

            func(bottom, args);
        }