<commit_before>package com.spaceproject.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import com.spaceproject.SpaceProject;

public abstract class MyScreenAdapter extends ScreenAdapter implements InputProcessor {
    
    public static SpaceProject game;
    
    // rendering objects
    public static OrthographicCamera cam;
    public static SpriteBatch batch;
    public static ShapeRenderer shape;
    public static ExtendViewport viewport;
    
    // rendering resolution
    private final static float VIRTUAL_HEIGHT  = 40f;//meters
    public final static float SCALE = 60f;
    private final static float INV_SCALE = 1.f / SCALE;
    private final static float VIEWPORT_WIDTH = 1280 * INV_SCALE;
    private final static float VIEWPORT_HEIGHT = 720 * INV_SCALE;
    
    //save window size for switching between fullscreen and windowed
    private static int prevWindowWidth = (int) VIEWPORT_WIDTH;
    private static int prevWindowHeight = (int) VIEWPORT_HEIGHT;
    
    private static boolean vsync = true;
    
    
    private static float zoomTarget = 1;
    private static float zoomSpeed = 3;
    //private static float panSpeed/panTarget(lerp to entity)
    
    protected InputMultiplexer inputMultiplexer;
    
    public MyScreenAdapter() {
        Gdx.app.log(this.getClass().getSimpleName(), "ScreenAdapter Reset.");
        
        cam = new OrthographicCamera();
        batch = new SpriteBatch();
        shape = new ShapeRenderer();
        viewport = new ExtendViewport(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, cam);
        viewport.apply();
        
        //reset camera
        cam.zoom = 1;
        setZoomTarget(1);
        
        //set this as input processor for mouse wheel scroll events
        inputMultiplexer = new InputMultiplexer();
        inputMultiplexer.addProcessor(this);
        Gdx.input.setInputProcessor(inputMultiplexer);
        
        //debug
        toggleVsync();
    }
    
    
    @Override
    public void render(float delta) {
        
        //cam.update();
        batch.setProjectionMatrix(cam.combined);
        shape.setProjectionMatrix(cam.combined);
        
        //adjust zoom
        zoomCamera(delta);
        
        
        //fullscreen toggle
        if (Gdx.input.isKeyJustPressed(SpaceProject.keycfg.fullscreen)) {
            MyScreenAdapter.toggleFullscreen();
        }
        
        //vsync toggle
        if (Gdx.input.isKeyJustPressed(SpaceProject.keycfg.vsync)) {
            MyScreenAdapter.toggleVsync();
        }
        
        //reset zoom
        if (Gdx.input.isButtonPressed(Buttons.MIDDLE)) {
            cam.zoom = 1;
            setZoomTarget(1);
        }
        
    }
    
    public InputMultiplexer getInputMultiplexer() {
        return inputMultiplexer;
    }
    
    
    @Override
    public void resize(int width, int height) {
        viewport.update(width, height);
        //Gdx.app.log(this.getClass().getSimpleName(), "resize: " + width + ", " + height);
    }
    
    /**
     * Switch between fullscreen and windowed mode.
     */
    public static void toggleFullscreen() {
        if (Gdx.graphics.isFullscreen()) {
            //set window to previous window size
            Gdx.graphics.setWindowedMode(prevWindowWidth, prevWindowHeight);
            Gdx.app.log(MyScreenAdapter.class.getSimpleName(), "Set to windowed.");
        } else {
            //save window size
            prevWindowWidth = Gdx.graphics.getWidth();
            prevWindowHeight = Gdx.graphics.getHeight();
            
            //set to fullscreen
            if (Gdx.graphics.supportsDisplayModeChange()) {
                Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
                Gdx.app.log(MyScreenAdapter.class.getSimpleName(), "Set to fullscreen.");
            } else {
                Gdx.app.log(MyScreenAdapter.class.getSimpleName(), "DisplayModeChange not supported.");
            }
        }
    }
    
