From 7bf9f39301da7eb2a093fb8b79efacafd2975f83 Mon Sep 17 00:00:00 2001 From: Thibaud Date: Thu, 31 May 2018 11:56:21 +0200 Subject: [PATCH] Update events with GetAxis --- SpaceNavEvent.cs | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/SpaceNavEvent.cs b/SpaceNavEvent.cs index bfb7515..3a243ff 100644 --- a/SpaceNavEvent.cs +++ b/SpaceNavEvent.cs @@ -1,26 +1,44 @@ using System; +using System.Collections.Generic; namespace SpaceNavWrapper { + public enum SpaceNavAxis { + X, Y, Z, Rx, Ry, Rz + } + public class MotionEventArgs : EventArgs { - public readonly int X, Y, Z; - public readonly int Rx, Ry, Rz; - + public readonly Dictionary axisValues; + public MotionEventArgs(int x, int y, int z, int rx, int ry, int rz) { - X = x; - Y = y; - Z = z; - Rx = rx; - Ry = ry; - Rz = rz; + axisValues = new Dictionary + { + [SpaceNavAxis.X] = x, + [SpaceNavAxis.Y] = y, + [SpaceNavAxis.Z] = y, + [SpaceNavAxis.Rx] = rx, + [SpaceNavAxis.Ry] = ry, + [SpaceNavAxis.Rz] = rz + }; } + public int X => axisValues[SpaceNavAxis.X]; + public int Y => axisValues[SpaceNavAxis.Y]; + public int Z => axisValues[SpaceNavAxis.Z]; + public int Rx => axisValues[SpaceNavAxis.Rx]; + public int Ry => axisValues[SpaceNavAxis.Ry]; + public int Rz => axisValues[SpaceNavAxis.Rz]; + public override string ToString() + { + return string.Format("x={0} y={1} z={2} rx={3} ry={4} rz={5}", X, Y, Z, Rx, Ry, Rz); + } + + public int GetAxis(SpaceNavAxis axis) { - return "x=" + X + " y=" + Y + " z=" + Z + - " rx=" + Rz + " ry=" + Ry + " rz=" + Rz; + return axisValues[axis]; } } @@ -34,9 +52,10 @@ namespace SpaceNavWrapper Pressed = pressed; Button = button; } + public override string ToString() { - return string.Format("[ButtonEventArgs: button={0}, pressed={1}]", Button, Pressed); + return string.Format("button={0}, pressed={1}", Button, Pressed); } } }