Loss of Mouse event propogation

Dec 1, 2009 at 8:49 PM

Hello Generoso,

Excellent work on the MIRIA project!

One problem I am having is the loss of the built-in platform touch support when using MIRIA.  Windows7 will, by default, propogate touch events to mouse events so that the various UI controls built in to Silverlight will still function using touch.  But when the TouchListener is instantiated in my Silverlight code, it appears that it disables mouse event propogation for all touch events, even when the touch is not over a visual element that implements Touchable.  I can't catch the cursor down/up and propogate the events in my own code because the mouse event constructors are protected in Silverlight.

Is there a workaround for this, or can you have TouchListener propogate the mouse events when not over a Touchable element?

Thanks again for the great library.

Coordinator
Dec 1, 2009 at 9:15 PM

If you send me example code to reproduce the issue I'll try to figure out and fix.

Thanks for feedback.

Gene.

Dec 2, 2009 at 9:44 PM

Hi Gene,

Here is code for a simple page that contains a base Silverlight TextBox and a ComboBox.  Notice that when the line to instantiate the TouchListener is commented out, you are able to operate the ComboBox by touch, dropping it down and making a selection.  You are also able to return focus by touch to the TextBox.  When the TouchListener is instantiated, the ComboBox no longer receives the mouse events propogated from touch, even though it doesn't implement Touchable.  It doesn't matter if the TouchListener constructor is passed the LayoutRoot or the inner Canvas that doesn't contain the ComboBox as a child - the problem is the same.

Thank you so much for looking at this.

<UserControl x:Class="SilverlightApplication1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
  <Canvas x:Name="LayoutRoot">

            <Canvas x:Name="cnvInner" Canvas.Left="0" Canvas.Top="0">
                <TextBox x:Name="txtSelected" TextWrapping="Wrap" Height="100" Width="200"/>
            </Canvas>
            <ComboBox x:Name="cmbTest" SelectionChanged="cmbTest_SelectionChanged" Height="36" Width="180" Canvas.Top="120">
                <ComboBoxItem Content="Item 1" IsSelected="True" />
                <ComboBoxItem Content="Item 2"/>
                <ComboBoxItem Content="Item 3"/>
            </ComboBox>

    </Canvas>
</UserControl>
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using MIRIA.Devices.MultiTouch;

namespace SilverlightApplication1
{
    public partial class MainPage : UserControl
    {
        private TouchListener touchListener_;

        public MainPage()
        {
            InitializeComponent();
            //touchListener_ = new TouchListener(LayoutRoot);
            //touchListener_ = new TouchListener(cnvInner);
        }

        private void cmbTest_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cmbTest == null) return;
            ComboBoxItem item = (ComboBoxItem)cmbTest.SelectedItem;
            txtSelected.Text = (String)item.Content;
        }
    }
}
Nov 24, 2010 at 1:17 AM

Hi there, was there any resolution to this? I am having the same issue.

Nov 24, 2010 at 1:25 AM

Not as far as I know.  I was not made aware of a fix.

Coordinator
Feb 4, 2011 at 10:36 PM

Complete MIRIA Core source code is now available both for download and from svn.

I did not have time to check the propagation issue yet but in the meantime I'll give you a tip =) check line 142 of the source file MIRIA-SDK\Devices\Multitouch\TouchListener.cs .

There may be the right place for the fix.

 

G.

 

Apr 19, 2011 at 7:00 PM

Hi,

I'm having the same issue - is there a way to temporarily disable Miria, then re-enable Miria?

Coordinator
Apr 26, 2011 at 5:51 PM
Hi,

have you tried setting TouchListener.ProcessMouseEvents to false ?

G.


acohan51 wrote:

Hi,

I'm having the same issue - is there a way to temporarily disable Miria, then re-enable Miria?

 

Apr 27, 2011 at 10:24 PM

Thanks for your reply. I’ve tried that and it doesn’t seem to work. Any other direction is much appreciated. -A

From: Generoso [mailto:[email removed]]
Sent: Tuesday, April 26, 2011 12:52 PM
To: [email removed]
Subject: Re: Loss of Mouse event propogation [miria:76758]

