Permalink
Browse files

[Platform] Make MouseCursor actor public

  • Loading branch information...
1 parent 0ed1e8b commit d013ef1868347535b1d4e2360acf3bbac71bc134 @thefiddler thefiddler committed Apr 30, 2014
Showing with 59 additions and 16 deletions.
  1. +12 −16 Source/OpenTK/MouseCursor.cs
  2. +47 −0 Source/OpenTK/WindowIcon.cs
@@ -40,9 +40,6 @@ public sealed class MouseCursor : WindowIcon
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 @@ public sealed class MouseCursor : WindowIcon
}
// 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)
+ if (x < 0 || x >= Width || y < 0 || y >= Height)
throw new ArgumentOutOfRangeException();
- if (rgba.Length < width * height * 4)
- throw new ArgumentOutOfRangeException();
- if (x < 0 || x >= width || y < 0 || y >= height)
+
+ 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; } }
@@ -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; } }
}
}

0 comments on commit d013ef1

Please sign in to comment.