Beispiel #1
0
    private void SetFocus(FocusState contextual)
    {
        if (CurrentFocus == contextual)
        {
            CurrentFocus = FocusState.None;
        }
        else
        {
            CurrentFocus = contextual;
        }

        SetTerminalState(CurrentFocus);
    }
        public FrequencyControl()
        {
            mDefIncr = 1000;
            mMaxDigits = 8;
            mIsEditing = false;
            mFocusState = FocusState.None;
            mFocusBackColor = Color.DarkGray;
            mEditColor = Color.White;

            mBlinkTimer = new Timer();
            mBlinkTimer.Tick += OnBlinkTick;

            SetStyle(ControlStyles.ResizeRedraw | ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint |
                ControlStyles.UserPaint | ControlStyles.Selectable | ControlStyles.StandardClick, true);

            Value = 0;
            BackColor = Color.Black;
            ForeColor = Color.Yellow;
        }
        private bool CheckListBoxAndItemsFocusState(FocusState focusState)
        {
            var listBoxIsUnfocused = _resultsListBox.FocusState == focusState;
            var allItemsAreUnfocused = _resultsListBox.Items
                .Select(o => _resultsListBox.ContainerFromItem(o))
                .Cast<ListBoxItem>()
                .Where(x => x != null)
                .All(i => i.FocusState == focusState);

            return allItemsAreUnfocused && listBoxIsUnfocused;
        }
Beispiel #4
0
 internal virtual void TryFocusCell(DataGridCellInfo cellInfo, FocusState state)
 {
 }
Beispiel #5
0
    private void UpdateFocus()
    {
        if (SquareState == FocusState.Putdown)
        {
            return;
        }
        //use center of screen for focusing
        Vector3 center = new Vector3(Screen.width / 2, Screen.height / 2, findingSquareDist);

#if UNITY_EDITOR
        Ray        ray = Camera.main.ScreenPointToRay(center);
        RaycastHit hit;

        //we'll try to hit one of the plane collider gameobjects that were generated by the plugin
        //effectively similar to calling HitTest with ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent
        if (Physics.Raycast(ray, out hit, maxRayDistance, collisionLayerMask))
        {
            //we're going to get the position from the contact point
            foundSquare.transform.position = hit.point;
            //Debug.Log(string.Format("x:{0:0.######} y:{1:0.######} z:{2:0.######}", foundSquare.transform.position.x, foundSquare.transform.position.y, foundSquare.transform.position.z));

            //and the rotation from the transform of the plane collider
            SquareState = FocusState.Found;
            foundSquare.transform.rotation = hit.transform.rotation;
            if (!m_ShowedButton)
            {
                Anywhere.NotifCenter.GetNotice.PostDispatchEvent(Anywhere.NotifEventKey.UI_SHOWCALLBTN);
                m_ShowedButton = true;
            }
            return;
        }

        //#endif
#else
        var     screenPosition = Camera.main.ScreenToViewportPoint(center);
        ARPoint point          = new ARPoint
        {
            x = screenPosition.x,
            y = screenPosition.y
        };

        // prioritize reults types
        ARHitTestResultType[] resultTypes =
        {
            ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent,
            // if you want to use infinite planes use this:
            //ARHitTestResultType.ARHitTestResultTypeExistingPlane,
            //ARHitTestResultType.ARHitTestResultTypeHorizontalPlane,
            //ARHitTestResultType.ARHitTestResultTypeFeaturePoint
        };

        foreach (ARHitTestResultType resultType in resultTypes)
        {
            if (HitTestWithResultType(point, resultType))
            {
                SquareState = FocusState.Found;
                if (!m_ShowedButton)
                {
                    m_ShowedButton = true;
                    Anywhere.NotifCenter.GetNotice.PostDispatchEvent(Anywhere.NotifEventKey.UI_SHOWCALLBTN);
                }
                return;
            }
        }
#endif
        //if you got here, we have not found a plane, so if camera is facing below horizon, display the focus "finding" square
        if (trackingInitialized)
        {
            SquareState    = FocusState.Finding;
            m_ShowedButton = false;
            Anywhere.NotifCenter.GetNotice.PostDispatchEvent(Anywhere.NotifEventKey.UI_HIDECALLBTN);
            //check camera forward is facing downward
            if (Vector3.Dot(Camera.main.transform.forward, Vector3.down) > 0)
            {
                //position the focus finding square a distance from camera and facing up
                findingSquare.transform.position = Camera.main.ScreenToWorldPoint(center);

                //vector from camera to focussquare
                Vector3 vecToCamera = findingSquare.transform.position - Camera.main.transform.position;

                //find vector that is orthogonal to camera vector and up vector
                Vector3 vecOrthogonal = Vector3.Cross(vecToCamera, Vector3.up);

                //find vector orthogonal to both above and up vector to find the forward vector in basis function
                Vector3 vecForward = Vector3.Cross(vecOrthogonal, Vector3.up);


                findingSquare.transform.rotation = Quaternion.LookRotation(vecForward, Vector3.up);
            }
            else
            {
                //we will not display finding square if camera is not facing below horizon
                findingSquare.SetActive(false);
            }
        }
    }
Beispiel #6
0
 internal virtual void UpdateFocusState(FocusState focusState)
 {
     FocusState = focusState;
 }
Beispiel #7
0
 // Use this for initialization
 void Start()
 {
     TargetState         = FocusState.Initializing;
     trackingInitialized = true;
 }
Beispiel #8
0
 public void SearchInputFocus(FocusState state)
 {
     SearchInput.Focus(state);
 }