From: Generoso

Hi,

have you tried setting TouchListener.ProcessMouseEvents to false ?

G.

acohan51 wrote:

Hi,

I'm having the same issue - is there a way to temporarily disable Miria, then re-enable Miria?

May 13, 2011 at 8:04 PM

Are you interested in taking a look at my project?  I'm willing to pay hourly.  Thanks.

Coordinator
May 13, 2011 at 9:46 PM
acohan51 wrote:

Are you interested in taking a look at my project?  I'm willing to pay hourly.  Thanks.

I am releasing in the next few days a new version of MIRIA and mono-MIG.

I will try to fix this issue in time =) There is lot of new cool stuff in this release.

I will add some property to disable this behaviour. Can this be of any help for you project?

 

Gene.

May 13, 2011 at 9:50 PM

If it allows other touch events to propagate through as mouse events to other controls, then it should help, yes. Thanks!

From: Generoso [mailto:[email removed]]
Sent: Friday, May 13, 2011 4:47 PM
To: [email removed]
Subject: Re: Loss of Mouse event propogation [miria:76758]

From: Generoso

acohan51 wrote:

Are you interested in taking a look at my project? I'm willing to pay hourly. Thanks.

I am releasing in the next few days a new version of MIRIA and mono-MIG.

I will try to fix this issue in time =) There is lot of new cool stuff in this release.

I will add some property to disable this behaviour. Can this be of any help for you project?

Gene.

Coordinator
May 13, 2011 at 9:57 PM
acohan51 wrote:

If it allows other touch events to propagate through as mouse events to other controls, then it should help, yes. Thanks!

 

 

From: Generoso [mailto:[email removed]]
Sent: Friday, May 13, 2011 4:47 PM
To: [email removed]
Subject: Re: Loss of Mouse event propogation [miria:76758]

 

From: Generoso

acohan51 wrote: 

Are you interested in taking a look at my project? I'm willing to pay hourly. Thanks.

I am releasing in the next few days a new version of MIRIA and mono-MIG.

I will try to fix this issue in time =) There is lot of new cool stuff in this release.

I will add some property to disable this behaviour. Can this be of any help for you project?

 

Gene.

Ok... I'll try to achieve this =) Stay tuned.

 

 

G.

May 13, 2011 at 10:07 PM

Great, thanks! Is there a way to donate to Miria? Also, are you interested in freelance Silverlight development? Can you email me adam@briosolutions.com. Thanks!

Coordinator
May 13, 2011 at 10:54 PM
acohan51 wrote:

If it allows other touch events to propagate through as mouse events to other controls, then it should help, yes. Thanks!

 

 

From: Generoso [mailto:[email removed]]
Sent: Friday, May 13, 2011 4:47 PM
To: [email removed]
Subject: Re: Loss of Mouse event propogation [miria:76758]

 

From: Generoso

acohan51 wrote: 

Are you interested in taking a look at my project? I'm willing to pay hourly. Thanks.

I am releasing in the next few days a new version of MIRIA and mono-MIG.

I will try to fix this issue in time =) There is lot of new cool stuff in this release.

I will add some property to disable this behaviour. Can this be of any help for you project?

 

Gene.

 

one question... are you using just the TouchListener? Right? (no kinect or wii remote I mean)

 

G.

May 13, 2011 at 10:56 PM

Correct. Just the TouchListener

Jun 6, 2011 at 9:08 AM

Hi Generoso,
Did you eventually solved this issue? I've the same problem...

Coordinator
Jun 6, 2011 at 9:38 AM
shadowsheep wrote:

Hi Generoso,
Did you eventually solved this issue? I've the same problem...

Yes,

issue solved. Checkout latest SVN revision or just copy the TouchListener.cs file from it.

 

Gene.

Jun 6, 2011 at 10:18 AM

Yep! it works!
But now I've got another issue.
I use Navigation Frame in the main page

