public Greeter( string defaultWindowId, Rectangle defaultWindowBounds, Action onGazeEnters, Action onGazeLeaves) { _host = new Host(); _interactorAgent = _host.InitializeVirtualInteractorAgent(defaultWindowId); _greetingInteractor = _interactorAgent.AddInteractorFor(defaultWindowBounds); _greetingInteractor .WithGazeAware() .HasGaze(onGazeEnters) .LostGaze(onGazeLeaves); }
private static VirtualInteractorAgent CreateGazeAwareZones(Host host, VirtualInteractorAgent interactorAgent = null) { // InteractorAgents are defined per window, so we need a handle to it. var currentWindowHandle = Process.GetCurrentProcess().MainWindowHandle; // Let's also obtain its bounds using Windows API calls (hidden in a helper method below). var currentWindowBounds = GetWindowBounds(currentWindowHandle); // Create bounds of window sides. var sizeOfSides = 0.2; var rightSideOfWindow = currentWindowBounds; rightSideOfWindow.X = currentWindowBounds.X + (currentWindowBounds.Width - currentWindowBounds.X) * (1 - sizeOfSides); rightSideOfWindow.Y = currentWindowBounds.Height + (currentWindowBounds.Y - currentWindowBounds.Height) * (1 - sizeOfSides); rightSideOfWindow.Height = currentWindowBounds.Height + (currentWindowBounds.Y - currentWindowBounds.Height) * sizeOfSides; Console.WriteLine(rightSideOfWindow.ToString()); var leftSideOfWindow = currentWindowBounds; leftSideOfWindow.Width = currentWindowBounds.X + (currentWindowBounds.Width - currentWindowBounds.X) * sizeOfSides; leftSideOfWindow.Y = currentWindowBounds.Height + (currentWindowBounds.Y - currentWindowBounds.Height) * (1 - sizeOfSides); leftSideOfWindow.Height = currentWindowBounds.Height + (currentWindowBounds.Y - currentWindowBounds.Height) * sizeOfSides; Console.WriteLine(leftSideOfWindow.ToString()); var topSideOfWindow = currentWindowBounds; topSideOfWindow.Height = currentWindowBounds.Height + (currentWindowBounds.Y - currentWindowBounds.Height) * (1 - sizeOfSides); Console.WriteLine(topSideOfWindow.ToString()); var bottomSideOfWindow = currentWindowBounds; bottomSideOfWindow.Y = currentWindowBounds.Height + (currentWindowBounds.Y - currentWindowBounds.Height) * sizeOfSides; Console.WriteLine(bottomSideOfWindow.ToString()); // Remove Interactors from InteractorAgent if it exists and create it if it doesn't. if (interactorAgent != null) { foreach (Interactor i in interactorAgent.Interactors) { interactorAgent.RemoveInteractor(i.Id); } } else { interactorAgent = host.InitializeVirtualInteractorAgent(currentWindowHandle, "ConsoleWindowAgent"); } // Next we are going to create an interactor, which we will define with the gaze aware behavior. // Gaze aware behavior simply tells you whether somebody is looking at the interactor or not. interactorAgent .AddInteractorFor(rightSideOfWindow) .WithGazeAware() .HasGaze(() => { Console.WriteLine("Gaze found. Right."); _camera.CameraMovement.ContinuousMove(MoveDirection.Right); }) .LostGaze(() => { Console.WriteLine("Gaze lost. Right."); _camera.CameraMovement.StopMovement(); }); interactorAgent .AddInteractorFor(leftSideOfWindow) .WithGazeAware() .HasGaze(() => { Console.WriteLine("Gaze found. Left."); _camera.CameraMovement.ContinuousMove(MoveDirection.Left); }) .LostGaze(() => { Console.WriteLine("Gaze lost. Left."); _camera.CameraMovement.StopMovement(); }); interactorAgent .AddInteractorFor(topSideOfWindow) .WithGazeAware() .HasGaze(() => { Console.WriteLine("Gaze found. Top."); _camera.CameraMovement.ContinuousMove(MoveDirection.Up); }) .LostGaze(() => { Console.WriteLine("Gaze lost. Top."); _camera.CameraMovement.StopMovement(); }); interactorAgent .AddInteractorFor(bottomSideOfWindow) .WithGazeAware() .HasGaze(() => { Console.WriteLine("Gaze found. Bottom."); _camera.CameraMovement.ContinuousMove(MoveDirection.Down); }) .LostGaze(() => { Console.WriteLine("Gaze lost. Bottom."); _camera.CameraMovement.StopMovement(); }); return(interactorAgent); }