Beispiel #9
0
        private static bool UpdateFocus(DependencyObject newFocus, FocusNavigationDirection focusNavigationDirection, FocusState focusState)
        {
            // TODO: check AllowFocusOnInteraction
            var oldFocusedElement = GetFocusedElement();

            if (_log.Value.IsEnabled(LogLevel.Debug))
            {
                _log.Value.LogDebug($"{nameof(UpdateFocus)}()- oldFocus={oldFocusedElement}, newFocus={newFocus}, oldFocus.FocusState={(oldFocusedElement as Control)?.FocusState}, focusState={focusState}");
            }

            if (newFocus == oldFocusedElement)
            {
                if (newFocus is Control newFocusAsControl && newFocusAsControl.FocusState != focusState)
                {
                    // We do not raise GettingFocus here since the OldFocusedElement and NewFocusedElement
                    // would be the same element.
                    RaiseGotFocusEvent(oldFocusedElement);

                    // Make sure the FocusState is up-to-date.
                    newFocusAsControl.UpdateFocusState(focusState);
                }
                // No change in focus element - can skip the rest of this method.
                return(true);
            }

            //TODO: RaiseAndProcessGettingAndLosingFocusEvents

            (oldFocusedElement as Control)?.UpdateFocusState(FocusState.Unfocused);             // Set previous unfocused

            // Update the focused control
            SetFocusedElement(newFocus);

            (newFocus as Control)?.UpdateFocusState(focusState);

            FocusNative(newFocus as Control);

            if (oldFocusedElement != null)
            {
                RaiseLostFocusEvent(oldFocusedElement);
            }

            if (newFocus != null)
            {
                RaiseGotFocusEvent(newFocus);
            }

            return(true);
        }
Beispiel #10
0
 protected override void OnFocusStateChanged(FocusState oldValue, FocusState newValue)
 => OnFocusStateChanged(oldValue, newValue, initial: false);
Beispiel #11
0
        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            char ch = e.KeyChar;

            switch (ch)
            {
            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
            {
                switch (mFocusState)
                {
                case FocusState.Char:
                case FocusState.Insert:
                {
                    string text = Text;
                    int    pos  = text.Length - Math.Min(Math.Max(mFocusPos, 0), text.Length - 1) - 1;
                    text = text.Substring(0, pos) + ch + text.Substring(pos + (mFocusState == FocusState.Char ? 1 : 0));
                    if (text.Length <= mMaxDigits)
                    {
                        try
                        {
                            Text = text;
                        }
                        catch (ArgumentException)
                        {
                            Editing = true;
                            Text    = text;
                        }
                    }
                    Invalidate();
                    e.Handled = true;
                }
                break;

                case FocusState.General:
                    Editing     = true;
                    Text        = ch.ToString();
                    mFocusState = FocusState.Insert;
                    mFocusPos   = -1;
                    Invalidate();
                    e.Handled = true;
                    break;
                }
            }
            break;

            case (char)8:     // backspace
            {
                switch (mFocusState)
                {
                case FocusState.Char:
                case FocusState.Insert:
                {
                    string text = Text;
                    int    pos  = text.Length - Math.Min(Math.Max(mFocusPos, 0), text.Length - 1) - 1;
                    text = text.Substring(0, pos - 1) + text.Substring(pos);
                    try
                    {
                        Text = text;
                    }
                    catch (ArgumentException)
                    {
                        Editing = true;
                        Text    = text;
                    }
                    mFocusPos   = text.Length - pos;
                    mFocusState = FocusState.Insert;
                    Invalidate();
                    e.Handled = true;
                }
                break;

                case FocusState.General:
                    Editing     = true;
                    Text        = "";
                    mFocusState = FocusState.Insert;
                    mFocusPos   = -1;
                    Invalidate();
                    e.Handled = true;
                    break;
                }
            }
            break;

            case (char)13:     // enter
                if (Editing)
                {
                    try
                    {
                        Editing = false;
                    }
                    catch (ArgumentException) { }
                    e.Handled = true;
                }
                break;

            case (char)27:     // escape
                if (Editing)
                {
                    Text      = mValue.ToString();
                    Editing   = false;
                    e.Handled = true;
                }
                break;
            }

            base.OnKeyPress(e);
        }
Beispiel #12
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            int len = Text.Length;

            switch (e.KeyData)
            {
            case Keys.Insert:
                if (mFocusState == FocusState.Char)
                {
                    mFocusState = FocusState.Insert;
                    Invalidate();
                    CursorOn();
                    e.Handled = true;
                }
                else if (mFocusState == FocusState.Insert)
                {
                    mFocusState = FocusState.Char;
                    if (mFocusPos < 0)
                    {
                        mFocusPos = 0;
                    }
                    else if (mFocusPos > len)
                    {
                        mFocusPos = len;
                    }
                    Invalidate();
                    CursorOn();
                    e.Handled = true;
                }
                break;

            case Keys.Left:
                if (mFocusState != FocusState.Char && mFocusState != FocusState.Insert)
                {
                    break;
                }
                if (mFocusPos < len - 1)
                {
                    mFocusPos++;
                }
                Invalidate();
                CursorOn();
                e.Handled = true;
                break;

            case Keys.Right:
                if (mFocusState == FocusState.Char)
                {
                    if (mFocusPos > 0)
                    {
                        mFocusPos--;
                    }
                }
                else if (mFocusState == FocusState.Insert)
                {
                    if (mFocusPos >= 0)
                    {
                        mFocusPos--;
                    }
                }
                else
                {
                    break;
                }
                Invalidate();
                CursorOn();
                e.Handled = true;
                break;

            case Keys.Up:
            {
                long off = mDefIncr;
                if (mFocusState == FocusState.Char)
                {
                    int pos = Math.Min(Math.Max(mFocusPos, 0), len - 1);
                    off = (long)Math.Pow(10, pos);
                }
                try
                {
                    Value += off;
                }
                catch (ArgumentException) {}
                Invalidate();
                CursorOn();
                e.Handled = true;
            }
            break;

            case Keys.Down:
            {
                long off = mDefIncr;
                if (mFocusState == FocusState.Char)
                {
                    int pos = Math.Min(Math.Max(mFocusPos, 0), len - 1);
                    off = (long)Math.Pow(10, pos);
                }
                try
                {
                    Value -= off;
                }
                catch (ArgumentException) {}
                Invalidate();
                CursorOn();
                e.Handled = true;
            }
            break;

            case Keys.Delete:
            {
                switch (mFocusState)
                {
                case FocusState.Char:
                case FocusState.Insert:
                    if (mFocusPos >= 0)
                    {
                        string text = Text;
                        int    pos  = text.Length - Math.Min(mFocusPos, text.Length - 1) - 1;
                        text = text.Substring(0, pos) + text.Substring(pos + 1);
                        try
                        {
                            Text = text;
                        }
                        catch (ArgumentException)
                        {
                            Editing = true;
                            Text    = text;
                        }
                        Invalidate();
                        mFocusState = FocusState.Insert;
                        mFocusPos   = text.Length - pos - 1;
                        e.Handled   = true;
                    }
                    break;

                case FocusState.General:
                    Editing     = true;
                    Text        = "";
                    mFocusState = FocusState.Insert;
                    mFocusPos   = -1;
                    Invalidate();
                    e.Handled = true;
                    break;
                }
            }
            break;
            }
            base.OnKeyDown(e);
        }
