2014-04-27 19:44:45 +02:00
|
|
|
|
#region License
|
|
|
|
|
//
|
|
|
|
|
// WindowIcon.cs
|
|
|
|
|
//
|
|
|
|
|
// Author:
|
|
|
|
|
// Stefanos A. <stapostol@gmail.com>
|
|
|
|
|
//
|
|
|
|
|
// Copyright (c) 2006-2014 Stefanos Apostolopoulos
|
|
|
|
|
//
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
//
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
//
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
//
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
2014-04-30 08:37:34 +02:00
|
|
|
|
using System.Runtime.InteropServices;
|
2014-04-27 19:44:45 +02:00
|
|
|
|
|
|
|
|
|
namespace OpenTK
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Stores a window icon. A window icon is defined
|
|
|
|
|
/// as a 2-dimensional buffer of RGBA values.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class WindowIcon
|
|
|
|
|
{
|
2014-04-30 20:04:31 +02:00
|
|
|
|
byte[] data;
|
2014-04-30 08:37:34 +02:00
|
|
|
|
int width;
|
|
|
|
|
int height;
|
|
|
|
|
|
2014-04-30 20:04:31 +02:00
|
|
|
|
/// \internal
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="OpenTK.WindowIcon"/> class.
|
|
|
|
|
/// </summary>
|
2014-04-27 19:44:45 +02:00
|
|
|
|
internal protected WindowIcon()
|
|
|
|
|
{
|
|
|
|
|
}
|
2014-04-30 08:37:34 +02:00
|
|
|
|
|
|
|
|
|
WindowIcon(int width, int height)
|
|
|
|
|
{
|
|
|
|
|
if (width < 0 || width > 256 || height < 0 || height > 256)
|
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
|
|
|
|
|
|
this.width = width;
|
|
|
|
|
this.height = height;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-30 20:04:31 +02:00
|
|
|
|
internal WindowIcon(int width, int height, byte[] data)
|
2014-04-30 08:37:34 +02:00
|
|
|
|
: this(width, height)
|
|
|
|
|
{
|
2014-04-30 20:04:31 +02:00
|
|
|
|
if (data == null)
|
2014-04-30 08:37:34 +02:00
|
|
|
|
throw new ArgumentNullException();
|
2014-04-30 20:04:31 +02:00
|
|
|
|
if (data.Length < Width * Height * 4)
|
2014-04-30 08:37:34 +02:00
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
|
|
2014-04-30 20:04:31 +02:00
|
|
|
|
this.data = data;
|
2014-04-30 08:37:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-30 20:04:31 +02:00
|
|
|
|
internal WindowIcon(int width, int height, IntPtr data)
|
2014-04-30 08:37:34 +02:00
|
|
|
|
: this(width, height)
|
|
|
|
|
{
|
2014-04-30 20:04:31 +02:00
|
|
|
|
if (data == IntPtr.Zero)
|
2014-04-30 08:37:34 +02:00
|
|
|
|
throw new ArgumentNullException();
|
|
|
|
|
|
|
|
|
|
// We assume that width and height are correctly set.
|
|
|
|
|
// If they are not, we will read garbage and probably
|
|
|
|
|
// crash.
|
2014-04-30 20:04:31 +02:00
|
|
|
|
this.data = new byte[width * height * 4];
|
|
|
|
|
Marshal.Copy(data, this.data, 0, this.data.Length);
|
2014-04-30 08:37:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-30 20:04:31 +02:00
|
|
|
|
internal byte[] Data { get { return data; } }
|
2014-04-30 08:37:34 +02:00
|
|
|
|
internal int Width { get { return width; } }
|
|
|
|
|
internal int Height { get { return height; } }
|
2014-04-27 19:44:45 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|