* DisplayDevice.cs: Made DisplayDevice properties settable
internally (simplifies device detection code). Bounds property is now independent of the default resolution. * DisplayResolution.cs: Obsoleted the Bounds property, as this becomes invalid as soon as the resolution of any display device is changed.
This commit is contained in:
parent
39b4e329fd
commit
2af357c106
2 changed files with 75 additions and 21 deletions
|
@ -1,4 +1,4 @@
|
||||||
#region --- License ---
|
#region --- License ---
|
||||||
/* Licensed under the MIT/X11 license.
|
/* Licensed under the MIT/X11 license.
|
||||||
* Copyright (c) 2006-2008 the OpenTK team.
|
* Copyright (c) 2006-2008 the OpenTK team.
|
||||||
* This notice may not be removed.
|
* This notice may not be removed.
|
||||||
|
@ -29,11 +29,13 @@ namespace OpenTK
|
||||||
|
|
||||||
#region --- Fields ---
|
#region --- Fields ---
|
||||||
|
|
||||||
DisplayResolution current_resolution, original_resolution;
|
DisplayResolution current_resolution = new DisplayResolution(), original_resolution;
|
||||||
readonly List<DisplayResolution> available_resolutions = new List<DisplayResolution>();
|
List<DisplayResolution> available_resolutions = new List<DisplayResolution>();
|
||||||
readonly IList<DisplayResolution> available_resolutions_readonly;
|
IList<DisplayResolution> available_resolutions_readonly;
|
||||||
bool primary;
|
bool primary;
|
||||||
|
|
||||||
|
Rectangle bounds;
|
||||||
|
|
||||||
static readonly List<DisplayDevice> available_displays = new List<DisplayDevice>();
|
static readonly List<DisplayDevice> available_displays = new List<DisplayDevice>();
|
||||||
static readonly IList<DisplayDevice> available_displays_readonly;
|
static readonly IList<DisplayDevice> available_displays_readonly;
|
||||||
static readonly object display_lock = new object();
|
static readonly object display_lock = new object();
|
||||||
|
@ -51,16 +53,8 @@ namespace OpenTK
|
||||||
available_displays_readonly = available_displays.AsReadOnly();
|
available_displays_readonly = available_displays.AsReadOnly();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal DisplayDevice(DisplayResolution currentResolution, bool primary,
|
internal DisplayDevice()
|
||||||
IEnumerable<DisplayResolution> availableResolutions)
|
|
||||||
{
|
{
|
||||||
this.current_resolution = currentResolution;
|
|
||||||
this.primary = primary;
|
|
||||||
this.available_resolutions.AddRange(availableResolutions);
|
|
||||||
|
|
||||||
Debug.Print("DisplayDevice {0} ({1}) supports {2} resolutions.",
|
|
||||||
available_displays.Count, primary ? "primary" : "secondary", available_resolutions.Count);
|
|
||||||
|
|
||||||
lock (display_lock)
|
lock (display_lock)
|
||||||
{
|
{
|
||||||
available_displays.Add(this);
|
available_displays.Add(this);
|
||||||
|
@ -71,6 +65,18 @@ namespace OpenTK
|
||||||
available_resolutions_readonly = available_resolutions.AsReadOnly();
|
available_resolutions_readonly = available_resolutions.AsReadOnly();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal DisplayDevice(DisplayResolution currentResolution, bool primary,
|
||||||
|
IEnumerable<DisplayResolution> availableResolutions, Rectangle bounds)
|
||||||
|
: this()
|
||||||
|
{
|
||||||
|
this.current_resolution = currentResolution;
|
||||||
|
this.primary = primary;
|
||||||
|
this.available_resolutions.AddRange(availableResolutions);
|
||||||
|
|
||||||
|
Debug.Print("DisplayDevice {0} ({1}) supports {2} resolutions.",
|
||||||
|
available_displays.Count, primary ? "primary" : "secondary", available_resolutions.Count);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region --- Public Methods ---
|
#region --- Public Methods ---
|
||||||
|
@ -78,11 +84,17 @@ namespace OpenTK
|
||||||
#region public Rectangle Bounds
|
#region public Rectangle Bounds
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a System.Drawing.Rectangle that contains the current bounds of this DisplayDevice.
|
/// Gets the bounds of this instance in pixel coordinates..
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Rectangle Bounds
|
public Rectangle Bounds
|
||||||
{
|
{
|
||||||
get { return current_resolution.Bounds; }
|
get { return bounds; }
|
||||||
|
internal set
|
||||||
|
{
|
||||||
|
bounds = value;
|
||||||
|
current_resolution.Height = bounds.Height;
|
||||||
|
current_resolution.Width = bounds.Width;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -104,7 +116,11 @@ namespace OpenTK
|
||||||
#region public int BitsPerPixel
|
#region public int BitsPerPixel
|
||||||
|
|
||||||
/// <summary>Gets a System.Int32 that contains number of bits per pixel of this display. Typical values include 8, 16, 24 and 32.</summary>
|
/// <summary>Gets a System.Int32 that contains number of bits per pixel of this display. Typical values include 8, 16, 24 and 32.</summary>
|
||||||
public int BitsPerPixel { get { return current_resolution.BitsPerPixel; } }
|
public int BitsPerPixel
|
||||||
|
{
|
||||||
|
get { return current_resolution.BitsPerPixel; }
|
||||||
|
internal set { current_resolution.BitsPerPixel = value; }
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -116,6 +132,7 @@ namespace OpenTK
|
||||||
public float RefreshRate
|
public float RefreshRate
|
||||||
{
|
{
|
||||||
get { return current_resolution.RefreshRate; }
|
get { return current_resolution.RefreshRate; }
|
||||||
|
internal set { current_resolution.RefreshRate = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -123,7 +140,22 @@ namespace OpenTK
|
||||||
#region public bool IsPrimary
|
#region public bool IsPrimary
|
||||||
|
|
||||||
/// <summary>Gets a System.Boolean that indicates whether this Display is the primary Display in systems with multiple Displays.</summary>
|
/// <summary>Gets a System.Boolean that indicates whether this Display is the primary Display in systems with multiple Displays.</summary>
|
||||||
public bool IsPrimary { get { return primary; } }
|
public bool IsPrimary
|
||||||
|
{
|
||||||
|
get { return primary; }
|
||||||
|
internal set
|
||||||
|
{
|
||||||
|
if (primary_display != null && primary_display != this)
|
||||||
|
primary_display.IsPrimary = false;
|
||||||
|
|
||||||
|
lock (display_lock)
|
||||||
|
{
|
||||||
|
primary = value;
|
||||||
|
if (value)
|
||||||
|
primary_display = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -167,6 +199,11 @@ namespace OpenTK
|
||||||
public IList<DisplayResolution> AvailableResolutions
|
public IList<DisplayResolution> AvailableResolutions
|
||||||
{
|
{
|
||||||
get { return available_resolutions_readonly; }
|
get { return available_resolutions_readonly; }
|
||||||
|
internal set
|
||||||
|
{
|
||||||
|
available_resolutions = (List<DisplayResolution>)value;
|
||||||
|
available_resolutions_readonly = available_resolutions.AsReadOnly();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#region --- License ---
|
#region --- License ---
|
||||||
/* Licensed under the MIT/X11 license.
|
/* Licensed under the MIT/X11 license.
|
||||||
* Copyright (c) 2006-2008 the OpenTK team.
|
* Copyright (c) 2006-2008 the OpenTK team.
|
||||||
* This notice may not be removed.
|
* This notice may not be removed.
|
||||||
|
@ -23,6 +23,8 @@ namespace OpenTK
|
||||||
|
|
||||||
#region --- Constructors ---
|
#region --- Constructors ---
|
||||||
|
|
||||||
|
internal DisplayResolution() { }
|
||||||
|
|
||||||
#region public DisplayResolution(int width, int height, int bitsPerPixel, float refreshRate)
|
#region public DisplayResolution(int width, int height, int bitsPerPixel, float refreshRate)
|
||||||
|
|
||||||
// Creates a new DisplayResolution object for the primary DisplayDevice.
|
// Creates a new DisplayResolution object for the primary DisplayDevice.
|
||||||
|
@ -82,6 +84,8 @@ namespace OpenTK
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a System.Drawing.Rectangle that contains the bounds of this display device.
|
/// Gets a System.Drawing.Rectangle that contains the bounds of this display device.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Obsolete("This property will return invalid results if a monitor changes resolution. Use DisplayDevice.Bounds instead.")]
|
||||||
|
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||||
public Rectangle Bounds
|
public Rectangle Bounds
|
||||||
{
|
{
|
||||||
get { return bounds; }
|
get { return bounds; }
|
||||||
|
@ -92,21 +96,33 @@ namespace OpenTK
|
||||||
#region public int Width
|
#region public int Width
|
||||||
|
|
||||||
/// <summary>Gets a System.Int32 that contains the width of this display in pixels.</summary>
|
/// <summary>Gets a System.Int32 that contains the width of this display in pixels.</summary>
|
||||||
public int Width { get { return bounds.Width; } }
|
public int Width
|
||||||
|
{
|
||||||
|
get { return bounds.Width; }
|
||||||
|
internal set { bounds.Width = value; }
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region public int Height
|
#region public int Height
|
||||||
|
|
||||||
/// <summary>Gets a System.Int32 that contains the height of this display in pixels.</summary>
|
/// <summary>Gets a System.Int32 that contains the height of this display in pixels.</summary>
|
||||||
public int Height { get { return bounds.Height; } }
|
public int Height
|
||||||
|
{
|
||||||
|
get { return bounds.Height; }
|
||||||
|
internal set { bounds.Height = value; }
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region public int BitsPerPixel
|
#region public int BitsPerPixel
|
||||||
|
|
||||||
/// <summary>Gets a System.Int32 that contains number of bits per pixel of this display. Typical values include 8, 16, 24 and 32.</summary>
|
/// <summary>Gets a System.Int32 that contains number of bits per pixel of this display. Typical values include 8, 16, 24 and 32.</summary>
|
||||||
public int BitsPerPixel { get { return bits_per_pixel; } }
|
public int BitsPerPixel
|
||||||
|
{
|
||||||
|
get { return bits_per_pixel; }
|
||||||
|
internal set { bits_per_pixel = value; }
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -118,6 +134,7 @@ namespace OpenTK
|
||||||
public float RefreshRate
|
public float RefreshRate
|
||||||
{
|
{
|
||||||
get { return refresh_rate; }
|
get { return refresh_rate; }
|
||||||
|
internal set { refresh_rate = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
Loading…
Reference in a new issue