<Canvas x:Name="rootElement" OpacityMask="Black" Background="#FFF4F0EF">
        <sdk:Frame x:Name="ContentFrame" Source="Home">
            <sdk:Frame.UriMapper>
                <sdk:UriMapper>
                    <sdk:UriMapping Uri="Home" MappedUri="/Home.xaml"/>
                    <sdk:UriMapping Uri="Sofa" MappedUri="/SelSofa.xaml"/>
                    <sdk:UriMapping Uri="SofaType" MappedUri="/SelSofaType.xaml"/>
                    <sdk:UriMapping Uri="SofaTypeUpdate" MappedUri="/SelSofaTypeUpdate.xaml"/>
...

The page that use the TouchListener is that

<sdk:UriMapping Uri="Catal" MappedUri="/Catalogue.xaml"/>

So, now, the first time I enter this page all works fine but when I enter another page (let's say Home.xaml) and then I come back, the moultitouch event is not fired. 


Coordinator
Jun 6, 2011 at 1:52 PM
shadowsheep wrote:

Yep! it works!
But now I've got another issue.
I use Navigation Frame in the main page

<Canvas x:Name="rootElement" OpacityMask="Black" Background="#FFF4F0EF">
        <sdk:Frame x:Name="ContentFrame" Source="Home">
            <sdk:Frame.UriMapper>
                <sdk:UriMapper>
                    <sdk:UriMapping Uri="Home" MappedUri="/Home.xaml"/>
                    <sdk:UriMapping Uri="Sofa" MappedUri="/SelSofa.xaml"/>
                    <sdk:UriMapping Uri="SofaType" MappedUri="/SelSofaType.xaml"/>
                    <sdk:UriMapping Uri="SofaTypeUpdate" MappedUri="/SelSofaTypeUpdate.xaml"/>
...

The page that use the TouchListener is that

<sdk:UriMapping Uri="Catal" MappedUri="/Catalogue.xaml"/>

So, now, the first time I enter this page all works fine but when I enter another page (let's say Home.xaml) and then I come back, the moultitouch event is not fired. 



Pheraps the panel where the TouchListner listen on, is not in view or has got another control with transparent background on top of it.

Can you check those things and report?

Thanks,

Gene.

Jun 7, 2011 at 8:36 AM

I've tried to implement a simple multi touch scale function to 2 images in the following way:

	Dim _primaryContactId As Integer = -1
    Dim _primaryTouchPoint As TouchPoint = Nothing
    Private Sub _touchFrameReported(ByVal sender As Object, ByVal e As TouchFrameEventArgs)
        _debug_lbl.Text = ""
        _debug_lbl.Text = "Multitouch Event! -> _touchFrameReported" & Environment.NewLine

        ' get all active touchpoints relative to the plugin root
        Dim _touchPoints As TouchPointCollection = e.GetTouchPoints(Nothing)
        _debug_lbl.Text = "Touch Points #" & _touchPoints.Count & Environment.NewLine

        ' get the first touch message point 
        _primaryTouchPoint = e.GetPrimaryTouchPoint(Nothing)

        ' if we want we can disable the mouse clicks...
        If Not _primaryTouchPoint Is Nothing And TouchAction.Down.Equals(_primaryTouchPoint.Action) Then
            _debug_lbl2.Text = "primary touch point: " & _primaryTouchPoint.Position.ToString & Environment.NewLine
            ' I won't call this method otherwise I cannot click on all my other buttons
            ' e.SuspendMousePromotionUntilTouchUp()
        End If

        For Each _tp As TouchPoint In _touchPoints
            Dim _touchDeviceId As Integer = _tp.TouchDevice.Id
            Select Case _tp.Action

                Case TouchAction.Down
                    Dim _hitImage As Image = GetHitImage(_tp.Position)
                    If Not _hitImage Is Nothing Then
                        _points.Add(_tp.TouchDevice.Id, _tp.Position)

                        If 1 = _points.Count Then
                            ' save the first "finger" id
                            _primaryContactId = _tp.TouchDevice.Id
                        End If
                    End If

                Case TouchAction.Move
                    Dim _id As Integer = _tp.TouchDevice.Id
                    Dim _p1 As Point = _tp.Position
                    Dim _p2 As Point = _points(_id)

                    If 1 = _points.Count Then
                        ' Single Touch Gesture
                    Else
                        ' Multi Touch Gesture
                        If Not _tp.TouchDevice.Id = _primaryContactId Then
                            Dim _fe As FrameworkElement = GetHitImage(_tp.Position)
                            If Not _fe Is Nothing Then
                                ScaleImage(_fe, _points(_primaryContactId), _p1, _p2)
                            End If
                        End If
                    End If
                    _points(_id) = _p1

                Case TouchAction.Up
                        ' stop tracking device position
                        _points.Remove(_tp.TouchDevice.Id)
            End Select
        Next
    End Sub

    Private Function GetHitImage(ByVal _position As Point) As FrameworkElement
        Dim _i As Image = Nothing
        For Each _el As FrameworkElement In VisualTreeHelper.FindElementsInHostCoordinates(_position, Me)
            Try
                _i = CType(_el, Image)
                Return _i
            Catch ex As Exception
                Return Nothing
            End Try
        Next
        Return Nothing
    End Function

    Private Function Get2PointsDistance(ByVal _p1 As Point, ByVal _p2 As Point)
        Return Math.Sqrt(Math.Pow(_p1.X - _p2.X, 2) + Math.Pow(_p1.Y - _p2.Y, 2))
    End Function

    Private Sub ScaleImage(ByRef _fe As FrameworkElement, ByVal _origin As Point, ByVal _oldP As Point, ByVal _newP As Point)

        Dim _previousLen As Double = Get2PointsDistance(_origin, _oldP)
        Dim _newLen As Double = Get2PointsDistance(_origin, _newP)
        Dim _scale As Double = (_previousLen - _newLen) / _newLen

        _debug_lbl.Text &= "scale %: " & _scale & Environment.NewLine
        If Not 0 = _scale Then
            ' Apply a scale transform!
            If _fe.Name.ToLower.Contains("odd") Then
                _even_page.SetValue(Canvas.ZIndexProperty, 0)
                _odd_page.SetValue(Canvas.ZIndexProperty, 200)
                Dim _check_scale As Double = _op_scale.ScaleY + _scale
                If _check_scale > 0.5 And _check_scale < 1.5 Then
                    _op_scale.ScaleY += _scale
                    _op_scale.ScaleX += _scale
                End If
            Else
                _odd_page.SetValue(Canvas.ZIndexProperty, 0)
                _even_page.SetValue(Canvas.ZIndexProperty, 200)
                Dim _check_scale As Double = _ep_scale.ScaleY + _scale
                If _check_scale > 0.5 And _check_scale < 1.5 Then
                    _ep_scale.ScaleX += _scale
                    _ep_scale.ScaleY += _scale
                End If
            End If
        End If
    End Sub

It works until I change page. When I enter again the page with multi touch something is not working... I had to remove and add again the handler to Touch.FrameReported in this way

 Private Sub _loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
        _points.Clear()
        RemoveHandler Touch.FrameReported, AddressOf _touchFrameReported
        AddHandler Touch.FrameReported, AddressOf _touchFrameReported
    End Sub
In order to make things work.
Coordinator
Jun 7, 2011 at 9:14 AM

Ok, but I don't see MIRIA TouchListener in your code?

Pheraps you need a way to reset/readd the FrameReported event handler used in the TouchListener class?

 

Gene.

Jun 7, 2011 at 9:56 AM

Yep! I guess that's the point.

The code above was just to easily debug silverlight multitouch much deeper.

I thing that if someone use Navigation Frame he needs a way to set/reset FrameReported event. That's what I've found out with the debug code.

Coordinator
Jun 11, 2011 at 10:52 PM
shadowsheep wrote:

Yep! I guess that's the point.

The code above was just to easily debug silverlight multitouch much deeper.

I thing that if someone use Navigation Frame he needs a way to set/reset FrameReported event. That's what I've found out with the debug code.

 

Hi guys,

last SVN commit finally resolves the issue =)

Still Example MIRIA-Web app is not complete at all, but MIRIA.DLL is fully functional for the mouse/multitouch part. Kinect and Wii remote interaction logic not completed though.

Gene.