/// <summary>
        ///     Processes the machine update for controls which weren't seen with the current (latest) point.
        /// </summary>
        /// <param name="control">The control (which was not seen).</param>
        /// <param name="data">The view-model for the control.</param>
        /// <param name="window">The window where the control is located.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///     Thrown if the control is in an unexpected state (e.g. infrastructure created a new state and a module considers it,
        ///     but this module has not been updated).
        /// </exception>
        private void StateMachineUpdateForOtherControls(
            SelectableControl control,
            ISelectableControlViewModel data,
            Window window)
        {
            switch (data.State)
            {
            case SelectableState.Idle:
                break;

            case SelectableState.SeenButWaiting:
                if (data.CurrentGazeTimeSpan == TimeSpan.Zero)
                {
                    data.State = SelectableState.Idle;
                }

                break;

            case SelectableState.AnimationRunning:
                if (data.CurrentGazeTimeSpan == TimeSpan.Zero)
                {
                    data.State = SelectableState.Idle;
                    window.Dispatcher.Invoke(control.StopAnimation);
                }
                else
                {
                    data.State = SelectableState.AnimationOnHold;
                    window.Dispatcher.Invoke(control.PauseAnimation);
                }

                break;

            case SelectableState.AnimationOnHold:
                if (data.CurrentGazeTimeSpan == TimeSpan.Zero)
                {
                    data.State = SelectableState.Idle;
                    window.Dispatcher.Invoke(control.StopAnimation);
                }

                break;

            case SelectableState.RecentlySelected:
                if (data.CurrentGazeTimeSpan >= data.GazeTimeSpanBeforeCooldown)
                {
                    data.CurrentGazeTimeSpan = TimeSpan.Zero;
                }

                if (data.CurrentGazeTimeSpan == TimeSpan.Zero)
                {
                    data.State = SelectableState.Idle;
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #2
0
    public static Rect GetSelectedArea()
    {
        SelectableControl sel = GetSelection();

        if (sel == null)
        {
            return(new Rect(0, 0, 0, 0));
        }
        return(GetSelection().area);
    }
Beispiel #3
0
    public static string GetSelectedName()
    {
        SelectableControl sel = GetSelection();

        if (sel == null)
        {
            return("");
        }
        return(GetSelection().name);
    }
Beispiel #4
0
        /// <summary>
        /// Resets the current selection and sets the <see cref="SelectableControl"/> at <see cref="Vector2.Zero"/> to be selected.
        /// </summary>
        protected void ResetSelection()
        {
            GetMenu.Controls.FindControl(Vector2.Zero).BorderStyle(BorderArea.Horizontal, '~');

            if (OiskiEngine.Input.GetSelectedIndex != Vector2.Zero)
            {
                SelectableControl control = GetMenu.Controls.FindControl(OiskiEngine.Input.GetSelectedIndex);
                control.BorderStyle(BorderArea.Horizontal, '-');
            }

            OiskiEngine.Input.ResetSlection();
        }
Beispiel #5
0
        /// <summary>
        ///     Finds the selectable control on which a gaze-point falls and populates a field in the class.
        /// </summary>
        /// <param name="result">The result.</param>
        /// <returns>
        ///     <see cref="HitTestResultBehavior.Stop" /> as soon as the first <see cref="SelectableControl" /> under the point is
        ///     found. Otherwise it returns <see cref="HitTestResultBehavior.Continue" />.
        /// </returns>
        public static HitTestResultBehavior FindSelectableControlSeen(HitTestResult result)
        {
            var visualHit = result.VisualHit;

            while ((visualHit != null) && !(visualHit is SelectableControl))
            {
                visualHit = VisualTreeHelper.GetParent(visualHit);
            }

            if (visualHit == null)
            {
                return(HitTestResultBehavior.Continue);
            }

            _selectableControlSeen = visualHit as SelectableControl;
            return(HitTestResultBehavior.Stop);
        }
Beispiel #6
0
        /// <summary>
        /// Finds the <see cref="SelectableControl"/> under the given <see cref="Point"/> in the given <see cref="Window"/>.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="window">The window.</param>
        /// <returns>The <see cref="SelectableControl"/> under the point.</returns>
        public static SelectableControl SelectableControlUnderPoint(Point point, Window window)
        {
            _selectableControlSeen = null;
            window.Dispatcher.Invoke(
                () =>
            {
                if (PresentationSource.FromVisual(window) == null)
                {
                    return;
                }

                var pt = window.PointFromScreen(point);

                VisualTreeHelper.HitTest(
                    window,
                    null,
                    FindSelectableControlSeen,
                    new PointHitTestParameters(pt));
            });
            return(_selectableControlSeen);
        }
        /// <summary>
        ///     Processes the machine update for the control which was seen with the current (latest) point.
        /// </summary>
        /// <param name="seenControl">The control which was seen.</param>
        /// <param name="data">The view-model for the control.</param>
        /// <param name="window">The window where the control is located.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///     Thrown if the control is in an unexpected state (e.g. infrastructure created a new state and a module considers it,
        ///     but this module has not been updated).
        /// </exception>
        private void StateMachineUpdateForSeenControl(
            SelectableControl seenControl,
            ISelectableControlViewModel data,
            Window window)
        {
            bool isAlwaysSelectable = false;

            window.Dispatcher.Invoke(() => isAlwaysSelectable = seenControl.IsAlwaysSelectable);
            if (!data.IsSelectable &&
                !isAlwaysSelectable)
            {
                return;
            }

            switch (data.State)
            {
            case SelectableState.Idle:
                data.State = SelectableState.SeenButWaiting;
                break;

            case SelectableState.SeenButWaiting:
                if (data.CurrentGazeTimeSpan == TimeSpan.Zero)
                {
                    data.State = SelectableState.Idle;
                }

                if (data.CurrentGazeTimeSpan >= data.GazeTimeSpanBeforeAnimationBegins)
                {
                    window.Dispatcher.Invoke(seenControl.PlayAnimation);
                    data.State = SelectableState.AnimationRunning;
                }

                break;

            case SelectableState.AnimationRunning:
                if (data.CurrentGazeTimeSpan >= data.GazeTimeSpanBeforeSelectionOccurs)
                {
                    window.Dispatcher.Invoke(seenControl.Select);
                    data.State = SelectableState.RecentlySelected;
                }

                if (data.CurrentGazeTimeSpan == TimeSpan.Zero)
                {
                    data.State = SelectableState.Idle;
                    window.Dispatcher.Invoke(seenControl.StopAnimation);
                }

                break;

            case SelectableState.AnimationOnHold:
                window.Dispatcher.Invoke(seenControl.ResumeAnimation);
                data.State = SelectableState.AnimationRunning;
                if (data.CurrentGazeTimeSpan == TimeSpan.Zero)
                {
                    data.State = SelectableState.Idle;
                    window.Dispatcher.Invoke(seenControl.StopAnimation);
                }

                break;

            case SelectableState.RecentlySelected:
                if (data.CurrentGazeTimeSpan >= data.GazeTimeSpanBeforeCooldown)
                {
                    data.CurrentGazeTimeSpan = TimeSpan.Zero;
                }

                if (data.CurrentGazeTimeSpan == TimeSpan.Zero)
                {
                    data.State = SelectableState.Idle;
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #8
0
 public static void AddControl(SelectableControl c)
 {
     controls.Add(c);
 }
Beispiel #9
0
 public static void AddControl(SelectableControl c)
 {
     controls.Add(c);
 }