コード例 #1
0
        }   // end of HandleTouchInput()

        private bool TouchHitElement(UIGridElement element, Camera camera, Vector2 screenPos)
        {
            float  width, height;
            Matrix invMat;

            GetElementInfo(element, out invMat, out width, out height);
            Vector2 hitUV = TouchInput.GetHitUV(screenPos, camera, ref invMat, width, height, useRtCoords: false);

            return(!((hitUV.X < 0 || hitUV.X > 1) ||
                     (hitUV.Y < 0 || hitUV.Y > 1)));
        }
コード例 #2
0
        }   // end of BrushPicker UpdateIndex()

        public bool TouchIsOverBrushSelection(TouchContact touch, Camera camera)
        {
            float  width;
            float  height;
            Matrix invMat;

            // Test in-focus element for hit.
            UIGridElement e = grid.SelectionElement;

            if (e != null)
            {
                GetElementInfo(e, out invMat, out width, out height);

                Vector2 hitUV = TouchInput.GetHitUV(touch.position, camera, ref invMat, width, height, useRtCoords: false);

                if (hitUV.X > 0 && hitUV.X < 1 && hitUV.Y > 0 && hitUV.Y < 1)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #3
0
        private void UpdateTouchSliders(Camera uicamera)
        {
            TouchContact touch  = TouchInput.GetOldestTouch();
            Vector2      hitPos = Vector2.Zero;

            if (touch != null)
            {
                hitPos = touch.position;

                Matrix mat = slider.InvWorldMatrix;

                // Convert mouse hit into UV coords.
                Vector2 hitUV = TouchInput.GetHitUV(hitPos, uicamera, ref mat, slider.Size.X, slider.Size.Y, useRtCoords: false);

                bool outside = true;
                if (hitUV.X >= 0 && hitUV.X < 1 && hitUV.Y >= 0 && hitUV.Y < 1)
                {
                    slider.HandleTouchInput(touch, hitUV);
                    outside = false;
                }

                mat = Matrix.Identity;
                slider.Update(ref mat);

                //Get Close position matrix.
                mat             = slider.WorldMatrix;
                mat.Translation = new Vector3(closePosition.X, closePosition.Y, mat.Translation.Z);
                mat             = Matrix.Invert(mat);

                hitUV = TouchInput.GetHitUV(hitPos, uicamera, ref mat, closeSize.X, closeSize.Y, useRtCoords: false);

                if (hitUV.X >= 0 && hitUV.X < 1 && hitUV.Y >= 0 && hitUV.Y < 1)
                {
                    //   if (MouseInput.Left.WasPressed)
                    if (touch.phase == TouchPhase.Began)
                    {
                        touch.TouchedObject = this;
                    }
                    if (touch.phase == TouchPhase.Ended && touch.TouchedObject == this)
                    {
                        sliderActive = false;
                    }

                    if (touch.TouchedObject == this)
                    {
                        closeSquareTexture = closeSquareLitTexture;
                    }
                }
                else
                {
                    closeSquareTexture = closeSquareUnlitTexture;

                    // If user clicked outside of slide and close box, close slider.
                    if ((TouchInput.GetOldestTouch() != null) &&
                        (TouchInput.GetOldestTouch().phase == TouchPhase.Began) &&
                        outside)
                    {
                        sliderActive = false;
                    }
                }
                if (Actions.Cancel.WasPressed)
                {
                    Actions.Cancel.ClearAllWasPressedState();
                    sliderActive = false;
                }
            }
        }
コード例 #4
0
        private void UpdateMouseSliders(Camera uicamera)
        {
            Vector2 hitPos = new Vector2(MouseInput.Position.X, MouseInput.Position.Y);

            Matrix mat = Matrix.Invert(slider.WorldMatrix);

            // Convert mouse hit into UV coords.
            Vector2 hitUV = TouchInput.GetHitUV(hitPos, uicamera, ref mat, slider.Size.X, slider.Size.Y, useRtCoords: false);


            bool outside = true;

            if (hitUV.X >= 0 && hitUV.X < 1 && hitUV.Y >= 0 && hitUV.Y < 1)
            {
                slider.HandleMouseInput(hitUV);
                outside = false;
            }

            Matrix identity = Matrix.Identity;

            slider.Update(ref identity);

            //Get Close position matrix.
            mat             = slider.WorldMatrix;
            mat.Translation = new Vector3(closePosition.X, closePosition.Y, mat.Translation.Z);
            mat             = Matrix.Invert(mat);

            hitUV = TouchInput.GetHitUV(hitPos, uicamera, ref mat, closeSize.X, closeSize.Y, useRtCoords: false);

            if (hitUV.X >= 0 && hitUV.X < 1 && hitUV.Y >= 0 && hitUV.Y < 1)
            {
                if (MouseInput.Left.WasPressed)
                {
                    MouseInput.ClickedOnObject = this;
                }
                if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == this)
                {
                    sliderActive = false;
                }

                if (MouseInput.ClickedOnObject == this)
                {
                    closeSquareTexture = closeSquareLitTexture;
                }
            }
            else
            {
                closeSquareTexture = closeSquareUnlitTexture;

                // If user clicked outside of slide and close box, close slider.
                if (MouseInput.Left.WasPressed && outside)
                {
                    MouseInput.Left.ClearAllWasPressedState();
                    sliderActive = false;
                }
            }
            if (Actions.Cancel.WasPressed)
            {
                Actions.Cancel.ClearAllWasPressedState();
                sliderActive = false;
            }
        }
コード例 #5
0
        private void HandleSliderInput(Camera uicamera)
        {
            if (sliderActive)
            {
                Vector2      dragPos;
                TouchContact touch = null;
                if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch)
                {
                    touch = TouchInput.GetOldestTouch();
                    if (touch != null)
                    {
                        dragPos = touch.position;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    dragPos = new Vector2(MouseInput.Position.X, MouseInput.Position.Y);
                }


                // Convert mouse hit into UV coords. (GetHitUV for MouseInput and TouchInput have same implementation...)
                Matrix  worldMat = Matrix.Invert(slider.WorldMatrix);
                Vector2 hitUV    = TouchInput.GetHitUV(dragPos, uicamera, ref worldMat, slider.Size.X, slider.Size.Y, useRtCoords: false);;

                bool outside = true;
                if (hitUV.X >= 0 && hitUV.X < 1 && hitUV.Y >= 0 && hitUV.Y < 1)
                {
                    /// \TODO : add touch input for sliders
                    if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch)
                    {
                        slider.HandleTouchInput(touch, hitUV);
                    }
                    else
                    {
                        slider.HandleMouseInput(hitUV);
                    }
                    outside = false;
                }

                Matrix identity = Matrix.Identity;
                slider.Update(ref identity);

                //Get Close position matrix.
                worldMat             = slider.WorldMatrix;
                worldMat.Translation = new Vector3(closePosition.X, closePosition.Y, worldMat.Translation.Z);
                worldMat             = Matrix.Invert(worldMat);

                hitUV = TouchInput.GetHitUV(dragPos, uicamera, ref worldMat, closeSize.X, closeSize.Y, useRtCoords: false);

                if (hitUV.X >= 0 && hitUV.X < 1 && hitUV.Y >= 0 && hitUV.Y < 1)
                {
                    if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch)
                    {
                        if (touch.phase == TouchPhase.Began)
                        {
                            touch.TouchedObject = this;
                        }
                        if (touch.phase == TouchPhase.Ended && touch.TouchedObject == this)
                        {
                            sliderActive = false;
                        }

                        if (touch.TouchedObject == this)
                        {
                            closeSquareTexture = closeSquareLitTexture;
                        }
                    }
                    else
                    {
                        if (MouseInput.Left.WasPressed)
                        {
                            MouseInput.ClickedOnObject = this;
                        }
                        if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == this)
                        {
                            sliderActive = false;
                        }

                        if (MouseInput.ClickedOnObject == this)
                        {
                            closeSquareTexture = closeSquareLitTexture;
                        }
                    }
                }
                else
                {
                    closeSquareTexture = closeSquareUnlitTexture;
                    if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch)
                    {
                        // If user TOUCHED outside of slide and close box, close slider.
                        if (TouchInput.WasTouched && outside)
                        {
                            sliderActive = false;
                        }
                    }
                    else
                    {
                        // If user clicked outside of slide and close box, close slider.
                        if (MouseInput.Left.WasPressed && outside)
                        {
                            MouseInput.Left.ClearAllWasPressedState();
                            sliderActive = false;
                        }
                    }
                }
                if (Actions.Cancel.WasPressed)
                {
                    Actions.Cancel.ClearAllWasPressedState();
                    sliderActive = false;
                }
            }
        }
