예제 #1
0
        private void HandleTouchInput(TouchContact touch, Vector2 hit)
        {
            if (hitBox.Touched(touch, hit))
            {
                Deactivate();
            }

            // Check for hover and adjust text color to match.
            Color newColor;

            newColor = hitBox.Contains(hit) ? hoverTextColor : lightTextColor;
            if (newColor != labelATargetColor)
            {
                labelATargetColor = newColor;
                Vector3 curColor  = new Vector3(labelAColor.R / 255.0f, labelAColor.G / 255.0f, labelAColor.B / 255.0f);
                Vector3 destColor = new Vector3(newColor.R / 255.0f, newColor.G / 255.0f, newColor.B / 255.0f);

                TwitchManager.Set <Vector3> set = delegate(Vector3 value, Object param)
                {
                    labelAColor.R = (byte)(value.X * 255.0f + 0.5f);
                    labelAColor.G = (byte)(value.Y * 255.0f + 0.5f);
                    labelAColor.B = (byte)(value.Z * 255.0f + 0.5f);
                };
                TwitchManager.CreateTwitch <Vector3>(curColor, destColor, set, 0.1f, TwitchCurve.Shape.EaseOut);
            }
        }   // end of HandleTouchInput()
        }   // end of ToggleState()

        public override void HandleMouseInput(Vector2 hitUV)
        {
            //check x button first
            if (xButtonBox.Contains(hitUV))
            {
                if (MouseInput.Left.WasPressed)
                {
                    MouseInput.ClickedOnObject = xButtonBox;
                }

                if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == xButtonBox)
                {
                    if (onXButton != null)
                    {
                        onXButton();
                    }
                }
            }
            else
            {
                // The hit region is the square at the left end of the tile.
                float maxU = height / width;
                if (hitUV.X < maxU)
                {
                    if (MouseInput.Left.WasPressed)
                    {
                        MouseInput.ClickedOnObject = this;
                    }
                    if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == this)
                    {
                        ToggleState();
                    }
                }
            }
        }   // end of HandleMouseInput()
예제 #3
0
        public void SetHoverState(Vector2 mouseHit)
        {
            Color newColor = box.Contains(mouseHit) ? hoverColor : color;

            if (newColor != targetColor)
            {
                if (newColor != color)
                {
                    state = ButtonState.Pressed;
                }
                else
                {
                    state = ButtonState.Released;
                }

                targetColor = newColor;
                Vector3 curColor  = new Vector3(renderColor.R / 255.0f, renderColor.G / 255.0f, renderColor.B / 255.0f);
                Vector3 destColor = new Vector3(newColor.R / 255.0f, newColor.G / 255.0f, newColor.B / 255.0f);

                TwitchManager.Set <Vector3> set = delegate(Vector3 value, Object param)
                {
                    renderColor.R = (byte)(value.X * 255.0f + 0.5f);
                    renderColor.G = (byte)(value.Y * 255.0f + 0.5f);
                    renderColor.B = (byte)(value.Z * 255.0f + 0.5f);
                };
                TwitchManager.CreateTwitch <Vector3>(curColor, destColor, set, 0.1f, TwitchCurve.Shape.EaseOut);
            }
        }   // end of SetHoverState()