Beispiel #13
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;
            Brush    b = new SolidBrush(mIsEditing ? EditColor : ForeColor);

            int        blinkWidth = Math.Max(2, SystemInformation.CaretWidth);
            FocusState focusState = Focused ? mFocusState : FocusState.None;
            string     text       = Text;
            int        focusPos   = Math.Min(text.Length - 1, mFocusPos);

            StringFormat sf = (StringFormat)StringFormat.GenericTypographic.Clone();

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;

            PointF lastPos = new PointF(ClientRectangle.Right - Margin.Right,
                                        (ClientRectangle.Height - Margin.Vertical + mMajorSize.Height) / 2 + ClientRectangle.Top + Margin.Top);

            if (mBlinkOn && focusState == FocusState.Insert && focusPos < 0)
            {
                RectangleF focusRect = new RectangleF(lastPos.X - 1.5f, lastPos.Y - mMinorFont.Height + 4,
                                                      blinkWidth, mMinorFont.Height - 8);
                g.FillRectangle(new SolidBrush(mEditColor), focusRect);
            }

            Font  thisFont = mMinorFont;
            SizeF thisSize = mMinorSize;

            for (int idx = text.Length - 1, cnt = 0; idx >= 0; idx--, cnt++)
            {
                if (cnt == 3)
                {
                    thisFont = Font;
                    thisSize = mMajorSize;
                }
                RectangleF thisRect = new RectangleF(lastPos.X - thisSize.Width, lastPos.Y - thisSize.Height,
                                                     thisSize.Width, thisSize.Height);
                g.DrawString(text.Substring(idx, 1), thisFont, b, thisRect, sf);

                if (mBlinkOn && focusPos == cnt)
                {
                    switch (focusState)
                    {
                    case FocusState.Char:
                    {
                        RectangleF focusRect = new RectangleF(thisRect.X, thisRect.Bottom - 5, thisRect.Width, blinkWidth);
                        g.FillRectangle(new SolidBrush(mEditColor), focusRect);
                    }
                    break;

                    case FocusState.Insert:
                    {
                        RectangleF focusRect = new RectangleF(thisRect.X - 1.5f, thisRect.Y + 4, blinkWidth, thisRect.Height - 8);
                        g.FillRectangle(new SolidBrush(mEditColor), focusRect);
                    }
                    break;
                    }
                }

                lastPos.X = thisRect.Left;
                if (cnt % 3 == 2)
                {
                    lastPos.X -= mMajorSize.Width / 3;
                }
            }
        }
 // TODO: remove this
 private void CodeEditBox_FocusChanged(object sender, RoutedEventArgs e)
 {
     OrigFocus.Text = FocusState.ToString();
 }
Beispiel #15
0
 internal bool FocusImpl(FocusState focusState) =>
 FocusWithDirection(focusState, FocusNavigationDirection.None);
Beispiel #16
0
    private void SetTerminalState(FocusState st)
    {
        BlurEffect.enabled = st != FocusState.None;
        TerminalCamera.enabled = st != FocusState.None;

        if (st == FocusState.Terminal)
        {
            Term.transform.parent.gameObject.SetActive(true);
            Term.ShowStatus();
        }
        else if (st == FocusState.Generator)
        {
            Gen.transform.parent.gameObject.SetActive(true);
            Gen.PrintStatus(TerminalManager.GeneratorName);
        }
        else
        {
            Gen.transform.parent.gameObject.SetActive(false);
            Term.transform.parent.gameObject.SetActive(false);
            Term.StopStatus();
        }
    }
 /// <summary>
 /// Initializes a new instance of the <see cref="FocusStateChangedEventArgs"/> class.
 /// </summary>
 /// <param name="focusState">Focus state.</param>
 /// <param name="continuous">Whether the currnet event is raised by the continuous auto-focus operation.</param>
 public FocusStateChangedEventArgs(FocusState focusState, bool continuous)
     : this(focusState, continuous, null)
 {
     // Do nothing.
 }
