Skip to content

Commit

Permalink
Input handling fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rds1983 committed Nov 11, 2023
1 parent 6f85a03 commit 9188797
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MonoGame.Framework.Android" Version="$(MonoGameVersion)" />
<PackageReference Include="MonoGame.Content.Builder.Task" Version="$(MonoGameVersion)" />
<PackageReference Include="MonoGame.Framework.Android" Version="$(AppMonoGameVersion)" />
<PackageReference Include="MonoGame.Content.Builder.Task" Version="$(AppMonoGameVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/Myra/Graphics2D/UI/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@ public void RemoveChild(Widget child)
{
Widgets.Remove(child);
}

public override bool InputFallsThrough(Point localPos) => Background == null;
}
}
16 changes: 16 additions & 0 deletions src/Myra/Graphics2D/UI/Containers/ScrollViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -643,5 +643,21 @@ protected override void InternalSetStyle(Stylesheet stylesheet, string name)
{
ApplyScrollViewerStyle(stylesheet.ScrollViewerStyles.SafelyGetStyle(name));
}

public override bool InputFallsThrough(Point localPos)
{
if (Background != null)
{
return false;
}

if (_horizontalScrollingOn && _horizontalScrollbarFrame.Contains(localPos) ||
_verticalScrollingOn && _verticalScrollbarFrame.Contains(localPos))
{
return false;
}

return true;
}
}
}
4 changes: 2 additions & 2 deletions src/Myra/Graphics2D/UI/Widget.Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ protected internal virtual void ProcessInput(InputContext inputContext)
{
if (!Desktop.IsMobile)
{
if (IsMouseInside)
if (IsMouseInside && !InputFallsThrough(LocalMousePosition.Value))
{
inputContext.MouseOrTouchHandled = true;
}
}
else
{
if (IsTouchInside)
if (IsTouchInside && !InputFallsThrough(LocalTouchPosition.Value))
{
inputContext.MouseOrTouchHandled = true;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Myra/Graphics2D/UI/Widget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1410,12 +1410,15 @@ public virtual Widget HitTest(Point p)
}
}

if (result == null && !this.FallsThrough(p))
var localPos = ToLocal(p);
if (result == null && !InputFallsThrough(localPos))
{
result = this;
}

return result;
}

public virtual bool InputFallsThrough(Point localPos) => false;
}
}
28 changes: 0 additions & 28 deletions src/Myra/Utility/UIUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,33 +64,5 @@ public static void SortWidgetsByZIndex(this List<Widget> list)
n = newN;
} while (n > 1);
}

public static bool FallsThrough(this Widget w, Point p)
{
// Only containers can fall through
if (!(w is Container || w is ScrollViewer))
{
return false;
}

// Real containers are solid only if backround is set
if (w.Background != null)
{
return false;
}

var asScrollViewer = w as ScrollViewer;
if (asScrollViewer != null)
{
// Special case
if (asScrollViewer._horizontalScrollingOn && asScrollViewer._horizontalScrollbarFrame.Contains(p) ||
asScrollViewer._verticalScrollingOn && asScrollViewer._verticalScrollbarFrame.Contains(p))
{
return false;
}
}

return true;
}
}
}
1 change: 1 addition & 0 deletions src/MyraPad/Studio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ protected override void LoadContent()
base.LoadContent();

MyraEnvironment.Game = this;
MyraEnvironment.EnableModalDarkening = true;

_desktop = new Desktop();

Expand Down

0 comments on commit 9188797

Please sign in to comment.