예제 #4
0
            /// <summary>
            /// Updates the text color to show hover status.
            /// </summary>
            /// <param name="mouseHit"></param>
            public static void UpdateTextColor(Vector2 mouseHit)
            {
                Color newColor = undoHitBox.Contains(mouseHit) ? hoverColor : noHoverColor;

                if (newColor != undoTargetTextColor)
                {
                    undoTargetTextColor = newColor;
                    Vector3 curColor  = new Vector3(undoTextColor.R / 255.0f, undoTextColor.G / 255.0f, undoTextColor.B / 255.0f);
                    Vector3 destColor = new Vector3(newColor.R / 255.0f, newColor.G / 255.0f, newColor.B / 255.0f);

                    TwitchManager.Set <Vector3> set = delegate(Vector3 value, Object param)
                    {
                        undoTextColor.R = (byte)(value.X * 255.0f + 0.5f);
                        undoTextColor.G = (byte)(value.Y * 255.0f + 0.5f);
                        undoTextColor.B = (byte)(value.Z * 255.0f + 0.5f);
                    };
                    TwitchManager.CreateTwitch <Vector3>(curColor, destColor, set, 0.1f, TwitchCurve.Shape.EaseOut);
                }

                newColor = redoHitBox.Contains(mouseHit) ? hoverColor : noHoverColor;
                if (newColor != redoTargetTextColor)
                {
                    redoTargetTextColor = newColor;
                    Vector3 curColor  = new Vector3(redoTextColor.R / 255.0f, redoTextColor.G / 255.0f, redoTextColor.B / 255.0f);
                    Vector3 destColor = new Vector3(newColor.R / 255.0f, newColor.G / 255.0f, newColor.B / 255.0f);

                    TwitchManager.Set <Vector3> set = delegate(Vector3 value, Object param)
                    {
                        redoTextColor.R = (byte)(value.X * 255.0f + 0.5f);
                        redoTextColor.G = (byte)(value.Y * 255.0f + 0.5f);
                        redoTextColor.B = (byte)(value.Z * 255.0f + 0.5f);
                    };
                    TwitchManager.CreateTwitch <Vector3>(curColor, destColor, set, 0.1f, TwitchCurve.Shape.EaseOut);
                }
            }   // end of UpdateTextColor()
        public override void HandleMouseInput(Vector2 hitUV)
        {
            if (xButtonBox.Contains(hitUV))
            {
                if (MouseInput.Left.WasPressed)
                {
                    MouseInput.ClickedOnObject = xButtonBox;
                    clickedOnIndex             = -1;
                }

                if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == xButtonBox)
                {
                    if (onXButton != null)
                    {
                        onXButton(curIndex);
                    }
                    clickedOnIndex = -1;
                }
            }
            else if (iconButtonBox.Contains(hitUV))
            {
                if (MouseInput.Left.WasPressed)
                {
                    MouseInput.ClickedOnObject = iconButtonBox;
                    clickedOnIndex             = (int)(3.0f * (hitUV.X - iconButtonBox.Min.X) / (iconButtonBox.Max.X - iconButtonBox.Min.X));
                }

                if (MouseInput.Left.WasReleased)
                {
                    // Make sure we're still over the ClickedOnItem.
                    if (MouseInput.ClickedOnObject == iconButtonBox)
                    {
                        int newIndex = (int)(3.0f * (hitUV.X - iconButtonBox.Min.X) / (iconButtonBox.Max.X - iconButtonBox.Min.X));

                        if (newIndex == clickedOnIndex && newIndex != CurIndex)
                        {
                            CurIndex = newIndex;
                        }
                    }
                    clickedOnIndex = -1;
                }
            }
        }   // end of HandleMouseInput()
            }   // end of Render()

            /// <summary>
            /// Does hit testing for key.
            /// </summary>
            /// <param name="hitPosition"></param>
            /// <returns></returns>
            public bool HitTest(Vector2 hitPosition)
            {
                // Detect user press.
                if (!Pressed && hitBox.Contains(hitPosition))
                {
                    Pressed          = true;
                    timeOfLastPress  = Time.GameTimeTotalSeconds;
                    timeOfLastRepeat = 0;
                }

                return(Pressed);
            }   // end of HitTest()
        }   // end of UIGridModularCheckboxElement Update()

        public override void HandleMouseInput(Vector2 hitUV)
        {
            if (MouseInput.Left.WasPressed)
            {
                MouseInput.ClickedOnObject = this;
            }
            if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == this)
            {
                //if the click was in the clear hit box, clear it out - otherwise, assume selection
                if (clearHitBox.Contains(hitUV))
                {
                    NextLevel = null;
                    if (onClear != null)
                    {
                        onClear();
                    }
                }
                else
                {
                    onSetNextLevel();
                }
            }
        }   // end of HandleMouseInput()
예제 #8
0
        public void SetHoverState(Vector2 mouseHit)
        {
            Color newColor = box.Contains(mouseHit) ? hoverColor : defaultColor;

            /*
             *   Vector3 curColor = new Vector3(renderColor.R / 255.0f, renderColor.G / 255.0f, renderColor.B / 255.0f);
             *   Vector3 destColor = new Vector3(newColor.R / 255.0f, newColor.G / 255.0f, newColor.B / 255.0f);
             *
             *   TwitchManager.Set<Vector3> set = delegate(Vector3 value, Object param)
             *   {
             *       renderColor.R = (byte)(value.X * 255.0f + 0.5f);
             *       renderColor.G = (byte)(value.Y * 255.0f + 0.5f);
             *       renderColor.B = (byte)(value.Z * 255.0f + 0.5f);
             *   };
             *   TwitchManager.CreateTwitch<Vector3>(curColor, destColor, set, 0.1f, TwitchCurve.Shape.EaseOut);
             * }
             */
        }   // end of SetHoverState()
예제 #9
0
        }     // end of Update()

        private void HandleTouchInput(TouchContact touch, Vector2 hit)
        {
            continueButton.SetHoverState(hit);
            backButton.SetHoverState(hit);
            exitTutorialButton.SetHoverState(hit);

            if (continueButton.Box.Contains(hit))
            {
                if (touch.phase == TouchPhase.Ended)
                {
                    if (OnContinue != null)
                    {
                        OnContinue();
                    }
                    Deactivate();
                }
            }
            else if (exitTutorialButton.Box.Contains(hit))
            {
                if (touch.phase == TouchPhase.Ended)
                {
                    if (OnExitTutorial != null)
                    {
                        OnExitTutorial();
                    }
                    Deactivate();
                }
            }
            else if (upBox.Contains(hit))
            {
                if (touch.phase == TouchPhase.Ended)
                {
                    ScrollDown();
                }
            }
            else if (downBox.Contains(hit))
            {
                if (touch.phase == TouchPhase.Ended)
                {
                    ScrollUp();
                }
            }
        }   // end of HandleTouchInput()
