00001 #region --- License ---
00002
00003
00004
00005
00006
00007 #endregion
00008
00009 using System;
00010 using System.Collections.Generic;
00011 using System.Text;
00012 using System.Diagnostics;
00013 using System.Drawing;
00014
00015 namespace OpenTK
00016 {
00018 public class DisplayResolution
00019 {
00020 Rectangle bounds;
00021 int bits_per_pixel;
00022 float refresh_rate;
00023
00024 #region --- Constructors ---
00025
00026 internal DisplayResolution() { }
00027
00028 #region public DisplayResolution(int width, int height, int bitsPerPixel, float refreshRate)
00029
00030
00031 internal DisplayResolution(int x, int y, int width, int height, int bitsPerPixel, float refreshRate)
00032 {
00033
00034 if (width <= 0) throw new ArgumentOutOfRangeException("width", "Must be greater than zero.");
00035 if (height <= 0) throw new ArgumentOutOfRangeException("height", "Must be greater than zero.");
00036 if (bitsPerPixel <= 0) throw new ArgumentOutOfRangeException("bitsPerPixel", "Must be greater than zero.");
00037 if (refreshRate < 0) throw new ArgumentOutOfRangeException("refreshRate", "Must be greater than, or equal to zero.");
00038
00039 this.bounds = new Rectangle(x, y, width, height);
00040 this.bits_per_pixel = bitsPerPixel;
00041 this.refresh_rate = refreshRate;
00042 }
00043
00044 #endregion
00045
00046 #region public DisplayResolution(int width, int height, int bitsPerPixel, float refreshRate, DisplayDevice device)
00047
00048 #if false
00049
00059 public DisplayResolution(int width, int height, int bitsPerPixel, float refreshRate, DisplayDevice device)
00060 {
00061
00062 if (width <= 0) throw new ArgumentOutOfRangeException("width", "Must be greater than zero.");
00063 if (height <= 0) throw new ArgumentOutOfRangeException("height", "Must be greater than zero.");
00064 if (bitsPerPixel <= 0) throw new ArgumentOutOfRangeException("bitsPerPixel", "Must be greater than zero.");
00065 if (refreshRate < 0) throw new ArgumentOutOfRangeException("refreshRate", "Must be greater than, or equal to zero.");
00066 if (device == null) throw new ArgumentNullException("DisplayDevice", "Must be a valid DisplayDevice");
00067
00068 DisplayResolution res = device.SelectResolution(width, height, bitsPerPixel, refreshRate);
00069
00070 this.width = res.width;
00071 this.height = res.height;
00072 this.bits_per_pixel = res.bits_per_pixel;
00073 this.refresh_rate = res.refresh_rate;
00074 }
00075 #endif
00076 #endregion
00077
00078 #endregion
00079
00080 #region --- Public Methods ---
00081
00082 #region Bounds
00083
00087 [Obsolete("This property will return invalid results if a monitor changes resolution. Use DisplayDevice.Bounds instead.")]
00088 [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
00089 public Rectangle Bounds
00090 {
00091 get { return bounds; }
00092 }
00093
00094 #endregion
00095
00096 #region public int Width
00097
00099 public int Width
00100 {
00101 get { return bounds.Width; }
00102 internal set { bounds.Width = value; }
00103 }
00104
00105 #endregion
00106
00107 #region public int Height
00108
00110 public int Height
00111 {
00112 get { return bounds.Height; }
00113 internal set { bounds.Height = value; }
00114 }
00115
00116 #endregion
00117
00118 #region public int BitsPerPixel
00119
00121 public int BitsPerPixel
00122 {
00123 get { return bits_per_pixel; }
00124 internal set { bits_per_pixel = value; }
00125 }
00126
00127 #endregion
00128
00129 #region public float RefreshRate
00130
00134 public float RefreshRate
00135 {
00136 get { return refresh_rate; }
00137 internal set { refresh_rate = value; }
00138 }
00139
00140 #endregion
00141
00142 #endregion
00143
00144 #region --- Overrides ---
00145
00146 #region public override string ToString()
00147
00152 public override string ToString()
00153 {
00154 return String.Format("{0}x{1}@{2}Hz", Bounds, bits_per_pixel, refresh_rate);
00155 }
00156
00157 #endregion
00158
00159 #region public override bool Equals(object obj)
00160
00164 public override bool Equals(object obj)
00165 {
00166 if (obj == null) return false;
00167 if (this.GetType() == obj.GetType())
00168 {
00169 DisplayResolution res = (DisplayResolution)obj;
00170 return
00171 Width == res.Width &&
00172 Height == res.Height &&
00173 BitsPerPixel == res.BitsPerPixel &&
00174 RefreshRate == res.RefreshRate;
00175 }
00176
00177 return false;
00178 }
00179
00180 #endregion
00181
00182 #region public override int GetHashCode()
00183
00186 public override int GetHashCode()
00187 {
00188 return Bounds.GetHashCode() ^ bits_per_pixel ^ refresh_rate.GetHashCode();
00189 }
00190
00191 #endregion
00192
00193 #endregion
00194
00195 #region --- Operator Overloads ---
00196
00203 public static bool operator== (DisplayResolution left, DisplayResolution right)
00204 {
00205 if (((object)left) == null && ((object)right) == null)
00206 return true;
00207 else if ((((object)left) == null && ((object)right) != null) ||
00208 (((object)left) != null && ((object)right) == null))
00209 return false;
00210 return left.Equals(right);
00211 }
00212
00219 public static bool operator !=(DisplayResolution left, DisplayResolution right)
00220 {
00221 return !(left == right);
00222 }
00223
00224 #endregion
00225 }
00226 }