1SDL::Cursor(3) User Contributed Perl Documentation SDL::Cursor(3)
2
3
4
6 SDL::Cursor - Mouse cursor structure
7
9 Core, Mouse, Structure
10
12 my $cursor = SDL::Cursor->new(
13 \@data,
14 \@mask,
15 $width,
16 $height,
17 $hotspot_left,
18 $hotspot_top
19 );
20
21 SDL::Mouse::set_cursor($cursor);
22
24 The "SDL::Cursor" module handles mouse cursors, and allows the
25 developer to use custom-made cursors. Note that cursors can only be in
26 black and white.
27
29 new
30 my $cursor = SDL::Cursor->new(
31 \@data, \@mask, $width, $height, $hotspot_left, $hotspot_top
32 );
33
34 Create a cursor using the specified data and mask (in MSB format). The
35 cursor is created in black and white according to the following:
36
37 Data / Mask Resulting pixel on screen
38 0 / 1 White
39 1 / 1 Black
40 0 / 0 Transparent
41 1 / 0 Inverted color if possible, black if not.
42
43 If you want to have color cursor, then this function is not for you.
44 Instead, you should hide the cursor with
45 "SDL::Mouse::show_cursor(SDL_DISABLE)". Then in your main loop, when
46 you draw graphics, draw a "SDL::Surface" at the location of the mouse
47 cursor.
48
49 Example:
50
51 use SDL;
52 use SDL::Video;
53 use SDL::Mouse;
54 use SDL::Cursor;
55
56 SDL::init(SDL_INIT_VIDEO);
57 SDL::Video::set_video_mode(640, 480, 16, SDL_SWSURFACE);
58
59 my @data = (
60 0b00000000,
61 0b00111100,
62 0b01111110,
63 0b01111110,
64 0b01111110,
65 0b01111110,
66 0b00111100,
67 0b00000000
68 );
69 my @mask = (
70 0b00111100,
71 0b01111110,
72 0b11100111,
73 0b11000011,
74 0b11000011,
75 0b11100111,
76 0b01111110,
77 0b00111100
78 );
79 my $cursor = SDL::Cursor->new(\@data, \@mask, 8, 8, 0, 0);
80 sleep(1);
81
82 SDL::Mouse::set_cursor($cursor);
83 sleep(5);
84
85 The width of cursors work in groups of 8. If the width is above 8,
86 twice the amount of elements in @data and @mask are required. If the
87 width is above 16, three times are required, and so on. For example,
88 if you wanted a 9 pixel crosshair you might do the following:
89
90 my @data = (
91 0b00001000,0b00000000,
92 0b00001000,0b00000000,
93 0b00001000,0b00000000,
94 0b00001000,0b00000000,
95 0b11111111,0b10000000,
96 0b00001000,0b00000000,
97 0b00001000,0b00000000,
98 0b00001000,0b00000000,
99 0b00001000,0b00000000,
100 );
101 my @mask = @data;
102
103 my $cursor = SDL::Cursor->new(\@data, \@mask, 9, 9, 4, 4);
104
105 The hotspot is offset by 4 pixels because a crosshair clicks from the
106 center instead of the top left.
107
109 See "AUTHORS" in SDL.
110
112 perl SDL::Mouse
113
114
115
116perl v5.36.0 2022-07-22 SDL::Cursor(3)