Beispiel #18
0
        internal static bool SetFocusedElement(DependencyObject newFocus, FocusNavigationDirection focusNavigationDirection, FocusState focusState)
        {
            var control = newFocus as Control;             // For now only called for Control

            if (control != null && !control.IsFocusable)
            {
                control = control.FindFirstChild <Control>(c => c.IsFocusable);
            }

            if (control == null)
            {
                return(false);
            }

            return(UpdateFocus(control, focusNavigationDirection, focusState));
        }
    void OnLostFocus()
    {
        _editSelectRenderer = null;
        _focusState = FocusState.None;

        _isFocus = false;
    }
 private void MainWindow_Deactivated(object sender, EventArgs e)
 {
     focusstate = FocusState.UNFOCUSED;
 }
        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            char ch = e.KeyChar;
            switch (ch)
            {
                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                    {
                        switch (mFocusState)
                        {
                            case FocusState.Char:
                            case FocusState.Insert:
                                {
                                    string text = Text;
                                    int pos = text.Length - Math.Min(Math.Max(mFocusPos, 0), text.Length-1) - 1;
                                    text = text.Substring(0, pos) + ch + text.Substring(pos + (mFocusState == FocusState.Char ? 1 : 0));
                                    if (text.Length <= mMaxDigits)
                                    {
                                        try
                                        {
                                            Text = text;
                                        }
                                        catch (ArgumentException)
                                        {
                                            Editing = true;
                                            Text = text;
                                        }
                                    }
                                    Invalidate();
                                    e.Handled = true;
                                }
                                break;
                            case FocusState.General:
                                Editing = true;
                                Text = ch.ToString();
                                mFocusState = FocusState.Insert;
                                mFocusPos = -1;
                                Invalidate();
                                e.Handled = true;
                                break;
                        }
                    }
                    break;

                case (char)8: // backspace
                    {
                        switch (mFocusState)
                        {
                            case FocusState.Char:
                            case FocusState.Insert:
                                {
                                    string text = Text;
                                    int pos = text.Length - Math.Min(Math.Max(mFocusPos, 0), text.Length - 1) - 1;
                                    text = text.Substring(0, pos - 1) + text.Substring(pos);
                                    try
                                    {
                                        Text = text;
                                    }
                                    catch (ArgumentException)
                                    {
                                        Editing = true;
                                        Text = text;
                                    }
                                    mFocusPos = text.Length - pos;
                                    mFocusState = FocusState.Insert;
                                    Invalidate();
                                    e.Handled = true;
                                }
                                break;
                            case FocusState.General:
                                Editing = true;
                                Text = "";
                                mFocusState = FocusState.Insert;
                                mFocusPos = -1;
                                Invalidate();
                                e.Handled = true;
                                break;
                        }
                    }
                    break;

                case (char)13: // enter
                    if (Editing)
                    {
                        try
                        {
                            Editing = false;
                        }
                        catch (ArgumentException) { }
                        e.Handled = true;
                    }
                    break;

                case (char)27: // escape
                    if (Editing)
                    {
                        Text = mValue.ToString();
                        Editing = false;
                        e.Handled = true;
                    }
                    break;

            }

            base.OnKeyPress(e);
        }
    void Update()
    {
        //use center of screen for focusing
        Vector3 center = new Vector3(Screen.width / 2, Screen.height / 2, findingSquareDist);

        #if UNITY_EDITOR
        Ray        ray = Camera.main.ScreenPointToRay(center);
        RaycastHit hit;

        //we'll try to hit one of the plane collider gameobjects that were generated by the plugin
        //effectively similar to calling HitTest with ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent
        if (Physics.Raycast(ray, out hit, maxRayDistance, collisionLayerMask))
        {
            //we're going to get the position from the contact point
            foundSquare.transform.position = hit.point;
            //Debug.Log (string.Format ("x:{0:0.######} y:{1:0.######} z:{2:0.######}", foundSquare.transform.position.x, foundSquare.transform.position.y, foundSquare.transform.position.z));

            //and the rotation from the transform of the plane collider
            SquareState = FocusState.Found;
            foundSquare.transform.rotation = hit.transform.rotation;
            return;
        }
        #else
        var     screenPosition = Camera.main.ScreenToViewportPoint(center);
        ARPoint point          = new ARPoint {
            x = screenPosition.x,
            y = screenPosition.y
        };

        // prioritize reults types
        var resultTypes = new List <ARHitTestResultType>();
        resultTypes.Add(ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent);
        if (useProjectedPlanes)
        {
            var otherTypes = new List <ARHitTestResultType>();
            otherTypes.Add(ARHitTestResultType.ARHitTestResultTypeExistingPlane);
            otherTypes.Add(ARHitTestResultType.ARHitTestResultTypeHorizontalPlane);
            otherTypes.Add(ARHitTestResultType.ARHitTestResultTypeFeaturePoint);
            resultTypes.AddRange(otherTypes);
        }

        foreach (ARHitTestResultType resultType in resultTypes)
        {
            if (HitTestWithResultType(point, resultType))
            {
                SquareState = FocusState.Found;
                return;
            }
        }
        #endif

        //if you got here, we have not found a plane, so if camera is facing below horizon, display the focus "finding" square
        if (trackingInitialized)
        {
            SquareState = FocusState.Finding;

            //check camera forward is facing downward
            if (Vector3.Dot(Camera.main.transform.forward, Vector3.down) > 0)
            {
                //position the focus finding square a distance from camera and facing up
                var pos = Camera.main.ScreenToWorldPoint(center);
                pos.y += 0.01f;                 // move the square up off the plane just a little bit
                findingSquare.transform.position = pos;

                //vector from camera to focussquare
                Vector3 vecToCamera = findingSquare.transform.position - Camera.main.transform.position;

                //find vector that is orthogonal to camera vector and up vector
                Vector3 vecOrthogonal = Vector3.Cross(vecToCamera, Vector3.up);

                //find vector orthogonal to both above and up vector to find the forward vector in basis function
                Vector3 vecForward = Vector3.Cross(vecOrthogonal, Vector3.up);

                findingSquare.transform.rotation = Quaternion.LookRotation(vecForward, Vector3.up);
            }
            else
            {
                //we will not display finding square if camera is not facing below horizon
                findingSquare.SetActive(false);
            }
        }
    }
