package zero1hd.rhythmbullet.desktop.graphics.ui.components;

import java.awt.Dimension;
import java.awt.Toolkit;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;

public class ResolutionButton extends TextButton {
	
	public ResolutionButton(int width, int height, Skin skin, Preferences prefs) {
		super(width + "x" + height, skin);
		
		Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
		
		if (screenDim.getWidth() < width || screenDim.getHeight() < height) {
			setDisabled(true);
		}
		
		addListener(new ChangeListener() {
			
			@Override
			public void changed(ChangeEvent event, Actor actor) {
				Gdx.graphics.setWindowedMode(width, height);
				prefs.putInteger("screen-width", width);
				prefs.putInteger("screen-height", height);
				prefs.putBoolean("fullscreen", false);
				prefs.flush();
			}
		});
	}
}
