Forces defined parameters to blit
[sdlgit/SDL_perl.git] / lib / SDL / Video.pm
CommitLineData
bfd90409 1#!/usr/bin/env perl
2#
3# Video.pm
4#
5# Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
6#
7# ------------------------------------------------------------------------------
8#
9# This library is free software; you can redistribute it and/or
10# modify it under the terms of the GNU Lesser General Public
11# License as published by the Free Software Foundation; either
12# version 2.1 of the License, or (at your option) any later version.
13#
14# This library is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17# Lesser General Public License for more details.
18#
19# You should have received a copy of the GNU Lesser General Public
20# License along with this library; if not, write to the Free Software
21# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22#
23# ------------------------------------------------------------------------------
24#
25# Please feel free to send questions, suggestions or improvements to:
26#
27# David J. Goehrig
28# dgoehrig@cpan.org
29#
30
31package SDL::Video;
32
33use strict;
084b921f 34use warnings;
35use Carp;
bfd90409 36use SDL;
37use SDL::Surface;
38use SDL::MPEG;
39
40sub new {
41 my $proto = shift;
42 my $class = ref($proto) || $proto;
43 my %options = @_;
44
45 verify (%options, qw/ -name -audio / ) if $SDL::DEBUG;
46
47 my $n = $options{-name} || die "SDL::Video must supply a filename to SDL::Video::new\n";
48 my $a = $options{'-audio'} ? 1 : 0;
49 my $info = new SDL::MPEG();
50
51 my $self = \SDL::NewSMPEG($n,$$info,$a);
cc6d0c7c 52 croak SDL::GetError() unless $$self;
bfd90409 53 bless $self,$class;
54 $self->audio(1);
55 $self->video(1);
56 return $self, $info;
57}
58
59sub DESTROY {
60 SDL::FreeSMPEG(${$_[0]});
61}
62
63sub error {
64 SDL::SMPEGError(${$_[0]});
65}
66
67sub audio {
68 SDL::SMPEGEnableAudio( ${$_[0]}, $_[1]);
69}
70
71sub video {
72 SDL::SMPEGEnableVideo( ${$_[0]}, $_[1]);
73}
74
75sub volume {
76 SDL::SMPEGSetVolume( ${$_[0]}, $_[1] );
77}
78
79sub display {
084b921f 80 croak "SDL::Video::Display requires a SDL::Surface\n" unless $_[1]->isa('SDL::Surface');
bfd90409 81 SDL::SMPEGSetDisplay( ${$_[0]}, ${$_[1]}, 0);
82}
83
84sub scale {
85 return SDL::SMPEGScaleXY(${$_[0]},$_[1],$_[2]) if (@_ == 3 );
86 return SDL::SMPEGScaleXY(${$_[0]},$_[1]->width(),$_[1]->height()) if $_[1]->isa('SDL::Surface');
87 SDL::SMPEGScale(${$_[0]},$_[1]);
88}
89
90sub play {
91 SDL::SMPEGPlay(${$_[0]});
92}
93
94sub pause {
95 SDL::SMPEGPause(${$_[0]});
96}
97
98sub stop {
99 SDL::SMPEGStop(${$_[0]});
100}
101
102sub rewind {
103 SDL::SMPEGRewind(${$_[0]});
104}
105
106sub seek {
107 SDL::SMPEGSeek(${$_[0]},$_[1]);
108}
109
110sub skip {
111 SDL::SMPEGSkip(${$_[0]},$_[1]);
112}
113
114sub loop {
115 SDL::SMPEGLoop(${$_[0]},$_[1]);
116}
117
118sub region {
084b921f 119 croak "SDL::Video::region requires a SDL::Rect\n" unless $_[1]->isa('SDL::Rect');
bfd90409 120 SDL::SMPEGDisplayRegion(${$_[0]},${$_[1]});
121}
122
123sub frame {
124 SDL::SMPEGRenderFrame(${$_[0]},$_[1]);
125}
126
127sub info {
128 new SDL::MPEG -from => $_[0];
129}
130
131sub status {
132 SDL::SMPEGStatus(${$_[0]});
133}
134
1351;
136
137__END__;
138
139=pod
140
141
142=head1 NAME
143
144SDL::Video - a SDL perl extension
145
146=head1 SYNOPSIS
147
148 $video = new SDL::Video ( -name => 'pr0n.mpg' );
149
150=head1 DESCRIPTION
151
152C<SDL::Video> adds support for MPEG video to your
153SDL Perl application. Videos are objects bound to
154surfaces, whose playback is controled through the
155object's interface.
156
157=head2 METHODS
158
159
160=over 4
161
162=item *
163
164C<SDL::Video::error()> returns any error messages associated with playback
165
166=item *
167
168C<SDL::Video::audio(bool)> enables or disables audio playback, (on by default)
169
170=item *
171
172C<SDL::Video::video(bool)> enables or disable video playback, (on by default)
173
174=item *
175
176C<SDL::Video::loop(bool)> enables or disable playback looping (off by default)
177
178=item *
179
180C<SDL::Video::volume(int)> set the volume as per the mixer volume
181
182=item *
183
184C<SDL::Video:display(surface)> binds the clip to a display surface
185
186=item *
187
188C<SDL::Video::scale([x,y]|[surface]|int)> scales the clip by either x,y
189factors, scales to the image dimensions, or a single scalar.
190
191=item *
192
193C<SDL::Video::play()> plays the video clip, call C<SDL::Video::display()> before playing
194
195=item *
196
197C<SDL::Video::pause()> pauses video playback
198
199=item *
200
201C<SDL::Video::stop()> stops video playback
202
203=item *
204
205C<SDL::Video::rewind()> resets the clip to the beginning
206
207=item *
208
209C<SDL::Video::seek(offset)> seeks to a particular byte offset
210
211=item *
212
213C<SDL::Video::skip(time)> skips to a particular time
214
215=item *
216
217C<SDL::Video::region(rect)> takes a SDL::Rect and defines the display area
218
219=item *
220
221C<SDL::Video::frame(int)> renders a specific frame to the screen
222
223=item *
224
225C<SDL::Video::info()> returns a new C<SDL::MPEG> object reflecting the current status
226
227=item *
228
229C<SDL::Video::status()> returns either SMPEG_PLAYING or SMPEG_STOPPED or SMPEG_ERROR
230
231=back
232
233=head1 AUTHOR
234
235David J. Goehrig
236
237=head1 SEE ALSO
238
239perl(1) SDL::Surface(3) SDL::MPEG(3)
240
241=cut
242