[Platform] Make MouseCursor actor public

This commit is contained in:
thefiddler 2014-04-30 08:37:34 +02:00
parent 0ed1e8b6d8
commit d013ef1868
2 changed files with 60 additions and 17 deletions

View file

@ -40,9 +40,6 @@ namespace OpenTK
static readonly MouseCursor empty_cursor = new MouseCursor(
new byte[16 * 16 * 4], 16, 16, 0, 0);
byte[] rgba;
int width;
int height;
int x;
int y;
@ -51,27 +48,26 @@ namespace OpenTK
}
// Todo: make public when byte-order issues are resolved
internal MouseCursor(byte[] rgba, int width, int height, int x, int y)
public MouseCursor(byte[] argb, int width, int height, int x, int y)
: base(argb, width, height)
{
if (rgba == null)
throw new ArgumentNullException();
if (width < 0 || width > 256 || height < 0 || height > 256)
throw new ArgumentOutOfRangeException();
if (rgba.Length < width * height * 4)
throw new ArgumentOutOfRangeException();
if (x < 0 || x >= width || y < 0 || y >= height)
if (x < 0 || x >= Width || y < 0 || y >= Height)
throw new ArgumentOutOfRangeException();
this.x = x;
this.y = y;
}
public MouseCursor(IntPtr argb, int width, int height, int x, int y)
: base(argb, width, height)
{
if (x < 0 || x >= Width || y < 0 || y >= Height)
throw new ArgumentOutOfRangeException();
this.rgba = rgba;
this.width = width;
this.height = height;
this.x = x;
this.y = y;
}
internal byte[] Rgba { get { return rgba; } }
internal int Width { get { return width; } }
internal int Height { get { return height; } }
internal int X { get { return x; } }
internal int Y { get { return y; } }

View file

@ -28,6 +28,7 @@
#endregion
using System;
using System.Runtime.InteropServices;
namespace OpenTK
{
@ -37,9 +38,55 @@ namespace OpenTK
/// </summary>
public class WindowIcon
{
byte[] argb;
int width;
int height;
internal protected WindowIcon()
{
}
WindowIcon(int width, int height)
{
if (width < 0 || width > 256 || height < 0 || height > 256)
throw new ArgumentOutOfRangeException();
this.width = width;
this.height = height;
}
internal WindowIcon(byte[] argb, int width, int height)
: this(width, height)
{
if (argb == null)
throw new ArgumentNullException();
if (argb.Length < Width * Height * 4)
throw new ArgumentOutOfRangeException();
this.argb = argb;
}
internal WindowIcon(IntPtr argb, int width, int height)
: this(width, height)
{
if (argb == IntPtr.Zero)
throw new ArgumentNullException();
// We assume that width and height are correctly set.
// If they are not, we will read garbage and probably
// crash.
this.argb = new byte[width * height * 4];
for (int y = 0; y < height; y++)
{
var stride = width * 4;
var offset = new IntPtr(argb.ToInt64() + y * stride);
Marshal.Copy(offset, Argb, y * stride, stride);
}
}
internal byte[] Argb { get { return argb; } }
internal int Width { get { return width; } }
internal int Height { get { return height; } }
}
}