Brought all packages under eye of strict, warnings and love of Carp, For
[sdlgit/SDL_perl.git] / lib / SDL / Video.pm
1 #
2 #       Video.pm
3 #
4 #       A package for manipulating MPEG video 
5 #
6 #       Copyright (C) 2004 David J. Goehrig
7
8 package SDL::Video;
9
10 use strict;
11 use warnings;
12 use Carp;
13 use SDL;
14 use SDL::Surface;
15 use SDL::MPEG;
16
17 sub new {
18         my $proto = shift;
19         my $class = ref($proto) || $proto;
20         my %options = @_;
21
22         verify (%options, qw/ -name -audio / ) if $SDL::DEBUG;
23
24         my $n = $options{-name} || croak "SDL::Video must supply a filename to SDL::Video::new\n";
25         my $a = $options{'-audio'} ? 1 : 0;
26         my $info = new SDL::MPEG();
27         
28         my $self = \SDL::NewSMPEG($n,$$info,$a);
29         bless $self,$class;
30         $self->audio(1);
31         $self->video(1);
32         return $self, $info;
33 }
34
35 sub DESTROY {
36         SDL::FreeSMPEG(${$_[0]});
37 }
38
39 sub error {
40         SDL::SMPEGError(${$_[0]});
41 }
42
43 sub audio {
44         SDL::SMPEGEnableAudio( ${$_[0]}, $_[1]);
45 }
46
47 sub video {
48         SDL::SMPEGEnableVideo( ${$_[0]}, $_[1]);
49 }
50
51 sub volume {
52         SDL::SMPEGSetVolume( ${$_[0]}, $_[1] );
53 }
54
55 sub display {
56         croak "SDL::Video::Display requires a SDL::Surface\n" unless $_[1]->isa('SDL::Surface');
57         SDL::SMPEGSetDisplay( ${$_[0]}, ${$_[1]}, 0);
58 }
59
60 sub scale {
61         return SDL::SMPEGScaleXY(${$_[0]},$_[1],$_[2]) if (@_ == 3 );
62         return SDL::SMPEGScaleXY(${$_[0]},$_[1]->width(),$_[1]->height()) if $_[1]->isa('SDL::Surface');
63         SDL::SMPEGScale(${$_[0]},$_[1]);
64 }
65
66 sub play {
67         SDL::SMPEGPlay(${$_[0]});
68 }
69
70 sub pause {
71         SDL::SMPEGPause(${$_[0]});
72 }
73
74 sub stop {
75         SDL::SMPEGStop(${$_[0]});
76 }
77
78 sub rewind {
79         SDL::SMPEGRewind(${$_[0]});
80 }
81
82 sub seek {
83         SDL::SMPEGSeek(${$_[0]},$_[1]);
84 }
85
86 sub skip {
87         SDL::SMPEGSkip(${$_[0]},$_[1]);
88 }
89
90 sub loop {
91         SDL::SMPEGLoop(${$_[0]},$_[1]);
92 }
93
94 sub region {
95         croak "SDL::Video::region requires a SDL::Rect\n" unless $_[1]->isa('SDL::Rect');
96         SDL::SMPEGDisplayRegion(${$_[0]},${$_[1]});
97 }
98
99 sub frame {
100         SDL::SMPEGRenderFrame(${$_[0]},$_[1]);
101 }
102
103 sub info {
104         new SDL::MPEG -from => $_[0];
105 }
106
107 sub status {
108         SDL::SMPEGStatus(${$_[0]});
109 }
110
111 1;
112
113 __END__;
114
115 =pod
116
117
118 =head1 NAME
119
120 SDL::Video - a SDL perl extension
121
122 =head1 SYNOPSIS
123
124   $video = new SDL::Video ( -name => 'pr0n.mpg' );
125
126 =head1 DESCRIPTION
127
128 C<SDL::Video> adds support for MPEG video to your
129 SDL Perl application.  Videos are objects bound to
130 surfaces, whose playback is controled through the
131 object's interface.
132
133 =head2 METHODS 
134
135
136 =over 4
137
138 =item *
139
140 C<SDL::Video::error()> returns any error messages associated with playback 
141
142 =item * 
143
144 C<SDL::Video::audio(bool)> enables or disables audio playback, (on by default)
145
146 =item * 
147
148 C<SDL::Video::video(bool)> enables or disable video playback, (on by default)
149
150 =item * 
151
152 C<SDL::Video::loop(bool)> enables or disable playback looping (off by default) 
153
154 =item * 
155
156 C<SDL::Video::volume(int)> set the volume as per the mixer volume
157
158 =item * 
159
160 C<SDL::Video:display(surface)> binds the clip to a display surface
161
162 =item * 
163
164 C<SDL::Video::scale([x,y]|[surface]|int)> scales the clip by either x,y
165 factors, scales to the image dimensions, or a single scalar.
166
167 =item * 
168
169 C<SDL::Video::play()> plays the video clip, call C<SDL::Video::display()> before playing
170
171 =item * 
172
173 C<SDL::Video::pause()> pauses video playback
174
175 =item * 
176
177 C<SDL::Video::stop()> stops video playback
178
179 =item * 
180
181 C<SDL::Video::rewind()> resets the clip to the beginning 
182
183 =item * 
184
185 C<SDL::Video::seek(offset)> seeks to a particular byte offset
186
187 =item * 
188
189 C<SDL::Video::skip(time)> skips to a particular time
190
191 =item * 
192
193 C<SDL::Video::region(rect)> takes a SDL::Rect and defines the display area
194
195 =item * 
196
197 C<SDL::Video::frame(int)> renders a specific frame to the screen
198
199 =item * 
200
201 C<SDL::Video::info()> returns a new C<SDL::MPEG> object reflecting the current status
202
203 =item *
204
205 C<SDL::Video::status()> returns either SMPEG_PLAYING or SMPEG_STOPPED or SMPEG_ERROR
206
207 =back
208
209 =head1 AUTHOR
210
211 David J. Goehrig
212
213 =head1 SEE ALSO
214
215 perl(1) SDL::Surface(3) SDL::MPEG(3)
216
217 =cut
218