-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Multiple Monitors in jme-LWJGL3 #2030 #2031
base: master
Are you sure you want to change the base?
Changes from 2 commits
acd2cb3
94fb53b
2251e2e
75f6d66
8ef3c5e
6a590db
8594c1d
03dd250
7050d7a
48a7980
8088109
be6624e
35e8857
1bda3f0
d8d827b
8ddb04b
2f39669
7010af6
5445d3f
f25ce69
7dd8693
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,6 +266,7 @@ public final class AppSettings extends HashMap<String, Object> { | |
public static final String JOAL = "JOAL"; | ||
|
||
static { | ||
defaults.put("Monitor", 0); | ||
defaults.put("CenterWindow", true); | ||
defaults.put("Width", 640); | ||
defaults.put("Height", 480); | ||
|
@@ -1479,4 +1480,32 @@ public int getWindowYPosition() { | |
public void setWindowYPosition(int pos) { | ||
putInteger("WindowYPosition", pos); | ||
} | ||
|
||
|
||
/** | ||
* Gets the monitor number used when creating a window. | ||
* | ||
* <p>This setting is used only with LWJGL3, it defines which monitor | ||
* to use when creating a OpenGL window. | ||
* | ||
* @return the desired monitor used when creating a OpenGL window | ||
* @see #setMonitor(long) | ||
*/ | ||
public int getMonitor() { | ||
return getInteger("Monitor"); | ||
} | ||
|
||
/** | ||
* Sets the monitor number used when creating a window. The position | ||
* number is the number in the list of monitors GlfwGetMonitors returns. | ||
* | ||
* <p>This setting is used only with LWJGL3, it defines which monitor | ||
* to use when creating a OpenGL window. its default value is -1. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
But looks like it is 0? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to update comment. |
||
* | ||
* @param mon the desired monitor used when creating a OpenGL window | ||
* | ||
*/ | ||
public void setMonitor(int mon) { | ||
putInteger("Monitor", mon); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (c) 2009-2022 jMonkeyEngine | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are | ||
* met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software | ||
* without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.jme3.system; | ||
|
||
/** | ||
* This class holds information about the monitor that was | ||
* returned by glfwGetMonitors() calls in the context | ||
* class | ||
* | ||
* @author Kevin Bales | ||
*/ | ||
public class MonitorInfo { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be marked as |
||
|
||
/** | ||
* monitorID - monitor id that was return from Lwjgl3. | ||
*/ | ||
public long monitorID = 0; | ||
|
||
/** | ||
* width - width that was return from Lwjgl3. | ||
*/ | ||
public int width = 1080; | ||
|
||
/** | ||
* height - height that was return from Lwjgl3. | ||
*/ | ||
public int height = 1920; | ||
|
||
/** | ||
* rate - refresh rate that was return from Lwjgl3. | ||
*/ | ||
public int rate = 60; | ||
|
||
/** | ||
* primary - indicates if the monitor is the primary monitor. | ||
*/ | ||
public boolean primary = false; | ||
|
||
/** | ||
* name - monitor name that was return from Lwjgl3. | ||
*/ | ||
public String name = "Generic Monitor"; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Copyright (c) 2009-2022 jMonkeyEngine | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are | ||
* met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software | ||
* without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.jme3.system; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* This class holds all information about all monitors that where | ||
* return from the glfwGetMonitors() call. It stores them into | ||
* an <ArrayList> | ||
* | ||
* @author Kevin Bales | ||
*/ | ||
public class Monitors { | ||
|
||
private ArrayList<MonitorInfo> monitors = new ArrayList<MonitorInfo>(); | ||
|
||
public int addNewMonitor(long monitorID) | ||
{ | ||
MonitorInfo info = new MonitorInfo(); | ||
info.monitorID = monitorID; | ||
monitors.add(info); | ||
return monitors.size() - 1; | ||
} | ||
|
||
/** | ||
* This function returns the size of the monitor ArrayList | ||
* @return the | ||
*/ | ||
public int size() | ||
{ | ||
return monitors.size(); | ||
} | ||
|
||
/** | ||
* Call to get monitor information on a certain monitor. | ||
* | ||
* @param pos the position in the arraylist of the monitor | ||
* information that you want to get. | ||
* @return returns the MonitorInfo data for the monitor | ||
* called for. | ||
*/ | ||
public MonitorInfo get(int pos) | ||
{ | ||
if (pos < monitors.size()) | ||
return monitors.get(pos); | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Set information about this monitor stored in monPos position | ||
* in the array list. | ||
* | ||
* @param monPos arraylist position of monitor to update | ||
* @param width the current width the monitor is displaying | ||
* @param height the current height the monitor is displaying | ||
* @param rate the current refresh rate the monitor is set to | ||
*/ | ||
public void setInfo(int monPos, String name, int width, int height, int rate) { | ||
if (monPos < monitors.size() ) { | ||
MonitorInfo info = monitors.get(monPos); | ||
if (info != null) { | ||
info.width = width; | ||
info.height = height; | ||
info.rate = rate; | ||
info.name = name; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* This function will mark a certain monitor as the | ||
* primary monitor. | ||
* | ||
* @param monPos the position in the arraylist of which | ||
* monitor is the primary monitor | ||
*/ | ||
public void setPrimaryMonitor(int monPos) { | ||
if (monPos < monitors.size() ) { | ||
MonitorInfo info = monitors.get(monPos); | ||
if (info != null) | ||
info.primary = true; | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to wrap the
"Monitor"
string key in a constant object for future refactoring and testing purposes, you can use theMonitorInfo
to define default static Keys there.