コード例 #6
0
        }   // end of DeleteAll()

        public void Update(Camera camera, ref Matrix parentMatrix)
        {
            // Check for input.
            if (active && itemList.Count > 1 && !IgnoreInput && CommandStack.Peek() == commandMap)
            {
                bool selectionChanged = false;
                bool moveUp           = false;
                bool moveDown         = false;

                {
                    // Mouse input
                    if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse)
                    {
                        // If the mouse is over the menu, move the selection index to the item under the mouse.
                        // On mouse down, make the item (if any) under the mouse the ClickedOnItem.
                        // On mouse up, if the mouse is still over the ClickedOnItem, activate it.  If not, just clear ClickedOnItem.

                        Vector2 hitUV = MouseInput.GetHitUV(camera, ref invWorldMatrix, width, height, useRtCoords);

                        // See if we're over anything.  If so, set that item to being selected but only if we've moved the mouse.
                        // This prevents the menu from feeling 'broken' if the mouse is over it and the user tries to use
                        // the gamepad or keyboard.
                        int mouseOverItem = -1;
                        for (int i = 0; i < itemList.Count; i++)
                        {
                            if (itemList[i].UVBoundingBox != null && itemList[i].UVBoundingBox.Contains(hitUV))
                            {
                                // Only update the current in-focus element when the mouse moves.
                                if (MouseInput.Position != MouseInput.PrevPosition)
                                {
                                    CurIndex = i;
                                }
                                mouseOverItem = i;
                            }
                        }

                        if (MouseInput.Left.WasPressed && mouseOverItem != -1)
                        {
                            MouseInput.ClickedOnObject = itemList[mouseOverItem];
                        }

                        if (MouseInput.Left.WasReleased && mouseOverItem != -1 && MouseInput.ClickedOnObject == itemList[mouseOverItem])
                        {
                            // Normally this is already set except in the case where the app didn't have focus and a menu item is clicked.
                            // In that case, the CurIndex value stays stuck at its previous position.  In particular this was causing Kodu's
                            // Main Menu to think RESUME was clicked even when it was one of the other menu items.
                            CurIndex = mouseOverItem;
                            if (onSelect != null)
                            {
                                onSelect(this);
                            }
                            Foley.PlayPressA();
                            return;
                        }

                        // Allow scroll wheel to cycle through elements.
                        int wheel = MouseInput.ScrollWheel - MouseInput.PrevScrollWheel;

                        if (wheel > 0)
                        {
                            moveUp = true;
                        }
                        else if (wheel < 0)
                        {
                            moveDown = true;
                        }
                    }   // end if KeyboardMouse mode.

                    if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch)
                    {
                        // Look for Tap gesture first.  No need to care about touch response if we've got a tap.
                        bool goodTapGesture = false;
                        if (TouchGestureManager.Get().TapGesture.WasTapped())
                        {
                            // Check if tap position hit any of the menu elements.
                            Vector2 tapPosition = TouchGestureManager.Get().TapGesture.Position;
                            Vector2 touchHitUV  = TouchInput.GetHitUV(tapPosition, camera, ref invWorldMatrix, width, height, useRtCoords);
                            for (int index = 0; index < itemList.Count; index++)
                            {
                                if (itemList[index].UVBoundingBox != null && itemList[index].UVBoundingBox.Contains(touchHitUV))
                                {
                                    CurIndex = index;
                                    if (onSelect != null)
                                    {
                                        onSelect(this);
                                        Foley.PlayPressA();
                                        selectionChanged = true;
                                        goodTapGesture   = true;
                                    }
                                }
                            }
                        }

                        // Look for touch events to change focus.  Ignore this if we had a good tap gesture.
                        if (!goodTapGesture)
                        {
                            for (int i = 0; i < TouchInput.TouchCount; i++)
                            {
                                TouchContact touch = TouchInput.GetTouchContactByIndex(i);

                                // Touch input
                                // If the user touched the menu, move the selection index to the item under the touch.
                                // On touch down, make the item (if any) under the contact the touchedItem.
                                // On touch up, if the touch is still over the touchedItem, activate it.  If not, just clear touchedItem.

                                Vector2 touchHitUV = TouchInput.GetHitUV(touch.position, camera, ref invWorldMatrix, width, height, useRtCoords);

                                // See what UI element we are over, if anything.  If it hits, set that item to being selected but only if the touch has moved.
                                // This emulates how the mouse is being handled by allowing the input to change only if the touch has moved. If a user moves
                                // the gamepad or keyboard but doesn't move their touch contact, then the selection won't flicker back and forth and feel 'broken'
                                int touchOverIndex = -1;
                                for (int index = 0; index < itemList.Count; index++)
                                {
                                    if (itemList[index].UVBoundingBox != null && itemList[index].UVBoundingBox.Contains(touchHitUV))
                                    {
                                        touchOverIndex = index;
                                    }
                                }

                                if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved)
                                {
                                    // Touch is down!
                                    if (touchOverIndex != -1)
                                    {
                                        touch.TouchedObject = itemList[touchOverIndex];
                                        if (CurIndex != touchOverIndex)
                                        {
                                            selectionChanged = true;
                                        }
                                        CurIndex = touchOverIndex;
                                    }
                                }
                                else if (touch.phase == TouchPhase.Moved)
                                {
                                    // Touch moved!!! Update Something!!
                                    if (CurIndex != touchOverIndex)
                                    {
                                        CurIndex = touchOverIndex;
                                    }
                                }
                            }
                        }   // end if not good tap gesture.

                        if (selectionChanged)
                        {
                            if (onChange != null)
                            {
                                onChange(this);
                            }
                            dirty = true;
                            //RecalcPositions();
                            // Ensure that the selected state of all items is correct.
                            for (int i = 0; i < itemList.Count; i++)
                            {
                                itemList[i].Selected = i == CurIndex;
                            }
                        }
                    }   // end of touch mode processing.
                }

                if (GamePadInput.ActiveMode == GamePadInput.InputMode.GamePad ||
                    GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse)
                {
                    // Gamepad / Keyboard input.
                    GamePadInput pad = GamePadInput.GetGamePad0();

                    if ((AcceptStartForCancel && Actions.Start.WasPressed) || Actions.Cancel.WasPressed)
                    {
                        Actions.Cancel.ClearAllWasPressedState();
                        if (onCancel != null)
                        {
                            onCancel(this);
                        }
                        Foley.PlayBack();
                        return;
                    }

                    if (Actions.Select.WasPressed)
                    {
                        Actions.Select.ClearAllWasPressedState();
                        if (onSelect != null)
                        {
                            onSelect(this);
                        }
                        Foley.PlayPressA();
                        return;
                    }

                    int prevIndex = CurIndex;

                    // Handle input changes here.
                    if (Actions.ComboDown.WasPressedOrRepeat || moveDown)
                    {
                        ++CurIndex;
                        if (CurIndex >= itemList.Count)
                        {
                            CurIndex = 0;
                        }

                        selectionChanged = true;
                    }

                    if (Actions.ComboUp.WasPressedOrRepeat || moveUp)
                    {
                        --CurIndex;
                        if (CurIndex < 0)
                        {
                            CurIndex = itemList.Count - 1;
                        }

                        selectionChanged = true;
                    }

                    if (selectionChanged)
                    {
                        if (onChange != null)
                        {
                            onChange(this);
                        }
                        dirty = true;
                        //RecalcPositions();
                    }

                    // Ensure that the selected state of all items is correct.
                    for (int i = 0; i < itemList.Count; i++)
                    {
                        itemList[i].Selected = i == CurIndex;
                    }
                }
            }

            RefreshTexture();
        }   // end of UIGridModularMenu Update()
