Brought all packages under eye of strict, warnings and love of Carp, For
[sdlgit/SDL_perl.git] / lib / SDL / Rect.pm
1 #
2 #       Rect.pm
3 #
4 #       A package for manipulating SDL_Rect *
5 #
6 #       Copyright (C) 2003 David J. Goehrig
7
8 package SDL::Rect;
9 use strict;
10 use warnings;
11 use Carp;
12 use SDL;
13
14 sub new {
15         my $proto = shift;
16         my $class = ref($proto) || $proto;
17         my %options = @_;
18
19         verify (%options, qw/ -x -y -width -height -w -h / ) if $SDL::DEBUG;
20
21         my $x = $options{-x}            || 0;
22         my $y = $options{-y}            || 0;
23         my $w = $options{-width}        || $options{-w}         || 0;
24         my $h = $options{-height}       || $options{-h}         || 0;
25         
26         my $self = \SDL::NewRect($x,$y,$w,$h);
27         bless $self,$class;
28         return $self;
29 }
30
31 sub DESTROY {
32         SDL::FreeRect(${$_[0]});
33 }
34
35 sub x {
36         my $self = shift;
37         SDL::RectX($$self,@_);
38 }
39
40 sub y {
41         my $self = shift;
42         SDL::RectY($$self,@_);
43 }
44
45 sub width {
46         my $self = shift;
47         SDL::RectW($$self,@_);
48 }
49
50 sub height {
51         my $self = shift;
52         SDL::RectH($$self,@_);
53 }
54
55 1;
56
57 __END__;
58
59 =pod
60
61
62 =head1 NAME
63
64 SDL::Rect - a SDL perl extension
65
66 =head1 SYNOPSIS
67
68   $rect = new SDL::Rect ( -height => 4, -width => 40 );
69
70 =head1 DESCRIPTION
71
72 C<SDL::Rect::new> creates a SDL_Rect structure which is
73 used for specifying regions for filling, blitting, and updating.
74 These objects make it easy to cut and backfill.
75 By default, x, y, h, w are 0.
76
77 =head2 METHODS 
78
79 The four fields of a rectangle can be set simply
80 by passing a value to the applicable method.  These are:
81
82 =over 4
83
84 =item *
85
86 C<SDL::Rect::x> sets and fetches the x position.
87
88 =item *
89
90 C<SDL::Rect::y> sets and fetches the y position.
91
92 =item *
93
94 C<SDL::Rect::width> sets and fetched the width.
95
96 =item *
97
98 C<SDL::Rect::height> sets and fetched the height.
99
100 =back
101
102 =head1 AUTHOR
103
104 David J. Goehrig
105
106 =head1 SEE ALSO
107
108 perl(1) SDL::Surface(3)
109
110
111 =cut
112