Exemplo n.º 1
0
        private IEnumerator <int> PressedState()
        {
            TryRunAnimation("Press");
            var wasMouseOver = true;

            while (true)
            {
                if (clickGesture.WasRecognized())
                {
                    while (IsRunning)
                    {
                        yield return(0);
                    }
                    Clicked?.Invoke();
                    // buz: don't play release animation
                    // if button's parent became invisible due to
                    // button press (or it will be played when
                    // parent is visible again)
                    if (!GloballyVisible)
                    {
#if WIN || MAC
                        SetState(HoveredState());
#else
                        SetState(NormalState());
#endif
                    }
                    else
                    {
                        SetState(ReleaseState());
                    }
                }
                else if (clickGesture.WasCanceled())
                {
                    if (CurrentAnimation == "Press")
                    {
                        TryRunAnimation("Release");
                        while (IsRunning)
                        {
                            yield return(0);
                        }
                    }
                    SetState(NormalState());
                }
                var mouseOver = IsMouseOverThisOrDescendant();
                if (wasMouseOver && !mouseOver)
                {
                    TryRunAnimation("Release");
                }
                else if (!wasMouseOver && mouseOver)
                {
                    TryRunAnimation("Press");
                }
                wasMouseOver = mouseOver;
                yield return(0);
            }
        }
Exemplo n.º 2
0
        private IEnumerator <object> HandleInputTask()
        {
            bool wasFocused = false;

            var rightClickGesture  = new ClickGesture(1);
            var clickGesture       = new ClickGesture();
            var doubleClickGesture = new DoubleClickGesture();
            var dragGesture        = new DragGesture(0, DragDirection.Any, dragThreshold: EditorParams.MouseSelectionThreshold);

            ClickableWidget.Gestures.Add(rightClickGesture);
            ClickableWidget.Gestures.Add(clickGesture);
            ClickableWidget.Gestures.Add(doubleClickGesture);
            ClickableWidget.Gestures.Add(dragGesture);

            while (true)
            {
                if (EditorParams.SelectAllOnFocus && !wasFocused && FocusableWidget.IsFocused())
                {
                    SelectAll();
                    CaretPos.TextPos = TextLength;
                }
                if (FocusableWidget.IsFocused())
                {
                    HandleKeys();
                    HandleTextInput();
                }
                if (clickGesture.WasRecognized())
                {
                    if (!FocusableWidget.IsFocused())
                    {
                        if (EditorParams.SelectAllOnFocus)
                        {
                            SelectAll();
                        }
                    }
                    else
                    {
                        HideSelection();
                    }
                    FocusableWidget.SetFocus();
                    CaretPos.WorldPos = DisplayWidget.LocalMousePosition();
                }
                if (doubleClickGesture.WasRecognized())
                {
                    if (IsTextReadable)
                    {
                        SelectWord();
                    }
                    else
                    {
                        SelectAll();
                    }
                }
                if (rightClickGesture.WasRecognized())
                {
                    FocusableWidget.SetFocus();
                    ShowContextMenu(true);
                }
                if (dragGesture.WasRecognized())
                {
                    FocusableWidget.SetFocus();
                    CaretPos.WorldPos = DisplayWidget.ToLocalMousePosition(dragGesture.MousePressPosition);
                    HideSelection();
                    EnsureSelection();
                    SelectionStart.AssignFrom(CaretPos);
                }
                else if (dragGesture.WasChanged())
                {
                    CaretPos.WorldPos = DisplayWidget.LocalMousePosition();
                    EnsureSelection();
                    SelectionEnd.AssignFrom(CaretPos);
                }
                Text.SyncCaretPosition();
                AdjustSizeAndScrollToCaret();
                var isFocused = CaretPos.IsVisible = FocusableWidget.IsFocused();
                if (wasFocused && !isFocused)
                {
                    HideSelection();
                    if (History.CanUndo())
                    {
                        History.Clear();
                        Text.Submit();
                    }
                }
                wasFocused = isFocused;
                yield return(null);
            }
        }
Exemplo n.º 3
0
 public override bool WasClicked() => clickGesture?.WasRecognized() ?? false;