예제 #10
0
// end of HandleMouseInput()

        private void HandleTouchInput()
        {
            //if (TouchInput.TouchCount == 0) { return; } // nothing to see here.

            //TouchContact touch = TouchInput.GetOldestTouch();
            //Vector2 touchHit = TouchInput.GetAspectRatioAdjustedPosition(
            //    touch.position,
            //    camera,
            //    true
            //);

            if (TouchInput.TouchCount == 0)
            {
                return;
            }                                           // nothing to see here.

            TouchContact touch = TouchInput.GetOldestTouch();

            Vector2 touchHit = ScreenWarp.ScreenToRT(touch.position);

            if (TouchGestureManager.Get().TapGesture.WasTapped())
            {
                if (okButton.Box.Contains(touchHit))
                {
                    Accept();
                }
                if (cancelButton.Box.Contains(touchHit))
                {
                    Cancel();
                }
                if (textBox.Contains(touchHit))
                {
                    KeyboardInput.ShowOnScreenKeyboard();
                }
            }
        }   // end of HandleTouchInput()
예제 #11
0
 public bool IsInFocus(Vector2 pos)
 {
     return(hitbox.Contains(pos));
 }
예제 #12
0
 public bool IsInScrollwindow(Vector2 pos)
 {
     return(hitBox.Contains(pos));// - scrollBoxPos);
 }
예제 #13
0
        }     // end of Update()

        private void HandleTouchInput(TouchContact touch, Vector2 hit)
        {
            if (hitBoxA.Touched(touch, hit))
            {
                // Disable this hint for this session.
                if (curHint.ShowOnce)
                {
                    curHint.Disabled = true;
                }

                Deactivate();
            }
            else if (hitBoxB.Touched(touch, hit))
            {
                // Disable this hint until reset by user.
                XmlOptionsData.SetHintAsDisabled(curHint.ID);

                // Disable this hint for this session.
                if (curHint.ShowOnce)
                {
                    curHint.Disabled = true;
                }

                Deactivate();
            }

            // Check for hover and adjust text color to match.
            Color newColor;

            newColor = hitBoxA.Contains(hit) ? hoverTextColor : lightTextColor;
            if (newColor != labelATargetColor)
            {
                labelATargetColor = newColor;
                Vector3 curColor  = new Vector3(labelAColor.R / 255.0f, labelAColor.G / 255.0f, labelAColor.B / 255.0f);
                Vector3 destColor = new Vector3(newColor.R / 255.0f, newColor.G / 255.0f, newColor.B / 255.0f);

                TwitchManager.Set <Vector3> set = delegate(Vector3 value, Object param)
                {
                    labelAColor.R = (byte)(value.X * 255.0f + 0.5f);
                    labelAColor.G = (byte)(value.Y * 255.0f + 0.5f);
                    labelAColor.B = (byte)(value.Z * 255.0f + 0.5f);
                };
                TwitchManager.CreateTwitch <Vector3>(curColor, destColor, set, 0.1f, TwitchCurve.Shape.EaseOut);
            }

            newColor = hitBoxB.Contains(hit) ? hoverTextColor : lightTextColor;
            if (newColor != labelBTargetColor)
            {
                labelBTargetColor = newColor;
                Vector3 curColor  = new Vector3(labelBColor.R / 255.0f, labelBColor.G / 255.0f, labelBColor.B / 255.0f);
                Vector3 destColor = new Vector3(newColor.R / 255.0f, newColor.G / 255.0f, newColor.B / 255.0f);

                TwitchManager.Set <Vector3> set = delegate(Vector3 value, Object param)
                {
                    labelBColor.R = (byte)(value.X * 255.0f + 0.5f);
                    labelBColor.G = (byte)(value.Y * 255.0f + 0.5f);
                    labelBColor.B = (byte)(value.Z * 255.0f + 0.5f);
                };
                TwitchManager.CreateTwitch <Vector3>(curColor, destColor, set, 0.1f, TwitchCurve.Shape.EaseOut);
            }
        }   // end of HandleTouchInput()
        }   // end of HandleGamePad()

        private void HandleTouch()
        {
            // Touch input
            TouchContact touch = TouchInput.GetOldestTouch();

            if (touch != null)
            {
                //Vector2 hit = TouchInput.GetAspectRatioAdjustedPosition(touch.position, shared.camera, true);
                Vector2 hit = touch.position;

                // Cancel
                if (cancelButton.Box.Touched(touch, hit))
                {
                    Deactivate(saveChanges: false);
                    return;
                }

                // Save
                if (saveButton.Box.Touched(touch, hit))
                {
                    Deactivate(saveChanges: true);
                    return;
                }

                // Toggle LED
                if (toggleLEDButton.Box.Touched(touch, hit))
                {
                    ledGrid.LEDs[ledGrid.FocusLEDIndex] = !ledGrid.LEDs[ledGrid.FocusLEDIndex];
                    return;
                }

                // Get hit point in camera coords.
                Vector2 cameraHit = -camera.PixelsToCameraSpaceScreenCoords(hit);

                // Handle clicks on ledGrid.  Hit boxes are in camera coords.
                if (touch.phase == TouchPhase.Began)
                {
                    for (int i = 0; i < ledGrid.ledHitBoxes.Length; i++)
                    {
                        if (ledGrid.ledHitBoxes[i].Contains(cameraHit))
                        {
                            ledGrid.FocusLEDIndex = i;
                            // Also toggle when clicked.
                            ledGrid.LEDs[ledGrid.FocusLEDIndex] = !ledGrid.LEDs[ledGrid.FocusLEDIndex];
                        }
                    }
                }

                // Handle touch on sliders.
                {
                    // Brightness Slider
                    Vector2 position = new Vector2(brightnessSlider.Position.X, brightnessSlider.Position.Y);
                    Vector2 min      = position - brightnessSlider.Size / 2.0f;
                    Vector2 max      = position + brightnessSlider.Size / 2.0f;
                    AABB2D  box      = new AABB2D(min, max);
                    if (box.Contains(cameraHit))
                    {
                        brightnessSlider.Selected = true;
                        durationSlider.Selected   = false;

                        Vector2 uv = (cameraHit - min) / (max - min);
                        uv.Y = 1.0f - uv.Y;
                        brightnessSlider.HandleTouchInput(touch, uv);
                    }

                    // Duration Slider
                    position = new Vector2(durationSlider.Position.X, durationSlider.Position.Y);
                    min      = position - durationSlider.Size / 2.0f;
                    max      = position + durationSlider.Size / 2.0f;
                    box      = new AABB2D(min, max);
                    if (box.Contains(cameraHit))
                    {
                        durationSlider.Selected   = true;
                        brightnessSlider.Selected = false;

                        Vector2 uv = (cameraHit - min) / (max - min);
                        uv.Y = 1.0f - uv.Y;
                        durationSlider.HandleTouchInput(touch, uv);
                    }
                }
            } // end if we have a touch.
        }     // end of HandleTouch()
