Fixed up some things to do with the Java screen
This commit is contained in:
@@ -13,6 +13,8 @@ public abstract class AbstractScreen {
|
||||
public long minecraftWindow;
|
||||
public int width;
|
||||
public int height;
|
||||
public int scaledWidth;
|
||||
public int scaledHeight;
|
||||
public int mouseX = 0;
|
||||
public int mouseY = 0;
|
||||
/** Weather it should close when you press the escape key */
|
||||
@@ -27,6 +29,8 @@ public abstract class AbstractScreen {
|
||||
public abstract void render(float delta);
|
||||
public void tick() {}
|
||||
|
||||
/** Called every time the window gets re-sized */
|
||||
public void onResize() {};
|
||||
/** What happens when the user closes the screen*/
|
||||
public void onClose() {}
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.seibel.lod.core.config.gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
import javafx.embed.swing.JFXPanel;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class ConfigScreen extends JFrame {
|
||||
private final JFXPanel fxPanel = new JFXPanel();
|
||||
|
||||
public ConfigScreen() {
|
||||
// super("JavaFX in Swing");
|
||||
// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setLayout(new BorderLayout());
|
||||
add(fxPanel, BorderLayout.CENTER);
|
||||
// setSize(300, 200);
|
||||
// setLocationRelativeTo(null);
|
||||
// setVisible(true);
|
||||
|
||||
Platform.runLater(() -> initFX(fxPanel));
|
||||
}
|
||||
|
||||
private void initFX(JFXPanel fxPanel) {
|
||||
Scene scene = createScene();
|
||||
fxPanel.setScene(scene);
|
||||
}
|
||||
|
||||
private Scene createScene() {
|
||||
Label label = new Label("Hello from JavaFX!");
|
||||
return new Scene(label);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
JFrame frame = new ConfigScreen();
|
||||
frame.setSize(300, 200);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setVisible(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.seibel.lod.core.config.gui;
|
||||
|
||||
import com.seibel.lod.core.jar.Platform;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.lwjgl.system.jawt.JAWT;
|
||||
import org.lwjgl.system.macosx.*;
|
||||
|
||||
@@ -122,22 +123,16 @@ public final class EmbeddedFrameUtil {
|
||||
}
|
||||
}
|
||||
|
||||
// The code below is by Ran
|
||||
|
||||
public static void hideFrame(Frame embeddedFrame) {
|
||||
if (embeddedFrame != null) {
|
||||
embeddedFrame.setVisible(false);
|
||||
embeddedFrameSynthesizeWindowActivation(embeddedFrame, false);
|
||||
}
|
||||
public static void hideFrame(@NotNull Frame embeddedFrame) {
|
||||
embeddedFrame.setVisible(false);
|
||||
embeddedFrameSynthesizeWindowActivation(embeddedFrame, false);
|
||||
}
|
||||
|
||||
public static void showFrame(Frame embeddedFrame) {
|
||||
if (embeddedFrame != null) {
|
||||
embeddedFrameSynthesizeWindowActivation(embeddedFrame, true);
|
||||
embeddedFrame.setVisible(true);
|
||||
}
|
||||
public static void showFrame(@NotNull Frame embeddedFrame) {
|
||||
embeddedFrameSynthesizeWindowActivation(embeddedFrame, true);
|
||||
embeddedFrame.setVisible(true);
|
||||
}
|
||||
|
||||
public static void placeAtCenter(Frame embeddedFrame, int windowWidth, int windowHeight, int frameWidth, int frameHeight, float scale) {
|
||||
float scaleFactor = (100.0F - scale) / 100.0F;
|
||||
float newWidth = frameWidth * scaleFactor;
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.seibel.lod.core.config.gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class JavaFXConfigScreen extends AbstractScreen {
|
||||
static {
|
||||
System.setProperty("java.awt.headless", "false");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
Frame frame = EmbeddedFrameUtil.embeddedFrameCreate(this.minecraftWindow);
|
||||
frame.add(new ExampleScreen());
|
||||
EmbeddedFrameUtil.placeAtCenter(frame, this.width, this.height, 100, 100, 1);
|
||||
}
|
||||
|
||||
public class ExampleScreen extends JComponent {
|
||||
public ExampleScreen() {
|
||||
setLayout(new GridBagLayout());
|
||||
GridBagConstraints constraints = new GridBagConstraints();
|
||||
constraints.fill = GridBagConstraints.HORIZONTAL;
|
||||
constraints.weightx = 0.5;
|
||||
constraints.gridx = 0;
|
||||
constraints.gridy = 0;
|
||||
add(new JLabel("Hello World!"), constraints);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.seibel.lod.core.config.gui;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class JavaScreenHandlerScreen extends AbstractScreen {
|
||||
public static Frame frame;
|
||||
public static boolean firstRun = true;
|
||||
public final Component jComponent;
|
||||
|
||||
static {
|
||||
// Required to run this
|
||||
System.setProperty("java.awt.headless", "false");
|
||||
}
|
||||
|
||||
public JavaScreenHandlerScreen(@NotNull Component component) {
|
||||
this.jComponent = component;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
if (firstRun)
|
||||
frame = EmbeddedFrameUtil.embeddedFrameCreate(this.minecraftWindow); // Don't call this multiple times
|
||||
|
||||
frame.add(jComponent);
|
||||
|
||||
if (firstRun) {
|
||||
EmbeddedFrameUtil.embeddedFrameSetBounds(frame, 0, 0, this.width, this.height);
|
||||
firstRun = false;
|
||||
} else
|
||||
EmbeddedFrameUtil.showFrame(frame);
|
||||
}
|
||||
|
||||
/** A testing/debug screen */
|
||||
public static class ExampleScreen extends JComponent {
|
||||
public ExampleScreen() {
|
||||
setLayout(new GridBagLayout());
|
||||
GridBagConstraints constraints = new GridBagConstraints();
|
||||
constraints.fill = GridBagConstraints.HORIZONTAL;
|
||||
constraints.weightx = 0.5;
|
||||
constraints.gridx = 0;
|
||||
constraints.gridy = 0;
|
||||
add(new JLabel("Hello World!"), constraints);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
// TODO: Make screen only update on this being called
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResize() {
|
||||
EmbeddedFrameUtil.embeddedFrameSetBounds(frame, 0, 0, this.width, this.height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
frame.remove(jComponent);
|
||||
EmbeddedFrameUtil.hideFrame(frame);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user