コード例 #7
0
        }   // end of Update()

        private void HandleTouchInput()
        {
            if (GamePadInput.ActiveMode != GamePadInput.InputMode.Touch)
            {
                return;
            }
            if (TouchInput.TouchCount == 0)
            {
                return;
            }

            bool hitMenu = false;

            TouchContact touch = TouchInput.GetOldestTouch();

            // If in focus element has help available, get it.
            UIGridElement focusElement = grid.SelectionElement;
            string        helpID       = focusElement.HelpID;
            string        helpText     = TweakScreenHelp.GetHelp(helpID);

            // Check for help tile.
            Matrix mat = Matrix.CreateTranslation(-helpSquare.Position.X, -helpSquare.Position.Y, 0);

            if (touch != null)
            {
                Vector2 hitHelpUV = Vector2.Zero;
                hitHelpUV = TouchInput.GetHitUV(touch.position, camera, ref mat, helpSquare.Size,
                                                helpSquare.Size, true);

                if (grid.SelectionElement.ShowHelpButton)
                {
                    if (hitHelpUV.X >= 0 && hitHelpUV.X < 1 && hitHelpUV.Y >= 0 && hitHelpUV.Y < 1)
                    {
                        if (TouchInput.WasTouched)
                        {
                            touch.TouchedObject = helpSquare;
                        }
                        if (TouchInput.WasReleased && touch.TouchedObject == helpSquare)
                        {
                            if (helpText != null)
                            {
                                ShowHelp(helpText);
                            }
                        }
                        hitMenu = true;
                    }
                }

                // Check if mouse hitting current selection object.  Or should this be done in the object?
                mat = Matrix.Invert(focusElement.WorldMatrix);
                Vector2 hitFocusUV = TouchInput.GetHitUV(touch.position, camera, ref mat, focusElement.Size.X,
                                                         focusElement.Size.Y, true);
                bool focusElementHit = false;

                if (hitFocusUV.X >= 0 && hitFocusUV.X < 1 && hitFocusUV.Y >= 0 && hitFocusUV.Y < 1)
                {
                    if (touch.phase == TouchPhase.Began)
                    {
                        touch.TouchedObject = focusElement;
                    }
                    focusElement.HandleTouchInput(touch, hitFocusUV);
                    focusElementHit = true;
                    hitMenu         = true;
                }

                // If we didn't hit the focus object, see if we hit any of the others.
                // If so, bring them into focus.
                if (!focusElementHit && TouchGestureManager.Get().TapGesture.WasTapped())
                {
                    for (int i = 0; i < grid.ActualDimensions.Y; i++)
                    {
                        if (i == grid.SelectionIndex.Y)
                        {
                            continue;
                        }

                        UIGridElement e = grid.Get(0, i);
                        mat = Matrix.Invert(e.WorldMatrix);
                        Vector2 hitUV = TouchInput.GetHitUV(touch.position, camera, ref mat, e.Size.X,
                                                            e.Size.Y, true);

                        if (hitUV.X >= 0 && hitUV.X < 1 && hitUV.Y >= 0 && hitUV.Y < 1)
                        {
                            // We hit an element, so bring it into focus.
                            grid.SelectionIndex = new Point(0, i);
                            hitMenu             = true;
                            break;
                        }
                    }
                }

                if ((hitFocusUV.X >= 0) && (hitFocusUV.X < 1))
                {
                    hitMenu = true;
                }
                if (!hitMenu && TouchGestureManager.Get().TapGesture.WasTapped())
                {
                    Deactivate();
                }

                // Handle free-form scrolling
                if (touch.TouchedObject != focusElement)
                {
                    grid.HandleTouchInput(camera);
                }
            }   // end of touch input
        }
