Skip to content

Commit 11db477

Browse files
committed
Add new configs to AWT launcher
1 parent eef69a0 commit 11db477

2 files changed

Lines changed: 114 additions & 5 deletions

File tree

jme3-awt-dialogs/src/main/java/com/jme3/awt/AWTSettingsDialog.java

Lines changed: 106 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.jme3.asset.AssetNotFoundException;
3535
import com.jme3.system.AppSettings;
3636
import com.jme3.system.JmeSystem;
37+
import com.jme3.system.Platform;
3738

3839
import java.awt.*;
3940
import java.awt.event.*;
@@ -42,7 +43,6 @@
4243
import java.net.MalformedURLException;
4344
import java.net.URL;
4445
import java.text.MessageFormat;
45-
import java.util.ArrayList;
4646
import java.util.Arrays;
4747
import java.util.Comparator;
4848
import java.util.LinkedHashSet;
@@ -125,11 +125,13 @@ public interface SelectionListener {
125125
private JCheckBox vsyncBox = null;
126126
private JCheckBox gammaBox = null;
127127
private JCheckBox fullscreenBox = null;
128+
private JCheckBox x11PlatformPreferredBox = null;
128129
private JComboBox<String> displayResCombo = null;
129130
private JComboBox<String> colorDepthCombo = null;
130131
private JComboBox<String> displayFreqCombo = null;
131132
private JComboBox<String> antialiasCombo = null;
132133
private JComboBox<String> rendererCombo = null;
134+
private JComboBox<DisplayScaleModeOption> displayScaleModeCombo = null;
133135
private JLabel icon = null;
134136
private int selection = 0;
135137
private SelectionListener selectionListener = null;
@@ -466,6 +468,8 @@ public void keyPressed(KeyEvent e) {
466468
antialiasCombo.addKeyListener(aListener);
467469
rendererCombo = setUpRendererChooser();
468470
rendererCombo.addKeyListener(aListener);
471+
displayScaleModeCombo = setUpDisplayScaleModeChooser();
472+
displayScaleModeCombo.addKeyListener(aListener);
469473
fullscreenBox = new JCheckBox(resourceBundle.getString("checkbox.fullscreen"));
470474
fullscreenBox.setSelected(source.isFullscreen());
471475
fullscreenBox.addActionListener(new ActionListener() {
@@ -481,6 +485,10 @@ public void actionPerformed(ActionEvent e) {
481485
gammaBox = new JCheckBox(resourceBundle.getString("checkbox.gamma"));
482486
gammaBox.setSelected(source.isGammaCorrection());
483487

488+
x11PlatformPreferredBox = new JCheckBox(resourceBundle.getString("checkbox.x11PlatformPreferred"));
489+
x11PlatformPreferredBox.setSelected(source.isX11PlatformPreferred());
490+
boolean linux = JmeSystem.getPlatform().getOs() == Platform.Os.Linux;
491+
484492
GridBagConstraints gbc = new GridBagConstraints();
485493
gbc.weightx = 0.5;
486494
gbc.gridx = 0;
@@ -562,10 +570,34 @@ public void actionPerformed(ActionEvent e) {
562570
gbc = new GridBagConstraints();
563571
gbc.gridx = 1;
564572
gbc.gridy = 4;
565-
gbc.gridwidth = 3;
573+
gbc.gridwidth = linux ? 1 : 3;
566574
gbc.anchor = GridBagConstraints.WEST;
567575
mainPanel.add(rendererCombo, gbc);
568576

577+
if (linux) {
578+
gbc = new GridBagConstraints();
579+
gbc.insets = new Insets(4, 16, 4, 4);
580+
gbc.gridx = 2;
581+
gbc.gridy = 4;
582+
gbc.gridwidth = 2;
583+
gbc.anchor = GridBagConstraints.WEST;
584+
mainPanel.add(x11PlatformPreferredBox, gbc);
585+
}
586+
587+
gbc = new GridBagConstraints();
588+
gbc.insets = new Insets(4, 4, 4, 4);
589+
gbc.gridx = 0;
590+
gbc.gridy = 5;
591+
gbc.anchor = GridBagConstraints.EAST;
592+
gbc.weightx = 0.5;
593+
mainPanel.add(new JLabel(resourceBundle.getString("label.displayScaleMode")), gbc);
594+
gbc = new GridBagConstraints();
595+
gbc.gridx = 1;
596+
gbc.gridy = 5;
597+
gbc.gridwidth = 3;
598+
gbc.anchor = GridBagConstraints.WEST;
599+
mainPanel.add(displayScaleModeCombo, gbc);
600+
569601
// Set the button action listeners. Cancel disposes without saving, OK
570602
// saves.
571603
ok.addActionListener(new ActionListener() {
@@ -600,14 +632,14 @@ public void actionPerformed(ActionEvent e) {
600632
gbc = new GridBagConstraints();
601633
gbc.gridx = 0;
602634
gbc.gridwidth = 2;
603-
gbc.gridy = 5;
635+
gbc.gridy = 6;
604636
gbc.anchor = GridBagConstraints.EAST;
605637
mainPanel.add(ok, gbc);
606638
gbc = new GridBagConstraints();
607639
gbc.insets = new Insets(4, 16, 4, 4);
608640
gbc.gridx = 2;
609641
gbc.gridwidth = 2;
610-
gbc.gridy = 5;
642+
gbc.gridy = 6;
611643
gbc.anchor = GridBagConstraints.WEST;
612644
mainPanel.add(cancel, gbc);
613645

@@ -739,6 +771,12 @@ private boolean verifyAndSaveCurrentSelection() {
739771
source.setFullscreen(fullscreen);
740772
source.setVSync(vsync);
741773
source.setGammaCorrection(gamma);
774+
source.setX11PlatformPreferred(x11PlatformPreferredBox.isSelected());
775+
DisplayScaleModeOption displayScaleMode
776+
= (DisplayScaleModeOption) displayScaleModeCombo.getSelectedItem();
777+
if (displayScaleMode != null) {
778+
source.setDisplayScaleMode(displayScaleMode.value);
779+
}
742780
source.setRenderer(renderer);
743781
source.setSamples(multisample);
744782

@@ -804,6 +842,55 @@ private JComboBox<String> setUpRendererChooser() {
804842
return rendererBox;
805843
}
806844

845+
private JComboBox<DisplayScaleModeOption> setUpDisplayScaleModeChooser() {
846+
JComboBox<DisplayScaleModeOption> scaleModeBox = new JComboBox<>();
847+
float currentMode = source.getDisplayScaleMode();
848+
float[] standardModes = {
849+
AppSettings.DISPLAY_SCALE_DISABLED,
850+
AppSettings.DISPLAY_SCALE_NATIVE_PIXELS,
851+
AppSettings.DISPLAY_SCALE_DPI_AWARE,
852+
2f,
853+
3f,
854+
4f,
855+
5f,
856+
6f,
857+
7f,
858+
8f
859+
};
860+
861+
boolean currentModeAdded = false;
862+
for (float mode : standardModes) {
863+
DisplayScaleModeOption option = createDisplayScaleModeOption(mode);
864+
scaleModeBox.addItem(option);
865+
if (Float.compare(mode, currentMode) == 0) {
866+
scaleModeBox.setSelectedItem(option);
867+
currentModeAdded = true;
868+
}
869+
}
870+
871+
if (!currentModeAdded) {
872+
DisplayScaleModeOption option = createDisplayScaleModeOption(currentMode);
873+
scaleModeBox.addItem(option);
874+
scaleModeBox.setSelectedItem(option);
875+
}
876+
877+
return scaleModeBox;
878+
}
879+
880+
private DisplayScaleModeOption createDisplayScaleModeOption(float mode) {
881+
String label;
882+
if (mode == AppSettings.DISPLAY_SCALE_DISABLED) {
883+
label = resourceBundle.getString("displayScaleMode.disabled");
884+
} else if (mode == AppSettings.DISPLAY_SCALE_NATIVE_PIXELS) {
885+
label = resourceBundle.getString("displayScaleMode.nativePixels");
886+
} else if (mode == AppSettings.DISPLAY_SCALE_DPI_AWARE) {
887+
label = resourceBundle.getString("displayScaleMode.dpiAware");
888+
} else {
889+
label = MessageFormat.format(resourceBundle.getString("displayScaleMode.supersampling"), mode);
890+
}
891+
return new DisplayScaleModeOption(label, mode);
892+
}
893+
807894
/**
808895
* <code>updateDisplayChoices</code> updates the available color depth and
809896
* display frequency options to match the currently selected resolution.
@@ -1069,4 +1156,19 @@ public int compare(DisplayMode a, DisplayMode b) {
10691156
return 0;
10701157
}
10711158
}
1159+
1160+
private static final class DisplayScaleModeOption {
1161+
private final String label;
1162+
private final float value;
1163+
1164+
private DisplayScaleModeOption(String label, float value) {
1165+
this.label = label;
1166+
this.value = value;
1167+
}
1168+
1169+
@Override
1170+
public String toString() {
1171+
return label;
1172+
}
1173+
}
10721174
}

jme3-desktop/src/main/resources/com/jme3/app/SettingsDialog.properties

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@ button.cancel=Cancel
66
checkbox.fullscreen=Fullscreen?
77
checkbox.vsync=Vsync?
88
checkbox.gamma=Gamma correction
9+
checkbox.x11PlatformPreferred=Prefer X11
910

10-
label.resolutions=Screen Resolution
11+
label.resolutions=Resolution
1112
label.colordepth=Color Depth
1213
label.refresh=Refresh Rate
1314
label.antialias=Anti-Aliasing
1415
label.renderer=Renderer
16+
label.displayScaleMode=Display Scale
17+
18+
displayScaleMode.disabled=Disabled
19+
displayScaleMode.nativePixels=Native pixels
20+
displayScaleMode.dpiAware=DPI aware
21+
displayScaleMode.supersampling=Supersampling {0}x
1522

1623
antialias.disabled=Disabled
1724
refresh.na=n/a

0 commit comments

Comments
 (0)