Skip to content

Commit

Permalink
introduce DisplayInfo interface to have read access of "Display" for …
Browse files Browse the repository at this point in the history
…jogl and lwjgl
  • Loading branch information
davidB committed Oct 31, 2015
1 parent 58e32b8 commit 6a5577a
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 36 deletions.
86 changes: 86 additions & 0 deletions src/main/java/com/jme3/system/jogl/DisplayInfo_Jogl.java
@@ -0,0 +1,86 @@
package com.jme3.system.jogl;

import java.util.concurrent.atomic.AtomicBoolean;

import org.lwjgl.opengl.Display;

import com.jme3x.jfx.DisplayInfo;
import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.event.WindowListener;
import com.jogamp.newt.event.WindowUpdateEvent;
import com.jogamp.newt.opengl.GLWindow;

public class DisplayInfo_Jogl implements DisplayInfo {
final AtomicBoolean resized = new AtomicBoolean(false);
final GLWindow canvas;

public DisplayInfo_Jogl(JoglNewtAbstractDisplay d) {
this(d.canvas);
}

public DisplayInfo_Jogl(GLWindow canvas) {
super();
this.canvas = canvas;
canvas.addWindowListener(new WindowListener() {

@Override
public void windowResized(WindowEvent e) {
resized.set(true);
}

@Override
public void windowRepaint(WindowUpdateEvent e) {
}

@Override
public void windowMoved(WindowEvent e) {
}

@Override
public void windowLostFocus(WindowEvent e) {
}

@Override
public void windowGainedFocus(WindowEvent e) {
}

@Override
public void windowDestroyed(WindowEvent e) {
}

@Override
public void windowDestroyNotify(WindowEvent e) {
}
});
}

@Override
public int getWidth() {
return canvas.getWidth();
}

@Override
public int getHeight() {
return canvas.getHeight();
}

@Override
public int getX() {
return canvas.getX();
}

@Override
public int getY() {
return canvas.getY();
}

@Override
public boolean isFullscreen() {
return canvas.isFullscreen();
}

@Override
public AtomicBoolean wasResized() {
return resized;
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/jme3x/jfx/DisplayInfo.java
@@ -0,0 +1,12 @@
package com.jme3x.jfx;

import java.util.concurrent.atomic.AtomicBoolean;

public interface DisplayInfo {
int getWidth();
int getHeight();
int getX();
int getY();
boolean isFullscreen();
AtomicBoolean wasResized();
}
19 changes: 19 additions & 0 deletions src/main/java/com/jme3x/jfx/DisplayInfoProvider.java
@@ -0,0 +1,19 @@
package com.jme3x.jfx;

import com.jme3.app.Application;
import com.jme3.system.JmeContext;
import com.jme3.system.jogl.DisplayInfo_Jogl;

public class DisplayInfoProvider {

public static DisplayInfo find(Application app) {
JmeContext ctx = app.getContext();
if (ctx.getClass().getName().startsWith("com.jme3.system.jogl.JoglNewt")) {
return new DisplayInfo_Jogl((com.jme3.system.jogl.JoglNewtAbstractDisplay) ctx);
}
if (ctx.getClass().getName().startsWith("com.jme3.system.lwjgl")) {
return new DisplayInfo_Lwjgl();
}
return new DisplayInfo_AppSettings(ctx.getSettings());
}
}
53 changes: 53 additions & 0 deletions src/main/java/com/jme3x/jfx/DisplayInfo_AppSettings.java
@@ -0,0 +1,53 @@
package com.jme3x.jfx;

import java.util.concurrent.atomic.AtomicBoolean;

import org.lwjgl.opengl.Display;

import com.jme3.system.AppSettings;

class DisplayInfo_AppSettings implements DisplayInfo {
final AtomicBoolean resized = new AtomicBoolean(false);
final AppSettings settings;

public DisplayInfo_AppSettings(AppSettings settings) {
super();
this.settings = settings;
}

@Override
public int getWidth() {
return settings.getWidth();
}

@Override
public int getHeight() {
return settings.getHeight();
}

/**
* Always return 0; (not supported by avoid throwing exception)
*/
@Override
public int getX() {
return 0;
}

/**
* Always return 0; (not supported by avoid throwing exception)
*/
@Override
public int getY() {
return 0;
}

@Override
public boolean isFullscreen() {
return settings.isFullscreen();
}

@Override
public AtomicBoolean wasResized() {
return resized;
}
}
46 changes: 46 additions & 0 deletions src/main/java/com/jme3x/jfx/DisplayInfo_Lwjgl.java
@@ -0,0 +1,46 @@
package com.jme3x.jfx;

import java.util.concurrent.atomic.AtomicBoolean;

import org.lwjgl.opengl.Display;

class DisplayInfo_Lwjgl implements DisplayInfo {
final AtomicBoolean resized = new AtomicBoolean(false);

public DisplayInfo_Lwjgl() {
super();
}

@Override
public int getWidth() {
return Display.getWidth();
}

@Override
public int getHeight() {
return Display.getHeight();
}

@Override
public int getX() {
return Display.getX();
}

@Override
public int getY() {
return Display.getY();
}

@Override
public boolean isFullscreen() {
return Display.isFullscreen();
}

@Override
public AtomicBoolean wasResized() {
resized.set(Display.wasResized());
return resized;
}

}

54 changes: 27 additions & 27 deletions src/main/java/com/jme3x/jfx/JmeFxScreenContainer.java
Expand Up @@ -7,8 +7,6 @@
import javafx.application.Platform;
import javafx.scene.Scene;

import org.lwjgl.opengl.Display;

import com.jme3.app.Application;
import com.jme3.app.state.AbstractAppState;
import com.jme3.asset.AssetManager;
Expand All @@ -23,24 +21,26 @@

public class JmeFxScreenContainer extends JmeFxContainer {



/** Indent the window position to account for window decoration by Ronn */
protected int windowOffsetX;
protected int windowOffsetY;

private final Picture picture;

private final DisplayInfo displayInfo;

public JmeFxScreenContainer(AssetManager assetManager, Application app, boolean fullScreenSupport, ICursorDisplayProvider cursorDisplayProvider) {
super();

final Point decorationSize = JFXUtils.getWindowDecorationSize();

this.windowOffsetX = (int) decorationSize.getX();
this.windowOffsetY = (int) decorationSize.getY();
this.cursorDisplayProvider = cursorDisplayProvider;
this.app = app;
this.fullScreenSuppport = fullScreenSupport;
this.displayInfo = DisplayInfoProvider.find(app);

app.getStateManager().attach(new AbstractAppState() {

Expand All @@ -63,22 +63,22 @@ public void updateLogicalState(final float tpf) {
if(currentStage == null) {
return;
}
if (stage != null && Display.isFullscreen() ) {

if (stage != null && displayInfo.isFullscreen() ) {
sceneContainerMap.put(stage, JmeFxScreenContainer.this);
} else {
sceneContainerMap.remove(stage);
}

final int currentWidth = Display.getWidth();
final int currentHeight = Display.getHeight();
final int currentWidth = displayInfo.getWidth();
final int currentHeight = displayInfo.getHeight();

if(currentWidth != getpWidth() || currentHeight != getpHeight()) {
handleResize();
}

final int x = Display.getX() + (Display.isFullscreen() ? 0 : getWindowOffsetX());
final int y = Display.getY() + (Display.isFullscreen() ? 0 : getWindowOffsetY());
final int x = displayInfo.getX() + (displayInfo.isFullscreen() ? 0 : getWindowOffsetX());
final int y = displayInfo.getY() + (displayInfo.isFullscreen() ? 0 : getWindowOffsetY());

if(getOldX() != x || getOldY() != y) {

Expand All @@ -101,10 +101,10 @@ public void updateLogicalState(final float tpf) {

this.tex = new Texture2D(this.jmeImage);
this.picture.setTexture(assetManager, this.tex, true);

}


public Picture getJmeNode() {
return this.picture;
}
Expand All @@ -118,7 +118,7 @@ public int getWindowX() {
public int getWindowY() {
return this.oldY;
}

private int getOldX() {
return oldX;
}
Expand Down Expand Up @@ -170,16 +170,16 @@ public int getWindowOffsetX() {
public int getWindowOffsetY() {
return windowOffsetY;
}


private void handleResize() {

try {
this.imageExchange.acquire();
dispose();

this.pWidth = Display.getWidth();
this.pHeight = Display.getHeight();
this.pWidth = displayInfo.getWidth();
this.pHeight = displayInfo.getHeight();
if (this.pWidth < 64) {
this.pWidth = 64;
}
Expand Down Expand Up @@ -224,7 +224,7 @@ public void run() {
}
}


@Override
protected void setSceneImpl(Scene newScene) {
super.setSceneImpl(newScene);
Expand All @@ -237,22 +237,22 @@ public Void call() {
}
});
}

@Override
public int getXPosition() {
if (!Display.isFullscreen()) {
return Display.getX();
if (!displayInfo.isFullscreen()) {
return displayInfo.getX();
}
return 0;
}

@Override
public int getYPosition() {
if (!Display.isFullscreen()) {
return Display.getY();
if (!displayInfo.isFullscreen()) {
return displayInfo.getY();
}
return 0;
}


}

0 comments on commit 6a5577a

Please sign in to comment.