Is it possible to get "contextual" gestures in Monogame/XNA?
Asked Answered
C

1

17

I am working on a multi-touch app using Monogame, where multiple users can work on a larger multi-touch screen with separate documents/images/videos simultaneously, and I was wondering if it's possible to make gestures "context-aware", i.e. two fingers pinching a document on one side of the wall shouldn't affect somebody panning the other side of the wall.

The way Monogame works is, all input points are translated into gestures, which can be read using:

if (TouchPanel.IsGestureAvailable)
{
     var gesture = TouchPanel.ReadGesture();
     // do stuff
}

Is there a way to make gestures limited to a certain point on the screen, or do I need to implement this myself? For example, by looking at the source code, it appears that the TouchPanelState class does all the work, but unfortunately its constructors are internal.

Cassimere answered 6/12, 2014 at 10:34 Comment(1)
I don't know and didn't experience any XNA or Monogame programming, but for the record, it appears there is a TouchPanel static class, which has a GetState() method. Maybe that could help instantiating the TouchPanelState class you want?Mongolian
P
2

That feature is not built in to MonoGame, as it is not part of original XNA. Essentially you'd want more than one 'logical' TouchPanel defined by its sub-rectangle of the window. However TouchPanel is static, hence there is only one for the whole game in default XNA.

The good news is that MonoGame does its own gesture recognition. So, the code is there, you just need to make some changes to MonoGame.

Eg...
-Make TouchPanel a non-static class that can be allocated with a given subrect.
-Add non-static versions of all TouchPanel methods.
-The static methods redirect to a singleton/instance of TouchPanel, preserving the old API.
...now you can optionally allocate more TouchPanel(s) that AREN'T the whole screen.

Note: This doesn't help you, but MonoGame does allow you to have more than one OS window (on windows only afaik) in which case the static TouchPanel is the first window and there is a separate API for accessing touch input / gestures for any additional windows.

Pestiferous answered 10/1, 2015 at 2:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.