aboutsummaryrefslogtreecommitdiffstatsci
path: root/testDrm/src/MouseCursor.cs
blob: df8cd0cf1add96f5287d5c0c493af7654ac9b9e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#region License
//
// Cursor.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;

namespace OpenTK
{
    /// <summary>
    /// Represents a predefined or custom mouse cursor.
    /// </summary>
    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()
        {
        }

        /// <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();

            x = hotx;
            y = hoty;
        }

        /// <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();

            x = hotx;
            y = hoty;
        }

        internal int X { get { return x; } }
        internal int Y { get { return y; } }

        /// <summary>
        /// Gets the default mouse cursor for this platform.
        /// </summary>
        public static MouseCursor Default
        {
            get
            {
                return default_cursor;
            }
        }

        /// <summary>
        /// Gets an empty (invisible) mouse cursor.
        /// </summary>
        public static MouseCursor Empty
        {
            get
            {
                return empty_cursor;
            }
        }
    }
}