    /**
     * Turn vsync on or off
     */
    public static void toggleVsync() {
        vsync = !vsync;
        Gdx.graphics.setVSync(vsync);
        Gdx.app.log(MyScreenAdapter.class.getSimpleName(), "vsync = " + vsync);
    }
    
    
    /**
     * Animate camera zoom. Will zoom camera in or out until it reaches zoomTarget.
     *
     * @param delta
     */
    private static void zoomCamera(float delta) {
        //todo: move cam zoom behavior to @CameraSystem
        //animate settings in CameraFocusComponent?
        //eg: pan / zoom speed, pan / zoom interpolation curve
        if (cam.zoom != zoomTarget) {
            //zoom in/out
            float scaleSpeed = zoomSpeed * delta;
            cam.zoom += (cam.zoom < zoomTarget) ? scaleSpeed : -scaleSpeed;
            
            //if zoom is close enough, just set it to target
            if (Math.abs(cam.zoom - zoomTarget) < 0.2) {
                cam.zoom = zoomTarget;
            }
        }
    }
    
    /**
     * Set zoom for camera to animate to.
     *
     * @param zoom
     */
    public static void setZoomTarget(float zoom) {
        zoomTarget = zoom;
    }
    
    @Override
    public void dispose() {
        shape.dispose();
        batch.dispose();
    }
    
    @Override
    public boolean scrolled(int amount) {
        setZoomTarget(cam.zoom += amount / 2f);
        return false;
    }
    
    @Override
    public boolean keyDown(int keycode) {
        return false;
    }
    
    @Override
    public boolean keyUp(int keycode) {
        return false;
    }
    
    @Override
    public boolean keyTyped(char character) {
        return false;
    }
    
    @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button) {
        return false;
    }
    
    @Override
    public boolean touchUp(int screenX, int screenY, int pointer, int button) {
        return false;
    }<commit_msg>scaled zoom<commit_after>package com.spaceproject.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import com.spaceproject.SpaceProject;

public abstract class MyScreenAdapter extends ScreenAdapter implements InputProcessor {
    
    public static SpaceProject game;
    
    // rendering objects
    public static OrthographicCamera cam;
    public static SpriteBatch batch;
    public static ShapeRenderer shape;
    public static ExtendViewport viewport;
    
    // rendering resolution
    private final static float VIRTUAL_HEIGHT  = 40f;//meters
    public final static float SCALE = 60f;
    private final static float INV_SCALE = 1.f / SCALE;
    private final static float VIEWPORT_WIDTH = 1280 * INV_SCALE;
    private final static float VIEWPORT_HEIGHT = 720 * INV_SCALE;
    
    //save window size for switching between fullscreen and windowed
    private static int prevWindowWidth = (int) VIEWPORT_WIDTH;
    private static int prevWindowHeight = (int) VIEWPORT_HEIGHT;
    
    private static boolean vsync = true;
    
    
    private static float zoomTarget = 1;
    private static float zoomSpeed = 3;
    //private static float panSpeed/panTarget(lerp to entity)
    
    protected InputMultiplexer inputMultiplexer;
    
    public MyScreenAdapter() {
        Gdx.app.log(this.getClass().getSimpleName(), "ScreenAdapter Reset.");
        
        cam = new OrthographicCamera();
        batch = new SpriteBatch();
        shape = new ShapeRenderer();
        viewport = new ExtendViewport(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, cam);
        viewport.apply();
        
        //reset camera
        cam.zoom = 1;
        setZoomTarget(1);
        
        //set this as input processor for mouse wheel scroll events
        inputMultiplexer = new InputMultiplexer();
        inputMultiplexer.addProcessor(this);
        Gdx.input.setInputProcessor(inputMultiplexer);
        
        //debug
        toggleVsync();
    }
    
    
    @Override
    public void render(float delta) {
        
        //cam.update();
        batch.setProjectionMatrix(cam.combined);
        shape.setProjectionMatrix(cam.combined);
        
        //adjust zoom
        zoomCamera(delta);
        
        
        //fullscreen toggle
        if (Gdx.input.isKeyJustPressed(SpaceProject.keycfg.fullscreen)) {
            MyScreenAdapter.toggleFullscreen();
        }
        
        //vsync toggle
        if (Gdx.input.isKeyJustPressed(SpaceProject.keycfg.vsync)) {
            MyScreenAdapter.toggleVsync();
        }
        
        //reset zoom
        if (Gdx.input.isButtonPressed(Buttons.MIDDLE)) {
            cam.zoom = 1;
            setZoomTarget(1);
        }
        
    }
    
