|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2009-2023 jMonkeyEngine All rights reserved. |
| 2 | + * Copyright (c) 2009-2025 jMonkeyEngine |
| 3 | + * All rights reserved. |
3 | 4 | *
|
4 |
| - * Redistribution and use in source and binary forms, with or without modification, are permitted |
5 |
| - * provided that the following conditions are met: |
| 5 | + * Redistribution and use in source and binary forms, with or without |
| 6 | + * modification, are permitted provided that the following conditions are |
| 7 | + * met: |
6 | 8 | *
|
7 |
| - * * Redistributions of source code must retain the above copyright notice, this list of conditions |
8 |
| - * and the following disclaimer. |
| 9 | + * * Redistributions of source code must retain the above copyright |
| 10 | + * notice, this list of conditions and the following disclaimer. |
9 | 11 | *
|
10 |
| - * * Redistributions in binary form must reproduce the above copyright notice, this list of |
11 |
| - * conditions and the following disclaimer in the documentation and/or other materials provided with |
12 |
| - * the distribution. |
| 12 | + * * Redistributions in binary form must reproduce the above copyright |
| 13 | + * notice, this list of conditions and the following disclaimer in the |
| 14 | + * documentation and/or other materials provided with the distribution. |
13 | 15 | *
|
14 |
| - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors may be used to endorse or |
15 |
| - * promote products derived from this software without specific prior written permission. |
| 16 | + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
| 17 | + * may be used to endorse or promote products derived from this software |
| 18 | + * without specific prior written permission. |
16 | 19 | *
|
17 |
| - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR |
18 |
| - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
19 |
| - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
20 |
| - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
21 |
| - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 |
| - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
23 |
| - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY |
24 |
| - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 20 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 22 | + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 23 | + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 24 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 25 | + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 26 | + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 27 | + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 28 | + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 29 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 30 | + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | 31 | */
|
26 | 32 | package com.jme3.system;
|
27 | 33 |
|
| 34 | +import java.util.Objects; |
| 35 | + |
28 | 36 | /**
|
29 | 37 | * This class holds information about the display that was returned by glfwGetMonitors() calls in
|
30 | 38 | * the context class
|
31 | 39 | *
|
32 | 40 | * @author Kevin Bales
|
| 41 | + * @author wil |
33 | 42 | */
|
34 |
| -public class DisplayInfo { |
| 43 | +public final class DisplayInfo { |
| 44 | + |
| 45 | + /** display - display id that was return from Lwjgl3. */ |
| 46 | + private long display; |
| 47 | + |
| 48 | + /** width - width that was return from Lwjgl3. */ |
| 49 | + private int width; |
| 50 | + |
| 51 | + /** height - height that was return from Lwjgl3. */ |
| 52 | + private int height; |
| 53 | + |
| 54 | + /** rate - refresh rate that was return from Lwjgl3. */ |
| 55 | + private int rate; |
| 56 | + |
| 57 | + /** primary - indicates if the display is the primary monitor. */ |
| 58 | + private boolean primary; |
35 | 59 |
|
36 | 60 | /**
|
37 |
| - * displayID - display id that was return from Lwjgl3. |
| 61 | + * name - display name that was return from Lwjgl3. |
38 | 62 | */
|
39 |
| - public long displayID = 0; |
| 63 | + private String name; |
40 | 64 |
|
41 | 65 | /**
|
42 |
| - * width - width that was return from Lwjgl3. |
| 66 | + * Create a new display mode object with the default values |
43 | 67 | */
|
44 |
| - public int width = 1080; |
| 68 | + DisplayInfo() { |
| 69 | + this(0L /*NULL*/, 1080, 1920, 60, false, "Generic Monitor"); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Create a new display mode object with the supplied parameters. |
| 74 | + * @param display the monitor pointer (native), the virtual memory |
| 75 | + * address used by lwjgl. |
| 76 | + * @param width the width of the display, provided by lwjgl. |
| 77 | + * @param height the height of the display, provided by lwjgl. |
| 78 | + * @param rate the refresh rate of the display, in hertz. |
| 79 | + * @param primary a logical value that determines whether this display is |
| 80 | + * primary or not; {@code true | false} |
| 81 | + * @param name display name |
| 82 | + */ |
| 83 | + DisplayInfo(long display, int width, int height, int rate, boolean primary, String name) { |
| 84 | + this.display = display; |
| 85 | + this.width = width; |
| 86 | + this.height = height; |
| 87 | + this.rate = rate; |
| 88 | + this.primary = primary; |
| 89 | + this.name = name; |
| 90 | + } |
45 | 91 |
|
| 92 | + // === ----------------------------------------------------------------- === |
| 93 | + // === SETTERS === |
| 94 | + // === ----------------------------------------------------------------- === |
| 95 | + |
46 | 96 | /**
|
47 |
| - * height - height that was return from Lwjgl3. |
| 97 | + * Sets the monitor pointer (native), the virtual memory address used by lwjgl. |
| 98 | + * |
| 99 | + * @param display the monitor pointer (native), the virtual memory |
| 100 | + * address used by lwjgl |
48 | 101 | */
|
49 |
| - public int height = 1920; |
| 102 | + void setDisplay(long display) { |
| 103 | + this.display = display; |
| 104 | + } |
50 | 105 |
|
51 | 106 | /**
|
52 |
| - * rate - refresh rate that was return from Lwjgl3. |
| 107 | + * Sets the width of the display. |
| 108 | + * @param width the width of the display |
53 | 109 | */
|
54 |
| - public int rate = 60; |
| 110 | + void setWidth(int width) { |
| 111 | + this.width = width; |
| 112 | + } |
55 | 113 |
|
56 | 114 | /**
|
57 |
| - * primary - indicates if the display is the primary monitor. |
| 115 | + * Sets the height of the display. |
| 116 | + * @param height the height of the display |
58 | 117 | */
|
59 |
| - public boolean primary = false; |
| 118 | + void setHeight(int height) { |
| 119 | + this.height = height; |
| 120 | + } |
60 | 121 |
|
61 | 122 | /**
|
62 |
| - * name - display name that was return from Lwjgl3. |
| 123 | + * Sets the refresh rate of the display, in hertz. |
| 124 | + * @param rate the refresh rate of the display, in hertz |
| 125 | + */ |
| 126 | + void setRate(int rate) { |
| 127 | + this.rate = rate; |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Set this display as primary or not. |
| 132 | + * @param primary {@code true} if the display is primary, {@code false} otherwise. |
| 133 | + */ |
| 134 | + void setPrimary(boolean primary) { |
| 135 | + this.primary = primary; |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * Set the screen (display) name |
| 140 | + * @param name display name |
| 141 | + */ |
| 142 | + void setName(String name) { |
| 143 | + this.name = name; |
| 144 | + } |
| 145 | + |
| 146 | + // === ----------------------------------------------------------------- === |
| 147 | + // === GETTERS === |
| 148 | + // === ----------------------------------------------------------------- === |
| 149 | + |
| 150 | + /** |
| 151 | + * Returns the monitor pointer (native), the virtual memory address used by lwjgl. |
| 152 | + * @return the monitor pointer (native), the virtual memory address used by lwjgl |
| 153 | + */ |
| 154 | + public long getDisplay() { |
| 155 | + return display; |
| 156 | + } |
| 157 | + |
| 158 | + /** |
| 159 | + * Returns the width of the display. |
| 160 | + * @return the width of the display. |
| 161 | + */ |
| 162 | + public int getWidth() { |
| 163 | + return width; |
| 164 | + } |
| 165 | + |
| 166 | + /** |
| 167 | + * Returns the height of the display. |
| 168 | + * @return the height of the display |
| 169 | + */ |
| 170 | + public int getHeight() { |
| 171 | + return height; |
| 172 | + } |
| 173 | + |
| 174 | + /** |
| 175 | + * Returns the refresh rate of the display, in hertz. |
| 176 | + * @return the refresh rate of the display, in hertz |
| 177 | + */ |
| 178 | + public int getRate() { |
| 179 | + return rate; |
| 180 | + } |
| 181 | + |
| 182 | + /** |
| 183 | + * Determines if this display belongs to the main monitor. |
| 184 | + * @return {@code true} if the display is primary, {@code false} otherwise. |
| 185 | + */ |
| 186 | + public boolean isPrimary() { |
| 187 | + return primary; |
| 188 | + } |
| 189 | + |
| 190 | + /** |
| 191 | + * Returns the display name. |
| 192 | + * @return display name |
| 193 | + */ |
| 194 | + public String getName() { |
| 195 | + return name; |
| 196 | + } |
| 197 | + |
| 198 | + /** |
| 199 | + * {@inheritDoc } |
| 200 | + */ |
| 201 | + @Override |
| 202 | + public int hashCode() { |
| 203 | + int hash = 3; |
| 204 | + hash = 97 * hash + (int) (this.display ^ (this.display >>> 32)); |
| 205 | + hash = 97 * hash + this.width; |
| 206 | + hash = 97 * hash + this.height; |
| 207 | + hash = 97 * hash + this.rate; |
| 208 | + hash = 97 * hash + (this.primary ? 1 : 0); |
| 209 | + hash = 97 * hash + Objects.hashCode(this.name); |
| 210 | + return hash; |
| 211 | + } |
| 212 | + |
| 213 | + /** |
| 214 | + * {@inheritDoc } |
| 215 | + */ |
| 216 | + @Override |
| 217 | + public boolean equals(Object obj) { |
| 218 | + if (this == obj) { |
| 219 | + return true; |
| 220 | + } |
| 221 | + if (obj == null) { |
| 222 | + return false; |
| 223 | + } |
| 224 | + if (getClass() != obj.getClass()) { |
| 225 | + return false; |
| 226 | + } |
| 227 | + final DisplayInfo other = (DisplayInfo) obj; |
| 228 | + if (this.display != other.display) { |
| 229 | + return false; |
| 230 | + } |
| 231 | + if (this.width != other.width) { |
| 232 | + return false; |
| 233 | + } |
| 234 | + if (this.height != other.height) { |
| 235 | + return false; |
| 236 | + } |
| 237 | + if (this.rate != other.rate) { |
| 238 | + return false; |
| 239 | + } |
| 240 | + if (this.primary != other.primary) { |
| 241 | + return false; |
| 242 | + } |
| 243 | + return Objects.equals(this.name, other.name); |
| 244 | + } |
| 245 | + |
| 246 | + /** |
| 247 | + * {@inheritDoc } |
63 | 248 | */
|
64 |
| - public String name = "Generic Monitor"; |
| 249 | + @Override |
| 250 | + public String toString() { |
| 251 | + return getDisplay() == 0L ? "NULL" : ("(" + getName() + "|" |
| 252 | + + getDisplay() + ")" + getWidth() + "x" + getHeight() + "@" |
| 253 | + + (getRate() > 0 ? getRate() + "Hz" : "[Unknown refresh rate]")); |
| 254 | + } |
65 | 255 | }
|
0 commit comments