1 /*
2  * Copyright (c) 2002-2008 LWJGL Project
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  *   notice, this list of conditions and the following disclaimer.
11  *
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.
15  *
16  * * Neither the name of 'LWJGL' nor the names of
17  *   its contributors may be used to endorse or promote products derived
18  *   from this software without specific prior written permission.
19  *
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.
31  */
32 package org.lwjgl.opengl;
33 
34 /**
35  *
36  * This class encapsulates the properties for a given display mode.
37  * This class is not instantiable, and is aquired from the <code>Display.
38  * getAvailableDisplayModes()</code> method.
39  *
40  * @author cix_foo <cix_foo@users.sourceforge.net>
41  * @version $Revision$
42  * $Id$
43  */
44 
45 public final class DisplayMode {
46 
47 	/** properties of the display mode */
48 	private final int width, height, bpp, freq;
49 	/** If true, this instance can be used for fullscreen modes */
50 	private final boolean fullscreen;
51 
52 	/**
53 	 * Construct a display mode. DisplayModes constructed through the
54 	 * public constructor can only be used to specify the dimensions of
55 	 * the Display in windowed mode. To get the available DisplayModes for
56 	 * fullscreen modes, use Display.getAvailableDisplayModes().
57 	 *
58 	 * @param width The Display width.
59 	 * @param height The Display height.
60 	 * @see Display
61 	 */
DisplayMode(int width, int height)62 	public DisplayMode(int width, int height) {
63 		this(width, height, 0, 0, false);
64 	}
65 
DisplayMode(int width, int height, int bpp, int freq)66 	DisplayMode(int width, int height, int bpp, int freq) {
67 		this(width, height, bpp, freq, true);
68 	}
69 
DisplayMode(int width, int height, int bpp, int freq, boolean fullscreen)70 	private DisplayMode(int width, int height, int bpp, int freq, boolean fullscreen) {
71 		this.width = width;
72 		this.height = height;
73 		this.bpp = bpp;
74 		this.freq = freq;
75 		this.fullscreen = fullscreen;
76 	}
77 
78 	/** True if this instance can be used for fullscreen modes */
isFullscreenCapable()79 	public boolean isFullscreenCapable() {
80 		return fullscreen;
81 	}
82 
getWidth()83 	public int getWidth() {
84 		return width;
85 	}
86 
getHeight()87 	public int getHeight() {
88 		return height;
89 	}
90 
getBitsPerPixel()91 	public int getBitsPerPixel() {
92 		return bpp;
93 	}
94 
getFrequency()95 	public int getFrequency() {
96 		return freq;
97 	}
98 
99 	/**
100 	 * Tests for <code>DisplayMode</code> equality
101 	 *
102 	 * @see java.lang.Object#equals(Object)
103 	 */
equals(Object obj)104 	public boolean equals(Object obj) {
105 		if (obj == null || !(obj instanceof DisplayMode)) {
106 			return false;
107 		}
108 
109 		DisplayMode dm = (DisplayMode) obj;
110 		return dm.width == width
111 			&& dm.height == height
112 			&& dm.bpp == bpp
113 			&& dm.freq == freq;
114 	}
115 
116 	/**
117 	 * Retrieves the hashcode for this object
118 	 *
119 	 * @see java.lang.Object#hashCode()
120 	 */
hashCode()121 	public int hashCode() {
122 		return width ^ height ^ freq ^ bpp;
123 	}
124 
125 	/**
126 	 * Retrieves a String representation of this <code>DisplayMode</code>
127 	 *
128 	 * @see java.lang.Object#toString()
129 	 */
toString()130 	public String toString() {
131 		StringBuilder sb = new StringBuilder(32);
132 		sb.append(width);
133 		sb.append(" x ");
134 		sb.append(height);
135 		sb.append(" x ");
136 		sb.append(bpp);
137 		sb.append(" @");
138 		sb.append(freq);
139 		sb.append("Hz");
140 		return sb.toString();
141 	}
142 }
143