<commit_before>﻿// Copyright(C) <NAME>, 2013
// Released to the public domain. Use, modify and relicense at will.

using System;

using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTK.Audio;
using OpenTK.Audio.OpenAL;
using OpenTK.Input;

using SimpleScene;

namespace TestBench0
{
	partial class TestBench0 : OpenTK.GameWindow 
	{
		SSObject selectedObject = null;

		public void setupInput()
		{
			this.MouseDown += mouseDownHandler;
			this.MouseUp += mouseUpHandler;
			this.MouseMove += mouseMoveHandler;
			this.MouseWheel += mouseWheelHandler;
			this.KeyUp += keyUpHandler;
		}

		void mouseDownHandler(object sender, MouseButtonEventArgs e)
		{
			this.mouseButtonDown = true;

			// cast ray for mouse click
			var clientRect = new System.Drawing.Size(ClientRectangle.Width, ClientRectangle.Height);
			Vector2 mouseLoc = new Vector2(e.X,e.Y);

			SSRay ray = OpenTKHelper.MouseToWorldRay(
				this.scene.ProjectionMatrix,this.scene.InvCameraViewMatrix, clientRect, mouseLoc);

			// Console.WriteLine("mouse ({0},{1}) unproject to ray ({2})",e.X,e.Y,ray);
			// scene.addObject(new SSObjectRay(ray));

			selectedObject = scene.Intersect(ref ray);
			updateWireframeDisplayText ();
		}

		void mouseUpHandler(object sender, MouseButtonEventArgs e)
		{ 
			this.mouseButtonDown = false;
		}

		void mouseMoveHandler(object sender, MouseMoveEventArgs e)
		{
			if (this.mouseButtonDown) {

				// Console.WriteLine("mouse dragged: {0},{1}",e.XDelta,e.YDelta);
				this.scene.ActiveCamera.MouseDeltaOrient(e.XDelta,e.YDelta);
				// this.activeModel.MouseDeltaOrient(e.XDelta,e.YDelta);
			}
		}

		void mouseWheelHandler(object sender, MouseWheelEventArgs e)
		{
			// Console.WriteLine("mousewheel {0} {1}",e.Delta,e.DeltaPrecise);
			SSCameraThirdPerson ctp = scene.ActiveCamera as SSCameraThirdPerson;
			if (ctp != null) {
				ctp.followDistance += -e.DeltaPrecise;
			} 
		}

		void keyUpHandler(object sender, KeyboardKeyEventArgs e)
		{
			switch (e.Key) {
			case Key.Number1:
				System.Console.WriteLine ("Toggling wireframe");
				if (autoWireframeMode == true) {
					autoWireframeMode = false;
				} else {
					scene.DrawWireFrameMode = SSRenderConfig.NextWireFrameMode (scene.DrawWireFrameMode);
					if (scene.DrawWireFrameMode == WireframeMode.None) {
						autoWireframeMode = true; // rollover completes toggling modes
					}
				}
				updateWireframeDisplayText ();
				break;
			case Key.Escape:
				Exit ();
				break;
			}
		}
	}
}
<commit_msg>Ignore inputs events when not in focus<commit_after>﻿// Copyright(C) <NAME>, 2013
// Released to the public domain. Use, modify and relicense at will.

using System;

using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTK.Audio;
using OpenTK.Audio.OpenAL;
using OpenTK.Input;

using SimpleScene;

namespace TestBench0
{
	partial class TestBench0 : OpenTK.GameWindow 
	{
		SSObject selectedObject = null;

		public void setupInput()
		{
			this.MouseDown += mouseDownHandler;
			this.MouseUp += mouseUpHandler;
			this.MouseMove += mouseMoveHandler;
			this.MouseWheel += mouseWheelHandler;
			this.KeyUp += keyUpHandler;
		}

		void mouseDownHandler(object sender, MouseButtonEventArgs e)
		{
			if (!base.Focused) return;

			this.mouseButtonDown = true;

			// cast ray for mouse click
			var clientRect = new System.Drawing.Size(ClientRectangle.Width, ClientRectangle.Height);
			Vector2 mouseLoc = new Vector2(e.X,e.Y);

			SSRay ray = OpenTKHelper.MouseToWorldRay(
				this.scene.ProjectionMatrix,this.scene.InvCameraViewMatrix, clientRect, mouseLoc);

			// Console.WriteLine("mouse ({0},{1}) unproject to ray ({2})",e.X,e.Y,ray);
			// scene.addObject(new SSObjectRay(ray));

			selectedObject = scene.Intersect(ref ray);
			updateWireframeDisplayText ();
		}

		void mouseUpHandler(object sender, MouseButtonEventArgs e)
		{ 
			this.mouseButtonDown = false;
		}

		void mouseMoveHandler(object sender, MouseMoveEventArgs e)
		{
			if (this.mouseButtonDown) {

				// Console.WriteLine("mouse dragged: {0},{1}",e.XDelta,e.YDelta);
				this.scene.ActiveCamera.MouseDeltaOrient(e.XDelta,e.YDelta);
				// this.activeModel.MouseDeltaOrient(e.XDelta,e.YDelta);
			}
		}

		void mouseWheelHandler(object sender, MouseWheelEventArgs e)
		{
			if (!base.Focused) return;

			// Console.WriteLine("mousewheel {0} {1}",e.Delta,e.DeltaPrecise);
			SSCameraThirdPerson ctp = scene.ActiveCamera as SSCameraThirdPerson;
			if (ctp != null) {
				ctp.followDistance += -e.DeltaPrecise;
			} 
		}

		void keyUpHandler(object sender, KeyboardKeyEventArgs e)
		{
			if (!base.Focused) return;

			switch (e.Key) {
			case Key.Number1:
				System.Console.WriteLine ("Toggling wireframe");
				if (autoWireframeMode == true) {
					autoWireframeMode = false;
				} else {
					scene.DrawWireFrameMode = SSRenderConfig.NextWireFrameMode (scene.DrawWireFrameMode);
					if (scene.DrawWireFrameMode == WireframeMode.None) {
						autoWireframeMode = true; // rollover completes toggling modes
					}
				}
				updateWireframeDisplayText ();
				break;
			case Key.Escape:
				Exit ();
				break;
			}
		}
	}
}

{'fraction_non_alphanumeric': 0.11612021857923498, 'fraction_numerical': 0.00624512099921936, 'mean_word_length': 3.803186504217432, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4368260', 'n_tokens_mistral': 1993, 'n_tokens_neox': 1653, 'n_words': 345}