mmb.engine.window.FullScreen Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of multimachinebuilder Show documentation
Show all versions of multimachinebuilder Show documentation
Dependency for the MultiMachineBuilder, a voxel game about building an industrial empire in a finite world.
THIS RELEASE IS NOT PLAYABLE. To play the game, donwload from >ITCH.IO LINK HERE< or >GH releases link here<
/**
*
*/
package mmb.engine.window;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import mmb.NN;
import mmb.data.variables.ListenableBoolean;
import mmb.engine.debug.Debugger;
/**
* @author oskar
*
*/
public class FullScreen {
@NN public static final ListenableBoolean isFullScreen = new ListenableBoolean();
private static MMBFrame fullScreenFrame;
private static Debugger debug = new Debugger("FullScreen");
static GraphicsDevice device = GraphicsEnvironment
.getLocalGraphicsEnvironment().getScreenDevices()[0];
private static boolean isInitialized = false;
public static void initialize() {
if(isInitialized) return;
debug.printl("Setting up FullScreen");
isFullScreen.add(b -> {
debug.printl("Setting fullscreen mode to: "+b);
setFullScreen(b);
});
isInitialized = true;
}
private FullScreen() {}
public static void setWindow(MMBFrame win) { //Stuck
if(fullScreenFrame != null) {
fullScreenFrame.undergoingScreenTransform = true;
fullScreenFrame.dispose(); //Dispose of the old frame GETS STUCK
fullScreenFrame.undergoingScreenTransform = false;
}
fullScreenFrame = win;
setFullScreen(isFullScreen.getValue()); //Create the new frame STUCK
}
private static void setFullScreen(boolean fullScreen) { //internal update method
if(fullScreenFrame == null) return;
fullScreenFrame.undergoingScreenTransform = true;
//windowed
if(fullScreen) {
fullScreenFrame.dispose();
fullScreenFrame.setUndecorated(true);
device.setFullScreenWindow(fullScreenFrame);
fullScreenFrame.setVisible(true);
}else{
device.setFullScreenWindow(null);
fullScreenFrame.dispose(); //STUCK
fullScreenFrame.setUndecorated(false);
fullScreenFrame.setVisible(true);
}
fullScreenFrame.undergoingScreenTransform = false;
}
}