diff options
author | Carsten Weisse <[email protected]> | 2008-03-02 14:58:22 +0000 |
---|---|---|
committer | Carsten Weisse <[email protected]> | 2008-03-02 14:58:22 +0000 |
commit | e6da1e14830ab5db1c3e9bc1f90ce17738931a43 (patch) | |
tree | e904092dc1d787489a1c3371c7cbc64dd3a71e4a | |
parent | 78d0a1f33aaca5d734122371c43fd51ff43ad3fd (diff) |
changes to handle resizable screens.
GridBagLayout is used to resize the GL canvas together with the frame
-rw-r--r-- | src/jake2/render/opengl/Jsr231Driver.java | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/src/jake2/render/opengl/Jsr231Driver.java b/src/jake2/render/opengl/Jsr231Driver.java index 565e79c..39c3384 100644 --- a/src/jake2/render/opengl/Jsr231Driver.java +++ b/src/jake2/render/opengl/Jsr231Driver.java @@ -136,7 +136,7 @@ public abstract class Jsr231Driver extends Jsr231GL implements GLDriver { VID.Printf(Defines.PRINT_ALL, "...setting mode " + mode + ":"); /* - * fullscreen handling + * full screen handling */ if (device == null) { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); @@ -160,12 +160,18 @@ public abstract class Jsr231Driver extends Jsr231GL implements GLDriver { 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); - window.add(canvas); + // 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 @@ -209,7 +215,7 @@ public abstract class Jsr231Driver extends Jsr231GL implements GLDriver { public void run() { //f2.setLocation(window_xpos, window_ypos); f2.pack(); - f2.setResizable(false); + f2.setResizable(true); f2.setVisible(true); } }); @@ -227,10 +233,6 @@ public abstract class Jsr231Driver extends Jsr231GL implements GLDriver { this.display = canvas; - Base.setVid(newDim.width, newDim.height); - - // let the sound and input subsystems know about the new window - VID.NewWindow(newDim.width, newDim.height); setGL(display.getGL()); init(0, 0); @@ -284,13 +286,13 @@ public abstract class Jsr231Driver extends Jsr231GL implements GLDriver { // clear the screen // first buffer beginFrame(0.0f); - glViewport(0, 0, window.getWidth(), window.getHeight()); + glViewport(0, 0, display.getWidth(), display.getHeight()); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); endFrame(); // second buffer beginFrame(0.0f); - glViewport(0, 0, window.getWidth(), window.getHeight()); + glViewport(0, 0, display.getWidth(), display.getHeight()); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); endFrame(); @@ -347,7 +349,26 @@ public abstract class Jsr231Driver extends Jsr231GL implements GLDriver { activate(); return context.getGL(); } - /** <B>Overrides:</B> + + + /** + * @see java.awt.Component#setBounds(int, int, int, int) + */ + public void setBounds(int x, int y, int width, int height) { + final int mask = ~0x03; + if ((width & 0x03) != 0) { + width &= mask; + width += 4; + } + +// System.out.println("display bounds: " + x + ", " + y + ", " + width + ", " + height); + super.setBounds(x, y, width, height); + Base.setVid(width, height); + // let the sound and input subsystems know about the new window + VID.NewWindow(width, height); + } + + /** <B>Overrides:</B> <DL><DD><CODE>paint</CODE> in class <CODE>java.awt.Component</CODE></DD></DL> */ // Overridden from Canvas to prevent the AWT's clearing of the // canvas from interfering with the OpenGL rendering. |