예제 #15
0
        private void HandleMouseInput(Camera camera)
        {
            if (GamePadInput.ActiveMode != GamePadInput.InputMode.KeyboardMouse)
            {
                return;
            }
            if (scrollItems.Count == 0)
            {
                return;
            }

            Vector2 mouseHit  = new Vector2(MouseInput.Position.X, MouseInput.Position.Y);
            Vector2 adjHitPos = mouseHit;

            if (MouseInput.PrevScrollWheel > MouseInput.ScrollWheel)
            {
                FocusNext();
            }
            else if (MouseInput.PrevScrollWheel < MouseInput.ScrollWheel)
            {
                FocusPrev();
            }
            else if (scrollBoxHit.Contains(adjHitPos) || startDragOffset != 0.0f)
            {
                if (MouseInput.Left.WasPressed)
                {
                    startDragOffset   = mouseHit.Y;
                    startScrollOffset = scrollOffset;
                }
                else if (MouseInput.Left.IsPressed)
                {
                    float dragDistance = mouseHit.Y - startDragOffset;

                    float desiredScrollOffset =
                        (ScrollableHeight * (dragDistance / MaxBoxTravelDistance)) + startScrollOffset;
                    ConstrainScrollBox(desiredScrollOffset);
                }
                else
                {
                    startDragOffset = 0.0f;
                }
            }
            else
            {
                adjHitPos -= relativePosition;

                for (int i = 0; i < scrollItems.Count; i++)
                {
                    if (scrollItems[i].IsInFocus(adjHitPos) || true)
                    {
                        Object obj;
                        if (MouseInput.Left.WasReleased)
                        {
                            scrollItems[i].Click(adjHitPos, out obj, ClickType.WasReleased);
                            if (indexFocusedItem != i)
                            {
                                indexFocusedItem = i;
                                scrollItems[indexFocusedItem].ResetFocus();
                            }
                        }
                        else if (MouseInput.Left.WasPressed)
                        {
                            scrollItems[i].Click(adjHitPos, out obj, ClickType.WasPressed);
                        }
                        else if (MouseInput.Left.IsPressed)
                        {
                            scrollItems[i].Click(adjHitPos, out obj, ClickType.IsPressed);
                        }
                        else
                        {
                            scrollItems[i].Hover(adjHitPos);
                        }
                    }
                }
            }
        }
