jmekaelthas 10 years ago
commit e6787f5c2e
  1. 11
      jme3-desktop/src/main/java/com/jme3/input/awt/AwtMouseInput.java
  2. 24
      jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanel.java
  3. 6
      jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanelsContext.java

@ -36,8 +36,6 @@ import com.jme3.input.MouseInput;
import com.jme3.input.RawInputListener; import com.jme3.input.RawInputListener;
import com.jme3.input.event.MouseButtonEvent; import com.jme3.input.event.MouseButtonEvent;
import com.jme3.input.event.MouseMotionEvent; import com.jme3.input.event.MouseMotionEvent;
import com.jme3.system.JmeSystem;
import com.jme3.system.Platform;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@ -170,7 +168,7 @@ public class AwtMouseInput implements MouseInput, MouseListener, MouseWheelListe
int newY = location.y; int newY = location.y;
int newWheel = wheelPos; int newWheel = wheelPos;
// invert DY // invert actual Y and DY for motion events
int actualX = lastKnownLocation.x; int actualX = lastKnownLocation.x;
int actualY = component.getHeight() - lastKnownLocation.y; int actualY = component.getHeight() - lastKnownLocation.y;
MouseMotionEvent evt = new MouseMotionEvent(actualX, actualY, MouseMotionEvent evt = new MouseMotionEvent(actualX, actualY,
@ -227,7 +225,9 @@ public class AwtMouseInput implements MouseInput, MouseListener, MouseWheelListe
} }
public void mousePressed(MouseEvent awtEvt) { 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()); evt.setTime(awtEvt.getWhen());
synchronized (eventQueue) { synchronized (eventQueue) {
eventQueue.add(evt); eventQueue.add(evt);
@ -235,7 +235,8 @@ public class AwtMouseInput implements MouseInput, MouseListener, MouseWheelListe
} }
public void mouseReleased(MouseEvent awtEvt) { 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()); evt.setTime(awtEvt.getWhen());
synchronized (eventQueue) { synchronized (eventQueue) {
eventQueue.add(evt); eventQueue.add(evt);

@ -288,19 +288,15 @@ public class AwtPanel extends Canvas implements SceneProcessor {
repaintRequest.set(true); repaintRequest.set(true);
} }
public void postFrame(FrameBuffer out) { void onFrameEnd() {
if (!attachAsMain && out != fb){ if (reshapeNeeded.getAndSet(false)) {
throw new IllegalStateException("Why did you change the output framebuffer?");
}
if (reshapeNeeded.getAndSet(false)){
reshapeInThread(newWidth, newHeight); reshapeInThread(newWidth, newHeight);
}else{ } else {
if (!checkVisibilityState()){ if (!checkVisibilityState()) {
return; return;
} }
switch (paintMode){ switch (paintMode) {
case Accelerated: case Accelerated:
drawFrameInThread(); drawFrameInThread();
break; break;
@ -308,7 +304,7 @@ public class AwtPanel extends Canvas implements SceneProcessor {
repaintInThread(); repaintInThread();
break; break;
case OnRequest: case OnRequest:
if (repaintRequest.getAndSet(false)){ if (repaintRequest.getAndSet(false)) {
repaintInThread(); repaintInThread();
} }
break; 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) { public void reshape(ViewPort vp, int w, int h) {
} }

@ -178,7 +178,7 @@ public class AwtPanelsContext implements JmeContext {
} }
} }
if (needThrottle){ if (needThrottle) {
try { try {
Thread.sleep(100); Thread.sleep(100);
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
@ -186,6 +186,10 @@ public class AwtPanelsContext implements JmeContext {
} }
listener.update(); listener.update();
for (AwtPanel panel : panels){
panel.onFrameEnd();
}
} }
private void destroyInThread(){ private void destroyInThread(){

Loading…
Cancel
Save