From 595183fb64479b87804068eab506065471e1ed50 Mon Sep 17 00:00:00 2001 From: shadowislord Date: Sun, 23 Nov 2014 18:39:19 -0500 Subject: [PATCH 1/2] Fix items in Translucent bucket not be rendered in AWT panels --- .../java/com/jme3/system/awt/AwtPanel.java | 26 +++++++++++-------- .../com/jme3/system/awt/AwtPanelsContext.java | 6 ++++- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanel.java b/jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanel.java index 1227cbdf2..c09d684ff 100644 --- a/jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanel.java +++ b/jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanel.java @@ -288,19 +288,15 @@ public class AwtPanel extends Canvas implements SceneProcessor { repaintRequest.set(true); } - public void postFrame(FrameBuffer out) { - if (!attachAsMain && out != fb){ - throw new IllegalStateException("Why did you change the output framebuffer?"); - } - - if (reshapeNeeded.getAndSet(false)){ + void onFrameEnd() { + if (reshapeNeeded.getAndSet(false)) { reshapeInThread(newWidth, newHeight); - }else{ - if (!checkVisibilityState()){ + } else { + if (!checkVisibilityState()) { return; } - - switch (paintMode){ + + switch (paintMode) { case Accelerated: drawFrameInThread(); break; @@ -308,7 +304,7 @@ public class AwtPanel extends Canvas implements SceneProcessor { repaintInThread(); break; case OnRequest: - if (repaintRequest.getAndSet(false)){ + if (repaintRequest.getAndSet(false)) { repaintInThread(); } break; @@ -316,6 +312,14 @@ public class AwtPanel extends Canvas implements SceneProcessor { } } + public void postFrame(FrameBuffer out) { + if (!attachAsMain && out != fb){ + throw new IllegalStateException("Why did you change the output framebuffer?"); + } + + // onFrameEnd(); + } + public void reshape(ViewPort vp, int w, int h) { } diff --git a/jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanelsContext.java b/jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanelsContext.java index 9f94e9231..d4e281f87 100644 --- a/jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanelsContext.java +++ b/jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanelsContext.java @@ -178,7 +178,7 @@ public class AwtPanelsContext implements JmeContext { } } - if (needThrottle){ + if (needThrottle) { try { Thread.sleep(100); } catch (InterruptedException ex) { @@ -186,6 +186,10 @@ public class AwtPanelsContext implements JmeContext { } listener.update(); + + for (AwtPanel panel : panels){ + panel.onFrameEnd(); + } } private void destroyInThread(){ From ec6befeeaa077a95cb018bd2c7a746cd6ccf3cbb Mon Sep 17 00:00:00 2001 From: shadowislord Date: Sun, 23 Nov 2014 18:54:09 -0500 Subject: [PATCH 2/2] AWT panels: fix flipped coords when mouse pressed or released --- .../main/java/com/jme3/input/awt/AwtMouseInput.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/jme3-desktop/src/main/java/com/jme3/input/awt/AwtMouseInput.java b/jme3-desktop/src/main/java/com/jme3/input/awt/AwtMouseInput.java index 501530699..f53a3b003 100644 --- a/jme3-desktop/src/main/java/com/jme3/input/awt/AwtMouseInput.java +++ b/jme3-desktop/src/main/java/com/jme3/input/awt/AwtMouseInput.java @@ -36,8 +36,6 @@ import com.jme3.input.MouseInput; import com.jme3.input.RawInputListener; import com.jme3.input.event.MouseButtonEvent; import com.jme3.input.event.MouseMotionEvent; -import com.jme3.system.JmeSystem; -import com.jme3.system.Platform; import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; @@ -141,7 +139,7 @@ public class AwtMouseInput implements MouseInput, MouseListener, MouseWheelListe public long getInputTimeNanos() { return System.nanoTime(); } - + public void setCursorVisible(boolean visible) { // if(JmeSystem.getPlatform() != Platform.MacOSX32 && // JmeSystem.getPlatform() != Platform.MacOSX64 && @@ -170,7 +168,7 @@ public class AwtMouseInput implements MouseInput, MouseListener, MouseWheelListe int newY = location.y; int newWheel = wheelPos; - // invert DY + // invert actual Y and DY for motion events int actualX = lastKnownLocation.x; int actualY = component.getHeight() - lastKnownLocation.y; MouseMotionEvent evt = new MouseMotionEvent(actualX, actualY, @@ -227,7 +225,9 @@ public class AwtMouseInput implements MouseInput, MouseListener, MouseWheelListe } public void mousePressed(MouseEvent awtEvt) { - MouseButtonEvent evt = new MouseButtonEvent(getJMEButtonIndex(awtEvt), true, awtEvt.getX(), awtEvt.getY()); + // Must flip Y! + int y = component.getHeight() - awtEvt.getY(); + MouseButtonEvent evt = new MouseButtonEvent(getJMEButtonIndex(awtEvt), true, awtEvt.getX(), y); evt.setTime(awtEvt.getWhen()); synchronized (eventQueue) { eventQueue.add(evt); @@ -235,7 +235,8 @@ public class AwtMouseInput implements MouseInput, MouseListener, MouseWheelListe } public void mouseReleased(MouseEvent awtEvt) { - MouseButtonEvent evt = new MouseButtonEvent(getJMEButtonIndex(awtEvt), false, awtEvt.getX(), awtEvt.getY()); + int y = component.getHeight() - awtEvt.getY(); + MouseButtonEvent evt = new MouseButtonEvent(getJMEButtonIndex(awtEvt), false, awtEvt.getX(), y); evt.setTime(awtEvt.getWhen()); synchronized (eventQueue) { eventQueue.add(evt);