# HG changeset patch # User Alys Brooks # Date 2023-01-11 07:26:18 # Node ID 4370c4f6e8f816fe980715b436d0024d0e50cdf9 # Parent b3e89dc5598bef1ff0524d616300f98c7f646e95 Only scroll after a slight delay. Wait about 1/3 of a second before beginning to scroll. Otherwise it becomes too easy to trigger by mistake when mousing over to the toolbar. diff --git a/isometric-park-fna/Engines/InputEngine.cs b/isometric-park-fna/Engines/InputEngine.cs --- a/isometric-park-fna/Engines/InputEngine.cs +++ b/isometric-park-fna/Engines/InputEngine.cs @@ -46,6 +46,9 @@ private int height; private int width; + private double timeInRange; + private const double SCROLL_THRESHOLD = 0.333f; + public InputEngine(int menuBarHeight, Camera camera, GraphicsDeviceManager gdm, int height, int width) { //initialize to blank for now @@ -56,6 +59,8 @@ this.graphicsDevice = gdm.GraphicsDevice; this.height = height; this.width = width; + + this.timeInRange = 0.0f; } @@ -245,20 +250,33 @@ #endregion misc_keys #region mouse_movement + var within_top_range = MathUtils.BetweenExclusive(mouseCur.Y, menuBarHeight, 50 + menuBarHeight); + var within_bottom_range = MathUtils.BetweenExclusive(mouseCur.Y, (viewHeight - 50 -menuBarHeight), viewHeight-menuBarHeight); + var within_left_range = MathUtils.BetweenExclusive(mouseCur.X, 0, 50); + var within_right_range = MathUtils.BetweenExclusive(mouseCur.X, (viewWidth - 50), viewWidth); - if (MathUtils.BetweenExclusive(mouseCur.Y, menuBarHeight, 50 + menuBarHeight)) + if (within_top_range || within_bottom_range || within_right_range || within_left_range) + { + this.timeInRange += dt; + } + else + { + this.timeInRange = 0; + } + + if (within_top_range && this.timeInRange > SCROLL_THRESHOLD) { SendMessage(new MoveCameraMessage {Movement = new Vector2(0, -4)}); } - else if (MathUtils.BetweenExclusive(mouseCur.Y, (viewHeight - 50 -menuBarHeight), viewHeight-menuBarHeight)) + else if (within_bottom_range && this.timeInRange > SCROLL_THRESHOLD) { SendMessage(new MoveCameraMessage {Movement = new Vector2(0, 4)}); } - if (MathUtils.BetweenExclusive(mouseCur.X, 0, 50)) + if (within_left_range && this.timeInRange > SCROLL_THRESHOLD) { SendMessage(new MoveCameraMessage {Movement = new Vector2(-4, 0)}); } - else if (MathUtils.BetweenExclusive(mouseCur.X, (viewWidth - 50), viewWidth)) + else if (within_right_range && this.timeInRange > SCROLL_THRESHOLD) { SendMessage(new MoveCameraMessage {Movement = new Vector2(4, 0)}); }