Skip to content

Commit d37973a

Browse files
committed
fix: re-shape|re-scale
1 parent b84dbb3 commit d37973a

1 file changed

Lines changed: 67 additions & 27 deletions

File tree

jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglCanvas.java

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ public Graphics getGraphics() {
401401
* Configuration data to start the AWT context, this is used by the
402402
* {@code lwjgl-awt} library.
403403
*/
404-
private GLData glData;
404+
private final GLData glData;
405405

406406
/** Used to notify the canvas status ({@code remove()/add()}). */
407407
private final AtomicBoolean hasNativePeer = new AtomicBoolean(false);
@@ -414,20 +414,26 @@ public Graphics getGraphics() {
414414
private final AtomicBoolean reinitcontext = new AtomicBoolean(false);
415415

416416
/** Notify if there is a change in canvas dimensions. */
417-
private AtomicBoolean needResize = new AtomicBoolean(false);
417+
private final AtomicBoolean needResize = new AtomicBoolean(false);
418+
/** Notify if there are changes to the canvas scales. */
419+
private final AtomicBoolean needRescale = new AtomicBoolean(false);
418420

419421
/**
420422
* Flag that uses the context to check if it is initialized or not, this prevents
421423
* it from being initialized multiple times and potentially breaking the JVM.
422424
*/
423-
private AtomicBoolean contextFlag = new AtomicBoolean(false);
425+
private final AtomicBoolean contextFlag = new AtomicBoolean(false);
424426

425427
/** lock-object. */
426428
private final Object lock = new Object();
427429

428-
/** Framebuffer width. */
429-
private int framebufferWidth = 1;
430+
/** Scale of the component in {@code x} */
431+
private float xScale = 1;
432+
/** Scale of the component in {@code y} */
433+
private float yScale = 1;
430434

435+
/** Framebuffer width. */
436+
private int framebufferWidth = 1;
431437
/** Framebuffer height. */
432438
private int framebufferHeight = 1;
433439

@@ -453,23 +459,7 @@ public LwjglCanvas() {
453459
@Override
454460
public void componentResized(ComponentEvent e) {
455461
synchronized (lock) {
456-
GraphicsConfiguration gc = canvas.getGraphicsConfiguration();
457-
if (gc == null) {
458-
return;
459-
}
460-
461-
AffineTransform at = gc.getDefaultTransform();
462-
float sx = (float) at.getScaleX(),
463-
sy = (float) at.getScaleY();
464-
465-
int fw = (int) (canvas.getWidth() * sx);
466-
int fh = (int) (canvas.getHeight() * sy);
467-
468-
if (fw != framebufferWidth || fh != framebufferHeight) {
469-
framebufferWidth = Math.max(fw, 1);
470-
framebufferHeight = Math.max(fh, 1);
471-
needResize.set(true);
472-
}
462+
updateSizes();
473463
}
474464
}
475465
});
@@ -509,6 +499,10 @@ public void run() {
509499
listener.reshape(framebufferWidth, framebufferHeight);
510500
}
511501

502+
if (needRescale.getAndSet(false)) {
503+
listener.rescale(xScale, yScale);
504+
}
505+
512506
synchronized (lock) {
513507
if (reinitcontext.getAndSet(false)) {
514508
LOGGER.log(Level.FINE, "LWJGX: Destroying display ..");
@@ -807,15 +801,61 @@ public JoyInput getJoyInput() {
807801
@Override public TouchInput getTouchInput() { return null; }
808802
/** (non-Javadoc) */
809803
@Override public void setTitle(String title) { }
810-
/** (non-Javadoc) */
811-
@Override protected void updateSizes() { }
804+
812805
/** (non-Javadoc) */
813806
@Override protected void showWindow() { }
814807
/** (non-Javadoc) */
815808
@Override protected void setWindowIcon(final AppSettings settings) { }
816-
/** (non-Javadoc) */
817-
@Override public Vector2f getWindowContentScale(Vector2f store) {
818-
return store == null ? new Vector2f() : store;
809+
810+
/**
811+
* {@inheritDoc }
812+
*/
813+
@Override
814+
protected void updateSizes() {
815+
synchronized (lock) {
816+
GraphicsConfiguration gc = canvas.getGraphicsConfiguration();
817+
if (gc == null) {
818+
return;
819+
}
820+
821+
AffineTransform at = gc.getDefaultTransform();
822+
float sx = (float) at.getScaleX(),
823+
sy = (float) at.getScaleY();
824+
825+
int fw = (int) (canvas.getWidth() * sx);
826+
int fh = (int) (canvas.getHeight() * sy);
827+
828+
if (fw != framebufferWidth || fh != framebufferHeight) {
829+
framebufferWidth = Math.max(fw, 1);
830+
framebufferHeight = Math.max(fh, 1);
831+
needResize.set(true);
832+
}
833+
834+
if (xScale != sx || yScale != sy) {
835+
xScale = sx;
836+
yScale = sy;
837+
needRescale.set(true);
838+
}
839+
}
840+
}
841+
842+
/**
843+
* {@inheritDoc }
844+
*/
845+
@Override
846+
public Vector2f getWindowContentScale(Vector2f store) {
847+
if (store == null) store = new Vector2f();
848+
849+
GraphicsConfiguration gc = canvas.getGraphicsConfiguration();
850+
if (gc == null) {
851+
return store;
852+
}
853+
AffineTransform at = gc.getDefaultTransform();
854+
float sx = (float) at.getScaleX(),
855+
sy = (float) at.getScaleY();
856+
857+
store.set(sx, sy);
858+
return store;
819859
}
820860

821861
/**

0 commit comments

Comments
 (0)