From: Kenneth B. R. <kbr...@us...> - 2008-03-02 20:21:27
|
Update of /cvsroot/jake2/jake2/src/jake2/render/opengl In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv16186/src/jake2/render/opengl Modified Files: Jsr231Driver.java Log Message: Changes to enable Jake2 to run well as an applet inside the next-generation Java Plug-In. Added Globals.appletMode, Globals.applet and Globals.sizeChangeListener to be able to easily pass around the knowledge that the system is running in applet mode, and the applet itself, which becomes the parent container for the output. Most changes were in Jsr231Driver to support putting the Display into a preexisting parent container rather than a new Frame each time. Changed JOGLKBD to allow manual initialization of the parent container rather than obtaining it from a CreateNotify or ConfigureNotify event since these will never be generated in the applet case. Removed various calls to System.exit(), although strictly speaking this is no longer necessary because it is expected that the separate_jvm parameter will be used in conjunction with the new Java Plug-In to create a fresh JVM instance for each run of Jake2. Video mode switching in applet mode is working; the applet resizes (via JavaScript) to accommodate the newly selected resolution. Full screen mode when running as an applet is not implemented at this point, as the intent was to show this inside the browser, though support could be added very straightforwardly. Index: Jsr231Driver.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/render/opengl/Jsr231Driver.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** Jsr231Driver.java 2 Mar 2008 14:58:22 -0000 1.26 --- Jsr231Driver.java 2 Mar 2008 20:21:15 -0000 1.27 *************** *** 27,30 **** --- 27,32 ---- import jake2.Defines; + import jake2.Globals; + import jake2.SizeChangeListener; import jake2.client.VID; import jake2.qcommon.Cbuf; *************** *** 55,58 **** --- 57,64 ---- private volatile Frame window; + // This is either the above Window reference or the global + // applet if we're running in applet mode + private volatile Container container; + // window position on the screen int window_xpos, window_ypos; *************** *** 136,139 **** --- 142,149 ---- VID.Printf(Defines.PRINT_ALL, "...setting mode " + mode + ":"); + if (Globals.appletMode && container == null) { + container = (Container) Globals.applet; + } + /* * full screen handling *************** *** 144,194 **** } ! if (oldDisplayMode == null) { ! oldDisplayMode = device.getDisplayMode(); ! } ! if (!VID.GetModeInfo(newDim, mode)) { ! VID.Printf(Defines.PRINT_ALL, " invalid mode\n"); ! return Base.rserr_invalid_mode; ! } ! VID.Printf(Defines.PRINT_ALL, " " + newDim.width + " " + newDim.height + '\n'); ! // destroy the existing window ! if (window != null) shutdown(); ! window = new Frame("Jake2 (jsr231)"); ! ImageIcon icon = new ImageIcon(getClass().getResource("/icon-small.png")); ! window.setIconImage(icon.getImage()); ! window.setLayout(new GridBagLayout()); ! Display canvas = new Display(new GLCapabilities()); ! // we want keypressed events for TAB key ! canvas.setFocusTraversalKeysEnabled(false); ! // the OpenGL canvas grows and shrinks with the window ! GridBagConstraints gbc = new GridBagConstraints(); ! gbc.fill = GridBagConstraints.BOTH; ! gbc.weightx = gbc.weighty = 1; ! window.add(canvas, gbc); ! ! canvas.setSize(newDim.width, newDim.height); ! // register event listener ! window.addWindowListener(new WindowAdapter() { ! public void windowClosing(WindowEvent e) { ! Cbuf.ExecuteText(Defines.EXEC_APPEND, "quit"); ! } ! }); ! // D I F F E R E N T J A K E 2 E V E N T P R O C E S S I N G ! window.addComponentListener(JOGLKBD.listener); ! canvas.addKeyListener(JOGLKBD.listener); ! canvas.addMouseListener(JOGLKBD.listener); ! canvas.addMouseMotionListener(JOGLKBD.listener); ! canvas.addMouseWheelListener(JOGLKBD.listener); if (fullscreen) { DisplayMode displayMode = findDisplayMode(newDim); --- 154,219 ---- } ! if (oldDisplayMode == null) { ! oldDisplayMode = device.getDisplayMode(); ! } ! if (!VID.GetModeInfo(newDim, mode)) { ! VID.Printf(Defines.PRINT_ALL, " invalid mode\n"); ! return Base.rserr_invalid_mode; ! } ! VID.Printf(Defines.PRINT_ALL, " " + newDim.width + " " + newDim.height + '\n'); ! if (!Globals.appletMode) { ! // destroy the existing window ! if (window != null) shutdown(); ! window = new Frame("Jake2 (jsr231)"); ! container = window; ! ImageIcon icon = new ImageIcon(getClass().getResource("/icon-small.png")); ! window.setIconImage(icon.getImage()); ! window.setLayout(new GridBagLayout()); ! // register event listener ! window.addWindowListener(new WindowAdapter() { ! public void windowClosing(WindowEvent e) { ! Cbuf.ExecuteText(Defines.EXEC_APPEND, "quit"); ! } ! }); ! } ! if (Globals.appletMode) { ! // Destroy the previous display if there is one ! shutdown(); ! // We don't support full-screen mode ! fullscreen = false; ! // We need to feed the container to the JOGL ! // keyboard class manually because we'll never get ! // a component shown event for it ! JOGLKBD.Init(container); ! } ! ! Display canvas = new Display(new GLCapabilities()); ! // we want keypressed events for TAB key ! canvas.setFocusTraversalKeysEnabled(false); ! canvas.setSize(newDim.width, newDim.height); ! ! // the OpenGL canvas grows and shrinks with the window ! final GridBagConstraints gbc = new GridBagConstraints(); ! gbc.fill = GridBagConstraints.BOTH; ! gbc.weightx = gbc.weighty = 1; ! // D I F F E R E N T J A K E 2 E V E N T P R O C E S S I N G ! container.addComponentListener(JOGLKBD.listener); ! canvas.addKeyListener(JOGLKBD.listener); ! canvas.addMouseListener(JOGLKBD.listener); ! canvas.addMouseMotionListener(JOGLKBD.listener); ! canvas.addMouseWheelListener(JOGLKBD.listener); if (fullscreen) { + container.add(canvas, gbc); + DisplayMode displayMode = findDisplayMode(newDim); *************** *** 210,233 **** } else { ! final Frame f2 = window; ! try { ! EventQueue.invokeAndWait(new Runnable() { ! public void run() { ! //f2.setLocation(window_xpos, window_ypos); ! f2.pack(); ! f2.setResizable(true); ! f2.setVisible(true); ! } ! }); ! } catch (Exception e) { ! e.printStackTrace(); ! } } ! while (!canvas.isDisplayable() || !window.isDisplayable()) { try { ! Thread.sleep(100); } catch (InterruptedException e) {} ! } canvas.requestFocus(); --- 235,280 ---- } else { ! if (!Globals.appletMode) { ! container.add(canvas, gbc); ! final Frame f2 = window; ! try { ! EventQueue.invokeAndWait(new Runnable() { ! public void run() { ! //f2.setLocation(window_xpos, window_ypos); ! f2.pack(); ! f2.setResizable(false); ! f2.setVisible(true); ! } ! }); ! } catch (Exception e) { ! e.printStackTrace(); ! } ! } else { ! final Display fd = canvas; ! try { ! EventQueue.invokeAndWait(new Runnable() { ! public void run() { ! container.add(fd, BorderLayout.CENTER); ! // Notify the size listener about the change ! SizeChangeListener listener = Globals.sizeChangeListener; ! if (listener != null) { ! listener.sizeChanged(newDim.width, newDim.height); ! } ! fd.setSize(newDim.width, newDim.height); ! } ! }); ! } catch (Exception e) { ! e.printStackTrace(); ! } ! } } ! if (!Globals.appletMode) { ! while (!canvas.isDisplayable() || !window.isDisplayable()) { try { ! Thread.sleep(100); } catch (InterruptedException e) {} ! } ! } canvas.requestFocus(); *************** *** 241,277 **** public void shutdown() { ! try { EventQueue.invokeAndWait(new Runnable() { public void run() { ! if (oldDisplayMode != null ! && device.getFullScreenWindow() != null) { ! try { ! if (device.isFullScreenSupported()) { ! if (!device.getDisplayMode().equals( ! oldDisplayMode)) ! device.setDisplayMode(oldDisplayMode); ! } ! device.setFullScreenWindow(null); ! } catch (Exception e) { ! e.printStackTrace(); ! } ! } } ! }); ! } catch (Exception e) { e.printStackTrace(); ! } ! if (window != null) { if (display != null) display.destroy(); window.dispose(); while (window.isDisplayable()) { ! try { ! Thread.sleep(100); ! } catch (InterruptedException e) { ! } } ! } display = null; } --- 288,332 ---- public void shutdown() { ! if (!Globals.appletMode) { ! try { EventQueue.invokeAndWait(new Runnable() { public void run() { ! if (oldDisplayMode != null ! && device.getFullScreenWindow() != null) { ! try { ! if (device.isFullScreenSupported()) { ! if (!device.getDisplayMode().equals(oldDisplayMode)) ! device.setDisplayMode(oldDisplayMode); ! } ! device.setFullScreenWindow(null); ! } catch (Exception e) { ! e.printStackTrace(); ! } ! } } ! }); ! } catch (Exception e) { e.printStackTrace(); ! } ! ! if (window != null) { if (display != null) display.destroy(); window.dispose(); while (window.isDisplayable()) { ! try { ! Thread.sleep(100); ! } catch (InterruptedException e) { ! } } ! } ! } else { ! if (display != null) { ! display.destroy(); ! // Remove the old display if there is one ! container.remove(display); ! } ! } display = null; } |