[ElmSharp] Fix SetNextFocusObject issue (#401)
[platform/core/csapi/tizenfx.git] / external / src / OpenTK / OpenTK / DisplayResolution.cs
1 /* Licensed under the MIT/X11 license.
2  * Copyright (c) 2006-2008 the OpenTK team.
3  * This notice may not be removed.
4  * See license.txt for licensing detailed licensing details.
5  */
6
7 using System;
8 #if !MINIMAL
9 using System.Drawing;
10 #endif
11
12 namespace OpenTK
13 {
14     /// <summary>Contains information regarding a monitor's display resolution.</summary>
15     public class DisplayResolution
16     {
17         private Rectangle bounds;
18
19         internal DisplayResolution() { }
20
21         // Creates a new DisplayResolution object for the primary DisplayDevice.
22         internal DisplayResolution(int x, int y, int width, int height, int bitsPerPixel, float refreshRate)
23         {
24             // Refresh rate may be zero, since this information may not be available on some platforms.
25             if (width <= 0)
26             {
27                 throw new ArgumentOutOfRangeException("width", "Must be greater than zero.");
28             }
29             if (height <= 0)
30             {
31                 throw new ArgumentOutOfRangeException("height", "Must be greater than zero.");
32             }
33             if (bitsPerPixel <= 0)
34             {
35                 throw new ArgumentOutOfRangeException("bitsPerPixel", "Must be greater than zero.");
36             }
37             if (refreshRate < 0)
38             {
39                 throw new ArgumentOutOfRangeException("refreshRate", "Must be greater than, or equal to zero.");
40             }
41
42             this.bounds = new Rectangle(x, y, width, height);
43             this.BitsPerPixel = bitsPerPixel;
44             this.RefreshRate = refreshRate;
45         }
46
47 #if false
48
49         /// <summary>
50         /// Creates a new DisplayResolution object for the specified DisplayDevice.
51         /// </summary>
52         /// <param name="width">The requested width in pixels.</param>
53         /// <param name="height">The requested height in pixels.</param>
54         /// <param name="bitsPerPixel">The requested bits per pixel in bits.</param>
55         /// <param name="refreshRate">The requested refresh rate in hertz.</param>
56         /// <remarks>OpenTK will select the closest match between all available resolutions on the specified DisplayDevice.</remarks>
57         ///
58         public DisplayResolution(int width, int height, int bitsPerPixel, float refreshRate, DisplayDevice device)
59         {
60             // Refresh rate may be zero, since this information may not be available on some platforms.
61             if (width <= 0) throw new ArgumentOutOfRangeException("width", "Must be greater than zero.");
62             if (height <= 0) throw new ArgumentOutOfRangeException("height", "Must be greater than zero.");
63             if (bitsPerPixel <= 0) throw new ArgumentOutOfRangeException("bitsPerPixel", "Must be greater than zero.");
64             if (refreshRate < 0) throw new ArgumentOutOfRangeException("refreshRate", "Must be greater than, or equal to zero.");
65             if (device == null) throw new ArgumentNullException("DisplayDevice", "Must be a valid DisplayDevice");
66
67             DisplayResolution res = device.SelectResolution(width, height, bitsPerPixel, refreshRate);
68
69             this.width = res.width;
70             this.height = res.height;
71             this.bits_per_pixel = res.bits_per_pixel;
72             this.refresh_rate = res.refresh_rate;
73         }
74 #endif
75
76         /// <summary>
77         /// Gets a System.Drawing.Rectangle that contains the bounds of this display device.
78         /// </summary>
79         [Obsolete("This property will return invalid results if a monitor changes resolution. Use DisplayDevice.Bounds instead.")]
80         [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
81         public Rectangle Bounds
82         {
83             get { return bounds; }
84         }
85
86         /// <summary>Gets a System.Int32 that contains the width of this display in pixels.</summary>
87         public int Width
88         {
89             get { return bounds.Width; }
90             internal set { bounds.Width = value; }
91         }
92
93         /// <summary>Gets a System.Int32 that contains the height of this display in pixels.</summary>
94         public int Height
95         {
96             get { return bounds.Height; }
97             internal set { bounds.Height = value; }
98         }
99
100         /// <summary>Gets a System.Int32 that contains number of bits per pixel of this display. Typical values include 8, 16, 24 and 32.</summary>
101         public int BitsPerPixel { get; internal set; }
102
103         /// <summary>
104         /// Gets a System.Single representing the vertical refresh rate of this display.
105         /// </summary>
106         public float RefreshRate { get; internal set; }
107
108         /// <summary>
109         /// Returns a System.String representing this DisplayResolution.
110         /// </summary>
111         /// <returns>A System.String representing this DisplayResolution.</returns>
112         public override string ToString()
113         {
114             #pragma warning disable 612,618
115             return String.Format("{0}x{1}@{2}Hz", Bounds, BitsPerPixel, RefreshRate);
116             #pragma warning restore 612,618
117         }
118
119         /// <summary>Determines whether the specified resolutions are equal.</summary>
120         /// <param name="obj">The System.Object to check against.</param>
121         /// <returns>True if the System.Object is an equal DisplayResolution; false otherwise.</returns>
122         public override bool Equals(object obj)
123         {
124             if (obj == null)
125             {
126                 return false;
127             }
128             if (this.GetType() == obj.GetType())
129             {
130                 DisplayResolution res = (DisplayResolution)obj;
131                 return
132                     Width == res.Width &&
133                     Height == res.Height &&
134                     BitsPerPixel == res.BitsPerPixel &&
135                     RefreshRate == res.RefreshRate;
136             }
137
138             return false;
139         }
140
141         /// <summary>Returns a unique hash representing this resolution.</summary>
142         /// <returns>A System.Int32 that may serve as a hash code for this resolution.</returns>
143         public override int GetHashCode()
144         {
145             #pragma warning disable 612,618
146             return Bounds.GetHashCode() ^ BitsPerPixel ^ RefreshRate.GetHashCode();
147             #pragma warning restore 612,618
148         }
149
150         /// <summary>
151         /// Compares two instances for equality.
152         /// </summary>
153         /// <param name="left">The first instance.</param>
154         /// <param name="right">The second instance.</param>
155         /// <returns>True, if left equals right; false otherwise.</returns>
156         public static bool operator== (DisplayResolution left, DisplayResolution right)
157         {
158             if (((object)left) == null && ((object)right) == null)
159             {
160                 return true;
161             }
162             else if ((((object)left) == null && ((object)right) != null) ||
163                      (((object)left) != null && ((object)right) == null))
164             {
165                 return false;
166             }
167             return left.Equals(right);
168         }
169
170         /// <summary>
171         /// Compares two instances for inequality.
172         /// </summary>
173         /// <param name="left">The first instance.</param>
174         /// <param name="right">The second instance.</param>
175         /// <returns>True, if left does not equal right; false otherwise.</returns>
176         public static bool operator !=(DisplayResolution left, DisplayResolution right)
177         {
178             return !(left == right);
179         }
180     }
181 }