Esempio n. 1
0
        public DwellTrialTrigger(IClock clock, SpellerController spellerController, GazePointHandler gazePointHandler, SpellerExperiment.Configuration.TestConfig testConfig)
        {
            _clock                   = clock;
            _spellerController       = spellerController;
            _gazePointHandler        = gazePointHandler;
            _cancellable             = testConfig.TrialCancellable;
            _minTrialInterval        = testConfig.Trial.Interval;
            _cursorMovementTolerance = testConfig.CursorMovementTolerance;
            _hoverToSelectDuration   = testConfig.SelectionDelay;

            spellerController.Starting += (sender, e) => Start();
            spellerController.Stopping += (sender, e) => Stop();

            Reset();
        }
Esempio n. 2
0
        public ButtonInsideTrialTrigger(IClock clock, SpellerController spellerController, GazePointHandler gazePointHandler,
                                        SpellerExperiment.Configuration.TestConfig testConfig, Func <Point, SpellerBaseWindow.UIButton> findButtonFunc)
        {
            _clock                 = clock;
            _spellerController     = spellerController;
            _gazePointHandler      = gazePointHandler;
            _cancellable           = testConfig.TrialCancellable;
            _minTrialInterval      = testConfig.Trial.Interval;
            _hoverToSelectDuration = testConfig.SelectionDelay;
            _findButtonFunc        = findButtonFunc;

            spellerController.Starting += (sender, e) => Start();
            spellerController.Stopping += (sender, e) => Stop();

            Reset();
        }
Esempio n. 3
0
        protected SpellerBaseWindow(Session session, SpellerController spellerController)
        {
            // ReSharper disable once LocalizableElement
            Text = "Speller";
            SuspendLayout();
            ControlBox      = false;
            IsFullscreen    = true;
            DoubleBuffered  = false;
            FormBorderStyle = FormBorderStyle.None;
            WindowState     = FormWindowState.Maximized;
            ResumeLayout(true);

            Load   += Window_OnLoaded;
            KeyUp  += Window_OnKeyUp;
            Resize += Window_OnResize;

            Session           = session;
            SpellerController = spellerController;
            Experiment        = (SpellerExperiment)session.Experiment;

            Result         = CreateResult(session);
            Result.Buttons = Experiment.Config.Test.Layout.Keys.Select(key => new SpellerExperiment.Result.Button(key)).ToArray();
            Result.Trials  = new LinkedList <SpellerExperiment.Result.Trial>();

            Markable   = session.StreamerCollection.FindFirstOrDefault <IMarkable>();
            LayoutSize = Experiment.Config.Test.Layout.GetLayoutSize(Experiment.Config.Gui.ColumnsOverridden);
            var maxButtonNum = LayoutSize[0] * LayoutSize[1];

            Buttons = new UIButton[maxButtonNum];
            var index       = 0;
            var scaleFactor = (float)GraphicsUtils.Scale;

            foreach (var key in Experiment.Config.Test.Layout.Keys)
            {
                if (index > maxButtonNum)
                {
                    break;
                }
                var button = new UIButton(index, index / LayoutSize[1], index % LayoutSize[1], key,
                                          (float)Experiment.Config.Gui.ButtonBorder.Width * scaleFactor,
                                          Experiment.Config.Gui.ButtonFixationPoint.Size * scaleFactor,
                                          Experiment.Config.Gui.ButtonFlashingMargins * (Experiment.Config.Gui.ButtonFlashingMargins.Relative ? 1 : scaleFactor))
                {
                    State = -1
                };
                var size = Experiment.Config.Gui.ButtonSize * scaleFactor;
                button.UpdateGeometries(new RawVector2(), new RawVector2(size, size));
                Buttons[index++] = button;
            }
            ButtonMatrix       = Buttons.Reshape(LayoutSize[0], LayoutSize[1], MatrixOrder.CRowMajor);
            ButtonCenterMatrix = new RawVector2[LayoutSize[0], LayoutSize[1]];
            Char2ButtonDict    = new Dictionary <char, UIButton>();
            foreach (var button in Buttons)
            {
                if (button?.Key?.InputChar != null)
                {
                    var ch = button.Key.InputChar.Value;
                    if (Char2ButtonDict.ContainsKey(ch))
                    {
                        throw new Exception($"duplicated char: '{ch}'");
                    }
                    Char2ButtonDict[button.Key.InputChar.Value] = button;
                }
            }

            StageProgram = Experiment.CreateStagedProgram(session, spellerController);
            StageProgram.StageChanged += (sender, e) =>
            {
                if (e.IsEndReached)
                {
                    this.ControlInvoke(self => Stop());
                }
                else
                {
                    OnNextStage(e);
                }
            };

            GazePointHandler = new GazePointHandler();
            if (session.StreamerCollection.TryFindFirst <GazePointStreamer>(out var gazePointStreamer))
            {
                gazePointStreamer.Attach(GazePointHandler);
                //                        if (_experiment.Config.Test.TrialCancellable)
                //                              TODO: blink to cancel
                if (gazePointStreamer.EyeTracker.GetType() != typeof(CursorTracker))
                {
                    this.HideCursorInside();
                }
            }
            else
            {
                throw new StateException("gaze point streamer not found for GazePointController");
            }


            if (Experiment.Config.Test.DynamicInterval)
            {
                if (Experiment.Config.Test.ActivationMode == SpellerActivationMode.Single)
                {
                    TrialTrigger = new ButtonInsideTrialTrigger(session.Clock, SpellerController, GazePointHandler, Experiment.Config.Test, FindButtonAt);
                }
                else
                {
                    TrialTrigger = new DwellTrialTrigger(session.Clock, SpellerController, GazePointHandler, Experiment.Config.Test);
                }
            }

            HintText = Experiment.Config.Test.HintText;

            /* Type conversion */
            BackgroundColor          = Experiment.Config.Gui.BackgroundColor.ToSdColor().ToSdx();
            ForegroundColor          = Experiment.Config.Gui.ForegroundColor.ToSdColor().ToSdx();
            CorrectTextColor         = Experiment.Config.Gui.CorrectTextColor.ToSdColor().ToSdx();
            WrongTextColor           = Experiment.Config.Gui.WrongTextColor.ToSdColor().ToSdx();
            ButtonBorderColor        = Experiment.Config.Gui.ButtonBorder.Color.ToSdColor().ToSdx();
            ButtonNormalColor        = Experiment.Config.Gui.ButtonNormalColor.ToSdColor().ToSdx();
            ButtonFlashingColor      = Experiment.Config.Gui.ButtonFlashingColor.ToSdColor().ToSdx();
            ButtonHintColor          = Experiment.Config.Gui.ButtonHintColor.ToSdColor().ToSdx();
            ButtonFixationPointColor = Experiment.Config.Gui.ButtonFixationPoint.Color.ToSdColor().ToSdx();
        }