예제 #16
0
        public override bool HandleTouchInput(Camera camera)
        {
            float scaleY = Math.Min((float)BokuGame.ScreenSize.Y / 576.0f, 1.0f);


            AABB2D box = new AABB2D(new Vector2(0, (BokuGame.ScreenSize.Y - (200.0f) * scaleY)), BokuGame.ScreenSize);



            TouchContact focusedTouch = null;

            //Finger ID is focused finger
            if (m_FingerID < 0)
            {
                TouchContact[] touches = TouchInput.Touches;

                for (int i = 0; i < touches.Length; ++i)
                {
                    if (TouchPhase.Began == touches[i].phase)
                    {
                        m_FingerID   = touches[i].fingerId;
                        m_bDraggable = box.Contains(touches[i].position);
                        break;
                    }
                }
            }
            else
            {
                focusedTouch = TouchInput.GetTouchContactByFingerId(m_FingerID);

                if (null != focusedTouch && TouchPhase.Ended != focusedTouch.phase)
                {
                    if (TouchPhase.Moved == focusedTouch.phase)
                    {
                        m_DragDelta += focusedTouch.deltaPosition;
                    }

                    if (!m_bDragging && m_bDraggable)
                    {
                        //Check to see if the dragging threshold has been exceeded to change material.
                        Vector2 distance = focusedTouch.position - focusedTouch.startPosition;

                        //Did we start a drag?
                        if (Math.Abs(distance.X) >= 20.0f)
                        {
                            m_bDragging = true;
                            m_DragDelta = distance;
                        }
                    }

                    if (m_bDragging)
                    {
                        while (Math.Abs(m_DragDelta.X) >= 200.0f)
                        {
                            if (m_DragDelta.X >= 200.0f)
                            {
                                DecrementFocus();
                                m_DragDelta.X -= 200.0f;
                            }
                            else if (m_DragDelta.X <= -200.0f)
                            {
                                IncrementFocus();
                                m_DragDelta.X += 200.0f;
                            }
                        }
                    }
                }
                else
                {
                    //When the focused touch is ended we check for selection
                    if (!m_bDragging && null != focusedTouch)
                    {
                        Ray    ray = new Ray(camera.From, camera.ScreenToWorldCoords(focusedTouch.position));
                        Matrix m   = (grid.SelectionElement as UIGridMaterialElement).HitWorldMatrix;

                        bool bSelectedMat = (null != ray.Intersects(new BoundingSphere(m.Translation, 2.5f * m.M33)));

                        if (bSelectedMat)
                        {
                            SelectCurrentChoice();
                            Foley.PlayPressA();
                        }
                        else
                        {
                            //Didn't select the center piece.  Check if we picked a material on the sides so we can go to it.
                            for (int i = 0; (!bSelectedMat && i < grid.SelectionIndex.X); i++)
                            {
                                m = (grid.Get(i, 0) as UIGridMaterialElement).HitWorldMatrix;
                                if (null != ray.Intersects(new BoundingSphere(m.Translation, 2.5f * m.M33)))
                                {
                                    int steps = grid.SelectionIndex.X - i;
                                    while (steps > 0)
                                    {
                                        DecrementFocus();
                                        --steps;
                                    }
                                    bSelectedMat = true;
                                    break;
                                }
                            }

                            for (int i = grid.SelectionIndex.X + 1; (!bSelectedMat && i < grid.ActualDimensions.X); i++)
                            {
                                m = (grid.Get(i, 0) as UIGridMaterialElement).HitWorldMatrix;
                                if (null != ray.Intersects(new BoundingSphere(m.Translation, 2.5f * m.M33)))
                                {
                                    int steps = i - grid.SelectionIndex.X;
                                    while (steps > 0)
                                    {
                                        IncrementFocus();
                                        --steps;
                                    }
                                    bSelectedMat = true;
                                    break;
                                }
                            }

                            //Cancel this menu.
                            if (!bSelectedMat &&
                                !box.Contains(focusedTouch.position) &&
                                (Time.WallClockTotalSeconds - focusedTouch.startTime <= 0.3))
                            {
                                //If we didn't select anything and we are outside the drag area + didn't move a lot then cancel.
                                RestorePreviousChoice();
                                Foley.PlayBack();
                                return(false);
                            }
                        }
                    }

                    m_bDraggable = false;
                    m_bDragging  = false;
                    m_FingerID   = -1;
                }
            }

            return(true);
        }   // end of HandleTouchInput()
