-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #456 from tonihele/feature/graphics-options
Feature/graphics options
- Loading branch information
Showing
10 changed files
with
462 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (C) 2014-2024 OpenKeeper | ||
* | ||
* OpenKeeper is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* OpenKeeper is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with OpenKeeper. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package toniarts.openkeeper.utils; | ||
|
||
import java.awt.GraphicsDevice; | ||
import java.awt.GraphicsEnvironment; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Uses Java's own way of getting available display modes. Often errorenious and | ||
* locks up on MacOS with LWJGL 3 | ||
* | ||
* @author Toni Helenius <[email protected]> | ||
*/ | ||
class AwtDisplayModeProvider extends DefaultDisplayModeProvider { | ||
|
||
public AwtDisplayModeProvider() { | ||
} | ||
|
||
@Override | ||
public List<DisplayMode> getDisplayModes() { | ||
GraphicsDevice device = getGraphicsDevice(); | ||
|
||
java.awt.DisplayMode[] modes = device.getDisplayModes(); | ||
|
||
List<DisplayMode> displayModes = new ArrayList<>(modes.length); | ||
|
||
// Loop them through | ||
for (java.awt.DisplayMode dm : modes) { | ||
DisplayMode mdm = getDisplayMode(dm); | ||
addDisplayMode(displayModes, mdm); | ||
} | ||
|
||
return displayModes; | ||
} | ||
|
||
private GraphicsDevice getGraphicsDevice() { | ||
return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); | ||
} | ||
|
||
private DisplayMode getDisplayMode(java.awt.DisplayMode dm) { | ||
DisplayMode displayMode = new DisplayMode(dm.getWidth(), dm.getHeight()); | ||
if (dm.getRefreshRate() != java.awt.DisplayMode.REFRESH_RATE_UNKNOWN) { | ||
displayMode.addRefreshRate(dm.getRefreshRate()); | ||
} | ||
if (dm.getBitDepth() != java.awt.DisplayMode.BIT_DEPTH_MULTI) { | ||
displayMode.addBitDepth(dm.getBitDepth()); | ||
} | ||
|
||
return displayMode; | ||
} | ||
|
||
@Override | ||
public boolean isFullScreenSupported() { | ||
GraphicsDevice device = getGraphicsDevice(); | ||
|
||
return device.isFullScreenSupported(); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
src/toniarts/openkeeper/utils/DefaultDisplayModeProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (C) 2014-2024 OpenKeeper | ||
* | ||
* OpenKeeper is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* OpenKeeper is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with OpenKeeper. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package toniarts.openkeeper.utils; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Simple groups some common methods for display mode providers | ||
* | ||
* @author Toni Helenius <[email protected]> | ||
*/ | ||
abstract class DefaultDisplayModeProvider implements DisplayModeProvider { | ||
|
||
protected void addDisplayMode(List<DisplayMode> displayModes, DisplayMode mdm) { | ||
int index = Collections.binarySearch(displayModes, mdm); | ||
if (index > -1) { | ||
DisplayMode existingDm = displayModes.get(index); | ||
for (Integer refreshRate : mdm.getRefreshRates()) { | ||
existingDm.addRefreshRate(refreshRate); | ||
} | ||
for (Integer bitDepth : mdm.getBitDepths()) { | ||
existingDm.addBitDepth(bitDepth); | ||
} | ||
} else { | ||
displayModes.add(~index, mdm); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (C) 2014-2024 OpenKeeper | ||
* | ||
* OpenKeeper is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* OpenKeeper is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with OpenKeeper. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package toniarts.openkeeper.utils; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* | ||
* @author Toni Helenius <[email protected]> | ||
*/ | ||
public interface DisplayModeProvider { | ||
|
||
/** | ||
* Gets the diplay modes supported by the current device. The resolutions | ||
* are sorted by their native order | ||
* | ||
* @return sorted list of available display modes | ||
*/ | ||
List<DisplayMode> getDisplayModes(); | ||
|
||
boolean isFullScreenSupported(); | ||
} |
Oops, something went wrong.