#region License // // Cursor.cs // // Author: // Stefanos A. // // 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; namespace OpenTK { /// /// Represents a predefined or custom mouse cursor. /// public sealed class MouseCursor : WindowIcon { static readonly MouseCursor default_cursor = new MouseCursor(); static readonly MouseCursor empty_cursor = new MouseCursor( 0, 0, 16, 16, new byte[16 * 16 * 4]); int x; int y; MouseCursor() { } /// /// Initializes a new 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: /// /// B = (byte)((B * A) / 255) /// G = (byte)((G * A) / 255) /// R = (byte)((R * A) / 255) /// /// /// The x-coordinate of the cursor hotspot, in the range [0, width] /// The y-coordinate of the cursor hotspot, in the range [0, height] /// The width of the cursor data, in pixels. /// The height of the cursor data, in pixels. /// /// A byte array representing the cursor image, /// laid out as a contiguous array of BGRA pixels. /// 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(); x = hotx; y = hoty; } /// /// Initializes a new 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: /// /// B = (byte)((B * A) / 255) /// G = (byte)((G * A) / 255) /// R = (byte)((R * A) / 255) /// /// /// The x-coordinate of the cursor hotspot, in the range [0, width] /// The y-coordinate of the cursor hotspot, in the range [0, height] /// The width of the cursor data, in pixels. /// The height of the cursor data, in pixels. /// /// A pointer to the cursor image, laid out as a contiguous array of BGRA pixels. /// 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(); x = hotx; y = hoty; } internal int X { get { return x; } } internal int Y { get { return y; } } /// /// Gets the default mouse cursor for this platform. /// public static MouseCursor Default { get { return default_cursor; } } /// /// Gets an empty (invisible) mouse cursor. /// public static MouseCursor Empty { get { return empty_cursor; } } } }