예제 #17
0
            public override void Update()
            {
                int  maxLines = 3;
                bool changed  = false;
                int  numLines = shared.descBlob != null ? shared.descBlob.NumLines : 0;

                // MouseInput
                {
                    Vector2 mouseHit = MouseInput.GetAspectRatioAdjustedPosition(shared.camera, true);

                    if (shared.chooseBox.LeftPressed(mouseHit))
                    {
                        Select();
                    }

                    if (shared.descBlob != null && shared.rightStickBox.LeftPressed(mouseHit))
                    {
                        // Up?
                        if (mouseHit.Y < (shared.rightStickBox.Min.Y + shared.rightStickBox.Max.Y) / 2.0f)
                        {
                            // Up
                            if (shared.topLine > 0)
                            {
                                --shared.topLine;
                                changed = true;
                            }
                        }
                        else
                        {
                            // Down
                            if (numLines - maxLines > shared.topLine)
                            {
                                ++shared.topLine;
                                changed = true;
                            }
                        }
                    }

                    if (shared.leftStickBox.LeftPressed(mouseHit))
                    {
                        // Up?
                        if (mouseHit.Y < (shared.leftStickBox.Min.Y + shared.leftStickBox.Max.Y) / 2.0f)
                        {
                            // Up
                            shared.examplesGrid.MoveUp();
                        }
                        else
                        {
                            // Down
                            shared.examplesGrid.MoveDown();
                        }
                    }

                    // If we get a mouse click outside of the help area, just exit.
                    // Use the leftStickBox and chooseBox as the extents of our box.
                    AABB2D bigBox = new AABB2D(shared.leftStickBox.Min, shared.chooseBox.Max);
                    if (MouseInput.Left.WasPressed && !bigBox.Contains(mouseHit))
                    {
                        // Done
                        parent.Deactivate();
                    }
                }   // end of mouse input

                // Our children may have input focus but we can still steal away the buttons we care about.
                GamePadInput pad = GamePadInput.GetGamePad0();

                if (Actions.Cancel.WasPressed)
                {
                    Actions.Cancel.ClearAllWasPressedState();

                    // Done
                    parent.Deactivate();
                }

                if (Actions.Select.WasPressed)
                {
                    Actions.Select.ClearAllWasPressedState();
                    Select();
                }

                if (shared.descBlob != null)
                {
                    if (Actions.AltUp.WasPressedOrRepeat)
                    {
                        Actions.AltUp.ClearAllWasPressedState();

                        if (shared.topLine > 0)
                        {
                            --shared.topLine;
                            changed = true;
                        }
                    }

                    if (Actions.AltDown.WasPressedOrRepeat)
                    {
                        Actions.AltDown.ClearAllWasPressedState();

                        if (numLines - maxLines > shared.topLine)
                        {
                            ++shared.topLine;
                            changed = true;
                        }
                    }

                    if (changed)
                    {
                        // Start a twitch to move the description text offset.
                        TwitchManager.Set <float> set = delegate(float value, Object param) { shared.descOffset = (int)value; };
                        TwitchManager.CreateTwitch <float>(shared.descOffset, -shared.topLine * UI2D.Shared.GameFont24.LineSpacing, set, 0.2f, TwitchCurve.Shape.EaseInOut);
                    }
                }

                // If we're not shutting down, update the child grids.
                if (parent.Active)
                {
                    Matrix world = Matrix.Identity;

                    if (shared.examplesGrid != null)
                    {
                        shared.examplesGrid.Update(ref world);
                    }
                } // end if not shutting down.
            }     // end of Update()
        }     // end of HandleTouch()

        private void HandleMouse()
        {
            // Mouse input
            Vector2 hit = MouseInput.PositionVec;

            // Cancel
            if (cancelButton.Box.LeftPressed(hit))
            {
                Deactivate(saveChanges: false);
                return;
            }

            // Save
            if (saveButton.Box.LeftPressed(hit))
            {
                Deactivate(saveChanges: true);
                return;
            }

            // Toggle LED
            if (toggleLEDButton.Box.LeftPressed(hit))
            {
                ledGrid.LEDs[ledGrid.FocusLEDIndex] = !ledGrid.LEDs[ledGrid.FocusLEDIndex];
                return;
            }

            // Change button label colors based on mouse hover.
            cancelButton.SetHoverState(hit);
            saveButton.SetHoverState(hit);
            toggleLEDButton.SetHoverState(hit);

            // Get hit point in camera coords.
            Vector2 cameraHit = -camera.PixelsToCameraSpaceScreenCoords(hit);

            // Handle clicks on ledGrid.  Hit boxes are in camera coords.
            if (MouseInput.Left.WasPressed)
            {
                for (int i = 0; i < ledGrid.ledHitBoxes.Length; i++)
                {
                    if (ledGrid.ledHitBoxes[i].Contains(cameraHit))
                    {
                        ledGrid.FocusLEDIndex = i;
                        // Also toggle when clicked.
                        ledGrid.LEDs[ledGrid.FocusLEDIndex] = !ledGrid.LEDs[ledGrid.FocusLEDIndex];
                    }
                }
            }

            // Handle clicks on sliders.
            if (MouseInput.Left.IsPressed)
            {
                // Brightness Slider
                Vector2 position = new Vector2(brightnessSlider.Position.X, brightnessSlider.Position.Y);
                Vector2 min      = position - brightnessSlider.Size / 2.0f;
                Vector2 max      = position + brightnessSlider.Size / 2.0f;
                AABB2D  box      = new AABB2D(min, max);
                if (box.Contains(cameraHit))
                {
                    brightnessSlider.Selected = true;
                    durationSlider.Selected   = false;

                    Vector2 uv = (cameraHit - min) / (max - min);
                    uv.Y = 1.0f - uv.Y;
                    brightnessSlider.HandleMouseInput(uv);
                }

                // Duration Slider
                position = new Vector2(durationSlider.Position.X, durationSlider.Position.Y);
                min      = position - durationSlider.Size / 2.0f;
                max      = position + durationSlider.Size / 2.0f;
                box      = new AABB2D(min, max);
                if (box.Contains(cameraHit))
                {
                    durationSlider.Selected   = true;
                    brightnessSlider.Selected = false;

                    Vector2 uv = (cameraHit - min) / (max - min);
                    uv.Y = 1.0f - uv.Y;
                    durationSlider.HandleMouseInput(uv);
                }
            }
        }   // end of HandleKeyboardMouse()