Beispiel #23
0
 protected virtual bool RequestFocus(FocusState state)
 {
     return(FocusManager.SetFocusedElement(this, FocusNavigationDirection.None, state));
 }
 // Use this for initialization
 void Start()
 {
     squareState = FocusState.Initializing;
 }
Beispiel #25
0
 partial void UpdateFocusStatePartial(FocusState focusState);
Beispiel #26
0
 // Use this for initialization
 void Start()
 {
     SquareState         = FocusState.Initializing;
     trackingInitialized = true;
 }
Beispiel #27
0
 public void SearchInputFocus(FocusState state)
 {
     SearchInput.Focus(state);
 }
Beispiel #28
0
 partial void OnFocusStateChangedPartial(FocusState focusState) => TextBoxView?.OnFocusStateChanged(focusState);
    void DragProcess()
    {
        if (_isDragLeft && Event.current.type == EventType.Repaint)
        {
            float dstY = GetRendererInfo(_focusSelectRenderer).leftEventRect.y - _originShiftPos;
            if (dstY != _scrollPosition.y)
            {
                _scrollPosition = new Vector2(_scrollPosition.x,
                                              Mathf.Lerp(_scrollPosition.y, GetRendererInfo(_focusSelectRenderer).leftEventRect.y - _originShiftPos, Mathf.Clamp01((Time.realtimeSinceStartup - _guiTime) * 1.0f))
                                              );
                Repaint();
            }
        }

        if (Event.current.type == EventType.MouseDrag)
        {
            if (Event.current.button == 0 && _focusSelectRenderer != null)
            {
                if (_focusState == FocusState.Right)
                {
                    _isDragRight = true;
					SortingRendererInfo tempInfo = GetRendererInfo(_focusSelectRenderer);
					if (tempInfo != null)
					{
                    	DragAndDrop.activeControlID = GetRendererInfo(_focusSelectRenderer).controlID;
                     	DragAndDrop.StartDrag("Dragging Renderers");
					}
                }
                else if (_focusState == FocusState.Left)
                {
                    _isDragLeft = true;
                    Vector2 mousePos = GUIUtility.GUIToScreenPoint(Event.current.mousePosition);
                    int diff = (int)(mousePos.y - _originMousePos.y) / 22;
                    int diffOrder = _originOrder + diff * _stride - _focusSelectRenderer.sortingOrder;
                    if (diffOrder != 0)
                    {
                        foreach (Renderer renderer in _selectRenderer)
                        {
                            if (renderer != null)
                            {
                                Undo.RecordObject(renderer, "Sorting Order Change");
								renderer.sortingOrder += diffOrder;
								renderer.enabled = false;
								renderer.enabled = true;

							}
						}

						SceneView.RepaintAll();
                        _guiTime = Time.realtimeSinceStartup;
                    }
                }

            }
            Event.current.Use();
        }
        else if (Event.current.type == EventType.DragUpdated && _isDragRight)
        {
            SortingLayerInfo dropLayer = GetDropLayer(Event.current.mousePosition + _scrollPosition + new Vector2(0, -24f));
            if (dropLayer == null)
                DragAndDrop.visualMode = DragAndDropVisualMode.Move;
            else
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

            Event.current.Use();
        }
        else if (Event.current.type == EventType.DragPerform && _isDragRight)
        {
            DragAndDrop.AcceptDrag();

            SortingLayerInfo dropLayer = GetDropLayer(Event.current.mousePosition + _scrollPosition + new Vector2(0, -24f));
            if (dropLayer != null)
            {
                foreach (Renderer renderer in _selectRenderer)
                {
                    if (renderer != null)
                    {
                        Undo.RecordObject(renderer, "Sorting Layer Change");
                        renderer.sortingLayerName = dropLayer.name;
                    }
                }
                
            }

            _isDragRight = false;
			_focusState = FocusState.None;
            DragAndDrop.activeControlID = 0;
            GUIUtility.hotControl = 0;
            GUIUtility.keyboardControl = 0;

            Event.current.Use();
        }
        else if (Event.current.rawType == EventType.DragPerform && _isDragLeft)
        {
            _isDragRight = false;
            _isDragLeft = false;
			_focusState = FocusState.None;
            GUIUtility.hotControl = 0;
            GUIUtility.keyboardControl = 0;
        }
        
    }
Beispiel #30
0
 /// <summary>
 /// Attempts to set the focus on the control.
 /// </summary>
 /// <param name="value">Specifies how focus was set, as a value of the enumeration.</param>
 /// <returns>True if focus was set to the control, or focus was already on the control. False if the control is not focusable.</returns>
 public new bool Focus(FocusState value) => FocusImpl(value);
