From a127d83e7a9f3ce7334968a0a7bf5119d0e141ff Mon Sep 17 00:00:00 2001 From: "Zer..om" Date: Sun, 3 Feb 2013 18:50:21 +0000 Subject: [PATCH] Improved the code to detect and present good "nearly full screen" windowed resolutions. Default to highest available resolution when switching between windowed and fullscreen. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10331 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../desktop/com/jme3/app/SettingsDialog.java | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/engine/src/desktop/com/jme3/app/SettingsDialog.java b/engine/src/desktop/com/jme3/app/SettingsDialog.java index 5cba595e7..d1e34722e 100644 --- a/engine/src/desktop/com/jme3/app/SettingsDialog.java +++ b/engine/src/desktop/com/jme3/app/SettingsDialog.java @@ -657,6 +657,9 @@ public final class SettingsDialog extends JDialog { if (!fullscreenBox.isSelected()) { displayResCombo.setModel(new DefaultComboBoxModel( getWindowedResolutions(windowModes))); + if (displayResCombo.getItemCount() > 0) { + displayResCombo.setSelectedIndex(displayResCombo.getItemCount()-1); + } colorDepthCombo.setModel(new DefaultComboBoxModel(new String[]{ "24 bpp", "16 bpp"})); displayFreqCombo.setModel(new DefaultComboBoxModel( @@ -664,7 +667,10 @@ public final class SettingsDialog extends JDialog { displayFreqCombo.setEnabled(false); } else { displayResCombo.setModel(new DefaultComboBoxModel( - getResolutions(modes, Integer.MAX_VALUE))); + getResolutions(modes, Integer.MAX_VALUE, Integer.MAX_VALUE))); + if (displayResCombo.getItemCount() > 0) { + displayResCombo.setSelectedIndex(displayResCombo.getItemCount()-1); + } displayFreqCombo.setEnabled(true); updateDisplayChoices(); } @@ -704,17 +710,21 @@ public final class SettingsDialog extends JDialog { * Returns every unique resolution from an array of DisplayModes * where the resolution is greater than the configured minimums. */ - private String[] getResolutions(DisplayMode[] modes, int heightLimit) { + private String[] getResolutions(DisplayMode[] modes, int heightLimit, int widthLimit) { + Insets insets = getInsets(); + heightLimit -= insets.top + insets.bottom; + widthLimit -= insets.left + insets.right; + ArrayList resolutions = new ArrayList(modes.length); for (int i = 0; i < modes.length; i++) { int height = modes[i].getHeight(); int width = modes[i].getWidth(); - if (width >= minWidth && height >= minHeight && height <= heightLimit) { - if (height == heightLimit) { - // If height is equal to height limit then subtract the size of the window frame and use that - Insets insets = getInsets(); - height -= insets.top + insets.bottom; - width -= insets.left + insets.right; + if (width >= minWidth && height >= minHeight) { + if (height >= heightLimit) { + height = heightLimit; + } + if (width >= widthLimit) { + width = widthLimit; } String res = width + " x " + height; @@ -736,13 +746,18 @@ public final class SettingsDialog extends JDialog { */ private String[] getWindowedResolutions(DisplayMode[] modes) { int maxHeight = 0; + int maxWidth = 0; + for (int i = 0; i < modes.length; i++) { if (maxHeight < modes[i].getHeight()) { maxHeight = modes[i].getHeight(); } + if (maxWidth < modes[i].getWidth()) { + maxWidth = modes[i].getWidth(); + } } - return getResolutions(modes, maxHeight); + return getResolutions(modes, maxHeight, maxWidth); } /**