From 0360d5f1c6117f1b989dc68d2b52085e2cbb7a09 Mon Sep 17 00:00:00 2001 From: Nicolas Vanhoren Date: Tue, 17 Nov 2020 17:41:04 +0100 Subject: [PATCH] Partial fix of #195 --- .../worldwind/WorldWindowGLAutoDrawable.java | 6 +++- .../worldwind/awt/WorldWindowGLCanvas.java | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/gov/nasa/worldwind/WorldWindowGLAutoDrawable.java b/src/gov/nasa/worldwind/WorldWindowGLAutoDrawable.java index 8005c6871b..bebebc3ecb 100644 --- a/src/gov/nasa/worldwind/WorldWindowGLAutoDrawable.java +++ b/src/gov/nasa/worldwind/WorldWindowGLAutoDrawable.java @@ -495,7 +495,11 @@ protected void doSwapBuffers(GLAutoDrawable drawable) */ public void reshape(GLAutoDrawable glAutoDrawable, int x, int y, int w, int h) { - // This is apparently necessary to enable the WWJ canvas to resize correctly with JSplitPane. + GL2 gl = this.drawable.getGL().getGL2(); // change this as needed + double dpiScalingFactor = (double) (Toolkit.getDefaultToolkit().getScreenResolution() / 96.0); + w = (int) (w * dpiScalingFactor); + h = (int) (h * dpiScalingFactor); + gl.glViewport(0, 0, w, h); ((Component) glAutoDrawable).setMinimumSize(new Dimension(0, 0)); } diff --git a/src/gov/nasa/worldwind/awt/WorldWindowGLCanvas.java b/src/gov/nasa/worldwind/awt/WorldWindowGLCanvas.java index 8a9942751b..bd1661653f 100644 --- a/src/gov/nasa/worldwind/awt/WorldWindowGLCanvas.java +++ b/src/gov/nasa/worldwind/awt/WorldWindowGLCanvas.java @@ -39,6 +39,8 @@ import com.jogamp.opengl.*; import com.jogamp.opengl.awt.GLCanvas; import java.awt.*; +import java.awt.event.MouseEvent; +import java.awt.event.MouseWheelEvent; import java.beans.*; import java.util.*; @@ -487,4 +489,34 @@ public Collection getPerFrameStatistics() { return this.wwd.getPerFrameStatistics(); } + + @Override + protected void processMouseEvent(MouseEvent e) { + double dpiScalingFactor = (double) (Toolkit.getDefaultToolkit().getScreenResolution() / 96.0); + int x = (int) (e.getPoint().x * dpiScalingFactor); + int y = (int) (e.getPoint().y * dpiScalingFactor); + MouseEvent scaledEvent = new MouseEvent((Component)e.getSource(), e.getID(), + e.getWhen(), e.getModifiersEx(), x, y, e.getXOnScreen(), e.getYOnScreen(), e.getClickCount(), false,e.getButton()); + super.processMouseEvent(scaledEvent); + } + + @Override + protected void processMouseMotionEvent(MouseEvent e) { + double dpiScalingFactor = (double) (Toolkit.getDefaultToolkit().getScreenResolution() / 96.0); + int x = (int) (e.getPoint().x * dpiScalingFactor); + int y = (int) (e.getPoint().y * dpiScalingFactor); + MouseEvent scaledEvent = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiersEx(), + x, y, e.getXOnScreen(), e.getYOnScreen(), e.getClickCount(), false, e.getButton()); + super.processMouseMotionEvent(scaledEvent); + } + + @Override + protected void processMouseWheelEvent(MouseWheelEvent e) { + double dpiScalingFactor = (double) (Toolkit.getDefaultToolkit().getScreenResolution() / 96.0);; + int x = (int) (e.getPoint().x * dpiScalingFactor); + int y = (int) (e.getPoint().y * dpiScalingFactor); + MouseWheelEvent scaledEvent = new MouseWheelEvent((Component) e.getSource(), + e.getID(), e.getWhen(), e.getModifiersEx(), x, y, e.getXOnScreen(), e.getYOnScreen(), e.getClickCount(), false, e.getScrollType(),e.getScrollAmount(),e.getWheelRotation()); + super.processMouseWheelEvent(scaledEvent); + } }