Beispiel #31
0
        private protected override void ChangeVisualState(bool useTransitions)
        {
            bool       isOn       = false;
            bool       isEnabled  = false;
            FocusState focusState = FocusState.Unfocused;

            base.ChangeVisualState(useTransitions);

            isEnabled  = IsEnabled;
            focusState = FocusState;

            if (!isEnabled)
            {
                GoToState(useTransitions, "Disabled");
            }
            else if (_isDragging)
            {
                GoToState(useTransitions, "Pressed");
            }

            else if (_isPointerOver)
            {
                GoToState(useTransitions, "PointerOver");
            }
            else
            {
                GoToState(useTransitions, "Normal");
            }

            if (focusState != FocusState.Unfocused && isEnabled)
            {
                if (focusState == FocusState.Pointer)
                {
                    GoToState(useTransitions, "PointerFocused");
                }
                else
                {
                    GoToState(useTransitions, "Focused");
                }
            }
            else
            {
                GoToState(useTransitions, "Unfocused");
            }


            if (_isDragging)
            {
                GoToState(useTransitions, "Dragging");
            }
            else
            {
                isOn = IsOn;
                GoToState(useTransitions, isOn ? "On" : "Off");
                GoToState(useTransitions, isOn ? "OnContent" : "OffContent");
                // TODO Uno specific: We must force the knob to position, because
                // we don't yet support the transitions which do this automatically
                // in XAML template.
                ForceSwitchKnobEndPosition();
            }
        }
Beispiel #32
0
 public static void OnFocusChanged(View control, FocusState state)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FocusStateChangedEventArgs"/> class.
 /// </summary>
 /// <param name="focusState">Focus state.</param>
 public FocusStateChangedEventArgs(FocusState focusState)
     : this(focusState, false, null)
 {
     // Do nothing.
 }
Beispiel #34
0
 protected override bool RequestFocus(FocusState state) => FocusTextView();
 /// <summary>
 /// Initializes a new instance of the <see cref="FocusStateChangedEventArgs"/> class.
 /// </summary>
 /// <param name="focusState">Focus state.</param>
 /// <param name="continuous">Whether the currnet event is raised by the continuous auto-focus operation.</param>
 /// <param name="focusPoint">Point of interest.</param>
 public FocusStateChangedEventArgs(FocusState focusState, bool continuous, Point? focusPoint)
 {
     this.FocusState = focusState;
     this.Continuous = continuous;
     this.FocusPoint = focusPoint;
 }
Beispiel #36
0
 partial void OnFocusStateChangedPartial(FocusState focusState);
    void OnEnable()
    {
        EditorApplication.playmodeStateChanged += SerializeProcess;

        // Initialize sort data.
        _layerList = new List<SortingLayerInfo>();

        // Initialize GUI data.
        
        _isFocus = false;

        if (_showSortingLayerContent == null)
        {
            _showSortingLayerContent = new Dictionary<string, bool>();
            if (_showSortingLayerContentName.Length > 0)
            {
                for (int index = 0; index < _showSortingLayerContentName.Length; index++)
                    _showSortingLayerContent[_showSortingLayerContentName[index]] = _showSortingLayerContentBoolean[index];
            }
        }

        if (_selectRenderer == null)
        {
            _selectRenderer = new HashSet<Renderer>();
            if (_selectRendererArray.Length > 0)
            {
                for (int index = 0; index < _selectRendererArray.Length; index++)
                    _selectRenderer.Add(_selectRendererArray[index]);
            }
        }

        _isDragRight = false;
        _isDragLeft = false;
        _focusState = FocusState.None;
        _originMousePos = Vector2.zero;
        _originShiftPos = 0;
        _originOrder = 0;

        _guiTime = 0;
        _keyDampState = KeyBoardDamp.None;

        _warnContent = new GUIContent(TextureResources.warnIcon, "Unknowable order in same value.");
    }