    public InputMultiplexer getInputMultiplexer() {
        return inputMultiplexer;
    }
    
    
    @Override
    public void resize(int width, int height) {
        viewport.update(width, height);
        //Gdx.app.log(this.getClass().getSimpleName(), "resize: " + width + ", " + height);
    }
    
    /**
     * Switch between fullscreen and windowed mode.
     */
    public static void toggleFullscreen() {
        if (Gdx.graphics.isFullscreen()) {
            //set window to previous window size
            Gdx.graphics.setWindowedMode(prevWindowWidth, prevWindowHeight);
            Gdx.app.log(MyScreenAdapter.class.getSimpleName(), "Set to windowed.");
        } else {
            //save window size
            prevWindowWidth = Gdx.graphics.getWidth();
            prevWindowHeight = Gdx.graphics.getHeight();
            
            //set to fullscreen
            if (Gdx.graphics.supportsDisplayModeChange()) {
                Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
                Gdx.app.log(MyScreenAdapter.class.getSimpleName(), "Set to fullscreen.");
            } else {
                Gdx.app.log(MyScreenAdapter.class.getSimpleName(), "DisplayModeChange not supported.");
            }
        }
    }
    
    /**
     * Turn vsync on or off
     */
    public static void toggleVsync() {
        vsync = !vsync;
        Gdx.graphics.setVSync(vsync);
        Gdx.app.log(MyScreenAdapter.class.getSimpleName(), "vsync = " + vsync);
    }
    
    
    /**
     * Animate camera zoom. Will zoom camera in or out until it reaches zoomTarget.
     *
     * @param delta
     */
    private static void zoomCamera(float delta) {
        //todo: move cam zoom behavior to @CameraSystem
        //animate settings in CameraFocusComponent?
        //eg: pan / zoom speed, pan / zoom interpolation curve
        if (cam.zoom != zoomTarget) {
            //zoom in/out
            float scaleSpeed = zoomSpeed * delta;
            cam.zoom += (cam.zoom < zoomTarget) ? scaleSpeed : -scaleSpeed;
            
            //if zoom is close enough, just set it to target
            if (Math.abs(cam.zoom - zoomTarget) < 0.2) {
                cam.zoom = zoomTarget;
            }
        }
    }
    
    /**
     * Set zoom for camera to animate to.
     *
     * @param zoom
     */
    public static void setZoomTarget(float zoom) {
        zoomTarget = zoom;
    }
    
    @Override
    public void dispose() {
        shape.dispose();
        batch.dispose();
    }
    
    @Override
    public boolean scrolled(int amount) {
        float scrollAmount = amount * cam.zoom / 2;
        setZoomTarget(cam.zoom += scrollAmount);
        return false;
    }
    
    @Override
    public boolean keyDown(int keycode) {
        return false;
    }
    
    @Override
    public boolean keyUp(int keycode) {
        return false;
    }
    
    @Override
    public boolean keyTyped(char character) {
        return false;
    }
    
    @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button) {
        return false;
    }
    
    @Override
    public boolean touchUp(int screenX, int screenY, int pointer, int button) {
        return false;
    }
{'fraction_non_alphanumeric': 0.09061178910425141, 'fraction_numerical': 0.003509611549812555, 'mean_word_length': 2.084378843788438, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '5522702', 'n_tokens_mistral': 3609, 'n_tokens_neox': 3535, 'n_words': 865}