Ejemplo n.º 1
0
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    IDisposable graphicsDispose = graphics as IDisposable;
                    if (graphicsDispose != null)
                    {
                        graphicsDispose.Dispose();
                        graphicsDispose = null;
                    }

                    if (contactTarget != null)
                    {
                        contactTarget.Dispose();
                        contactTarget = null;
                    }
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
Ejemplo n.º 2
0
 private void InitializeSurfaceInput()
 {
     hwnd          = new System.Windows.Interop.WindowInteropHelper(this).Handle;
     contactTarget = new Microsoft.Surface.Core.ContactTarget(hwnd);
     contactTarget.EnableInput();
     EnableRawImage();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes the surface input system. This should be called after any window
        /// initialization is done, and should only be called once.
        /// </summary>
        private void InitializeSurfaceInput()
        {
            System.Diagnostics.Debug.Assert(Window.Handle != System.IntPtr.Zero,
                                            "Window initialization must be complete before InitializeSurfaceInput is called");
            if (Window.Handle == System.IntPtr.Zero)
            {
                return;
            }
            //System.Diagnostics.Debug.Assert(contactTarget == null,
            //                                "Surface input already initialized");

            if (contactTarget != null)
            {
                return;
            }

            // Create a target for surface input.
            // Use an IntPtr.Zero as the handle, but still have a Window(!!) as an ivar
            // to get contacts globaly.
            contactTarget = new ContactTarget(IntPtr.Zero, EventThreadChoice.OnCurrentThread, true);

            // Enable the Surface input on this target:
            //bHasImage = contactTarget.EnableImage(ImageType.Normalized);
            //if (bHasImage) contactTarget.FrameReceived += new EventHandler<FrameReceivedEventArgs>(contactTarget_FrameReceived);

            contactTarget.EnableInput();
        }
Ejemplo n.º 4
0
        private void InitializeSurfaceInput()
        {
            hwnd          = new System.Windows.Interop.WindowInteropHelper(this).Handle;
            contactTarget = new Microsoft.Surface.Core.ContactTarget(hwnd);
            contactTarget.EnableInput();

            tracker                = new Tracker();
            tracker.DeviceAdded   += tracker_DeviceAdded;
            tracker.DeviceRemoved += tracker_DeviceRemoved;
            tracker.DeviceUpdated += tracker_DeviceUpdated;

            EnableRawImage();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a <strong><see cref="UIController"/></strong> instance with the specified parameters.
        /// </summary>
        /// <param name="contactTarget">A contact target to use for collecting contacts.</param>
        /// <param name="hitTestCallback">A delegate that is used to do hit testing.</param>
        public UIController(ContactTarget contactTarget, HitTestCallback hitTestCallback)
        {
            if (contactTarget == null)
                throw SurfaceCoreFrameworkExceptions.ArgumentNullException("contactTarget");

            if (hitTestCallback == null)
                throw SurfaceCoreFrameworkExceptions.ArgumentNullException("hitTestCallback");

            this.contactTarget = contactTarget;
            this.hitTestCallback = hitTestCallback;

            this.contactTarget.ContactAdded += new EventHandler<ContactEventArgs>(OnContactAdded);
            this.contactTarget.ContactChanged += new EventHandler<ContactEventArgs>(OnContactChanged);
            this.contactTarget.ContactRemoved += new EventHandler<ContactEventArgs>(OnContactRemoved);
        }
Ejemplo n.º 6
0
        public InputContext(InputProvider provider)
        {
            inputProvider = provider;

            window      = EventDispatchingNativeWindow.Instance;
            oldContacts = new List <Contact>();

            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());

            contactTarget = new ContactTarget(IntPtr.Zero, true);
            contactTarget.EnableInput();

            timer          = new System.Windows.Forms.Timer();
            timer.Interval = 1000 / 60;
            timer.Tick    += timer_Tick;
            timer.Start();
        }
        public void Init()
        {
            this.registeredTouches = new Dictionary <uint, PointerTouchInfo>();
            this.injectedIds       = new HashSet <uint>();
#if DEBUG
            this.debuginfo = new StringBuilder();
#endif
            this.touch.PointerInfo.pointerType = PointerInputType.TOUCH;
            this.touch.Orientation             = 90;
            this.touch.Pressure   = 32000;
            this.touch.TouchMasks = TouchMask.CONTACTAREA | TouchMask.ORIENTATION | TouchMask.PRESSURE;

            System.Diagnostics.Debug.Write($"{DateTime.Now}: Create native window with handle... ");
            this.window = new NativeWindow();
            this.window.CreateHandle(new CreateParams());
            System.Diagnostics.Debug.WriteLine($"[OK]");

            // Create a target for surface input
            System.Diagnostics.Debug.Write($"{DateTime.Now}: Create contact target... ");
            this.ContactTarget = new ContactTarget(IntPtr.Zero, EventThreadChoice.OnBackgroundThread);
            this.ContactTarget.EnableInput();
            System.Diagnostics.Debug.WriteLine($"[OK]");

            // Init the InputSimulator
            System.Diagnostics.Debug.Write($"{DateTime.Now}: Init input simulatOr... ");
            this.inputSimulator = new InputSimulator();
            System.Diagnostics.Debug.WriteLine($"[OK]");

            // Initialize the TouchInjector
            System.Diagnostics.Debug.Write($"{DateTime.Now}: Init touch injector... ");
            bool s = TouchInjector.InitializeTouchInjection(NumberOfSimultaniousTouches, TouchFeedback.DEFAULT);
            if (s)
            {
                System.Diagnostics.Debug.WriteLine($"[OK]");
            }
            else
            {
                System.Diagnostics.Debug.WriteLine($"[FAILED]");
                return;
            }

            // Setup event handlers
            this.InitEventHandlers();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes the surface input system. This should be called after any window
        /// initialization is done, and should only be called once.
        /// </summary>
        private void InitializeSurfaceInput()
        {
            System.Diagnostics.Debug.Assert(Window.Handle != System.IntPtr.Zero,
                                            "Window initialization must be complete before InitializeSurfaceInput is called");
            if (Window.Handle == System.IntPtr.Zero)
            {
                return;
            }
            System.Diagnostics.Debug.Assert(contactTarget == null,
                                            "Surface input already initialized");
            if (contactTarget != null)
            {
                return;
            }

            // Create a target for surface input.
            contactTarget = new ContactTarget(Window.Handle, EventThreadChoice.OnBackgroundThread);
            contactTarget.EnableInput();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes the surface input system. This should be called after any window
        /// initialization is done, and should only be called once.
        /// </summary>
        private void InitializeSurfaceInput()
        {
            Debug.Assert(Window.Handle != IntPtr.Zero,
                         "Window initialization must be complete before InitializeSurfaceInput is called");
            if (Window.Handle == IntPtr.Zero)
            {
                return;
            }
            Debug.Assert(contactTarget == null,
                         "Surface input already initialized");
            if (contactTarget != null)
            {
                return;
            }

            // Create a target for surface input.
            contactTarget = new ContactTarget(IntPtr.Zero, true);
            contactTarget.EnableInput();
        }
Ejemplo n.º 10
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Release managed resources.
                IDisposable graphicsDispose = graphics;
                if (graphicsDispose != null)
                {
                    graphicsDispose.Dispose();
                }
                if (contactTarget != null)
                {
                    contactTarget.Dispose();
                    contactTarget = null;
                }
            }

            // Release unmanaged Resources.

            // Set large objects to null to facilitate garbage collection.

            base.Dispose(disposing);
        }
        private void InitializeSurfaceInput()
        {
            hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
            contactTarget = new Microsoft.Surface.Core.ContactTarget(hwnd);
            contactTarget.EnableInput();

            EnableRawImage();
        }
 /// <summary>
 /// Enables the raw image input on the ContactTarget.
 /// </summary>
 /// <param name="contactTarget">The contact target.</param>
 private static void EnableRawImage(ContactTarget contactTarget)
 {
     contactTarget.EnableImage(Microsoft.Surface.Core.ImageType.Normalized);
     contactTarget.FrameReceived += OnContactTargetFrameReceived;
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Initializes the surface input system. This should be called after any window
        /// initialization is done, and should only be called once.
        /// </summary>
        private void InitializeSurfaceInput()
        {
            System.Diagnostics.Debug.Assert(Window.Handle != System.IntPtr.Zero,
                "Window initialization must be complete before InitializeSurfaceInput is called");
            if (Window.Handle == System.IntPtr.Zero)
                return;
            System.Diagnostics.Debug.Assert(contactTarget == null,
                "Surface input already initialized");
            if (contactTarget != null)
                return;

            capture = new SurfaceCapture();

            // Create a target for surface input.
            contactTarget = new ContactTarget(Window.Handle, EventThreadChoice.OnBackgroundThread);
            contactTarget.EnableInput();
            contactTarget.EnableImage(ImageType.Normalized);

            // Register events
            contactTarget.ContactAdded += OnContactStartRecord;
            contactTarget.FrameReceived += OnContactRecordGesture;
            contactTarget.ContactRemoved += OffContactStopRecord;
        }
Ejemplo n.º 14
0
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    IDisposable graphicsDispose = graphics as IDisposable;
                    if (graphicsDispose != null)
                    {
                        graphicsDispose.Dispose();
                        graphicsDispose = null;
                    }

                    if (contactTarget != null)
                    {
                        contactTarget.Dispose();
                        contactTarget = null;
                    }
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
Ejemplo n.º 15
0
    /// <summary>
    /// Initializes the surface input system. This should be called after any window
    /// initialization is done, and should only be called once.
    /// </summary>
    private void InitializeSurfaceInput()
    {
      System.Diagnostics.Debug.Assert(Window.Handle != System.IntPtr.Zero,
          "Window initialization must be complete before InitializeSurfaceInput is called");
      if (Window.Handle == System.IntPtr.Zero)
        return;
      System.Diagnostics.Debug.Assert(contactTarget == null,
          "Surface input already initialized");
      if (contactTarget != null)
        return;

      // Create a target for surface input.
      contactTarget = new ContactTarget(Window.Handle, EventThreadChoice.OnBackgroundThread);
      contactTarget.EnableInput();
    }
Ejemplo n.º 16
0
    protected override void Dispose(bool disposing)
    {
      if (disposing)
      {
        // Release managed resources.
        IDisposable graphicsDispose = graphics as IDisposable;
        if (graphicsDispose != null)
        {
          graphicsDispose.Dispose();
        }
        if (contactTarget != null)
        {
          contactTarget.Dispose();
          contactTarget = null;
        }
      }

      // Release unmanaged Resources.

      // Set large objects to null to facilitate garbage collection.

      base.Dispose(disposing);
    }
        /// <summary>
        /// Starts the listening for raw input.
        /// </summary>
        /// <param name="window">The window.</param>
        private static void StartListeningForRawInput(SurfaceWindow window)
        {
            // Get the hWnd for the SurfaceWindow object after it has been loaded.
            IntPtr hwnd = new WindowInteropHelper(window).Handle;
            contactTarget = new ContactTarget(hwnd);

            // Set up the ContactTarget object for the entire SurfaceWindow object.
            contactTarget.EnableInput();

            // Start listening to the FrameReceived event
            EnableRawImage(contactTarget);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Initializes the surface input system. This should be called after any window
        /// initialization is done, and should only be called once.
        /// </summary>
        private void InitializeSurfaceInput()
        {
            System.Diagnostics.Debug.Assert(Window.Handle != System.IntPtr.Zero,
                                            "Window initialization must be complete before InitializeSurfaceInput is called");
            if (Window.Handle == System.IntPtr.Zero)
                return;
            //System.Diagnostics.Debug.Assert(contactTarget == null,
            //                                "Surface input already initialized");

            if (contactTarget != null)
                return;

            // Create a target for surface input.
            // Use an IntPtr.Zero as the handle, but still have a Window(!!) as an ivar
            // to get contacts globaly.
            contactTarget = new ContactTarget(IntPtr.Zero,EventThreadChoice.OnCurrentThread,true);

            // Enable the Surface input on this target:
            //bHasImage = contactTarget.EnableImage(ImageType.Normalized);
            //if (bHasImage) contactTarget.FrameReceived += new EventHandler<FrameReceivedEventArgs>(contactTarget_FrameReceived);

            contactTarget.EnableInput();
        }
        /// <summary>
        /// Initializes the surface input system. This should be called after any window
        /// initialization is done, and should only be called once.
        /// </summary>
        public override void Initialize()
        {
            surfaceComp = Game.Components.OfType<SurfaceComponent>().First();

            System.Diagnostics.Debug.Assert(Game.Window.Handle != System.IntPtr.Zero,
                "Window initialization must be complete before InitializeSurfaceInput is called");
            if (Game.Window.Handle == System.IntPtr.Zero)
                return;
            System.Diagnostics.Debug.Assert(contactTarget == null,
                "Surface input already initialized");
            if (contactTarget != null)
                return;

            // Create a target for surface input.
            contactTarget = new ContactTarget(Game.Window.Handle, EventThreadChoice.OnBackgroundThread);
            contactTarget.EnableInput();

            contactTarget.EnableImage(ImageType.Normalized);
            contactTarget.FrameReceived += new EventHandler<FrameReceivedEventArgs>(contactTarget_FrameReceived);

            CurrentContacts = contactTarget.GetState();

            manipulationProcessor = new Affine2DManipulationProcessor(Affine2DManipulations.TranslateX | Affine2DManipulations.TranslateY
                | Affine2DManipulations.Rotate | Affine2DManipulations.Scale);
            manipulationProcessor.Affine2DManipulationDelta += new EventHandler<Affine2DOperationDeltaEventArgs>(manipulationDelta);
            manipulationProcessor.Affine2DManipulationStarted += (s, e) => IsManipulating = true;
            manipulationProcessor.Affine2DManipulationCompleted += (s, e) => IsManipulating = false;

            base.Initialize();
        }