public void ZoomHorizontal(int direction) { double viewportChangeInPercent = 0.25; Vector2 zoomPosition = Touch.activeTouches.Count == 2 // Center position of the touches ? (Touch.activeTouches[0].screenPosition + Touch.activeTouches[1].screenPosition) / 2f // Mouse position : InputUtils.GetMousePosition(); Vector2 localZoomPosition = rectTransform.InverseTransformPoint(zoomPosition); float width = rectTransform.rect.width; double xPercent = (localZoomPosition.x + (width / 2)) / width; double zoomFactor = (direction > 0) ? (1 - viewportChangeInPercent) : (1 + viewportChangeInPercent); int newViewportWidth = (int)(ViewportWidth * zoomFactor); newViewportWidth = NumberUtils.Limit(newViewportWidth, ViewportMinWidth, ViewportMaxWidth); // Already reached min or max zoom. if (newViewportWidth == ViewportWidth) { return; } int viewportChange = ViewportWidth - newViewportWidth; int viewportChangeLeftSide = (int)(viewportChange * xPercent); int newViewportX = ViewportX + viewportChangeLeftSide; int oldViewportWidth = ViewportWidth; if (oldViewportWidth != newViewportWidth) { SetViewportHorizontal(newViewportX, newViewportWidth); } }
public Vector2 GetTransFormedCursorPos(Vector2?addVector) { addVector = addVector ?? Vector2.Zero; if (UseRenderTarget && RendertargetTranformMatrix != null && !IncludeCursorInRenderTarget) { var matrix = Matrix.Invert(RendertargetTranformMatrix.Value); return(InputUtils.TransformCursorPos(matrix) + Vector2.Transform(addVector.Value, matrix)); } return(InputUtils.GetMousePosition() + addVector.Value); }
public void DrawCursor(SpriteBatch spriteBatch) { spriteBatch.Begin(SpriteSortMode.Deferred, BlendState, SamplerState, DepthStencilState.None, RasterizerState.CullCounterClockwise); float cursorSize = CursorScale * GlobalScale * ((float)p_CursorWidth / (float)p_CursorTexture.Width); Vector2 cursorPos = InputUtils.GetMousePosition(); spriteBatch.Draw(p_CursorTexture, new Rectangle( (int)(cursorPos.X + p_CursorOffset.X + cursorSize), (int)(cursorPos.Y + p_CursorOffset.Y + cursorSize), (int)(p_CursorTexture.Width * cursorSize), (int)(p_CursorTexture.Height * cursorSize)), Color.White); spriteBatch.End(); }
public void Update(GameTime gameTime) { InputUtils.Update(gameTime); if (InputUtils.IsActionTriggered("Open Console")) { ConsoleWindow.Visible = !ConsoleWindow.Visible; } p_gameTime = gameTime; string FPS = string.Format("UpdatesPS: {0}", (int)fps.AverageFramesPreSecond); SetCursor(CursorType.Default); double deltaTime = gameTime.ElapsedGameTime.TotalSeconds; if (p_DragTargetEntity != null && !InputUtils.IsMouseButtonLeftPressed()) { p_DragTargetEntity = null; } Entity target = null; bool wasEventHandled = false; Root.Update(ref target, ref p_DragTargetEntity, ref wasEventHandled, gameTime, Point.Zero); if (InputUtils.IsMouseButtonLeftPressed()) { ActiveEntity = target; } p_testform.SetMousePosText(InputUtils.GetMousePosition().X.ToString(), InputUtils.GetMousePosition().Y.ToString()); p_testform.SetEntityTargets(target, p_DragTargetEntity); ActiveEntity = ActiveEntity ?? Root; p_TargetEntity = target; WasEventHandled = wasEventHandled; fps.Update(deltaTime); UpdatesPreSecound = string.Format("UpdatesPS: {0}", (int)fps.AverageFramesPreSecond); }