From 444652da127f49d277c5f6853289ac277b0c2b6d Mon Sep 17 00:00:00 2001 From: Alessandro Proto Date: Wed, 22 Feb 2023 09:48:05 +0100 Subject: [PATCH] Bugfix mouse events and cursor not being offset by border --- Capy64/Eventing/InputManager.cs | 4 ++-- Capy64/Runtime/Libraries/Term.cs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Capy64/Eventing/InputManager.cs b/Capy64/Eventing/InputManager.cs index 11c2afc..57f26e8 100644 --- a/Capy64/Eventing/InputManager.cs +++ b/Capy64/Eventing/InputManager.cs @@ -74,7 +74,7 @@ public class InputManager }; public Texture2D Texture { get; set; } - public float WindowScale { get; set; } + public float WindowScale => Capy64.Instance.Scale; public const int MouseScrollDelta = 120; private Point mousePosition; @@ -113,7 +113,7 @@ public class InputManager if (!isActive) return; - var rawPosition = state.Position; + var rawPosition = state.Position - new Point(Capy64.Instance.Borders.Left, Capy64.Instance.Borders.Top); var pos = new Point((int)(rawPosition.X / WindowScale), (int)(rawPosition.Y / WindowScale)) + new Point(1, 1); if (pos.X < 1 || pos.Y < 1 || pos.X > Texture.Width || pos.Y > Texture.Height) diff --git a/Capy64/Runtime/Libraries/Term.cs b/Capy64/Runtime/Libraries/Term.cs index 4ee77f7..1d42d78 100644 --- a/Capy64/Runtime/Libraries/Term.cs +++ b/Capy64/Runtime/Libraries/Term.cs @@ -306,6 +306,7 @@ internal class Term : IComponent { var realpos = ToRealPos(CursorPosition - Vector2.One); var charpos = (realpos * _game.Scale) + (CharOffset + new Vector2(0, 2)) * _game.Scale; + charpos += new Vector2(Capy64.Instance.Borders.Left, Capy64.Instance.Borders.Top); _game.Game.SpriteBatch.Draw(cursorTexture, charpos, null, ForegroundColor, 0f, Vector2.Zero, _game.Scale, SpriteEffects.None, 0); } }