Importing SDLPerl 2.2
[sdlgit/SDL_perl.git] / lib / SDL / Rect.pm
1 #!/usr/bin/env perl
2 #
3 # Rect.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
31 package SDL::Rect;
32
33 use strict;
34 use SDL;
35
36 sub new {
37         my $proto = shift;
38         my $class = ref($proto) || $proto;
39         my %options = @_;
40
41         verify (%options, qw/ -x -y -width -height -w -h / ) if $SDL::DEBUG;
42
43         my $x = $options{-x}            || 0;
44         my $y = $options{-y}            || 0;
45         my $w = $options{-width}        || $options{-w}         || 0;
46         my $h = $options{-height}       || $options{-h}         || 0;
47         
48         my $self = \SDL::NewRect($x,$y,$w,$h);
49         die SDL::GetError() unless $$self;
50         bless $self,$class;
51         return $self;
52 }
53
54 sub DESTROY {
55         SDL::FreeRect(${$_[0]});
56 }
57
58 sub x {
59         my $self = shift;
60         SDL::RectX($$self,@_);
61 }
62
63 sub y {
64         my $self = shift;
65         SDL::RectY($$self,@_);
66 }
67
68 sub width {
69         my $self = shift;
70         SDL::RectW($$self,@_);
71 }
72
73 sub height {
74         my $self = shift;
75         SDL::RectH($$self,@_);
76 }
77
78 1;
79
80 __END__;
81
82 =pod
83
84
85 =head1 NAME
86
87 SDL::Rect - a SDL perl extension
88
89 =head1 SYNOPSIS
90
91   $rect = new SDL::Rect ( -height => 4, -width => 40 );
92
93 =head1 DESCRIPTION
94
95 C<SDL::Rect::new> creates a SDL_Rect structure which is
96 used for specifying regions for filling, blitting, and updating.
97 These objects make it easy to cut and backfill.
98 By default, x, y, h, w are 0.
99
100 =head2 METHODS 
101
102 The four fields of a rectangle can be set simply
103 by passing a value to the applicable method.  These are:
104
105 =over 4
106
107 =item *
108
109 C<SDL::Rect::x> sets and fetches the x position.
110
111 =item *
112
113 C<SDL::Rect::y> sets and fetches the y position.
114
115 =item *
116
117 C<SDL::Rect::width> sets and fetched the width.
118
119 =item *
120
121 C<SDL::Rect::height> sets and fetched the height.
122
123 =back
124
125 =head1 AUTHOR
126
127 David J. Goehrig
128
129 =head1 SEE ALSO
130
131 perl(1) SDL::Surface(3)
132
133
134 =cut
135