Beispiel #38
0
 partial void OnFocusStateChangedPartial(FocusState oldValue, FocusState newValue);
    /// <summary>
    /// Process the mouse button events.
    /// </summary>
    void ClickProcess()
    {
        if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
        {
            DragAndDrop.PrepareStartDrag();
            _editSelectRenderer = null;

            KeyValuePair<SortingRendererInfo, FocusState> result = GetFocusRenderer(Event.current.mousePosition + _scrollPosition + new Vector2(0, -24f));
            SortingRendererInfo focusRendererInfo = result.Key;

            if (focusRendererInfo != null)
            {
                Renderer focusRenderer = focusRendererInfo.renderer;

                if (Event.current.control)
                {
                    if (_selectRenderer.Contains(focusRenderer))
                    {
                        _selectRenderer.Remove(focusRenderer);
                        if (_focusSelectRenderer == focusRenderer)
                        {
                            _focusSelectRenderer = null;
                            if (_selectRenderer.Count > 0)
                            {
                                foreach (Renderer renderer in _selectRenderer)
                                {
                                    if (renderer != null)
                                    {
                                        _focusSelectRenderer = renderer;

                                        SortingRendererInfo rendererinfo = GetRendererInfo(renderer);
                                        GUIUtility.hotControl = rendererinfo.controlID;

                                        break;
                                    }
                                }
                                GUIUtility.keyboardControl = 0;
                            }
                        }
                    }
                    else
                    {
                        _selectRenderer.Add(focusRenderer);
                        _focusSelectRenderer = focusRenderer;

                        GUIUtility.hotControl = focusRendererInfo.controlID;
                        GUIUtility.keyboardControl = 0;
                    }
                }
                else if (Event.current.shift)
                {
                    if (focusRenderer != _focusSelectRenderer && _focusSelectRenderer != null)
                    {
                        int dstLayerIndex = 0;
                        int srcLayerIndex = 0;
                        string dstLayerName = focusRenderer.sortingLayerName;
                        if (dstLayerName == string.Empty)
                            dstLayerName = "Default";
                        string srcLayerName = _focusSelectRenderer.sortingLayerName;
                        if (srcLayerName == string.Empty)
                            srcLayerName = "Default";
                        for (int index = 0; index < _layerList.Count; index++)
                        {
                            if (dstLayerName == _layerList[index].name)
                                dstLayerIndex = index;
                            if (srcLayerName == _layerList[index].name)
                                srcLayerIndex = index;
                        }
                        // dstLayerIndex < srcLayerIndex
                        if (dstLayerIndex < srcLayerIndex)
                        {
                            bool start = false;
                            foreach (SortingRendererInfo rendererInfo in _layerList[dstLayerIndex].rendererList)
                            {
                                if (!start)
                                {
                                    if (rendererInfo.renderer == focusRenderer)
                                        start = true;
                                }
                                if (start)
                                {
                                    if (!_selectRenderer.Contains(rendererInfo.renderer))
                                        _selectRenderer.Add(rendererInfo.renderer);
                                }
                            }

                            for (int index = dstLayerIndex + 1; index < srcLayerIndex; index++)
                            {
                                foreach (SortingRendererInfo rendererInfo in _layerList[index].rendererList)
                                {
                                    if (!_selectRenderer.Contains(rendererInfo.renderer))
                                        _selectRenderer.Add(rendererInfo.renderer);
                                }
                            }

                            foreach (SortingRendererInfo rendererInfo in _layerList[srcLayerIndex].rendererList)
                            {
                                if (rendererInfo.renderer == _focusSelectRenderer)
                                    break;
                                if (!_selectRenderer.Contains(rendererInfo.renderer))
                                    _selectRenderer.Add(rendererInfo.renderer);
                            }
                        }
                        // dstLayerIndex > srcLayerIndex
                        else if (dstLayerIndex > srcLayerIndex)
                        {
                            bool start = false;
                            foreach (SortingRendererInfo rendererInfo in _layerList[srcLayerIndex].rendererList)
                            {
                                if (start)
                                {
                                    if (!_selectRenderer.Contains(rendererInfo.renderer))
                                        _selectRenderer.Add(rendererInfo.renderer);
                                }
                                if (!start)
                                {
                                    if (rendererInfo.renderer == _focusSelectRenderer)
                                        start = true;
                                }
                            }

                            for (int index = srcLayerIndex + 1; index < dstLayerIndex; index++)
                            {
                                foreach (SortingRendererInfo rendererInfo in _layerList[index].rendererList)
                                {
                                    if (!_selectRenderer.Contains(rendererInfo.renderer))
                                        _selectRenderer.Add(rendererInfo.renderer);
                                }
                            }

                            foreach (SortingRendererInfo rendererInfo in _layerList[dstLayerIndex].rendererList)
                            {
                                if (!_selectRenderer.Contains(rendererInfo.renderer))
                                    _selectRenderer.Add(rendererInfo.renderer);

                                if (rendererInfo.renderer == focusRenderer)
                                    break;
                            }
                        }
                        // dstLayerIndex == srcLayerIndex
                        else
                        {
                            bool start = false;
                            foreach (SortingRendererInfo rendererInfo in _layerList[dstLayerIndex].rendererList)
                            {
                                if (start)
                                {
                                    if (rendererInfo.renderer == focusRenderer || rendererInfo.renderer == _focusSelectRenderer)
                                        break;

                                    if (!_selectRenderer.Contains(rendererInfo.renderer))
                                        _selectRenderer.Add(rendererInfo.renderer);
                                }

                                if (!start)
                                {
                                    if (rendererInfo.renderer == focusRenderer || rendererInfo.renderer == _focusSelectRenderer)
                                        start = true;
                                }
                            }
                            if (!_selectRenderer.Contains(focusRenderer))
                                _selectRenderer.Add(focusRenderer);
                        }

                        GUIUtility.hotControl = focusRendererInfo.controlID;
                        GUIUtility.keyboardControl = 0;
                    }
                }
                else 
                {
                    _focusState = result.Value;

                    if (!_selectRenderer.Contains(focusRenderer))
                    {
                        _selectRenderer.Clear();
                        _selectRenderer.Add(focusRenderer);
                    }

                    _focusSelectRenderer = focusRenderer;

                    GUIUtility.hotControl = focusRendererInfo.controlID;
                    GUIUtility.keyboardControl = 0;

                    if (result.Value == FocusState.Right)
                    {
                        List<GameObject> objectReferenceList = new List<GameObject>();
                        foreach (Renderer renderer in _selectRenderer)
                        {
                            if (renderer != null && !objectReferenceList.Contains(renderer.gameObject))
                                objectReferenceList.Add(renderer.gameObject);
                        }
                        DragAndDrop.objectReferences = objectReferenceList.ToArray();
                    }
                    else if (result.Value == FocusState.Left)
                    {
                        _originMousePos = GUIUtility.GUIToScreenPoint(Event.current.mousePosition);
                        _originShiftPos = focusRendererInfo.leftEventRect.y - _scrollPosition.y;
                        _originOrder = _focusSelectRenderer.sortingOrder;
                    }
                }

                Event.current.Use();
            }
            else
            {
                _selectRenderer.Clear();
                _focusSelectRenderer = null;
                GUIUtility.hotControl = 0;
                GUIUtility.keyboardControl = 0;
                _focusState = FocusState.None;
                Event.current.Use();
            }

        }
        else if (Event.current.type == EventType.MouseUp)
        {
            _isDragRight = false;
            _isDragLeft = false;
            KeyValuePair<SortingRendererInfo, FocusState> result = GetFocusRenderer(Event.current.mousePosition + _scrollPosition + new Vector2(0, -24f));
            SortingRendererInfo focusRendererInfo = result.Key;

            GUIUtility.hotControl = 0;

            if (focusRendererInfo != null && _selectRenderer.Contains(focusRendererInfo.renderer))
            {
                Renderer focusRenderer = focusRendererInfo.renderer;

                if (Event.current.button == 0)
                {
                    if (!Event.current.control &&
                        !Event.current.shift &&
                        _selectRenderer.Contains(focusRenderer))
                    {
                        if (_selectRenderer.Count > 1)
                        {
                            _selectRenderer.Clear();
                            _selectRenderer.Add(focusRenderer);
                            _focusSelectRenderer = focusRenderer;
                        }
                        else if (result.Value == FocusState.Left && Selection.activeGameObject == _focusSelectRenderer.gameObject)
                        {
                            _editSelectRenderer = _focusSelectRenderer;
                        }
                    }

                    ChangeSelectObject();
                }
                else if (Event.current.button == 2)
                {
                    if (_selectRenderer.Contains(focusRenderer))
                    {
                        _focusSelectRenderer = focusRenderer;
                    }
                }
                    
                GUIUtility.hotControl = 0;
                GUIUtility.keyboardControl = 0;

                Event.current.Use();
            }
        }
        else if (Event.current.rawType == EventType.MouseUp)
        {
            _isDragRight = false;
            _isDragLeft = false;
            GUIUtility.hotControl = 0;
            GUIUtility.keyboardControl = 0;
            
        }

    }
 public void Focus(FocusState value) => FirstOrDefault <Control>()?.Focus(value);
        protected override void OnKeyDown(KeyEventArgs e)
        {
            int len = Text.Length;
            switch (e.KeyData)
            {
                case Keys.Insert:
                    if (mFocusState == FocusState.Char)
                    {
                        mFocusState = FocusState.Insert;
                        Invalidate();
                        CursorOn();
                        e.Handled = true;
                    }
                    else if (mFocusState == FocusState.Insert)
                    {
                        mFocusState = FocusState.Char;
                        if (mFocusPos < 0)
                        {
                            mFocusPos = 0;
                        }
                        else if (mFocusPos > len)
                        {
                            mFocusPos = len;
                        }
                        Invalidate();
                        CursorOn();
                        e.Handled = true;
                    }
                    break;

                case Keys.Left:
                    if (mFocusState != FocusState.Char && mFocusState != FocusState.Insert) break;
                    if (mFocusPos < len-1) mFocusPos++;
                    Invalidate();
                    CursorOn();
                    e.Handled = true;
                    break;

                case Keys.Right:
                    if (mFocusState == FocusState.Char)
                    {
                        if (mFocusPos > 0) mFocusPos--;
                    }
                    else if (mFocusState == FocusState.Insert)
                    {
                        if (mFocusPos >= 0) mFocusPos--;
                    }
                    else break;
                    Invalidate();
                    CursorOn();
                    e.Handled = true;
                    break;

                case Keys.Up:
                    {
                        long off = mDefIncr;
                        if (mFocusState == FocusState.Char)
                        {
                            int pos = Math.Min(Math.Max(mFocusPos, 0), len - 1);
                            off = (long)Math.Pow(10, pos);
                        }
                        try
                        {
                            Value += off;
                        }
                        catch (ArgumentException) {}
                        Invalidate();
                        CursorOn();
                        e.Handled = true;
                    }
                    break;

                case Keys.Down:
                    {
                        long off = mDefIncr;
                        if (mFocusState == FocusState.Char)
                        {
                            int pos = Math.Min(Math.Max(mFocusPos, 0), len - 1);
                            off = (long)Math.Pow(10, pos);
                        }
                        try
                        {
                            Value -= off;
                        }
                        catch (ArgumentException) {}
                        Invalidate();
                        CursorOn();
                        e.Handled = true;
                    }
                    break;

                case Keys.Delete:
                    {
                        switch (mFocusState)
                        {
                            case FocusState.Char:
                            case FocusState.Insert:
                                if(mFocusPos >= 0)
                                {
                                    string text = Text;
                                    int pos = text.Length - Math.Min(mFocusPos, text.Length - 1) - 1;
                                    text = text.Substring(0, pos) + text.Substring(pos + 1);
                                    try
                                    {
                                        Text = text;
                                    }
                                    catch (ArgumentException)
                                    {
                                        Editing = true;
                                        Text = text;
                                    }
                                    Invalidate();
                                    mFocusState = FocusState.Insert;
                                    mFocusPos = text.Length - pos - 1;
                                    e.Handled = true;
                                }
                                break;
                            case FocusState.General:
                                Editing = true;
                                Text = "";
                                mFocusState = FocusState.Insert;
                                mFocusPos = -1;
                                Invalidate();
                                e.Handled = true;
                                break;
                        }
                    }
                    break;
            }
            base.OnKeyDown(e);
        }