コード例 #8
0
        private void HandleTouchInput(Camera camera)
        {
            if (GamePadInput.ActiveMode != GamePadInput.InputMode.Touch)
            {
                return;
            }

            // Touch input
            // If the touch is over the menu, move the selection index to the item under the mouse.
            // On touch down, make the item (if any) under the touch the ClickedOnItem.
            // On tap, if the touch is still over the ClickedOnItem, activate it.  If not, just clear ClickedOnItem.
            TouchContact touch = TouchInput.GetOldestTouch();

            if (touch != null)
            {
                Vector2 hitUV = TouchInput.GetHitUV(touch.position, camera, ref invWorldMatrix, width, height, useRtCoords: useRtCoords);

                // See if we're over anything.  If so, set that item to being selected but only if we've moved the mouse.
                // This prevents the menu from feeling 'broken' if the mouse is over it and the user tries to use
                // the gamepad or keyboard.
                int touchItem = -1;
                for (int i = 0; i < itemList.Count; i++)
                {
                    if (itemList[i].UVBoundingBox != null && itemList[i].UVBoundingBox.Contains(hitUV))
                    {
                        // Only update the current in-focus element when the mouse moves.
                        if (true) // touch.position != touch.previousPosition)
                        {
                            CurIndex = i;
                        }
                        touchItem = i;
                    }
                }

                //if ( TouchInput.TapGesture.WasTapped() )
                if (TouchInput.IsTouched)
                {
                    if (touchItem != -1)
                    {
                        touch.TouchedObject = itemList[touchItem];
                    }
                }
                if (TouchGestureManager.Get().TapGesture.WasTapped())
                {
                    // Make sure we're still over the ClickedOnItem.
                    if (touchItem != -1 && touch.TouchedObject == itemList[touchItem])
                    {
                        ToggleState();
                    }
                }

                Vector2 hit = touch.position;
                if (useRtCoords)
                {
                    hit = ScreenWarp.ScreenToRT(hit);
                }

                if (changeBox.Touched(touch, hit))
                {
                    ToggleState();
                }
                if (backBox.Touched(touch, hit))
                {
                    Deactivate();
                    Foley.PlayBack();
                }

                // Allow Swipeto cycle through elements.
                // Allow scroll wheel to cycle through elements.
                SwipeGestureRecognizer swipeGesture = TouchGestureManager.Get().SwipeGesture;
                if (swipeGesture.WasSwiped())
                {
                    if (swipeGesture.SwipeDirection == Boku.Programming.Directions.South)
                    {
                        curIndex -= 6;
                        if (curIndex < 0)
                        {
                            curIndex = itemList.Count - 1;
                        }
                        Foley.PlayShuffle();
                    }
                    else if (swipeGesture.SwipeDirection == Boku.Programming.Directions.North)
                    {
                        curIndex += 6;
                        if (curIndex > (itemList.Count - 1))
                        {
                            curIndex = 0;
                        }
                        Foley.PlayShuffle();
                    }
                }

                // If we click outside of the list, close it treating it as if select was chosen.
                //if (TouchInput.TapGesture.WasTapped() && touch.touchedObject == null)
                if (TouchInput.WasTouched && touch.TouchedObject == null)
                {
                    Deactivate();
                }
            }
        }