Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 852
Lou Avatar asked Dec 06 '14 10:12

Lou


1 Answers

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.

like image 140
James Avatar answered Sep 20 '22 06:09

James