Beispiel #42
0
        protected virtual bool RequestFocus(FocusState state)
        {
            FocusState = state;

            return(true);
        }
 protected override void OnMouseClick(MouseEventArgs e)
 {
     base.OnMouseClick(e);
     switch (mFocusState)
     {
         case FocusState.General:
             {
                 int hitTest = FocusHitTest(e.Location);
                 if (hitTest == int.MinValue || hitTest == int.MaxValue)
                 {
                     mFocusState = FocusState.Insert;
                 }
                 else
                 {
                     mFocusState = FocusState.Char;
                 }
                 mFocusPos = hitTest;
                 Invalidate();
             }
             break;
         case FocusState.Insert:
         case FocusState.Char:
             {
                 int hitTest = FocusHitTest(e.Location);
                 if (hitTest == mFocusPos)
                 {
                     mFocusState = FocusState.General;
                 }
                 else if (hitTest == int.MinValue || hitTest == int.MaxValue)
                 {
                     mFocusState = FocusState.Insert;
                 }
                 else
                 {
                     mFocusState = FocusState.Char;
                 }
                 mFocusPos = hitTest;
                 Invalidate();
             }
             break;
         default:
             mFocusState = FocusState.General;
             Invalidate();
             break;
     }
     if (mFocusState != FocusState.General) CursorOn();
 }
 public bool SetFocusLevel(FocusState focusState)
 {
     this.focusState = focusState;
     return(this.UpdateDeviceLEDs());
 }