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; } } }
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; } } }
} // 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()