예제 #19
0
        private void HandleTouchInput(TouchContact touch, Vector2 hit)
        {
            if (hitBoxA.Touched(touch, hit))
            {
                // Disable this hint for this session.
                if (curHint.ShowOnce)
                {
                    curHint.Disabled = true;
                }

                Deactivate();
            }
            else if (hitBoxB.Touched(touch, hit))
            {
                // Disable this hint until reset by user.
                XmlOptionsData.SetHintAsDisabled(curHint.ID);

                // Disable this hint for this session.
                if (curHint.ShowOnce)
                {
                    curHint.Disabled = true;
                }

                Deactivate();
            }
            else if (upBox.Touched(touch, hit))
            {
                ScrollDown();
            }
            else if (downBox.Touched(touch, hit))
            {
                ScrollUp();
            }
            else
            {
                // Touch is active, but none of the buttons were hit so assume user is trying to scroll text.
                if (touch.phase == TouchPhase.Began)
                {
                    prevTouchY = touch.position.Y;
                }
                if (touch.phase == TouchPhase.Moved)
                {
                    // Note we calc the delta ourselves since the TouchInput code
                    // may return the TouchContact for multiple frames.
                    float delta = touch.position.Y - prevTouchY;

                    // Adjust for screen / rt ratio.
                    Vector2 ratio = TouchInput.GetWinRTRatio(camera);
                    delta /= ratio.Y;

                    accumulatedTouchInput += delta;
                    prevTouchY             = touch.position.Y;
                    if (accumulatedTouchInput > blob.TotalSpacing / 2)
                    {
                        accumulatedTouchInput -= blob.TotalSpacing;
                        ScrollDown();
                    }
                    else if (accumulatedTouchInput < -blob.TotalSpacing / 2)
                    {
                        accumulatedTouchInput += blob.TotalSpacing;
                        ScrollUp();
                    }
                }
            }

            // Check for hover and adjust text color to match.
            Color newColor;

            newColor = hitBoxA.Contains(hit) ? hoverTextColor : lightTextColor;
            if (newColor != labelATargetColor)
            {
                labelATargetColor = newColor;
                Vector3 curColor  = new Vector3(labelAColor.R / 255.0f, labelAColor.G / 255.0f, labelAColor.B / 255.0f);
                Vector3 destColor = new Vector3(newColor.R / 255.0f, newColor.G / 255.0f, newColor.B / 255.0f);

                TwitchManager.Set <Vector3> set = delegate(Vector3 value, Object param)
                {
                    labelAColor.R = (byte)(value.X * 255.0f + 0.5f);
                    labelAColor.G = (byte)(value.Y * 255.0f + 0.5f);
                    labelAColor.B = (byte)(value.Z * 255.0f + 0.5f);
                };
                TwitchManager.CreateTwitch <Vector3>(curColor, destColor, set, 0.1f, TwitchCurve.Shape.EaseOut);
            }

            newColor = hitBoxB.Contains(hit) ? hoverTextColor : lightTextColor;
            if (newColor != labelBTargetColor)
            {
                labelBTargetColor = newColor;
                Vector3 curColor  = new Vector3(labelBColor.R / 255.0f, labelBColor.G / 255.0f, labelBColor.B / 255.0f);
                Vector3 destColor = new Vector3(newColor.R / 255.0f, newColor.G / 255.0f, newColor.B / 255.0f);

                TwitchManager.Set <Vector3> set = delegate(Vector3 value, Object param)
                {
                    labelBColor.R = (byte)(value.X * 255.0f + 0.5f);
                    labelBColor.G = (byte)(value.Y * 255.0f + 0.5f);
                    labelBColor.B = (byte)(value.Z * 255.0f + 0.5f);
                };
                TwitchManager.CreateTwitch <Vector3>(curColor, destColor, set, 0.1f, TwitchCurve.Shape.EaseOut);
            }
        }   // end of HandleTouchInput()
