/// <summary>
/// Demonstrates the MouseCursor class.
/// </summary>
- [Example("MouseCursor Simple", ExampleCategory.OpenTK, "GameWindow", 1, Documentation = "MouseCursorSimple")]
+ [Example("Custom MouseCursor", ExampleCategory.OpenTK, "GameWindow", 1, Documentation = "MouseCursorSimple")]
public class MouseCursorSimple : GameWindow
{
readonly MouseCursor MyCursor;
System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
MyCursor = new OpenTK.MouseCursor(
- data.Scan0, bitmap.Width, bitmap.Height, 0, 0);
+ 0, 0, data.Width, data.Height, data.Scan0);
Cursor = MyCursor;
}
}
{
static readonly MouseCursor default_cursor = new MouseCursor();
static readonly MouseCursor empty_cursor = new MouseCursor(
- new byte[16 * 16 * 4], 16, 16, 0, 0);
+ 0, 0, 16, 16, new byte[16 * 16 * 4]);
int x;
int y;
{
}
- // Todo: make public when byte-order issues are resolved
- public MouseCursor(byte[] argb, int width, int height, int hotx, int hoty)
- : base(argb, width, height)
+ /// <summary>
+ /// Initializes a new <see cref="MouseCursor"/> instance from a
+ /// contiguous array of BGRA pixels.
+ /// Each pixel is composed of 4 bytes, representing B, G, R and A values,
+ /// respectively. For correct antialiasing of translucent cursors,
+ /// the B, G and R components should be premultiplied with the A component:
+ /// <code>
+ /// B = (byte)((B * A) / 255)
+ /// G = (byte)((G * A) / 255)
+ /// R = (byte)((R * A) / 255)
+ /// </code>
+ /// </summary>
+ /// <param name="hotx">The x-coordinate of the cursor hotspot, in the range [0, width]</param>
+ /// <param name="hoty">The y-coordinate of the cursor hotspot, in the range [0, height]</param>
+ /// <param name="width">The width of the cursor data, in pixels.</param>
+ /// <param name="height">The height of the cursor data, in pixels.</param>
+ /// <param name="data">
+ /// A byte array representing the cursor image,
+ /// laid out as a contiguous array of BGRA pixels.
+ /// </param>
+ public MouseCursor(int hotx, int hoty, int width, int height, byte[] data)
+ : base(width, height, data)
{
if (hotx < 0 || hotx >= Width || hoty < 0 || hoty >= Height)
throw new ArgumentOutOfRangeException();
y = hoty;
}
- public MouseCursor(IntPtr argb, int width, int height, int hotx, int hoty)
- : base(argb, width, height)
+ /// <summary>
+ /// Initializes a new <see cref="MouseCursor"/> instance from a
+ /// contiguous array of BGRA pixels.
+ /// Each pixel is composed of 4 bytes, representing B, G, R and A values,
+ /// respectively. For correct antialiasing of translucent cursors,
+ /// the B, G and R components should be premultiplied with the A component:
+ /// <code>
+ /// B = (byte)((B * A) / 255)
+ /// G = (byte)((G * A) / 255)
+ /// R = (byte)((R * A) / 255)
+ /// </code>
+ /// </summary>
+ /// <param name="hotx">The x-coordinate of the cursor hotspot, in the range [0, width]</param>
+ /// <param name="hoty">The y-coordinate of the cursor hotspot, in the range [0, height]</param>
+ /// <param name="width">The width of the cursor data, in pixels.</param>
+ /// <param name="height">The height of the cursor data, in pixels.</param>
+ /// <param name="data">
+ /// A pointer to the cursor image, laid out as a contiguous array of BGRA pixels.
+ /// </param>
+ public MouseCursor(int hotx, int hoty, int width, int height, IntPtr data)
+ : base(width, height, data)
{
if (hotx < 0 || hotx >= Width || hoty < 0 || hoty >= Height)
throw new ArgumentOutOfRangeException();
/// </summary>
public class WindowIcon
{
- byte[] argb;
+ byte[] data;
int width;
int height;
+ /// \internal
+ /// <summary>
+ /// Initializes a new instance of the <see cref="OpenTK.WindowIcon"/> class.
+ /// </summary>
internal protected WindowIcon()
{
}
this.height = height;
}
- internal WindowIcon(byte[] argb, int width, int height)
+ internal WindowIcon(int width, int height, byte[] data)
: this(width, height)
{
- if (argb == null)
+ if (data == null)
throw new ArgumentNullException();
- if (argb.Length < Width * Height * 4)
+ if (data.Length < Width * Height * 4)
throw new ArgumentOutOfRangeException();
- this.argb = argb;
+ this.data = data;
}
- internal WindowIcon(IntPtr argb, int width, int height)
+ internal WindowIcon(int width, int height, IntPtr data)
: this(width, height)
{
- if (argb == IntPtr.Zero)
+ if (data == 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);
- }
+ this.data = new byte[width * height * 4];
+ Marshal.Copy(data, this.data, 0, this.data.Length);
}
- internal byte[] Argb { get { return argb; } }
+ internal byte[] Data { get { return data; } }
internal int Width { get { return width; } }
internal int Height { get { return height; } }
}