Permalink
Browse files

Fixed bugs with WPF touch and mouse events

  • Loading branch information...
1 parent 7e3bbb3 commit d58dedcd551040e9da4f5a643b5147ff84ac56d9 @praeclarum committed Feb 6, 2013
Showing with 21 additions and 12 deletions.
  1. +2 −1 nuget/CrossGraphics.nuspec
  2. +2 −2 src/AssemblyInfo.cs
  3. +17 −9 src/XamlCanvas.cs
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
- <version>1.0.4</version>
+ <version>1.0.5</version>
<authors>Frank A. Krueger</authors>
<owners>Frank A. Krueger</owners>
<projectUrl>https://github.com/praeclarum/CrossGraphics</projectUrl>
@@ -14,6 +14,7 @@
<summary>Cross-platform library for rendering vector graphics.</summary>
<releaseNotes>
<![CDATA[
+ v1.0.5: Fixed bugs with WPF touch and mouse events
v1.0.4: Added framework: portable-sl4+wp71+windows8
v1.0.3: Added framework: windowsphone8
v1.0.2: Cleaned up the namespace
View
@@ -23,6 +23,6 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
-[assembly: AssemblyVersion("1.0.4.*")]
-[assembly: AssemblyFileVersion("1.0.4")]
+[assembly: AssemblyVersion("1.0.5.*")]
+[assembly: AssemblyFileVersion("1.0.5")]
//[assembly: ComVisible(false)]
View
@@ -30,13 +30,15 @@
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Input;
using DispatcherTimerTickEventArgs = System.Object;
+using NativeColors = Windows.UI.Colors;
#else
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using DispatcherTimerTickEventArgs = System.EventArgs;
+using NativeColors = System.Windows.Media.Colors;
#endif
namespace CrossGraphics
@@ -84,6 +86,8 @@ public CanvasContent Content
public XamlCanvas ()
{
+ Background = new SolidColorBrush (NativeColors.Transparent);
+
MinFps = 4;
MaxFps = 30;
Continuous = true;
@@ -604,8 +608,6 @@ void HandleTouchFrameReported(object sender, TouchFrameEventArgs e)
}
}
#else
- readonly Dictionary<IntPtr, CanvasTouch> activeTouches = new Dictionary<IntPtr, CanvasTouch> ();
-
static readonly IntPtr MouseId = new IntPtr (42424242);
void XamlCanvas_TouchDown (object sender, TouchEventArgs e)
@@ -623,7 +625,7 @@ void XamlCanvas_TouchDown (object sender, TouchEventArgs e)
t.CanvasPreviousLocation = t.CanvasLocation;
t.SuperCanvasPreviousLocation = t.SuperCanvasLocation;
- activeTouches[t.Handle] = t;
+ _activeTouches[t.Handle] = t;
if (Content != null) {
Content.TouchesBegan (new[] { t }, CanvasKeys.None);
@@ -634,7 +636,7 @@ void XamlCanvas_TouchMove (object sender, TouchEventArgs e)
{
var id = new IntPtr (e.TouchDevice.Id);
CanvasTouch t;
- if (!activeTouches.TryGetValue (id, out t)) return;
+ if (!_activeTouches.TryGetValue (id, out t)) return;
t.SuperCanvasPreviousLocation = t.SuperCanvasLocation;
t.CanvasPreviousLocation = t.CanvasLocation;
@@ -655,7 +657,9 @@ void XamlCanvas_TouchUp (object sender, TouchEventArgs e)
{
var id = new IntPtr (e.TouchDevice.Id);
CanvasTouch t;
- if (!activeTouches.TryGetValue (id, out t)) return;
+ if (!_activeTouches.TryGetValue (id, out t)) return;
+
+ _activeTouches.Remove (id);
if (Content != null) {
Content.TouchesEnded (new[] { t });
@@ -666,7 +670,9 @@ void XamlCanvas_TouchLeave (object sender, TouchEventArgs e)
{
var id = new IntPtr (e.TouchDevice.Id);
CanvasTouch t;
- if (!activeTouches.TryGetValue (id, out t)) return;
+ if (!_activeTouches.TryGetValue (id, out t)) return;
+
+ _activeTouches.Remove (id);
if (Content != null) {
Content.TouchesCancelled (new[] { t });
@@ -692,7 +698,7 @@ void XamlCanvas_MouseDown (object sender, MouseButtonEventArgs e)
t.CanvasPreviousLocation = t.CanvasLocation;
t.SuperCanvasPreviousLocation = t.SuperCanvasLocation;
- activeTouches[t.Handle] = t;
+ _activeTouches[t.Handle] = t;
if (Content != null) {
Content.TouchesBegan (new[] { t }, CanvasKeys.None);
@@ -702,7 +708,7 @@ void XamlCanvas_MouseDown (object sender, MouseButtonEventArgs e)
void XamlCanvas_MouseMove (object sender, MouseEventArgs e)
{
CanvasTouch t;
- if (!activeTouches.TryGetValue (MouseId, out t)) return;
+ if (!_activeTouches.TryGetValue (MouseId, out t)) return;
t.SuperCanvasPreviousLocation = t.SuperCanvasLocation;
t.CanvasPreviousLocation = t.CanvasLocation;
@@ -722,7 +728,9 @@ void XamlCanvas_MouseMove (object sender, MouseEventArgs e)
void XamlCanvas_MouseUp (object sender, MouseButtonEventArgs e)
{
CanvasTouch t;
- if (!activeTouches.TryGetValue (MouseId, out t)) return;
+ if (!_activeTouches.TryGetValue (MouseId, out t)) return;
+
+ _activeTouches.Remove (MouseId);
if (Content != null) {
Content.TouchesEnded (new[] { t });

0 comments on commit d58dedc

Please sign in to comment.