예제 #20
0
        }   // end of c'tor

        public void Update(Camera camera)
        {
            if (gettingFeeds)
            {
                msNewsFeed.Update();
                if (msNewsFeed.CurrentState == NewsFeeds.OpState.Failed)
                {
                    newsScroller.Clear();
                    FeedMs item = new FeedMs(FeedSize, "Failed to get news feed...", TitleFont, DateFont, BodyFont);
                    newsScroller.AddItem(item);
                    gettingFeeds       = false;
                    newsScroller.Dirty = true;
                }
                else if (msNewsFeed.CurrentState == NewsFeeds.OpState.Retrieving)
                {
                    newsScroller.Clear();
                    FeedMs item = new FeedMs(FeedSize, "Updating news...", TitleFont, DateFont, BodyFont);
                    newsScroller.AddItem(item);
                    //gettingFeeds = false;
                    newsScroller.Dirty = true;
                }
                else if (msNewsFeed.CurrentState == NewsFeeds.OpState.Retrieved)
                {
                    try
                    {
                        // Done getting Tweets
                        newsScroller.Clear();
                        List <FeedMs> feedList = msNewsFeed.GetFeedList(
                            (int)(FeedSize.X - newsScroller.ScrollBoxSize.X), TitleFont, DateFont, BodyFont);
                        if (feedList != null)
                        {
                            foreach (FeedMs newsItem in feedList)
                            {
                                newsScroller.AddItem(newsItem);
                            }
                        }
                        newsScroller.ResizeItemWidths();
                        gettingFeeds       = false;
                        newsScroller.Dirty = true;
                    }
                    catch
                    {
                        newsScroller.Clear();
                        FeedMs item = new FeedMs(FeedSize, "Error getting news feed...", TitleFont, DateFont, BodyFont);
                        newsScroller.AddItem(item);
                        gettingFeeds       = false;
                        newsScroller.Dirty = true;
                    }
                }
            }

            Vector2 pureMouseHit = new Vector2(MouseInput.Position.X, MouseInput.Position.Y);

            if (moreLessHitBox.Contains(pureMouseHit) && MouseInput.Left.WasReleased)
            {
                expanded = !expanded;
            }

            //check touch hit
            TouchContact touch = TouchInput.GetOldestTouch();

            if (TouchInput.WasLastReleased && moreLessHitBox.Contains(touch.position))
            {
                expanded = !expanded;
            }

            // Even if not active we need to refresh the rendertarget.
            newsScroller.RefreshRT();

            if (Active)
            {
                newsScroller.Update(camera);

                if (camera == null)
                {
                    camera = new PerspectiveUICamera();
                }

                if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse)
                {
                    Vector2 hit = MouseInput.GetAspectRatioAdjustedPosition(camera, useOverscanForHitTesting);
                    pureMouseHit = new Vector2(MouseInput.Position.X, MouseInput.Position.Y);
                    if (!IsInScrollwindow(pureMouseHit))
                    {
                        // Don't Deactivate here just because the mouse cursor has left the bounds of the scroll window.
                        // We should only deactivate if ComboRight is pressed.
                        //Deactivate();

                        // But if we're out of bounds and the used clicks, then Deactivate()
                        if (MouseInput.Left.WasPressed)
                        {
                            Deactivate();
                        }
                    }
                    else if (MouseInput.PrevPosition != MouseInput.Position)
                    {
                        newsScroller.Activate();
                    }

                    if (true) //newsScroller.IsFocused)
                    {
                        if (Actions.ComboUp.WasPressedOrRepeat)
                        {
                            newsScroller.FocusPrev();
                        }
                        else if (Actions.ComboDown.WasPressedOrRepeat)
                        {
                            newsScroller.FocusNext();
                        }
                        else if (Actions.ComboRight.WasPressed)
                        {
                            Deactivate();
                        }
                        if (Actions.ZoomIn.WasPressedOrRepeat)
                        {
                            newsScroller.FocusPrevItem();
                        }
                        else if (Actions.ZoomOut.WasPressedOrRepeat)
                        {
                            newsScroller.FocusNextItem();
                        }
                    }

                    if (Actions.ComboLeft.WasPressed)
                    {
                        newsScroller.Activate();
                    }
                }
                else if (GamePadInput.ActiveMode == GamePadInput.InputMode.GamePad)
                {
                    HandleGamepadInput();
                }
            } // end if active.
        }     // end of Update()