updated docs
[sdlgit/SDL-Site.git] / pages / SDL-Cursor.html-inc
1 <div class="pod">
2 <!-- INDEX START -->
3 <h3 id="TOP">Index</h3>
4
5 <ul><li><a href="#NAME">NAME</a></li>
6 <li><a href="#CATEGORY">CATEGORY</a></li>
7 <li><a href="#SYNOPSIS">SYNOPSIS</a></li>
8 <li><a href="#DESCRIPTION">DESCRIPTION</a></li>
9 <li><a href="#METHODS">METHODS</a>
10 <ul><li><a href="#new">new</a></li>
11 </ul>
12 </li>
13 <li><a href="#AUTHORS">AUTHORS</a></li>
14 <li><a href="#SEE_ALSO">SEE ALSO</a>
15 </li>
16 </ul><hr />
17 <!-- INDEX END -->
18
19 <h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
20 <div id="NAME_CONTENT">
21 <p>SDL::Cursor - Mouse cursor structure</p>
22
23 </div>
24 <h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
25 <div id="CATEGORY_CONTENT">
26 <p>Core, Mouse, Structure</p>
27
28 </div>
29 <h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
30 <div id="SYNOPSIS_CONTENT">
31 <pre> my $cursor = SDL::Cursor-&gt;new(
32      \@data,
33      \@mask,
34      $width,
35      $height,
36      $hotspot_left,
37      $hotspot_top
38  );
39
40  SDL::Mouse::set_cursor($cursor);
41
42 </pre>
43
44 </div>
45 <h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
46 <div id="DESCRIPTION_CONTENT">
47 <p>The <code>SDL::Cursor</code> module handles mouse cursors, and allows the developer to use custom-made cursors.
48 Note that cursors can only be in black and white.</p>
49
50 </div>
51 <h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
52 <div id="METHODS_CONTENT">
53
54 </div>
55 <h2 id="new">new</h2>
56 <div id="new_CONTENT">
57 <pre> my $cursor = SDL::Cursor-&gt;new(
58      \@data, \@mask, $width, $height, $hotspot_left, $hotspot_top
59  );
60
61 </pre>
62 <p>Create a cursor using the specified data and mask (in MSB format).
63 The cursor is created in black and white according to the following:</p>
64 <pre> Data / Mask   Resulting pixel on screen
65     0 / 1      White
66     1 / 1      Black
67     0 / 0      Transparent
68     1 / 0      Inverted color if possible, black if not.
69
70 </pre>
71 <p>If you want to have color cursor, then this function is not for you.
72 Instead, you should hide the cursor with <code>SDL::Mouse::show_cursor(SDL_DISABLE)</code>.
73 Then in your main loop, when you draw graphics, draw a <code>SDL::Surface</code> at the location of the mouse cursor.</p>
74 <p>Example:</p>
75 <pre> use SDL;
76  use SDL::Video;
77  use SDL::Mouse;
78  use SDL::Cursor;
79
80  SDL::init(SDL_INIT_VIDEO);
81  SDL::Video::set_video_mode(640, 480, 16, SDL_SWSURFACE);
82
83  my @data = (
84      0b00000000,
85      0b00111100,
86      0b01111110,
87      0b01111110,
88      0b01111110,
89      0b01111110,
90      0b00111100,
91      0b00000000
92  );
93  my @mask = (
94      0b00111100,
95      0b01111110,
96      0b11100111,
97      0b11000011,
98      0b11000011,
99      0b11100111,
100      0b01111110,
101      0b00111100
102  );
103  my $cursor = SDL::Cursor-&gt;new(\@data, \@mask, 8, 8, 0, 0);
104  sleep(1);
105
106  SDL::Mouse::set_cursor($cursor);
107  sleep(5);
108
109 </pre>
110 <p>The width of cursors work in groups of 8.
111 If the width is above 8, twice the amount of elements in <code>@data</code> and <code>@mask</code> are required.
112 If the width is above 16, three times are required, and so on.
113 For example, if you wanted a 9 pixel crosshair you might do the following:</p>
114 <pre> my @data = (
115      0b00001000,0b00000000,
116      0b00001000,0b00000000,
117      0b00001000,0b00000000,
118      0b00001000,0b00000000,
119      0b11111111,0b10000000,
120      0b00001000,0b00000000,
121      0b00001000,0b00000000,
122      0b00001000,0b00000000,
123      0b00001000,0b00000000,
124  );
125  my @mask = @data;
126
127  my $cursor = SDL::Cursor-&gt;new(\@data, \@mask, 9, 9, 4, 4);
128
129 </pre>
130 <p>The hotspot is offset by 4 pixels because a crosshair clicks from the center instead of the top left.</p>
131
132 </div>
133 <h1 id="AUTHORS">AUTHORS</h1><p><a href="#TOP" class="toplink">Top</a></p>
134 <div id="AUTHORS_CONTENT">
135 <p>See <b>AUTHORS</b> in <cite>SDL</cite>.</p>
136
137
138
139
140
141 </div>
142 <h1 id="SEE_ALSO">SEE ALSO</h1><p><a href="#TOP" class="toplink">Top</a></p>
143 <div id="SEE_ALSO_CONTENT">
144 <p><a href="http://search.cpan.org/perldoc?perl">perl</a> <a href="SDL-Mouse.html">SDL::Mouse</a></p>
145
146 </div>
147 </div>