docs for SDL::Mouse
[sdlgit/SDL-Site.git] / pages / SDL-Mouse.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="#METHODS">METHODS</a>
8 <ul><li><a href="#create_cursor">create_cursor</a></li>
9 <li><a href="#warp_mouse">warp_mouse</a></li>
10 <li><a href="#free_cursor">free_cursor</a></li>
11 <li><a href="#set_cursor">set_cursor</a></li>
12 <li><a href="#get_cursor">get_cursor</a></li>
13 <li><a href="#show_cursor">show_cursor</a>
14 </li>
15 </ul>
16 </li>
17 </ul><hr />
18 <!-- INDEX END -->
19
20 <h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
21 <div id="NAME_CONTENT">
22 <p>SDL::Mouse -- SDL Bindings for the Mouse device</p>
23
24 </div>
25 <h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
26 <div id="CATEGORY_CONTENT">
27 <p>Core, Mouse</p>
28
29 </div>
30 <h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
31 <div id="METHODS_CONTENT">
32
33 </div>
34 <h2 id="create_cursor">create_cursor</h2>
35 <div id="create_cursor_CONTENT">
36 <pre> my $cursor = SDL::Mouse::create_cursor( \@data, \@mask, $width, $height, $hotspot_left, $hotspot_top );
37
38 </pre>
39 <p>Create a cursor using the specified data and mask (in MSB format). The cursor width must be a multiple of 8 bits.</p>
40 <p>The cursor is created in black and white according to the following:</p>
41 <pre> Data / Mask   Resulting pixel on screen
42     0 / 1      White
43     1 / 1      Black
44     0 / 0      Transparent
45     1 / 0      Inverted color if possible, black if not.
46
47 </pre>
48 <p>Cursors created with this function must be freed with SDL_FreeCursor.</p>
49 <p>If you want to have color cursor, then this function is not for you; instead, you must hide normal system cursor with <code>SDL::Mouse::show_cursor</code>
50 and in your main loop, when you draw graphics, also draw a <code>SDL::Surface</code> at the location of the mouse cursor. </p>
51 <p>Example:</p>
52 <pre> use SDL;
53  use SDL::Cursor;
54  use SDL::Mouse;
55  use SDL::Surface;
56  use SDL::Video;
57
58  SDL::init(SDL_INIT_VIDEO);
59  SDL::Video::set_video_mode( 640, 480, 16, SDL_SWSURFACE);
60
61  my @data = (
62      bin2dec('00000000'),
63      bin2dec('00111100'),
64      bin2dec('01111110'),
65      bin2dec('01111110'),
66      bin2dec('01111110'),
67      bin2dec('01111110'),
68      bin2dec('00111100'),
69      bin2dec('00000000')
70  );
71
72  my @mask = (
73      bin2dec('00111100'),
74      bin2dec('01111110'),
75      bin2dec('11100111'),
76      bin2dec('11000011'),
77      bin2dec('11000011'),
78      bin2dec('11100111'),
79      bin2dec('01111110'),
80      bin2dec('00111100')
81  );
82
83  my $cursor = SDL::Mouse::create_cursor( \@data, \@mask, 8, 8, 0, 0 );
84
85  sleep(1);
86  SDL::Mouse::set_cursor($cursor);
87
88  sleep(5);
89
90  sub dec2bin {
91      my $str = unpack(&quot;B64&quot;, pack(&quot;N&quot;, shift));
92      $str =~ s/^0+(?=\d)//;   # otherwise you'll get leading zeros
93      return $str;
94  }
95
96  sub bin2dec {
97      return unpack(&quot;N&quot;, pack(&quot;B64&quot;, substr(&quot;0&quot; x 32 . shift, -32)));
98  }
99
100 </pre>
101
102 </div>
103 <h2 id="warp_mouse">warp_mouse</h2>
104 <div id="warp_mouse_CONTENT">
105 <pre> void warp_mouse( int $x, int $y );
106
107 </pre>
108 <p>Set the position of the mouse cursor (generates a mouse motion event).</p>
109
110 </div>
111 <h2 id="free_cursor">free_cursor</h2>
112 <div id="free_cursor_CONTENT">
113 <pre> void free_cursor( object );
114
115 </pre>
116 <p>Frees a cursor that was created using <code>SDL::Cursor-</code>new()&gt;. </p>
117
118 </div>
119 <h2 id="set_cursor">set_cursor</h2>
120 <div id="set_cursor_CONTENT">
121 <pre> void set_cursor( object );
122
123 </pre>
124 <p>Sets the currently active cursor to the specified one. If the cursor is currently visible, the change will be immediately represented 
125 on the display. <code>set_cursor()</code> can be used to force cursor redraw, if this is desired for any reason. </p>
126
127 </div>
128 <h2 id="get_cursor">get_cursor</h2>
129 <div id="get_cursor_CONTENT">
130 <pre> object get_cursor();
131
132 </pre>
133 <p>Gets the currently active mouse cursor.</p>
134
135 </div>
136 <h2 id="show_cursor">show_cursor</h2>
137 <div id="show_cursor_CONTENT">
138 <pre> int show_cursor( int toggle );
139
140 </pre>
141 <p>Toggle whether or not the cursor is shown on the screen. Passing <code>SDL_ENABLE</code> displays the cursor and passing <code>SDL_DISABLE</code> hides it. 
142 The current state of the mouse cursor can be queried by passing <code>SDL_QUERY</code>, either <code>SDL_DISABLE</code> or <code>SDL_ENABLE</code> will be returned.</p>
143 <pre> use SDL;
144  use SDL::Mouse;
145  use SDL::Video;
146
147  SDL::init(SDL_INIT_VIDEO);
148  SDL::Video::set_video_mode( 640, 480, 16, SDL_SWSURFACE);
149
150  printf(&quot;Cursor is %s\n&quot;, SDL::Mouse::show_cursor(SDL_QUERY) ? 'visible' : 'not visible');
151
152  sleep(3);
153
154  SDL::Mouse::show_cursor(SDL_DISABLE);
155  printf(&quot;Cursor is %s\n&quot;, SDL::Mouse::show_cursor(SDL_QUERY) ? 'visible' : 'not visible');
156
157  sleep(3);
158
159  SDL::Mouse::show_cursor(SDL_ENABLE);
160  printf(&quot;Cursor is %s\n&quot;, SDL::Mouse::show_cursor(SDL_QUERY) ? 'visible' : 'not visible');
161
162  sleep(3);
163
164 </pre>
165
166 </div>
167 </div>