LWJGL
May 22, 2013, 05:07:52 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL is now using GitHub
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: [FIXED] Display.setParent resizing clips mouse coordinates - Nightly 11.8. WINDOWS  (Read 1070 times)
Matthias
Talks Too Much
***
Posts: 180


WWW
« on: August 11, 2011, 16:21:09 »

The mouse coordinates are clipped to the original window size on the windows nightly from 11.8. (not checked with other platforms).
The following test case shows that DisplayImplementation.getWidth() doesn't change while resizing using Canvas:
Code:
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.concurrent.atomic.AtomicReference;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;

/**
 *
 * @author Matthias Mann
 */
public class Test {
   
   private static boolean closeRequested = false;
   final static AtomicReference<Dimension> newCanvasSize = new AtomicReference<Dimension>();
   
   public static void main(String[] args)
   {
      Frame frame = new Frame("Test");
      frame.setLayout(new BorderLayout());
      final Canvas canvas = new Canvas();
      canvas.addComponentListener(new ComponentAdapter() {
         @Override
         public void componentResized(ComponentEvent e)
         {
            newCanvasSize.set(canvas.getSize());
         }
      });
     
      frame.addWindowFocusListener(new WindowAdapter() {
         @Override
         public void windowGainedFocus(WindowEvent e)
         {
            canvas.requestFocusInWindow();
         }
      });
     
      frame.addWindowListener(new WindowAdapter() {
         @Override
         public void windowClosing(WindowEvent e)
         {
            closeRequested = true;
         }
      });
     
      frame.add(canvas, BorderLayout.CENTER);
      try {
         Display.setParent(canvas);
         Display.setVSyncEnabled(true);
         
         frame.setPreferredSize(new Dimension(1024, 786));
         frame.setMinimumSize(new Dimension(800, 600));
         frame.pack();
         frame.setVisible(true);
         Display.create();
         
         Dimension newDim;
         
         Field f = Display.class.getDeclaredField("display_impl");
         f.setAccessible(true);
         Object di = f.get(null);
         Method m = di.getClass().getMethod("getWidth");
         m.setAccessible(true);
         
         while(!Display.isCloseRequested() && !closeRequested)
         {
            newDim = newCanvasSize.getAndSet(null);
           
            if (newDim != null)
            {
               GL11.glViewport(0, 0, newDim.width, newDim.height);
                System.out.println(newDim.width + " " + m.invoke(di));
            }
           
            GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
            Display.update();
         }

         Display.destroy();
         frame.dispose();
         System.exit(0);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}
Logged

Matthias
Talks Too Much
***
Posts: 180


WWW
« Reply #1 on: August 13, 2011, 11:52:21 »

Ok more information as to why this is a critical regression:

By default the the mouse movement is clipped to the Display size. With this bug the size values used by Mouse are not updated when resizing using Display.setParent().
This causes the mouse movement to be clipped to the original display size.

A work around is to disable clipping of mouse coordinates using
Code:
Mouse.setClipMouseCoordinatesToWindow(false); // new in LWJGL 2.8
or using:
Code:
-Dorg.lwjgl.input.Mouse.allowNegativeMouseCoords=true

So most apps written against 2.7.x using the Canvas based resizing will break.
Logged

kappa
Administrator
Nerdus Imperius
*****
Posts: 1112



« Reply #2 on: August 13, 2011, 11:55:39 »

this should be fixed in svn now.

thx for finding and reporting.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!