<commit_before>/*******************************************************************************
 * Copyright 2011 See AUTHORS file.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package com.badlogic.gdx.backends.lwjgl3;

import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWCharCallback;
import org.lwjgl.glfw.GLFWCursorPosCallback;
import org.lwjgl.glfw.GLFWKeyCallback;
import org.lwjgl.glfw.GLFWMouseButtonCallback;
import org.lwjgl.glfw.GLFWScrollCallback;

import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputEventQueue;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration.HdpiMode;
import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.TimeUtils;

public class Lwjgl3Input implements Input, Disposable {
	private final Lwjgl3Window window;
	private InputProcessor inputProcessor;
	private final InputEventQueue eventQueue = new InputEventQueue();
		
	private int mouseX, mouseY;
	private int mousePressed;
	private int deltaX, deltaY;
	private boolean justTouched;
	private int pressedKeys;
	private boolean keyJustPressed;
	private boolean[] justPressedKeys = new boolean[256];
	private char lastCharacter;
	private float scrollYRemainder;
	private long lastScrollEventTime;
		
	private GLFWKeyCallback keyCallback = new GLFWKeyCallback() {		
		@Override
		public void invoke(long window, int key, int scancode, int action, int mods) {
			switch (action) {
			case GLFW.GLFW_PRESS:
				key = getGdxKeyCode(key);
				eventQueue.keyDown(key);								
				pressedKeys++;
				keyJustPressed = true;
				justPressedKeys[key] = true;
				Lwjgl3Input.this.window.getGraphics().requestRendering();
				lastCharacter = 0;
				char character = characterForKeyCode(key);
				if (character != 0) charCallback.invoke(window, character);				
				break;
			case GLFW.GLFW_RELEASE:
				pressedKeys--;
				Lwjgl3Input.this.window.getGraphics().requestRendering();
				eventQueue.keyUp(getGdxKeyCode(key));
				break;

			case GLFW.GLFW_REPEAT:
				if (lastCharacter != 0) {
					Lwjgl3Input.this.window.getGraphics().requestRendering();
					eventQueue.keyTyped(lastCharacter);
				}
				break;
			}
		}
	};
	
	private GLFWCharCallback charCallback = new GLFWCharCallback() {
		@Override
		public void invoke(long window, int codepoint) {
			if ((codepoint & 0xff00) == 0xf700) return;
			lastCharacter = (char)codepoint;
			Lwjgl3Input.this.window.getGraphics().requestRendering();
			eventQueue.keyTyped((char)codepoint);
		}
	};
	
	private GLFWScrollCallback scrollCallback = new GLFWScrollCallback() {
		long pauseTime = 250000000L; //250ms
		@Override
		public void invoke(long window, double scrollX, double scrollY) {
			Lwjgl3Input.this.window.getGraphics().requestRendering();
			if (scrollYRemainder > 0 && scrollY < 0 || scrollYRemainder < 0 && scrollY > 0 ||
				TimeUtils.nanoTime() - lastScrollEventTime > pauseTime ) { 
				// fire a scroll event immediately:
				//  - if the scroll direction changes; 
				//  - if the user did not move the wheel for more than 250ms
				scrollYRemainder = 0;
				int scrollAmount = (int)-Math.signum(scrollY);
				eventQueue.scrolled(scrollAmount);
				lastScrollEventTime = TimeUtils.nanoTime();
			}
			else {
				scrollYRemainder += scrollY;
				while (Math.abs(scrollYRemainder) >= 1) {
					int scrollAmount = (int)-Math.signum(scrollY);
					eventQueue.scrolled(scrollAmount);
					lastScrollEventTime = TimeUtils.nanoTime();
					scrollYRemainder += scrollAmount;
				}<commit_msg>Moving scrolling attributes to GLFWScrollCallback<commit_after>/*******************************************************************************
 * Copyright 2011 See AUTHORS file.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package com.badlogic.gdx.backends.lwjgl3;

import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWCharCallback;
import org.lwjgl.glfw.GLFWCursorPosCallback;
import org.lwjgl.glfw.GLFWKeyCallback;
import org.lwjgl.glfw.GLFWMouseButtonCallback;
import org.lwjgl.glfw.GLFWScrollCallback;

import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputEventQueue;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration.HdpiMode;
import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.TimeUtils;

public class Lwjgl3Input implements Input, Disposable {
	private final Lwjgl3Window window;
	private InputProcessor inputProcessor;
	private final InputEventQueue eventQueue = new InputEventQueue();
		
	private int mouseX, mouseY;
	private int mousePressed;
	private int deltaX, deltaY;
	private boolean justTouched;
	private int pressedKeys;
	private boolean keyJustPressed;
	private boolean[] justPressedKeys = new boolean[256];
	private char lastCharacter;
		
	private GLFWKeyCallback keyCallback = new GLFWKeyCallback() {		
		@Override
		public void invoke(long window, int key, int scancode, int action, int mods) {
			switch (action) {
			case GLFW.GLFW_PRESS:
				key = getGdxKeyCode(key);
				eventQueue.keyDown(key);								
				pressedKeys++;
				keyJustPressed = true;
				justPressedKeys[key] = true;
				Lwjgl3Input.this.window.getGraphics().requestRendering();
				lastCharacter = 0;
				char character = characterForKeyCode(key);
				if (character != 0) charCallback.invoke(window, character);				
				break;
			case GLFW.GLFW_RELEASE:
				pressedKeys--;
				Lwjgl3Input.this.window.getGraphics().requestRendering();
				eventQueue.keyUp(getGdxKeyCode(key));
				break;

			case GLFW.GLFW_REPEAT:
				if (lastCharacter != 0) {
					Lwjgl3Input.this.window.getGraphics().requestRendering();
					eventQueue.keyTyped(lastCharacter);
				}
				break;
			}
		}
	};
	
	private GLFWCharCallback charCallback = new GLFWCharCallback() {
		@Override
		public void invoke(long window, int codepoint) {
			if ((codepoint & 0xff00) == 0xf700) return;
			lastCharacter = (char)codepoint;
			Lwjgl3Input.this.window.getGraphics().requestRendering();
			eventQueue.keyTyped((char)codepoint);
		}
	};
	
	private GLFWScrollCallback scrollCallback = new GLFWScrollCallback() {
		private long pauseTime = 250000000L; //250ms
		private float scrollYRemainder;
		private long lastScrollEventTime;
		@Override
		public void invoke(long window, double scrollX, double scrollY) {
			Lwjgl3Input.this.window.getGraphics().requestRendering();
			if (scrollYRemainder > 0 && scrollY < 0 || scrollYRemainder < 0 && scrollY > 0 ||
				TimeUtils.nanoTime() - lastScrollEventTime > pauseTime ) { 
				// fire a scroll event immediately:
				//  - if the scroll direction changes; 
				//  - if the user did not move the wheel for more than 250ms
				scrollYRemainder = 0;
				int scrollAmount = (int)-Math.signum(scrollY);
				eventQueue.scrolled(scrollAmount);
				lastScrollEventTime = TimeUtils.nanoTime();
			}
			else {
				scrollYRemainder += scrollY;
				while (Math.abs(scrollYRemainder) >= 1) {
					int scrollAmount = (int)-Math.signum(scrollY);
					eventQueue.scrolled(scrollAmount);
					lastScrollEventTime = TimeUtils.nanoTime();
					scrollYRemainder += scrollAmount;
				}
{'fraction_non_alphanumeric': 0.12920396806194048, 'fraction_numerical': 0.012581659811275103, 'mean_word_length': 4.354274611398964, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '4336154', 'n_tokens_mistral': 2909, 'n_tokens_neox': 2489, 'n_words': 635}