Example #1
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;
                }
            }
        }
Example #2
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;
            }
        }
        }     // 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()